commit 7287776
default
·
2024-11-24 07:17:38 +0000 UTC
parent 35b35ec
New function pending_add().
3 files changed,
+44,
-11
+20,
-11
1@@ -1927,22 +1927,31 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
2 object_add(actor, actor_obj);
3 }
4
5- xs *f_msg = xs_dup(msg);
6- xs *reply = msg_accept(snac, f_msg, actor);
7+ if (xs_is_true(xs_dict_get(snac->config, "approve_followers"))) {
8+ pending_add(snac, actor, msg);
9
10- post_message(snac, actor, reply);
11-
12- if (xs_is_null(xs_dict_get(f_msg, "published"))) {
13- /* add a date if it doesn't include one (Mastodon) */
14- xs *date = xs_str_utctime(0, ISO_DATE_SPEC);
15- f_msg = xs_dict_set(f_msg, "published", date);
16+ snac_log(snac, xs_fmt("new pending follower approval %s", actor));
17 }
18+ else {
19+ /* automatic following */
20+ xs *f_msg = xs_dup(msg);
21+ xs *reply = msg_accept(snac, f_msg, actor);
22
23- timeline_add(snac, id, f_msg);
24+ post_message(snac, actor, reply);
25+
26+ if (xs_is_null(xs_dict_get(f_msg, "published"))) {
27+ /* add a date if it doesn't include one (Mastodon) */
28+ xs *date = xs_str_utctime(0, ISO_DATE_SPEC);
29+ f_msg = xs_dict_set(f_msg, "published", date);
30+ }
31
32- follower_add(snac, actor);
33+ timeline_add(snac, id, f_msg);
34+
35+ follower_add(snac, actor);
36+
37+ snac_log(snac, xs_fmt("new follower %s", actor));
38+ }
39
40- snac_log(snac, xs_fmt("new follower %s", actor));
41 do_notify = 1;
42 }
43 else
M
data.c
+22,
-0
1@@ -1202,6 +1202,28 @@ xs_list *follower_list(snac *snac)
2 }
3
4
5+/** pending followers **/
6+
7+int pending_add(snac *user, const char *actor, const xs_dict *msg)
8+/* stores the follow message for later confirmation */
9+{
10+ xs *dir = xs_fmt("%s/pending", user->basedir);
11+ xs *md5 = xs_md5_hex(actor, strlen(actor));
12+ xs *fn = xs_fmt("%s/%s.json", dir, md5);
13+ FILE *f;
14+
15+ mkdirx(dir);
16+
17+ if ((f = fopen(fn, "w")) == NULL)
18+ return -1;
19+
20+ xs_json_dump(msg, 4, f);
21+ fclose(f);
22+
23+ return 0;
24+}
25+
26+
27 /** timeline **/
28
29 double timeline_mtime(snac *snac)
M
snac.h
+2,
-0
1@@ -141,6 +141,8 @@ int follower_del(snac *snac, const char *actor);
2 int follower_check(snac *snac, const char *actor);
3 xs_list *follower_list(snac *snac);
4
5+int pending_add(snac *user, const char *actor, const xs_dict *msg);
6+
7 double timeline_mtime(snac *snac);
8 int timeline_touch(snac *snac);
9 int timeline_here(snac *snac, const char *md5);