diff options
| author | default <nobody@localhost> | 2024-12-19 10:05:11 +0100 |
|---|---|---|
| committer | default <nobody@localhost> | 2024-12-19 10:05:11 +0100 |
| commit | 13d4fde316c8281e3100017b4b8eca4fc0dfc925 (patch) | |
| tree | e82444e50f554e89e7eed812f30efabeb49ce5fd /activitypub.c | |
| parent | bde5748a6e52e6f124e708a64e95827d87c8850c (diff) | |
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, /* create the attachment list, if there are any */ if (!xs_is_null(attach)) { - int c = 0; - while (xs_list_next(attach, &v, &c)) { - xs *d = xs_dict_new(); + xs_list_foreach(attach, v) { const char *url = xs_list_get(v, 0); const char *alt = xs_list_get(v, 1); const char *mime = xs_mime_by_ext(url); + int add = 1; - d = xs_dict_append(d, "mediaType", mime); - d = xs_dict_append(d, "url", url); - d = xs_dict_append(d, "name", alt); - d = xs_dict_append(d, "type", - xs_startswith(mime, "image/") ? "Image" : "Document"); + /* check if it's already here */ + const xs_dict *ad; + xs_list_foreach(atls, ad) { + if (strcmp(xs_dict_get_def(ad, "url", ""), url) == 0) { + add = 0; + break; + } + } - atls = xs_list_append(atls, d); + if (add) { + xs *d = xs_dict_new(); + d = xs_dict_append(d, "mediaType", mime); + d = xs_dict_append(d, "url", url); + d = xs_dict_append(d, "name", alt); + d = xs_dict_append(d, "type", + xs_startswith(mime, "image/") ? "Image" : "Document"); + + atls = xs_list_append(atls, d); + } } } |