diff options
| author | 2023-04-11 19:59:02 +0200 | |
|---|---|---|
| committer | 2023-04-11 19:59:02 +0200 | |
| commit | df785849115e72f6a0e3dc694d2141ecf1fe16bb (patch) | |
| tree | fd2b863785ee9db415856bf0f61b8d1843002fa0 | |
| parent | Started work in /api/v1/statuses. (diff) | |
| download | penes-snac2-df785849115e72f6a0e3dc694d2141ecf1fe16bb.tar.gz penes-snac2-df785849115e72f6a0e3dc694d2141ecf1fe16bb.tar.xz penes-snac2-df785849115e72f6a0e3dc694d2141ecf1fe16bb.zip | |
Added support for statuses/:id and statuses/:id/context.
| -rw-r--r-- | mastoapi.c | 37 |
1 files changed, 36 insertions, 1 deletions
| @@ -789,11 +789,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 789 | if (valid_status(timeline_get_by_md5(&snac, id, &msg))) { | 789 | if (valid_status(timeline_get_by_md5(&snac, id, &msg))) { |
| 790 | if (op == NULL) { | 790 | if (op == NULL) { |
| 791 | /* return the status itself */ | 791 | /* return the status itself */ |
| 792 | out = mastoapi_status(&snac, msg); | ||
| 792 | } | 793 | } |
| 793 | else | 794 | else |
| 794 | if (strcmp(op, "context") == 0) { | 795 | if (strcmp(op, "context") == 0) { |
| 795 | /* return ancestors and children */ | 796 | /* return ancestors and children */ |
| 796 | srv_debug(0, xs_fmt("mastoapi status: context requested for %s", id)); | 797 | xs *anc = xs_list_new(); |
| 798 | xs *des = xs_list_new(); | ||
| 799 | xs_list *p; | ||
| 800 | xs_str *v; | ||
| 801 | char pid[64]; | ||
| 802 | |||
| 803 | /* build the [grand]parent list, moving up */ | ||
| 804 | strcpy(pid, id); | ||
| 805 | |||
| 806 | while (object_parent(pid, pid, sizeof(pid))) { | ||
| 807 | xs *m2 = NULL; | ||
| 808 | |||
| 809 | if (valid_status(timeline_get_by_md5(&snac, pid, &m2))) { | ||
| 810 | xs *st = mastoapi_status(&snac, m2); | ||
| 811 | anc = xs_list_append(anc, st); | ||
| 812 | } | ||
| 813 | else | ||
| 814 | break; | ||
| 815 | } | ||
| 816 | |||
| 817 | /* build the children list */ | ||
| 818 | xs *children = object_children(xs_dict_get(msg, "id")); | ||
| 819 | p = children; | ||
| 820 | while (xs_list_iter(&p, &v)) { | ||
| 821 | xs *m2 = NULL; | ||
| 822 | |||
| 823 | if (valid_status(timeline_get_by_md5(&snac, v, &m2))) { | ||
| 824 | xs *st = mastoapi_status(&snac, m2); | ||
| 825 | des = xs_list_append(des, st); | ||
| 826 | } | ||
| 827 | } | ||
| 828 | |||
| 829 | out = xs_dict_new(); | ||
| 830 | out = xs_dict_append(out, "ancestors", anc); | ||
| 831 | out = xs_dict_append(out, "descendants", des); | ||
| 797 | } | 832 | } |
| 798 | else | 833 | else |
| 799 | if (strcmp(op, "reblogged_by") == 0) { | 834 | if (strcmp(op, "reblogged_by") == 0) { |