diff options
| -rw-r--r-- | activitypub.c | 6 | ||||
| -rw-r--r-- | data.c | 57 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 4 insertions, 61 deletions
diff --git a/activitypub.c b/activitypub.c index 09fa55e..f19774c 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -399,7 +399,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type) | |||
| 399 | /* call the object */ | 399 | /* call the object */ |
| 400 | timeline_request(snac, object, snac->actor); | 400 | timeline_request(snac, object, snac->actor); |
| 401 | 401 | ||
| 402 | if ((a_msg = timeline_find(snac, object)) != NULL) { | 402 | if (valid_status(object_get(object, &a_msg, NULL))) { |
| 403 | xs *rcpts = xs_list_new(); | 403 | xs *rcpts = xs_list_new(); |
| 404 | 404 | ||
| 405 | msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); | 405 | msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); |
| @@ -592,7 +592,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 592 | /* demand this thing */ | 592 | /* demand this thing */ |
| 593 | timeline_request(snac, in_reply_to, NULL); | 593 | timeline_request(snac, in_reply_to, NULL); |
| 594 | 594 | ||
| 595 | if ((p_msg = timeline_find(snac, in_reply_to)) != NULL) { | 595 | if (valid_status(object_get(in_reply_to, &p_msg, NULL))) { |
| 596 | /* add this author as recipient */ | 596 | /* add this author as recipient */ |
| 597 | char *a, *v; | 597 | char *a, *v; |
| 598 | 598 | ||
| @@ -892,7 +892,7 @@ int process_message(snac *snac, char *msg, char *req) | |||
| 892 | 892 | ||
| 893 | timeline_request(snac, object, actor); | 893 | timeline_request(snac, object, actor); |
| 894 | 894 | ||
| 895 | if ((a_msg = timeline_find(snac, object)) != NULL) { | 895 | if (valid_status(object_get(object, &a_msg, NULL))) { |
| 896 | char *who = xs_dict_get(a_msg, "attributedTo"); | 896 | char *who = xs_dict_get(a_msg, "attributedTo"); |
| 897 | 897 | ||
| 898 | if (who && !is_muted(snac, who)) { | 898 | if (who && !is_muted(snac, who)) { |
| @@ -738,56 +738,11 @@ d_char *follower_list(snac *snac) | |||
| 738 | 738 | ||
| 739 | double timeline_mtime(snac *snac) | 739 | double timeline_mtime(snac *snac) |
| 740 | { | 740 | { |
| 741 | xs *fn = xs_fmt("%s/timeline", snac->basedir); | 741 | xs *fn = xs_fmt("%s/private.idx", snac->basedir); |
| 742 | return mtime(fn); | 742 | return mtime(fn); |
| 743 | } | 743 | } |
| 744 | 744 | ||
| 745 | 745 | ||
| 746 | d_char *_timeline_find_fn(snac *snac, char *id) | ||
| 747 | /* returns the file name of a timeline entry by its id */ | ||
| 748 | { | ||
| 749 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 750 | xs *spec = xs_fmt("%s/timeline/" "*-%s.json", snac->basedir, md5); | ||
| 751 | xs *list = NULL; | ||
| 752 | d_char *fn = NULL; | ||
| 753 | int l; | ||
| 754 | |||
| 755 | list = xs_glob(spec, 0, 0); | ||
| 756 | l = xs_list_len(list); | ||
| 757 | |||
| 758 | /* if there is something, get the first one */ | ||
| 759 | if (l > 0) { | ||
| 760 | fn = xs_str_new(xs_list_get(list, 0)); | ||
| 761 | |||
| 762 | if (l > 1) | ||
| 763 | snac_log(snac, xs_fmt("**ALERT** _timeline_find_fn %d > 1", l)); | ||
| 764 | } | ||
| 765 | |||
| 766 | return fn; | ||
| 767 | } | ||
| 768 | |||
| 769 | |||
| 770 | d_char *timeline_find(snac *snac, char *id) | ||
| 771 | /* gets a message from the timeline by id */ | ||
| 772 | { | ||
| 773 | xs *fn = _timeline_find_fn(snac, id); | ||
| 774 | d_char *msg = NULL; | ||
| 775 | |||
| 776 | if (fn != NULL) { | ||
| 777 | FILE *f; | ||
| 778 | |||
| 779 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 780 | xs *j = xs_readall(f); | ||
| 781 | |||
| 782 | msg = xs_json_loads(j); | ||
| 783 | fclose(f); | ||
| 784 | } | ||
| 785 | } | ||
| 786 | |||
| 787 | return msg; | ||
| 788 | } | ||
| 789 | |||
| 790 | |||
| 791 | int timeline_del(snac *snac, char *id) | 746 | int timeline_del(snac *snac, char *id) |
| 792 | /* deletes a message from the timeline */ | 747 | /* deletes a message from the timeline */ |
| 793 | { | 748 | { |
| @@ -800,16 +755,6 @@ int timeline_del(snac *snac, char *id) | |||
| 800 | } | 755 | } |
| 801 | 756 | ||
| 802 | 757 | ||
| 803 | d_char *_timeline_new_fn(snac *snac, char *id) | ||
| 804 | /* creates a new filename */ | ||
| 805 | { | ||
| 806 | xs *ntid = tid(0); | ||
| 807 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 808 | |||
| 809 | return xs_fmt("%s/timeline/%s-%s.json", snac->basedir, ntid, md5); | ||
| 810 | } | ||
| 811 | |||
| 812 | |||
| 813 | void timeline_update_indexes(snac *snac, const char *id) | 758 | void timeline_update_indexes(snac *snac, const char *id) |
| 814 | /* updates the indexes */ | 759 | /* updates the indexes */ |
| 815 | { | 760 | { |
| @@ -76,8 +76,6 @@ int follower_check(snac *snac, const char *actor); | |||
| 76 | d_char *follower_list(snac *snac); | 76 | d_char *follower_list(snac *snac); |
| 77 | 77 | ||
| 78 | double timeline_mtime(snac *snac); | 78 | double timeline_mtime(snac *snac); |
| 79 | d_char *_timeline_find_fn(snac *snac, char *id); | ||
| 80 | d_char *timeline_find(snac *snac, char *id); | ||
| 81 | int timeline_del(snac *snac, char *id); | 79 | int timeline_del(snac *snac, char *id); |
| 82 | d_char *timeline_list(snac *snac, const char *idx_name, int max); | 80 | d_char *timeline_list(snac *snac, const char *idx_name, int max); |
| 83 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); | 81 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); |