diff options
| -rw-r--r-- | activitypub.c | 31 | ||||
| -rw-r--r-- | data.c | 22 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 44 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c index 649b1f2..3ab093f 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1927,22 +1927,31 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 1927 | object_add(actor, actor_obj); | 1927 | object_add(actor, actor_obj); |
| 1928 | } | 1928 | } |
| 1929 | 1929 | ||
| 1930 | xs *f_msg = xs_dup(msg); | 1930 | if (xs_is_true(xs_dict_get(snac->config, "approve_followers"))) { |
| 1931 | xs *reply = msg_accept(snac, f_msg, actor); | 1931 | pending_add(snac, actor, msg); |
| 1932 | 1932 | ||
| 1933 | post_message(snac, actor, reply); | 1933 | snac_log(snac, xs_fmt("new pending follower approval %s", actor)); |
| 1934 | |||
| 1935 | if (xs_is_null(xs_dict_get(f_msg, "published"))) { | ||
| 1936 | /* add a date if it doesn't include one (Mastodon) */ | ||
| 1937 | xs *date = xs_str_utctime(0, ISO_DATE_SPEC); | ||
| 1938 | f_msg = xs_dict_set(f_msg, "published", date); | ||
| 1939 | } | 1934 | } |
| 1935 | else { | ||
| 1936 | /* automatic following */ | ||
| 1937 | xs *f_msg = xs_dup(msg); | ||
| 1938 | xs *reply = msg_accept(snac, f_msg, actor); | ||
| 1940 | 1939 | ||
| 1941 | timeline_add(snac, id, f_msg); | 1940 | post_message(snac, actor, reply); |
| 1941 | |||
| 1942 | if (xs_is_null(xs_dict_get(f_msg, "published"))) { | ||
| 1943 | /* add a date if it doesn't include one (Mastodon) */ | ||
| 1944 | xs *date = xs_str_utctime(0, ISO_DATE_SPEC); | ||
| 1945 | f_msg = xs_dict_set(f_msg, "published", date); | ||
| 1946 | } | ||
| 1942 | 1947 | ||
| 1943 | follower_add(snac, actor); | 1948 | timeline_add(snac, id, f_msg); |
| 1949 | |||
| 1950 | follower_add(snac, actor); | ||
| 1951 | |||
| 1952 | snac_log(snac, xs_fmt("new follower %s", actor)); | ||
| 1953 | } | ||
| 1944 | 1954 | ||
| 1945 | snac_log(snac, xs_fmt("new follower %s", actor)); | ||
| 1946 | do_notify = 1; | 1955 | do_notify = 1; |
| 1947 | } | 1956 | } |
| 1948 | else | 1957 | else |
| @@ -1202,6 +1202,28 @@ xs_list *follower_list(snac *snac) | |||
| 1202 | } | 1202 | } |
| 1203 | 1203 | ||
| 1204 | 1204 | ||
| 1205 | /** pending followers **/ | ||
| 1206 | |||
| 1207 | int pending_add(snac *user, const char *actor, const xs_dict *msg) | ||
| 1208 | /* stores the follow message for later confirmation */ | ||
| 1209 | { | ||
| 1210 | xs *dir = xs_fmt("%s/pending", user->basedir); | ||
| 1211 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 1212 | xs *fn = xs_fmt("%s/%s.json", dir, md5); | ||
| 1213 | FILE *f; | ||
| 1214 | |||
| 1215 | mkdirx(dir); | ||
| 1216 | |||
| 1217 | if ((f = fopen(fn, "w")) == NULL) | ||
| 1218 | return -1; | ||
| 1219 | |||
| 1220 | xs_json_dump(msg, 4, f); | ||
| 1221 | fclose(f); | ||
| 1222 | |||
| 1223 | return 0; | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | |||
| 1205 | /** timeline **/ | 1227 | /** timeline **/ |
| 1206 | 1228 | ||
| 1207 | double timeline_mtime(snac *snac) | 1229 | double timeline_mtime(snac *snac) |
| @@ -141,6 +141,8 @@ int follower_del(snac *snac, const char *actor); | |||
| 141 | int follower_check(snac *snac, const char *actor); | 141 | int follower_check(snac *snac, const char *actor); |
| 142 | xs_list *follower_list(snac *snac); | 142 | xs_list *follower_list(snac *snac); |
| 143 | 143 | ||
| 144 | int pending_add(snac *user, const char *actor, const xs_dict *msg); | ||
| 145 | |||
| 144 | double timeline_mtime(snac *snac); | 146 | double timeline_mtime(snac *snac); |
| 145 | int timeline_touch(snac *snac); | 147 | int timeline_touch(snac *snac); |
| 146 | int timeline_here(snac *snac, const char *md5); | 148 | int timeline_here(snac *snac, const char *md5); |