diff options
| -rw-r--r-- | activitypub.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index ce7e71f..4ce88c5 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -2143,6 +2143,60 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2143 | 2143 | ||
| 2144 | do_notify = 1; | 2144 | do_notify = 1; |
| 2145 | } | 2145 | } |
| 2146 | else | ||
| 2147 | if (strcmp(type, "Move") == 0) { /** **/ | ||
| 2148 | const char *old_account = xs_dict_get(msg, "object"); | ||
| 2149 | const char *new_account = xs_dict_get(msg, "target"); | ||
| 2150 | |||
| 2151 | if (!xs_is_null(old_account) && !xs_is_null(new_account)) { | ||
| 2152 | if (following_check(snac, old_account)) { | ||
| 2153 | xs *n_actor = NULL; | ||
| 2154 | |||
| 2155 | if (valid_status(object_get(new_account, &n_actor))) { | ||
| 2156 | const xs_list *aka = xs_dict_get(n_actor, "alsoKnownAs"); | ||
| 2157 | |||
| 2158 | if (xs_type(aka) == XSTYPE_LIST) { | ||
| 2159 | if (xs_list_in(aka, old_account) != -1) { | ||
| 2160 | /* all conditions met! */ | ||
| 2161 | |||
| 2162 | /* follow new account */ | ||
| 2163 | xs *f_msg = msg_follow(snac, new_account); | ||
| 2164 | |||
| 2165 | if (f_msg != NULL) { | ||
| 2166 | const char *new_actor = xs_dict_get(f_msg, "object"); | ||
| 2167 | following_add(snac, new_actor, f_msg); | ||
| 2168 | enqueue_output_by_actor(snac, f_msg, new_actor, 0); | ||
| 2169 | |||
| 2170 | snac_log(snac, xs_fmt("'Move': following %s", new_account)); | ||
| 2171 | } | ||
| 2172 | |||
| 2173 | /* unfollow old account */ | ||
| 2174 | xs *of_msg = NULL; | ||
| 2175 | |||
| 2176 | if (valid_status(following_get(snac, old_account, &of_msg))) { | ||
| 2177 | xs *uf_msg = msg_undo(snac, xs_dict_get(of_msg, "object")); | ||
| 2178 | following_del(snac, old_account); | ||
| 2179 | enqueue_output_by_actor(snac, uf_msg, old_account, 0); | ||
| 2180 | |||
| 2181 | snac_log(snac, xs_fmt("'Move': unfollowing %s", old_account)); | ||
| 2182 | } | ||
| 2183 | } | ||
| 2184 | else | ||
| 2185 | snac_log(snac, xs_fmt("'Move' error: old actor %s not found in %s 'alsoKnownAs'", | ||
| 2186 | old_account, new_account)); | ||
| 2187 | } | ||
| 2188 | else | ||
| 2189 | snac_log(snac, xs_fmt("'Move' error: cannot get %s 'alsoKnownAs'", new_account)); | ||
| 2190 | } | ||
| 2191 | else | ||
| 2192 | snac_log(snac, xs_fmt("'Move' error: cannot get new actor %s", new_account)); | ||
| 2193 | } | ||
| 2194 | else | ||
| 2195 | snac_log(snac, xs_fmt("'Move' error: actor %s is not being followed", old_account)); | ||
| 2196 | } | ||
| 2197 | else | ||
| 2198 | snac_log(snac, xs_fmt("'Move' error: malformed message from %s", actor)); | ||
| 2199 | } | ||
| 2146 | else { | 2200 | else { |
| 2147 | srv_archive_error("unsupported_type", "unsupported_type", req, msg); | 2201 | srv_archive_error("unsupported_type", "unsupported_type", req, msg); |
| 2148 | 2202 | ||