From 9e9d740199e11ca79463f9f4df6f55f0e25cc1aa Mon Sep 17 00:00:00 2001 From: default Date: Mon, 10 Apr 2023 13:22:59 +0200 Subject: Added image attachments. --- mastoapi.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index bbdcff9..b223ce4 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -622,7 +622,31 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, st = xs_dict_append(st, "spoiler_text", tmp); - st = xs_dict_append(st, "media_attachments", el); + /* create the list of attachments */ + xs *matt = xs_list_new(); + xs_list *att = xs_dict_get(msg, "attachment"); + xs_str *aobj; + + while (xs_list_iter(&att, &aobj)) { + const char *mtype = xs_dict_get(aobj, "mediaType"); + + if (!xs_is_null(mtype) && xs_startswith(mtype, "image/")) { + xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt)); + xs *matte = xs_dict_new(); + + matte = xs_dict_append(matte, "id", matteid); + matte = xs_dict_append(matte, "type", "image"); + matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); + matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); + matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); + matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name")); + + matt = xs_list_append(matt, matte); + } + } + + st = xs_dict_append(st, "media_attachments", matt); + st = xs_dict_append(st, "mentions", el); st = xs_dict_append(st, "tags", el); st = xs_dict_append(st, "emojis", el); -- cgit v1.2.3