mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-27 07:13:36 +00:00
New function pending_add().
This commit is contained in:
parent
35b35ec3af
commit
7287776fd1
3 changed files with 45 additions and 12 deletions
|
@ -1927,22 +1927,31 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
|
||||||
object_add(actor, actor_obj);
|
object_add(actor, actor_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
xs *f_msg = xs_dup(msg);
|
if (xs_is_true(xs_dict_get(snac->config, "approve_followers"))) {
|
||||||
xs *reply = msg_accept(snac, f_msg, actor);
|
pending_add(snac, actor, msg);
|
||||||
|
|
||||||
post_message(snac, actor, reply);
|
snac_log(snac, xs_fmt("new pending follower approval %s", actor));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* automatic following */
|
||||||
|
xs *f_msg = xs_dup(msg);
|
||||||
|
xs *reply = msg_accept(snac, f_msg, actor);
|
||||||
|
|
||||||
if (xs_is_null(xs_dict_get(f_msg, "published"))) {
|
post_message(snac, actor, reply);
|
||||||
/* add a date if it doesn't include one (Mastodon) */
|
|
||||||
xs *date = xs_str_utctime(0, ISO_DATE_SPEC);
|
if (xs_is_null(xs_dict_get(f_msg, "published"))) {
|
||||||
f_msg = xs_dict_set(f_msg, "published", date);
|
/* add a date if it doesn't include one (Mastodon) */
|
||||||
|
xs *date = xs_str_utctime(0, ISO_DATE_SPEC);
|
||||||
|
f_msg = xs_dict_set(f_msg, "published", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeline_add(snac, id, f_msg);
|
||||||
|
|
||||||
|
follower_add(snac, actor);
|
||||||
|
|
||||||
|
snac_log(snac, xs_fmt("new follower %s", actor));
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline_add(snac, id, f_msg);
|
|
||||||
|
|
||||||
follower_add(snac, actor);
|
|
||||||
|
|
||||||
snac_log(snac, xs_fmt("new follower %s", actor));
|
|
||||||
do_notify = 1;
|
do_notify = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
22
data.c
22
data.c
|
@ -1202,6 +1202,28 @@ xs_list *follower_list(snac *snac)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** pending followers **/
|
||||||
|
|
||||||
|
int pending_add(snac *user, const char *actor, const xs_dict *msg)
|
||||||
|
/* stores the follow message for later confirmation */
|
||||||
|
{
|
||||||
|
xs *dir = xs_fmt("%s/pending", user->basedir);
|
||||||
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
|
xs *fn = xs_fmt("%s/%s.json", dir, md5);
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
mkdirx(dir);
|
||||||
|
|
||||||
|
if ((f = fopen(fn, "w")) == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
xs_json_dump(msg, 4, f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** timeline **/
|
/** timeline **/
|
||||||
|
|
||||||
double timeline_mtime(snac *snac)
|
double timeline_mtime(snac *snac)
|
||||||
|
|
2
snac.h
2
snac.h
|
@ -141,6 +141,8 @@ int follower_del(snac *snac, const char *actor);
|
||||||
int follower_check(snac *snac, const char *actor);
|
int follower_check(snac *snac, const char *actor);
|
||||||
xs_list *follower_list(snac *snac);
|
xs_list *follower_list(snac *snac);
|
||||||
|
|
||||||
|
int pending_add(snac *user, const char *actor, const xs_dict *msg);
|
||||||
|
|
||||||
double timeline_mtime(snac *snac);
|
double timeline_mtime(snac *snac);
|
||||||
int timeline_touch(snac *snac);
|
int timeline_touch(snac *snac);
|
||||||
int timeline_here(snac *snac, const char *md5);
|
int timeline_here(snac *snac, const char *md5);
|
||||||
|
|
Loading…
Reference in a new issue