diff options
| -rw-r--r-- | activitypub.c | 91 | ||||
| -rw-r--r-- | main.c | 15 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 97 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c index bd79041..98a15bf 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -253,11 +253,12 @@ d_char *msg_admiration(snac *snac, char *object, char *type) | |||
| 253 | d_char *msg_actor(snac *snac) | 253 | d_char *msg_actor(snac *snac) |
| 254 | /* create a Person message for this actor */ | 254 | /* create a Person message for this actor */ |
| 255 | { | 255 | { |
| 256 | xs *ctxt = xs_list_new(); | 256 | xs *ctxt = xs_list_new(); |
| 257 | xs *icon = xs_dict_new(); | 257 | xs *icon = xs_dict_new(); |
| 258 | xs *keys = xs_dict_new(); | 258 | xs *keys = xs_dict_new(); |
| 259 | xs *avtr = NULL; | 259 | xs *avtr = NULL; |
| 260 | xs *kid = NULL; | 260 | xs *kid = NULL; |
| 261 | xs *f_bio = NULL; | ||
| 261 | d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL, NULL); | 262 | d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL, NULL); |
| 262 | char *p; | 263 | char *p; |
| 263 | int n; | 264 | int n; |
| @@ -271,10 +272,11 @@ d_char *msg_actor(snac *snac) | |||
| 271 | msg = xs_dict_set(msg, "name", xs_dict_get(snac->config, "name")); | 272 | msg = xs_dict_set(msg, "name", xs_dict_get(snac->config, "name")); |
| 272 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); | 273 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); |
| 273 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); | 274 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); |
| 274 | msg = xs_dict_set(msg, "summary", xs_dict_get(snac->config, "bio")); | ||
| 275 | 275 | ||
| 276 | char *folders[] = { "inbox", "outbox", "followers", "following", NULL }; | 276 | not_really_markdown(xs_dict_get(snac->config, "bio"), &f_bio); |
| 277 | msg = xs_dict_set(msg, "summary", f_bio); | ||
| 277 | 278 | ||
| 279 | char *folders[] = { "inbox", "outbox", "followers", "following", NULL }; | ||
| 278 | for (n = 0; folders[n]; n++) { | 280 | for (n = 0; folders[n]; n++) { |
| 279 | xs *f = xs_fmt("%s/%s", snac->actor, folders[n]); | 281 | xs *f = xs_fmt("%s/%s", snac->actor, folders[n]); |
| 280 | msg = xs_dict_set(msg, folders[n], f); | 282 | msg = xs_dict_set(msg, folders[n], f); |
| @@ -303,6 +305,81 @@ d_char *msg_actor(snac *snac) | |||
| 303 | } | 305 | } |
| 304 | 306 | ||
| 305 | 307 | ||
| 308 | d_char *msg_create(snac *snac, char *object) | ||
| 309 | /* creates a 'Create' message */ | ||
| 310 | { | ||
| 311 | d_char *msg = msg_base(snac, "Create", "@object", snac->actor, "@now", object); | ||
| 312 | |||
| 313 | msg = xs_dict_append(msg, "attributedTo", xs_dict_get(object, "attributedTo")); | ||
| 314 | msg = xs_dict_append(msg, "to", xs_dict_get(object, "to")); | ||
| 315 | msg = xs_dict_append(msg, "cc", xs_dict_get(object, "cc")); | ||
| 316 | |||
| 317 | return msg; | ||
| 318 | } | ||
| 319 | |||
| 320 | |||
| 321 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) | ||
| 322 | /* creates a 'Note' message */ | ||
| 323 | { | ||
| 324 | xs *ntid = tid(0); | ||
| 325 | xs *id = xs_fmt("%s/p/%s", snac->actor, ntid); | ||
| 326 | xs *ctxt = xs_fmt("%s#ctxt", id); | ||
| 327 | xs *fc1 = NULL; | ||
| 328 | xs *to = NULL; | ||
| 329 | xs *cc = xs_list_new(); | ||
| 330 | xs *irt = NULL; | ||
| 331 | xs *tag = NULL; | ||
| 332 | d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); | ||
| 333 | char *p, *v; | ||
| 334 | |||
| 335 | if (rcpts == NULL) | ||
| 336 | to = xs_list_new(); | ||
| 337 | else | ||
| 338 | to = xs_dup(rcpts); | ||
| 339 | |||
| 340 | /* format the content */ | ||
| 341 | not_really_markdown(content, &fc1); | ||
| 342 | |||
| 343 | if (in_reply_to != NULL) { | ||
| 344 | irt = xs_dup(in_reply_to); | ||
| 345 | } | ||
| 346 | else | ||
| 347 | irt = xs_val_new(XSTYPE_NULL); | ||
| 348 | |||
| 349 | if (tag == NULL) | ||
| 350 | tag = xs_list_new(); | ||
| 351 | |||
| 352 | /* add all mentions to the cc */ | ||
| 353 | p = tag; | ||
| 354 | while (xs_list_iter(&p, &v)) { | ||
| 355 | if (xs_type(v) == XSTYPE_DICT) { | ||
| 356 | char *t; | ||
| 357 | |||
| 358 | if ((t = xs_dict_get(v, "type")) != NULL && strcmp(t, "Mention") == 0) { | ||
| 359 | if ((t = xs_dict_get(v, "href")) != NULL) | ||
| 360 | cc = xs_list_append(cc, t); | ||
| 361 | } | ||
| 362 | } | ||
| 363 | } | ||
| 364 | |||
| 365 | /* no recipients? must be for everybody */ | ||
| 366 | if (xs_list_len(to) == 0) | ||
| 367 | to = xs_list_append(to, public_address); | ||
| 368 | |||
| 369 | msg = xs_dict_append(msg, "attributedTo", snac->actor); | ||
| 370 | msg = xs_dict_append(msg, "summary", ""); | ||
| 371 | msg = xs_dict_append(msg, "content", fc1); | ||
| 372 | msg = xs_dict_append(msg, "context", ctxt); | ||
| 373 | msg = xs_dict_append(msg, "url", id); | ||
| 374 | msg = xs_dict_append(msg, "to", to); | ||
| 375 | msg = xs_dict_append(msg, "cc", cc); | ||
| 376 | msg = xs_dict_append(msg, "inReplyTo", irt); | ||
| 377 | msg = xs_dict_append(msg, "tag", tag); | ||
| 378 | |||
| 379 | return msg; | ||
| 380 | } | ||
| 381 | |||
| 382 | |||
| 306 | /** queues **/ | 383 | /** queues **/ |
| 307 | 384 | ||
| 308 | void process_message(snac *snac, char *msg, char *req) | 385 | void process_message(snac *snac, char *msg, char *req) |
| @@ -165,9 +165,9 @@ int main(int argc, char *argv[]) | |||
| 165 | 165 | ||
| 166 | if (strcmp(cmd, "note") == 0) { | 166 | if (strcmp(cmd, "note") == 0) { |
| 167 | int status; | 167 | int status; |
| 168 | xs *data = NULL; | ||
| 169 | xs *content = NULL; | 168 | xs *content = NULL; |
| 170 | xs *f_content = NULL; | 169 | xs *msg = NULL; |
| 170 | xs *c_msg = NULL; | ||
| 171 | 171 | ||
| 172 | if (strcmp(url, "-") == 0) { | 172 | if (strcmp(url, "-") == 0) { |
| 173 | /* get the content from an editor */ | 173 | /* get the content from an editor */ |
| @@ -189,9 +189,16 @@ int main(int argc, char *argv[]) | |||
| 189 | else | 189 | else |
| 190 | content = xs_dup(url); | 190 | content = xs_dup(url); |
| 191 | 191 | ||
| 192 | not_really_markdown(content, &f_content); | 192 | msg = msg_note(&snac, content, NULL, NULL); |
| 193 | |||
| 194 | c_msg = msg_create(&snac, msg); | ||
| 195 | |||
| 196 | { | ||
| 197 | xs *j = xs_json_dumps_pp(c_msg, 4); | ||
| 198 | printf("%s\n", j); | ||
| 199 | } | ||
| 193 | 200 | ||
| 194 | printf("%s\n", f_content); | 201 | post(&snac, c_msg); |
| 195 | 202 | ||
| 196 | return 0; | 203 | return 0; |
| 197 | } | 204 | } |
| @@ -88,6 +88,8 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 88 | char **body, int *b_size, char **ctype); | 88 | char **body, int *b_size, char **ctype); |
| 89 | 89 | ||
| 90 | d_char *msg_admiration(snac *snac, char *object, char *type); | 90 | d_char *msg_admiration(snac *snac, char *object, char *type); |
| 91 | d_char *msg_create(snac *snac, char *object); | ||
| 92 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to); | ||
| 91 | 93 | ||
| 92 | int activitypub_request(snac *snac, char *url, d_char **data); | 94 | int activitypub_request(snac *snac, char *url, d_char **data); |
| 93 | int actor_request(snac *snac, char *actor, d_char **data); | 95 | int actor_request(snac *snac, char *actor, d_char **data); |