diff options
| author | 2022-09-26 07:13:39 +0200 | |
|---|---|---|
| committer | 2022-09-26 07:13:39 +0200 | |
| commit | d1a2a7438dddc898b794a7a9b3b0961afc1a36e4 (patch) | |
| tree | 09586a035fb76a7c1ddaa78e3573629ea3b1c5cf /data.c | |
| parent | Return the correct content-type. (diff) | |
| download | snac2-d1a2a7438dddc898b794a7a9b3b0961afc1a36e4.tar.gz snac2-d1a2a7438dddc898b794a7a9b3b0961afc1a36e4.tar.xz snac2-d1a2a7438dddc898b794a7a9b3b0961afc1a36e4.zip | |
New metadata 'referrer', that contains an actor.
This field contains the actor that boosted an entry.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 36 |
1 files changed, 19 insertions, 17 deletions
| @@ -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 | ||