summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorGravatar default2024-12-19 10:05:11 +0100
committerGravatar default2024-12-19 10:05:11 +0100
commit13d4fde316c8281e3100017b4b8eca4fc0dfc925 (patch)
treee82444e50f554e89e7eed812f30efabeb49ce5fd /format.c
parentMinor webfinger tweak. (diff)
downloadsnac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.gz
snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.tar.xz
snac2-13d4fde316c8281e3100017b4b8eca4fc0dfc925.zip
Avoid adding repeated attachments.
Diffstat (limited to 'format.c')
-rw-r--r--format.c52
1 files changed, 38 insertions, 14 deletions
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);