summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-12 10:19:43 +0200
committerGravatar default2023-04-12 10:19:43 +0200
commitaa86357237822b4b988fb24e05c36d12308aa2e0 (patch)
treed67184f4cfe396eb5654e56ebc4d52cee2ea26e5
parentNew functions object_ctime() and object_ctime_by_md5(). (diff)
downloadpenes-snac2-aa86357237822b4b988fb24e05c36d12308aa2e0.tar.gz
penes-snac2-aa86357237822b4b988fb24e05c36d12308aa2e0.tar.xz
penes-snac2-aa86357237822b4b988fb24e05c36d12308aa2e0.zip
Use the ctime instead of the published date in mastoapi_id().
-rw-r--r--mastoapi.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/mastoapi.c b/mastoapi.c
index a75a38e..be1ba61 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -403,26 +403,14 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
403xs_str *mastoapi_id(const xs_dict *msg) 403xs_str *mastoapi_id(const xs_dict *msg)
404/* returns a somewhat Mastodon-compatible status id */ 404/* returns a somewhat Mastodon-compatible status id */
405{ 405{
406 char tmp[15] = ""; 406 const char *id = xs_dict_get(msg, "id");
407 int n = 0; 407 xs *md5 = xs_md5_hex(id, strlen(id));
408 const char *id = xs_dict_get(msg, "id");
409 const char *published = xs_dict_get(msg, "published");
410
411 if (!xs_is_null(published)) {
412 /* transfer all numbers from the published date */
413 while (*published && n < sizeof(tmp) - 1) {
414 if (*published >= '0' && *published <= '9')
415 tmp[n++] = *published;
416 published++;
417 }
418 tmp[n] = '\0';
419 }
420
421 xs *md5 = xs_md5_hex(id, strlen(id));
422 408
423 return xs_str_cat(xs_str_new(tmp), md5); 409 return xs_fmt("%10.0f%s", object_ctime_by_md5(md5), md5);
424} 410}
425 411
412#define MID_TO_MD5(id) (id + 10)
413
426 414
427xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) 415xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
428/* converts an ActivityPub note to a Mastodon status */ 416/* converts an ActivityPub note to a Mastodon status */
@@ -867,7 +855,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
867 xs *out = NULL; 855 xs *out = NULL;
868 856
869 /* skip the fake part of the id (the date) */ 857 /* skip the fake part of the id (the date) */
870 id += 14; 858 id = MID_TO_MD5(id);
871 859
872 if (valid_status(timeline_get_by_md5(&snac, id, &msg))) { 860 if (valid_status(timeline_get_by_md5(&snac, id, &msg))) {
873 if (op == NULL) { 861 if (op == NULL) {
@@ -900,6 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
900 /* build the children list */ 888 /* build the children list */
901 xs *children = object_children(xs_dict_get(msg, "id")); 889 xs *children = object_children(xs_dict_get(msg, "id"));
902 p = children; 890 p = children;
891
903 while (xs_list_iter(&p, &v)) { 892 while (xs_list_iter(&p, &v)) {
904 xs *m2 = NULL; 893 xs *m2 = NULL;
905 894
@@ -1034,7 +1023,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1034 xs *out = NULL; 1023 xs *out = NULL;
1035 1024
1036 /* skip the fake part of the id (the date) */ 1025 /* skip the fake part of the id (the date) */
1037 mid += 14; 1026 mid = MID_TO_MD5(mid);
1038 1027
1039 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { 1028 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) {
1040 char *id = xs_dict_get(msg, "id"); 1029 char *id = xs_dict_get(msg, "id");