diff options
| author | 2024-12-19 10:05:11 +0100 | |
|---|---|---|
| committer | 2024-12-19 10:05:11 +0100 | |
| commit | 13d4fde316c8281e3100017b4b8eca4fc0dfc925 (patch) | |
| tree | e82444e50f554e89e7eed812f30efabeb49ce5fd /activitypub.c | |
| parent | Minor webfinger tweak. (diff) | |
| download | snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.gz snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.xz snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.zip | |
Avoid adding repeated attachments.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 29 |
1 files changed, 20 insertions, 9 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 | ||