summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-12-19 10:05:11 +0100
committerGravatar default2024-12-19 10:05:11 +0100
commit13d4fde316c8281e3100017b4b8eca4fc0dfc925 (patch)
treee82444e50f554e89e7eed812f30efabeb49ce5fd
parentMinor webfinger tweak. (diff)
downloadpenes-snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.gz
penes-snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.xz
penes-snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.zip
Avoid adding repeated attachments.
-rw-r--r--activitypub.c29
-rw-r--r--format.c52
2 files changed, 58 insertions, 23 deletions
diff --git a/activitypub.c b/activitypub.c
index 773df78..4d52efa 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1476,20 +1476,31 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
1476 1476
1477 /* create the attachment list, if there are any */ 1477 /* create the attachment list, if there are any */
1478 if (!xs_is_null(attach)) { 1478 if (!xs_is_null(attach)) {
1479 int c = 0; 1479 xs_list_foreach(attach, v) {
1480 while (xs_list_next(attach, &v, &c)) {
1481 xs *d = xs_dict_new();
1482 const char *url = xs_list_get(v, 0); 1480 const char *url = xs_list_get(v, 0);
1483 const char *alt = xs_list_get(v, 1); 1481 const char *alt = xs_list_get(v, 1);
1484 const char *mime = xs_mime_by_ext(url); 1482 const char *mime = xs_mime_by_ext(url);
1483 int add = 1;
1484
1485 /* check if it's already here */
1486 const xs_dict *ad;
1487 xs_list_foreach(atls, ad) {
1488 if (strcmp(xs_dict_get_def(ad, "url", ""), url) == 0) {
1489 add = 0;
1490 break;
1491 }
1492 }
1485 1493
1486 d = xs_dict_append(d, "mediaType", mime); 1494 if (add) {
1487 d = xs_dict_append(d, "url", url); 1495 xs *d = xs_dict_new();
1488 d = xs_dict_append(d, "name", alt); 1496 d = xs_dict_append(d, "mediaType", mime);
1489 d = xs_dict_append(d, "type", 1497 d = xs_dict_append(d, "url", url);
1490 xs_startswith(mime, "image/") ? "Image" : "Document"); 1498 d = xs_dict_append(d, "name", alt);
1499 d = xs_dict_append(d, "type",
1500 xs_startswith(mime, "image/") ? "Image" : "Document");
1491 1501
1492 atls = xs_list_append(atls, d); 1502 atls = xs_list_append(atls, d);
1503 }
1493 } 1504 }
1494 } 1505 }
1495 1506
diff --git a/format.c b/format.c
index d0b535d..12783ae 100644
--- a/format.c
+++ b/format.c
@@ -163,14 +163,26 @@ static xs_str *format_line(const char *line, xs_list **attach)
163 const char *mime = xs_mime_by_ext(img_url); 163 const char *mime = xs_mime_by_ext(img_url);
164 164
165 if (attach != NULL && xs_startswith(mime, "image/")) { 165 if (attach != NULL && xs_startswith(mime, "image/")) {
166 xs *d = xs_dict_new(); 166 const xs_dict *ad;
167 167 int add = 1;
168 d = xs_dict_append(d, "mediaType", mime); 168
169 d = xs_dict_append(d, "url", img_url); 169 xs_list_foreach(*attach, ad) {
170 d = xs_dict_append(d, "name", alt_text); 170 if (strcmp(xs_dict_get_def(ad, "url", ""), img_url) == 0) {
171 d = xs_dict_append(d, "type", "Image"); 171 add = 0;
172 172 break;
173 *attach = xs_list_append(*attach, d); 173 }
174 }
175
176 if (add) {
177 xs *d = xs_dict_new();
178
179 d = xs_dict_append(d, "mediaType", mime);
180 d = xs_dict_append(d, "url", img_url);
181 d = xs_dict_append(d, "name", alt_text);
182 d = xs_dict_append(d, "type", "Image");
183
184 *attach = xs_list_append(*attach, d);
185 }
174 } 186 }
175 else { 187 else {
176 xs *link = xs_fmt("<a href=\"%s\">%s</a>", img_url, alt_text); 188 xs *link = xs_fmt("<a href=\"%s\">%s</a>", img_url, alt_text);
@@ -191,14 +203,26 @@ static xs_str *format_line(const char *line, xs_list **attach)
191 203
192 if (attach != NULL && xs_startswith(mime, "image/")) { 204 if (attach != NULL && xs_startswith(mime, "image/")) {
193 /* if it's a link to an image, insert it as an attachment */ 205 /* if it's a link to an image, insert it as an attachment */
194 xs *d = xs_dict_new(); 206 const xs_dict *ad;
207 int add = 1;
208
209 xs_list_foreach(*attach, ad) {
210 if (strcmp(xs_dict_get_def(ad, "url", ""), v2) == 0) {
211 add = 0;
212 break;
213 }
214 }
195 215
196 d = xs_dict_append(d, "mediaType", mime); 216 if (add) {
197 d = xs_dict_append(d, "url", v2); 217 xs *d = xs_dict_new();
198 d = xs_dict_append(d, "name", ""); 218
199 d = xs_dict_append(d, "type", "Image"); 219 d = xs_dict_append(d, "mediaType", mime);
220 d = xs_dict_append(d, "url", v2);
221 d = xs_dict_append(d, "name", "");
222 d = xs_dict_append(d, "type", "Image");
200 223
201 *attach = xs_list_append(*attach, d); 224 *attach = xs_list_append(*attach, d);
225 }
202 } 226 }
203 else { 227 else {
204 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u); 228 xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);