summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastoapi.c67
1 files changed, 47 insertions, 20 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 94c29d1..abdce34 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -412,19 +412,10 @@ xs_str *mastoapi_id(const xs_dict *msg)
412#define MID_TO_MD5(id) (id + 10) 412#define MID_TO_MD5(id) (id + 10)
413 413
414 414
415xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) 415xs_dict *mastoapi_account(snac *snac, const xs_dict *actor)
416/* converts an ActivityPub note to a Mastodon status */ 416/* converts an ActivityPub actor to a Mastodon account */
417{ 417{
418 xs *actor = NULL; 418 xs_dict *acct = xs_dict_new();
419 actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
420
421 /* if the author is not here, discard */
422 if (actor == NULL)
423 return NULL;
424
425 /** shave the yak converting an ActivityPub Note to a Mastodon status **/
426
427 xs *acct = xs_dict_new();
428 419
429 const char *display_name = xs_dict_get(actor, "name"); 420 const char *display_name = xs_dict_get(actor, "name");
430 if (xs_is_null(display_name) || *display_name == '\0') 421 if (xs_is_null(display_name) || *display_name == '\0')
@@ -454,6 +445,24 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
454 445
455 acct = xs_dict_append(acct, "avatar", avatar); 446 acct = xs_dict_append(acct, "avatar", avatar);
456 447
448 return acct;
449}
450
451
452xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
453/* converts an ActivityPub note to a Mastodon status */
454{
455 xs *actor = NULL;
456 actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
457
458 /* if the author is not here, discard */
459 if (actor == NULL)
460 return NULL;
461
462 xs *acct = mastoapi_account(snac, actor);
463
464 /** shave the yak converting an ActivityPub Note to a Mastodon status **/
465
457 xs *f = xs_val_new(XSTYPE_FALSE); 466 xs *f = xs_val_new(XSTYPE_FALSE);
458 xs *t = xs_val_new(XSTYPE_TRUE); 467 xs *t = xs_val_new(XSTYPE_TRUE);
459 xs *n = xs_val_new(XSTYPE_NULL); 468 xs *n = xs_val_new(XSTYPE_NULL);
@@ -462,8 +471,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
462 xs *ixc = NULL; 471 xs *ixc = NULL;
463 472
464 char *tmp; 473 char *tmp;
465 id = xs_dict_get(msg, "id"); 474 char *id = xs_dict_get(msg, "id");
466 xs *mid = mastoapi_id(msg); 475 xs *mid = mastoapi_id(msg);
467 476
468 xs_dict *st = xs_dict_new(); 477 xs_dict *st = xs_dict_new();
469 478
@@ -916,12 +925,30 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
916 out = xs_dict_append(out, "descendants", des); 925 out = xs_dict_append(out, "descendants", des);
917 } 926 }
918 else 927 else
919 if (strcmp(op, "reblogged_by") == 0) { 928 if (strcmp(op, "reblogged_by") == 0 ||
920 /* return the list of boosts */ 929 strcmp(op, "favourited_by") == 0) {
921 } 930 /* return the list of likes or boosts */
922 else 931 out = xs_list_new();
923 if (strcmp(op, "favourited_by") == 0) { 932
924 /* return the list of likes */ 933 xs *l = NULL;
934
935 if (op[0] == 'r')
936 l = object_announces(xs_dict_get(msg, "id"));
937 else
938 l = object_likes(xs_dict_get(msg, "id"));
939
940 xs_list *p = l;
941 xs_str *v;
942
943 while (xs_list_iter(&p, &v)) {
944 xs *actor2 = NULL;
945
946 if (valid_status(object_get_by_md5(v, &actor2))) {
947 xs *acct2 = mastoapi_account(&snac, actor2);
948
949 out = xs_list_append(out, acct2);
950 }
951 }
925 } 952 }
926 } 953 }
927 else 954 else