commit aa86357
default
·
2023-04-12 08:19:43 +0000 UTC
parent 5046531
Use the ctime instead of the published date in mastoapi_id().
1 files changed,
+8,
-19
+8,
-19
1@@ -403,26 +403,14 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
2 xs_str *mastoapi_id(const xs_dict *msg)
3 /* returns a somewhat Mastodon-compatible status id */
4 {
5- char tmp[15] = "";
6- int n = 0;
7- const char *id = xs_dict_get(msg, "id");
8- const char *published = xs_dict_get(msg, "published");
9-
10- if (!xs_is_null(published)) {
11- /* transfer all numbers from the published date */
12- while (*published && n < sizeof(tmp) - 1) {
13- if (*published >= '0' && *published <= '9')
14- tmp[n++] = *published;
15- published++;
16- }
17- tmp[n] = '\0';
18- }
19-
20- xs *md5 = xs_md5_hex(id, strlen(id));
21+ const char *id = xs_dict_get(msg, "id");
22+ xs *md5 = xs_md5_hex(id, strlen(id));
23
24- return xs_str_cat(xs_str_new(tmp), md5);
25+ return xs_fmt("%10.0f%s", object_ctime_by_md5(md5), md5);
26 }
27
28+#define MID_TO_MD5(id) (id + 10)
29+
30
31 xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
32 /* converts an ActivityPub note to a Mastodon status */
33@@ -867,7 +855,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
34 xs *out = NULL;
35
36 /* skip the fake part of the id (the date) */
37- id += 14;
38+ id = MID_TO_MD5(id);
39
40 if (valid_status(timeline_get_by_md5(&snac, id, &msg))) {
41 if (op == NULL) {
42@@ -900,6 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
43 /* build the children list */
44 xs *children = object_children(xs_dict_get(msg, "id"));
45 p = children;
46+
47 while (xs_list_iter(&p, &v)) {
48 xs *m2 = NULL;
49
50@@ -1034,7 +1023,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
51 xs *out = NULL;
52
53 /* skip the fake part of the id (the date) */
54- mid += 14;
55+ mid = MID_TO_MD5(mid);
56
57 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) {
58 char *id = xs_dict_get(msg, "id");