user channel improvements

- allow arbitrary user channels to be subscribed, e.g. #follow or #friends, /sub ~user defaults to #follow
- friends & /invite'd strangers are allowed to join
This commit is contained in:
Gabor Adam Toth 2010-02-20 23:22:52 +01:00
parent 4d15033c34
commit 424bc2bf70
8 changed files with 103 additions and 20 deletions

View File

@ -391,10 +391,10 @@ object compile_object(string file) {
unless (name = SIMUL_EFUN_FILE->legal_name(name, 1))
return (object)0;
string username;
if (sscanf(file, "place/~%s#updates", username)) {
object p;
unless ((p = SIMUL_EFUN_FILE->summon_person(username, NET_PATH "user")) && p->vQuery("password")) {
string username, channel;
if (sscanf(file, "place/~%s#%s", username, channel)) {
object p = SIMUL_EFUN_FILE->summon_person(username, NET_PATH "user");
unless (p && !p->isNewbie()) {
P3(("PLACE %O NOT CLONED: %O isn't a registered user\n", name, username));
return (object)0;
}

View File

@ -547,11 +547,12 @@ int boss(mixed guy) {
mixed find_place(mixed a) {
P3((">> find_place(%O)\n", a))
string path, err;
string path, err, nick;
object o;
if (objectp(a)) return a;
if (path = lower_uniform(a)) return path;
if (sscanf(a, "~%s", nick) && legal_name(nick)) a += "#follow";
unless (a = legal_name(a, 1)) return 0;
path = PLACE_PATH + lower_case(a); // assumes amylaar
o = find_object(path);

View File

@ -27,9 +27,9 @@ varargs string legal_name(string name, int place) {
return 0;
}
string nick;
if (place && sscanf(name, "~%s#updates", nick))
n = nick;
string nick, channel;
if (place && sscanf(name, "~%s#%s", nick, channel))
return (legal_name(nick) && legal_name(channel)) ? name : 0;
string chars = "\
abcdefghijklmnopqrstuvwxyz\

View File

@ -655,6 +655,8 @@ sName2(a) {
if (v("locations")) linkCleanUp("_crash");
else vSet("locations", ([ ]));
unless (v("channels")) vSet("channels", ([]));
// protection against file read errors
if (IS_NEWBIE) {
if (boss(a)) {
@ -2917,6 +2919,26 @@ static qFriends() {
return present[1..];
}
qFriend(object snicker) {
P3((">> qFriend(%O)\n", snicker))
return member(friends, snicker);
}
qFollower(object snicker) {
P3((">> qFollower(%O)\n", snicker))
foreach (string c : v("channels")) {
object p = find_place(c);
P3((">>> c: %O, p: %O\n", c, p))
if (p && p->qMember(snicker)) return 1;
}
return 0;
}
sChannel(string channel) {
P3((">> sChannel(%O)\n", channel))
v("channels")[channel] = 1;
}
sPerson(person, ix, value) {
P2(("%O: sPerson(%O, %O, %O) bfor: %O\n", MYNICK, person, ix, value, ppl))
// TODO: we need some register_context / deregister_context here

View File

@ -2614,3 +2614,8 @@ qAide(snicker, aidesonly) {
qOwner(snicker) { return member(v("owners"), lower_case(snicker)); }
#endif
qMember(snicker) {
P3((">> qMember(%O) in _u: %O\n", snicker, _u))
return member(_u, snicker);
}

View File

@ -113,7 +113,7 @@ cmd(a, args, b, source, vars) {
case "blog":
case "submit":
case "addentry":
unless (qAide(SNICKER)) return;
unless (canPost(SNICKER)) return;
unless (sizeof(args) >= 1) {
sendmsg(source, "_warning_usage_submit",
"Usage: /submit <text>", ([ ]));
@ -123,7 +123,7 @@ cmd(a, args, b, source, vars) {
// TODO: append fuer multiline-sachen
#if 0
case "iterator":
unless (qAide(SNICKER)) return;
unless (canPost(SNICKER)) return;
sendmsg(source, "_notice_thread_iterator",
"[_iterator] blog entries have been requested "
"since creation.", ([
@ -135,7 +135,7 @@ cmd(a, args, b, source, vars) {
#endif
case "deblog":
case "delentry":
unless (qAide(SNICKER)) return;
unless (canPost(SNICKER)) return;
// ist das ein typecheck ob args ein int is?
if (sizeof(regexp( ({ args[1] }) , "^[0-9][0-9]*$"))) {
unless (delEntry(to_int(args[1]), source, vars)) {
@ -273,7 +273,8 @@ addComment(text, unick, entry_id) {
"_comment" : text,
"_nick" : unick,
]) );
return save();
save();
return 1;
}
return -1;
}
@ -288,7 +289,7 @@ delEntry(int number, source, vars) {
unless (size = sizeof(entries)) return 0;
if (number >= size) return 0;
if (qAide(unick = lower_case(SNICKER))) {
if (canPost(unick = lower_case(SNICKER))) {
unless (lower_case(entries[number]["author"]) == unick) return 0;
}
@ -349,7 +350,7 @@ htget(prot, query, headers, qs, data) {
// return 1;
}
#ifdef OWNED
if (qAide(nick)) {
if (canPost(nick)) {
#endif
#if 0
sendmsg(target, "_request_authentication", "please auth me!",
@ -628,3 +629,7 @@ displayHeader() {
displayFooter() {
w("_HTML_tail_threads", "</body></html>");
}
canPost(snicker) {
return qAide(snicker);
}

View File

@ -2,14 +2,64 @@
#include <person.h>
#include <status.h>
#define BLAME "!configuration"
#define DONT_REWRITE_NICKS
inherit NET_PATH "place/threads";
volatile mixed lastTry;
volatile string owner;
volatile string channel;
load(name, keep) {
P3((">> userthreads:load(%O, %O)\n", name, keep))
string nick;
P3((">> userthreads:load(%O, %O)\n", name, keep))
if (sscanf(name, "~%s#updates", nick))
vSet("owners", ([ nick: 0 ]));
sscanf(name, "~%s#%s", owner, channel);
vSet("owners", ([ owner: 0 ]));
return ::load(name, keep);
vSet("_restrict_invitation", BLAME);
vSet("_filter_conversation", BLAME);
return ::load(name, keep);
}
enter(source, mc, data, vars) {
P3((">> userthreads:enter(%O, %O, %O, %O)\n", source, mc, data, vars))
object p = summon_person(owner, NET_PATH "user");
string src = psyc_name(source);
unless (p && (p == source || qAide(src) || p->qFriend(source) || p->qFollower(source))) {
sendmsg(source, "_error_place_enter_necessary_invitation",
"[_nick_place] can only be entered upon invitation.",
([ "_nick_place" : qName() ]) );
if (source != lastTry) {
castmsg(ME, "_failure_place_enter_necessary_invitation",
"Admission into [_nick_place] denied for uninvited user [_nick].",
vars);
lastTry = source;
}
return 0;
}
if (p == source) {
p->sChannel(MYNICK);
}
return ::enter(source, mc, data, vars);
}
cmd(a, args, b, source, vars) {
P3((">> threads:cmd(%O, %O, %O, %O, %O)", a, args, b, source, vars))
switch (a) {
case "add": // or similar
// add follower to this channel, TODO
}
return ::cmd(a, args, b, source, vars);
}
canPost(snicker) {
return qOwner(snicker);
}

View File

@ -284,7 +284,7 @@ htDescription(anonymous, query, headers, qs, variant, vars) {
// <input type=hidden name=lang value=\""+v("language")+"\">\n\
//
object u = find_place("~" + nick + "#updates");
object u = find_place("~" + nick + "#follow"); //TODO
string updates = objectp(u) ? u->htMain(10) : "";
return psyctext(page, vars + ([