summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-09-27 07:54:05 +0200
committerGravatar default2022-09-27 07:54:05 +0200
commitec9115717be6e78b932b0c044fb47082d1c00628 (patch)
tree8425f20e090b7760330dd9e4162a9773a2f96215
parentCheck the digest before enqueueing. (diff)
downloadpenes-snac2-ec9115717be6e78b932b0c044fb47082d1c00628.tar.gz
penes-snac2-ec9115717be6e78b932b0c044fb47082d1c00628.tar.xz
penes-snac2-ec9115717be6e78b932b0c044fb47082d1c00628.zip
'Follow' messages are now processed.
-rw-r--r--activitypub.c74
1 files changed, 58 insertions, 16 deletions
diff --git a/activitypub.c b/activitypub.c
index 2347498..3a459bf 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -141,9 +141,30 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
141 141
142/** messages **/ 142/** messages **/
143 143
144d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date) 144d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object)
145/* creates a base ActivityPub message */ 145/* creates a base ActivityPub message */
146{ 146{
147 xs *did = NULL;
148 xs *published = NULL;
149
150 /* generated values */
151 if (date && strcmp(date, "@now") == 0)
152 date = published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ");
153
154 if (id != NULL) {
155 if (strcmp(id, "@dummy") == 0) {
156 xs *ntid = tid(0);
157 id = did = xs_fmt("%s/d/%s/%s", snac->actor, ntid, type);
158 }
159 else
160 if (strcmp(id, "@object") == 0) {
161 if (object != NULL)
162 id = did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type);
163 else
164 id = NULL;
165 }
166 }
167
147 d_char *msg = xs_dict_new(); 168 d_char *msg = xs_dict_new();
148 169
149 msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams"); 170 msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
@@ -155,10 +176,11 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date)
155 if (actor != NULL) 176 if (actor != NULL)
156 msg = xs_dict_append(msg, "actor", actor); 177 msg = xs_dict_append(msg, "actor", actor);
157 178
158 if (date != NULL) { 179 if (date != NULL)
159 xs *published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ"); 180 msg = xs_dict_append(msg, "published", date);
160 msg = xs_dict_append(msg, "published", published); 181
161 } 182 if (object != NULL)
183 msg = xs_dict_append(msg, "object", object);
162 184
163 return msg; 185 return msg;
164} 186}
@@ -167,7 +189,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date)
167d_char *msg_collection(snac *snac, char *id) 189d_char *msg_collection(snac *snac, char *id)
168/* creates an empty OrderedCollection message */ 190/* creates an empty OrderedCollection message */
169{ 191{
170 d_char *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL); 192 d_char *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL, NULL);
171 xs *ol = xs_list_new(); 193 xs *ol = xs_list_new();
172 xs *nz = xs_number_new(0); 194 xs *nz = xs_number_new(0);
173 195
@@ -179,14 +201,23 @@ d_char *msg_collection(snac *snac, char *id)
179} 201}
180 202
181 203
204d_char *msg_accept(snac *snac, char *object, char *to)
205/* creates an Accept message (as a response to a Follow) */
206{
207 d_char *msg = msg_base(snac, "Accept", "@dummy", snac->actor, NULL, object);
208
209 msg = xs_dict_append(msg, "to", to);
210
211 return msg;
212}
213
214
182d_char *msg_update(snac *snac, char *object) 215d_char *msg_update(snac *snac, char *object)
183/* creates an Update message */ 216/* creates an Update message */
184{ 217{
185 xs *id = xs_fmt("%s/Update", xs_dict_get(object, "id")); 218 d_char *msg = msg_base(snac, "Update", "@object", snac->actor, "@now", object);
186 d_char *msg = msg_base(snac, "Update", id, snac->actor, "");
187 219
188 msg = xs_dict_append(msg, "to", public_address); 220 msg = xs_dict_append(msg, "to", public_address);
189 msg = xs_dict_append(msg, "object", object);
190 221
191 return msg; 222 return msg;
192} 223}
@@ -202,17 +233,14 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
202 timeline_request(snac, object, snac->actor); 233 timeline_request(snac, object, snac->actor);
203 234
204 if ((a_msg = timeline_find(snac, object)) != NULL) { 235 if ((a_msg = timeline_find(snac, object)) != NULL) {
205 xs *ntid = tid(0);
206 xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type);
207 xs *rcpts = xs_list_new(); 236 xs *rcpts = xs_list_new();
208 237
209 msg = msg_base(snac, type, id, snac->actor, ""); 238 msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
210 239
211 rcpts = xs_list_append(rcpts, public_address); 240 rcpts = xs_list_append(rcpts, public_address);
212 rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); 241 rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo"));
213 242
214 msg = xs_dict_append(msg, "to", rcpts); 243 msg = xs_dict_append(msg, "to", rcpts);
215 msg = xs_dict_append(msg, "object", object);
216 } 244 }
217 else 245 else
218 snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object)); 246 snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object));
@@ -229,7 +257,7 @@ d_char *msg_actor(snac *snac)
229 xs *keys = xs_dict_new(); 257 xs *keys = xs_dict_new();
230 xs *avtr = NULL; 258 xs *avtr = NULL;
231 xs *kid = NULL; 259 xs *kid = NULL;
232 d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL); 260 d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL, NULL);
233 char *p; 261 char *p;
234 int n; 262 int n;
235 263
@@ -294,10 +322,19 @@ void process_message(snac *snac, char *msg, char *req)
294 /* check the signature */ 322 /* check the signature */
295 /* ... */ 323 /* ... */
296 324
297/*
298 if (strcmp(type, "Follow") == 0) { 325 if (strcmp(type, "Follow") == 0) {
326 xs *reply = msg_accept(snac, msg, actor);
327
328 post(snac, reply);
329
330 timeline_add(snac, xs_dict_get(msg, "id"), msg, NULL, NULL);
331
332 follower_add(snac, actor, msg);
333
334 snac_log(snac, xs_fmt("New follower %s", actor));
299 } 335 }
300 else 336 else
337/*
301 if (strcmp(type, "Undo") == 0) { 338 if (strcmp(type, "Undo") == 0) {
302 } 339 }
303 else 340 else
@@ -424,6 +461,11 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
424 char *l = lists[n]; 461 char *l = lists[n];
425 char *v; 462 char *v;
426 463
464 if (xs_type(l) == XSTYPE_STRING) {
465 if (xs_list_in(list, l) == -1)
466 list = xs_list_append(list, l);
467 }
468 else
427 while (xs_list_iter(&l, &v)) { 469 while (xs_list_iter(&l, &v)) {
428 if (expand_public && strcmp(v, public_address) == 0) { 470 if (expand_public && strcmp(v, public_address) == 0) {
429 /* iterate the followers and add them */ 471 /* iterate the followers and add them */