diff options
| -rw-r--r-- | activitypub.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/activitypub.c b/activitypub.c index 7533b0b..cede02c 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -117,7 +117,7 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s | |||
| 117 | 117 | ||
| 118 | /** messages **/ | 118 | /** messages **/ |
| 119 | 119 | ||
| 120 | d_char *msg_base(snac *snac, char *type, char *id, char *actor) | 120 | d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date) |
| 121 | /* creates a base ActivityPub message */ | 121 | /* creates a base ActivityPub message */ |
| 122 | { | 122 | { |
| 123 | d_char *msg = xs_dict_new(); | 123 | d_char *msg = xs_dict_new(); |
| @@ -128,12 +128,12 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor) | |||
| 128 | if (id != NULL) | 128 | if (id != NULL) |
| 129 | msg = xs_dict_append(msg, "id", id); | 129 | msg = xs_dict_append(msg, "id", id); |
| 130 | 130 | ||
| 131 | if (actor != NULL) { | 131 | if (actor != NULL) |
| 132 | /* if actor is "", replace it with this actor */ | ||
| 133 | if (actor[0] == '\0') | ||
| 134 | actor = snac->actor; | ||
| 135 | |||
| 136 | msg = xs_dict_append(msg, "actor", actor); | 132 | msg = xs_dict_append(msg, "actor", actor); |
| 133 | |||
| 134 | if (date != NULL) { | ||
| 135 | xs *published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ"); | ||
| 136 | msg = xs_dict_append(msg, "published", published); | ||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | return msg; | 139 | return msg; |
| @@ -143,7 +143,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor) | |||
| 143 | d_char *msg_collection(snac *snac, char *id) | 143 | d_char *msg_collection(snac *snac, char *id) |
| 144 | /* creates an empty OrderedCollection message */ | 144 | /* creates an empty OrderedCollection message */ |
| 145 | { | 145 | { |
| 146 | d_char *msg = msg_base(snac, "OrderedCollection", id, NULL); | 146 | d_char *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL); |
| 147 | xs *ol = xs_list_new(); | 147 | xs *ol = xs_list_new(); |
| 148 | xs *nz = xs_number_new(0); | 148 | xs *nz = xs_number_new(0); |
| 149 | 149 | ||
| @@ -155,6 +155,18 @@ d_char *msg_collection(snac *snac, char *id) | |||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | d_char *msg_update(snac *snac, char *object) | ||
| 159 | { | ||
| 160 | xs *id = xs_fmt("%s/Update", xs_dict_get(object, "id")); | ||
| 161 | d_char *msg = msg_base(snac, "Update", id, snac->actor, ""); | ||
| 162 | |||
| 163 | msg = xs_dict_append(msg, "to", public_address); | ||
| 164 | msg = xs_dict_append(msg, "object", object); | ||
| 165 | |||
| 166 | return msg; | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 158 | /** queues **/ | 170 | /** queues **/ |
| 159 | 171 | ||
| 160 | void process_message(snac *snac, char *msg, char *req) | 172 | void process_message(snac *snac, char *msg, char *req) |
| @@ -248,7 +260,7 @@ int activitypub_get_handler(d_char *req, char *q_path, | |||
| 248 | char *headers = xs_dict_get(req, "headers"); | 260 | char *headers = xs_dict_get(req, "headers"); |
| 249 | char *accept = xs_dict_get(headers, "accept"); | 261 | char *accept = xs_dict_get(headers, "accept"); |
| 250 | snac snac; | 262 | snac snac; |
| 251 | xs *msg = xs_dict_new(); | 263 | xs *msg = NULL; |
| 252 | 264 | ||
| 253 | if (accept == NULL) | 265 | if (accept == NULL) |
| 254 | return 400; | 266 | return 400; |
| @@ -276,6 +288,9 @@ int activitypub_get_handler(d_char *req, char *q_path, | |||
| 276 | if (strcmp(p_path, "outbox") == 0) { | 288 | if (strcmp(p_path, "outbox") == 0) { |
| 277 | xs *id = xs_fmt("%s/outbox", snac.actor); | 289 | xs *id = xs_fmt("%s/outbox", snac.actor); |
| 278 | msg = msg_collection(&snac, id); | 290 | msg = msg_collection(&snac, id); |
| 291 | |||
| 292 | /* replace the 'orderedItems' with the latest posts */ | ||
| 293 | /* ... */ | ||
| 279 | } | 294 | } |
| 280 | else | 295 | else |
| 281 | if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { | 296 | if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { |
| @@ -288,7 +303,7 @@ int activitypub_get_handler(d_char *req, char *q_path, | |||
| 288 | else | 303 | else |
| 289 | status = 404; | 304 | status = 404; |
| 290 | 305 | ||
| 291 | if (status == 200) { | 306 | if (status == 200 && msg != NULL) { |
| 292 | *body = xs_json_dumps_pp(msg, 4); | 307 | *body = xs_json_dumps_pp(msg, 4); |
| 293 | *b_size = strlen(*body); | 308 | *b_size = strlen(*body); |
| 294 | } | 309 | } |