diff options
author | default <nobody@localhost> | 2023-04-12 10:19:43 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-04-12 10:19:43 +0200 |
commit | aa86357237822b4b988fb24e05c36d12308aa2e0 (patch) | |
tree | d67184f4cfe396eb5654e56ebc4d52cee2ea26e5 /mastoapi.c | |
parent | 5046531d43525cfd1ce16aeae840d8a33d2fb9c7 (diff) |
Use the ctime instead of the published date in mastoapi_id().
Diffstat (limited to 'mastoapi.c')
-rw-r--r-- | mastoapi.c | 27 |
1 files changed, 8 insertions, 19 deletions
@@ -403,26 +403,14 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, xs_str *mastoapi_id(const xs_dict *msg) /* returns a somewhat Mastodon-compatible status id */ { - char tmp[15] = ""; - int n = 0; - const char *id = xs_dict_get(msg, "id"); - const char *published = xs_dict_get(msg, "published"); - - if (!xs_is_null(published)) { - /* transfer all numbers from the published date */ - while (*published && n < sizeof(tmp) - 1) { - if (*published >= '0' && *published <= '9') - tmp[n++] = *published; - published++; - } - tmp[n] = '\0'; - } - - xs *md5 = xs_md5_hex(id, strlen(id)); + const char *id = xs_dict_get(msg, "id"); + xs *md5 = xs_md5_hex(id, strlen(id)); - return xs_str_cat(xs_str_new(tmp), md5); + return xs_fmt("%10.0f%s", object_ctime_by_md5(md5), md5); } +#define MID_TO_MD5(id) (id + 10) + xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) /* converts an ActivityPub note to a Mastodon status */ @@ -867,7 +855,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = NULL; /* skip the fake part of the id (the date) */ - id += 14; + id = MID_TO_MD5(id); if (valid_status(timeline_get_by_md5(&snac, id, &msg))) { if (op == NULL) { @@ -900,6 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* build the children list */ xs *children = object_children(xs_dict_get(msg, "id")); p = children; + while (xs_list_iter(&p, &v)) { xs *m2 = NULL; @@ -1034,7 +1023,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, xs *out = NULL; /* skip the fake part of the id (the date) */ - mid += 14; + mid = MID_TO_MD5(mid); if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { char *id = xs_dict_get(msg, "id"); |