summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-04-11 19:59:02 +0200
committerdefault <nobody@localhost>2023-04-11 19:59:02 +0200
commitdf785849115e72f6a0e3dc694d2141ecf1fe16bb (patch)
treefd2b863785ee9db415856bf0f61b8d1843002fa0
parenta4051f7f3774ac6a1e25ebb81a13c455e735b862 (diff)
Added support for statuses/:id and statuses/:id/context.
-rw-r--r--mastoapi.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 3550264..c846223 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -789,11 +789,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (valid_status(timeline_get_by_md5(&snac, id, &msg))) {
if (op == NULL) {
/* return the status itself */
+ out = mastoapi_status(&snac, msg);
}
else
if (strcmp(op, "context") == 0) {
/* return ancestors and children */
- srv_debug(0, xs_fmt("mastoapi status: context requested for %s", id));
+ xs *anc = xs_list_new();
+ xs *des = xs_list_new();
+ xs_list *p;
+ xs_str *v;
+ char pid[64];
+
+ /* build the [grand]parent list, moving up */
+ strcpy(pid, id);
+
+ while (object_parent(pid, pid, sizeof(pid))) {
+ xs *m2 = NULL;
+
+ if (valid_status(timeline_get_by_md5(&snac, pid, &m2))) {
+ xs *st = mastoapi_status(&snac, m2);
+ anc = xs_list_append(anc, st);
+ }
+ else
+ break;
+ }
+
+ /* build the children list */
+ xs *children = object_children(xs_dict_get(msg, "id"));
+ p = children;
+ while (xs_list_iter(&p, &v)) {
+ xs *m2 = NULL;
+
+ if (valid_status(timeline_get_by_md5(&snac, v, &m2))) {
+ xs *st = mastoapi_status(&snac, m2);
+ des = xs_list_append(des, st);
+ }
+ }
+
+ out = xs_dict_new();
+ out = xs_dict_append(out, "ancestors", anc);
+ out = xs_dict_append(out, "descendants", des);
}
else
if (strcmp(op, "reblogged_by") == 0) {