Added support for like and boost lists.

This commit is contained in:
default 2023-04-12 15:28:43 +02:00
parent 0184297dce
commit ed957b4646

View File

@ -412,19 +412,10 @@ xs_str *mastoapi_id(const xs_dict *msg)
#define MID_TO_MD5(id) (id + 10) #define MID_TO_MD5(id) (id + 10)
xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs_dict *mastoapi_account(snac *snac, const xs_dict *actor)
/* converts an ActivityPub note to a Mastodon status */ /* converts an ActivityPub actor to a Mastodon account */
{ {
xs *actor = NULL; xs_dict *acct = xs_dict_new();
actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
/* if the author is not here, discard */
if (actor == NULL)
return NULL;
/** shave the yak converting an ActivityPub Note to a Mastodon status **/
xs *acct = xs_dict_new();
const char *display_name = xs_dict_get(actor, "name"); const char *display_name = xs_dict_get(actor, "name");
if (xs_is_null(display_name) || *display_name == '\0') if (xs_is_null(display_name) || *display_name == '\0')
@ -454,6 +445,24 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
acct = xs_dict_append(acct, "avatar", avatar); acct = xs_dict_append(acct, "avatar", avatar);
return acct;
}
xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
/* converts an ActivityPub note to a Mastodon status */
{
xs *actor = NULL;
actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
/* if the author is not here, discard */
if (actor == NULL)
return NULL;
xs *acct = mastoapi_account(snac, actor);
/** shave the yak converting an ActivityPub Note to a Mastodon status **/
xs *f = xs_val_new(XSTYPE_FALSE); xs *f = xs_val_new(XSTYPE_FALSE);
xs *t = xs_val_new(XSTYPE_TRUE); xs *t = xs_val_new(XSTYPE_TRUE);
xs *n = xs_val_new(XSTYPE_NULL); xs *n = xs_val_new(XSTYPE_NULL);
@ -462,8 +471,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
xs *ixc = NULL; xs *ixc = NULL;
char *tmp; char *tmp;
id = xs_dict_get(msg, "id"); char *id = xs_dict_get(msg, "id");
xs *mid = mastoapi_id(msg); xs *mid = mastoapi_id(msg);
xs_dict *st = xs_dict_new(); xs_dict *st = xs_dict_new();
@ -916,12 +925,30 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
out = xs_dict_append(out, "descendants", des); out = xs_dict_append(out, "descendants", des);
} }
else else
if (strcmp(op, "reblogged_by") == 0) { if (strcmp(op, "reblogged_by") == 0 ||
/* return the list of boosts */ strcmp(op, "favourited_by") == 0) {
} /* return the list of likes or boosts */
else out = xs_list_new();
if (strcmp(op, "favourited_by") == 0) {
/* return the list of likes */ xs *l = NULL;
if (op[0] == 'r')
l = object_announces(xs_dict_get(msg, "id"));
else
l = object_likes(xs_dict_get(msg, "id"));
xs_list *p = l;
xs_str *v;
while (xs_list_iter(&p, &v)) {
xs *actor2 = NULL;
if (valid_status(object_get_by_md5(v, &actor2))) {
xs *acct2 = mastoapi_account(&snac, actor2);
out = xs_list_append(out, acct2);
}
}
} }
} }
else else