commit ea49eba
default
·
2023-04-10 08:23:14 +0000 UTC
parent 429be77
More mastoapi timeline work.
1 files changed,
+37,
-11
+37,
-11
1@@ -440,7 +440,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 /* the private timeline */
3 if (logged_in) {
4 const char *max_id = xs_dict_get(args, "max_id");
5-// const char *since_id = xs_dict_get(args, "since_id");
6+ const char *since_id = xs_dict_get(args, "since_id");
7 // const char *min_id = xs_dict_get(args, "min_id");
8 const char *limit_s = xs_dict_get(args, "limit");
9 int limit = 20;
10@@ -449,7 +449,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
11 if (!xs_is_null(limit_s))
12 limit = atoi(limit_s);
13
14- xs *timeline = timeline_list(&snac, "private", 0, XS_ALL);
15+ xs *timeline = timeline_simple_list(&snac, "private", 0, XS_ALL);
16
17 xs *out = xs_list_new();
18 xs_list *p = timeline;
19@@ -466,11 +466,17 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
20 continue;
21 }
22
23+ /* only returns entries newer than since_id */
24+ if (since_id) {
25+ if (strcmp(v, since_id) == 0)
26+ break;
27+ }
28+
29 /* get the entry */
30 if (!valid_status(timeline_get_by_md5(&snac, v, &msg)))
31 continue;
32
33- /* discard not-Notes */
34+ /* discard non-Notes */
35 if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
36 continue;
37
38@@ -481,6 +487,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
39 if (actor == NULL)
40 continue;
41
42+ /** shave the yak converting an ActivityPub Note to a Mastodon status **/
43+
44 xs *acct = xs_dict_new();
45
46 const char *display_name = xs_dict_get(actor, "name");
47@@ -521,10 +529,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
48
49 st = xs_dict_append(st, "id", v);
50 st = xs_dict_append(st, "uri", id);
51+ st = xs_dict_append(st, "url", id);
52 st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published"));
53 st = xs_dict_append(st, "account", acct);
54 st = xs_dict_append(st, "content", xs_dict_get(msg, "content"));
55- st = xs_dict_append(st, "visibility", "public");
56+
57+ st = xs_dict_append(st, "visibility",
58+ is_msg_public(&snac, msg) ? "public" : "private");
59
60 tmp = xs_dict_get(msg, "sensitive");
61 if (xs_is_null(tmp))
62@@ -568,14 +579,29 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
63
64 st = xs_dict_append(st, "replies_count", ixc);
65
66- st = xs_dict_append(st, "url", id);
67-
68- st = xs_dict_append(st, "in_reply_to_id", n);
69- st = xs_dict_append(st, "in_reply_to_account_id", n);
70- st = xs_dict_append(st, "reblog", n);
71- st = xs_dict_append(st, "poll", n);
72- st = xs_dict_append(st, "card", n);
73+ tmp = xs_dict_get(msg, "inReplyTo");
74+ if (xs_is_null(tmp)) {
75+ st = xs_dict_append(st, "in_reply_to_id", n);
76+ st = xs_dict_append(st, "in_reply_to_account_id", n);
77+ }
78+ else {
79+ xs *irt_md5 = xs_md5_hex(tmp, strlen(tmp));
80+ st = xs_dict_append(st, "in_reply_to_id", irt_md5);
81+
82+ xs *irto = NULL;
83+ char *at = NULL;
84+ if (valid_status(object_get(tmp, &irto)) &&
85+ !xs_is_null(at = xs_dict_get(irto, "attributedTo"))) {
86+ xs *at_md5 = xs_md5_hex(at, strlen(at));
87+ st = xs_dict_append(st, "in_reply_to_account_id", at_md5);
88+ }
89+ else
90+ st = xs_dict_append(st, "in_reply_to_account_id", n);
91+ }
92
93+ st = xs_dict_append(st, "reblog", n);
94+ st = xs_dict_append(st, "poll", n);
95+ st = xs_dict_append(st, "card", n);
96 st = xs_dict_append(st, "language", n);
97
98 tmp = xs_dict_get(msg, "sourceContent");