diff options
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | data.c | 36 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 22 insertions, 20 deletions
diff --git a/activitypub.c b/activitypub.c index 13d7d85..4b2947e 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -91,7 +91,7 @@ void timeline_request(snac *snac, char *id) | |||
| 91 | timeline_request(snac, in_reply_to); | 91 | timeline_request(snac, in_reply_to); |
| 92 | 92 | ||
| 93 | /* finally store */ | 93 | /* finally store */ |
| 94 | timeline_add(snac, id, object, in_reply_to); | 94 | timeline_add(snac, id, object, in_reply_to, NULL); |
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| @@ -282,7 +282,7 @@ void process_message(snac *snac, char *msg, char *req) | |||
| 282 | 282 | ||
| 283 | timeline_request(snac, in_reply_to); | 283 | timeline_request(snac, in_reply_to); |
| 284 | 284 | ||
| 285 | if (timeline_add(snac, id, msg, in_reply_to)) | 285 | if (timeline_add(snac, id, msg, in_reply_to, NULL)) |
| 286 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); | 286 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); |
| 287 | } | 287 | } |
| 288 | } | 288 | } |
| @@ -526,7 +526,7 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent) | |||
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | 528 | ||
| 529 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent) | 529 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer) |
| 530 | /* adds a message to the timeline */ | 530 | /* adds a message to the timeline */ |
| 531 | { | 531 | { |
| 532 | xs *pfn = _timeline_find_fn(snac, id); | 532 | xs *pfn = _timeline_find_fn(snac, id); |
| @@ -545,12 +545,16 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent) | |||
| 545 | "\"liked_by\": []," | 545 | "\"liked_by\": []," |
| 546 | "\"announced_by\": []," | 546 | "\"announced_by\": []," |
| 547 | "\"version\": \"snac/2.x\"," | 547 | "\"version\": \"snac/2.x\"," |
| 548 | "\"referrer\": null," | ||
| 548 | "\"parent\": null" | 549 | "\"parent\": null" |
| 549 | "}"); | 550 | "}"); |
| 550 | 551 | ||
| 551 | if (!xs_is_null(parent)) | 552 | if (!xs_is_null(parent)) |
| 552 | md = xs_dict_set(md, "parent", parent); | 553 | md = xs_dict_set(md, "parent", parent); |
| 553 | 554 | ||
| 555 | if (!xs_is_null(referrer)) | ||
| 556 | md = xs_dict_set(md, "parent", referrer); | ||
| 557 | |||
| 554 | msg = xs_dict_set(msg, "_snac", md); | 558 | msg = xs_dict_set(msg, "_snac", md); |
| 555 | 559 | ||
| 556 | _timeline_write(snac, id, msg, parent); | 560 | _timeline_write(snac, id, msg, parent); |
| @@ -569,7 +573,6 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like) | |||
| 569 | FILE *f; | 573 | FILE *f; |
| 570 | 574 | ||
| 571 | if (ofn != NULL && (f = fopen(ofn, "r")) != NULL) { | 575 | if (ofn != NULL && (f = fopen(ofn, "r")) != NULL) { |
| 572 | int changed = 0; | ||
| 573 | xs *j1 = xs_readall(f); | 576 | xs *j1 = xs_readall(f); |
| 574 | fclose(f); | 577 | fclose(f); |
| 575 | 578 | ||
| @@ -583,27 +586,26 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like) | |||
| 583 | list = xs_dup(xs_dict_get(meta, "announced_by")); | 586 | list = xs_dup(xs_dict_get(meta, "announced_by")); |
| 584 | 587 | ||
| 585 | /* add the admirer if it's not already there */ | 588 | /* add the admirer if it's not already there */ |
| 586 | if (xs_list_in(list, admirer) == -1) { | 589 | if (xs_list_in(list, admirer) == -1) |
| 587 | list = xs_list_append(list, admirer); | 590 | list = xs_list_append(list, admirer); |
| 588 | changed = 1; | ||
| 589 | } | ||
| 590 | 591 | ||
| 591 | if (changed) { | 592 | /* set the admirer as the referrer */ |
| 592 | /* re-store */ | 593 | meta = xs_dict_set(meta, "referrer", admirer); |
| 593 | if (like) | 594 | |
| 594 | meta = xs_dict_set(meta, "liked_by", list); | 595 | /* re-store */ |
| 595 | else | 596 | if (like) |
| 596 | meta = xs_dict_set(meta, "announced_by", list); | 597 | meta = xs_dict_set(meta, "liked_by", list); |
| 598 | else | ||
| 599 | meta = xs_dict_set(meta, "announced_by", list); | ||
| 597 | 600 | ||
| 598 | msg = xs_dict_set(msg, "_snac", meta); | 601 | msg = xs_dict_set(msg, "_snac", meta); |
| 599 | 602 | ||
| 600 | unlink(ofn); | 603 | unlink(ofn); |
| 601 | 604 | ||
| 602 | _timeline_write(snac, id, msg, xs_dict_get(meta, "parent")); | 605 | _timeline_write(snac, id, msg, xs_dict_get(meta, "parent")); |
| 603 | 606 | ||
| 604 | snac_log(snac, xs_fmt("timeline_admire (%s) %s %s", | 607 | snac_log(snac, xs_fmt("timeline_admire (%s) %s %s", |
| 605 | like ? "Like" : "Announce", id, admirer)); | 608 | like ? "Like" : "Announce", id, admirer)); |
| 606 | } | ||
| 607 | } | 609 | } |
| 608 | } | 610 | } |
| 609 | 611 | ||
| @@ -56,7 +56,7 @@ d_char *timeline_find(snac *snac, char *id); | |||
| 56 | void timeline_del(snac *snac, char *id); | 56 | void timeline_del(snac *snac, char *id); |
| 57 | d_char *timeline_get(snac *snac, char *fn); | 57 | d_char *timeline_get(snac *snac, char *fn); |
| 58 | d_char *timeline_list(snac *snac); | 58 | d_char *timeline_list(snac *snac); |
| 59 | int timeline_add(snac *snac, char *id, char *msg, char *parent); | 59 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); |
| 60 | void timeline_admire(snac *snac, char *id, char *admirer, int like); | 60 | void timeline_admire(snac *snac, char *id, char *admirer, int like); |
| 61 | 61 | ||
| 62 | int following_add(snac *snac, char *actor, char *msg); | 62 | int following_add(snac *snac, char *actor, char *msg); |