commit 2d4860d
default
·
2024-01-24 18:58:51 +0000 UTC
parent 5b3a2fb
Use get_attachments() in mastoapi_status().
1 files changed,
+23,
-57
+23,
-57
1@@ -768,72 +768,38 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
2 st = xs_dict_append(st, "spoiler_text", tmp);
3
4 /* create the list of attachments */
5- xs *matt = xs_list_new();
6- xs_list *att = xs_dict_get(msg, "attachment");
7- xs_str *aobj;
8- xs *attr_list = NULL;
9-
10- if (xs_type(att) == XSTYPE_DICT) {
11- attr_list = xs_list_new();
12- attr_list = xs_list_append(attr_list, att);
13- }
14- else
15- if (xs_type(att) == XSTYPE_LIST)
16- attr_list = xs_dup(att);
17- else
18- attr_list = xs_list_new();
19-
20- /* if it has an image, add it as an attachment */
21- xs_dict *image = xs_dict_get(msg, "image");
22- if (!xs_is_null(image))
23- attr_list = xs_list_append(attr_list, image);
24-
25- att = attr_list;
26- while (xs_list_iter(&att, &aobj)) {
27- const char *mtype = xs_dict_get(aobj, "mediaType");
28- if (xs_is_null(mtype))
29- mtype = xs_dict_get(aobj, "type");
30-
31- const char *url = xs_dict_get(aobj, "url");
32- if (xs_is_null(url))
33- url = xs_dict_get(aobj, "href");
34- if (xs_is_null(url))
35- continue;
36-
37- /* if it's a plain Link, check if it can be "rewritten" */
38- if (xs_list_len(attr_list) < 2 && strcmp(mtype, "Link") == 0) {
39- const char *mt = xs_mime_by_ext(url);
40-
41- if (xs_startswith(mt, "image/") ||
42- xs_startswith(mt, "audio/") ||
43- xs_startswith(mt, "video/"))
44- mtype = mt;
45- }
46+ xs *attach = get_attachments(msg);
47+
48+ {
49+ xs_list *p = attach;
50+ xs_dict *v;
51
52- if (!xs_is_null(mtype)) {
53- if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") ||
54- strcmp(mtype, "Image") == 0 || strcmp(mtype, "Document") == 0) {
55+ xs *matt = xs_list_new();
56+
57+ while (xs_list_iter(&p, &v)) {
58+ char *type = xs_dict_get(v, "type");
59+ char *href = xs_dict_get(v, "href");
60+ char *name = xs_dict_get(v, "name");
61+
62+ if (xs_match(type, "image/*|video/*|Image|Video")) { /* */
63 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
64- xs *matte = xs_dict_new();
65
66- matte = xs_dict_append(matte, "id", matteid);
67- matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image");
68- matte = xs_dict_append(matte, "url", url);
69- matte = xs_dict_append(matte, "preview_url", url);
70- matte = xs_dict_append(matte, "remote_url", url);
71+ xs *d = xs_dict_new();
72
73- const char *name = xs_dict_get(aobj, "name");
74- if (xs_is_null(name))
75- name = "";
76+ d = xs_dict_append(d, "id", matteid);
77+ d = xs_dict_append(d, "url", href);
78+ d = xs_dict_append(d, "preview_url", href);
79+ d = xs_dict_append(d, "remote_url", href);
80+ d = xs_dict_append(d, "description", name);
81
82- matte = xs_dict_append(matte, "description", name);
83+ d = xs_dict_append(d, "type", (*type == 'v' || *type == 'V') ? "video" : "image");
84
85- matt = xs_list_append(matt, matte);
86+ matt = xs_list_append(matt, d);
87 }
88 }
89- }
90
91- st = xs_dict_append(st, "media_attachments", matt);
92+ st = xs_dict_append(st, "media_attachments", matt);
93+ }
94
95 {
96 xs *ml = xs_list_new();