diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 45 |
1 files changed, 21 insertions, 24 deletions
| @@ -1153,16 +1153,31 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1153 | s = xs_str_cat(s, "\n"); | 1153 | s = xs_str_cat(s, "\n"); |
| 1154 | 1154 | ||
| 1155 | /* add the attachments */ | 1155 | /* add the attachments */ |
| 1156 | xs_list *attach = xs_dict_get(msg, "attachment"); | 1156 | v = xs_dict_get(msg, "attachment"); |
| 1157 | xs_dict *image = xs_dict_get(msg, "image"); | ||
| 1158 | 1157 | ||
| 1159 | if (!xs_is_null(attach) || !xs_is_null(image)) { /** **/ | 1158 | if (!xs_is_null(v)) { /** attachments **/ |
| 1160 | char *v; | 1159 | xs *attach = NULL; |
| 1160 | |||
| 1161 | /* ensure it's a list */ | ||
| 1162 | if (xs_type(v) == XSTYPE_DICT) { | ||
| 1163 | attach = xs_list_new(); | ||
| 1164 | attach = xs_list_append(attach, v); | ||
| 1165 | } | ||
| 1166 | else | ||
| 1167 | attach = xs_dup(v); | ||
| 1168 | |||
| 1169 | /* does the message have an image? */ | ||
| 1170 | if (xs_type(v = xs_dict_get(msg, "image")) == XSTYPE_DICT) { | ||
| 1171 | /* add it to the attachment list */ | ||
| 1172 | attach = xs_list_append(attach, v); | ||
| 1173 | } | ||
| 1161 | 1174 | ||
| 1162 | /* make custom css for attachments easier */ | 1175 | /* make custom css for attachments easier */ |
| 1163 | s = xs_str_cat(s, "<p class=\"snac-content-attachments\">\n"); | 1176 | s = xs_str_cat(s, "<p class=\"snac-content-attachments\">\n"); |
| 1164 | 1177 | ||
| 1165 | while (xs_list_iter(&attach, &v)) { | 1178 | xs_list *p = attach; |
| 1179 | |||
| 1180 | while (xs_list_iter(&p, &v)) { | ||
| 1166 | const char *t = xs_dict_get(v, "mediaType"); | 1181 | const char *t = xs_dict_get(v, "mediaType"); |
| 1167 | 1182 | ||
| 1168 | if (xs_is_null(t)) | 1183 | if (xs_is_null(t)) |
| @@ -1171,7 +1186,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1171 | if (xs_is_null(t)) | 1186 | if (xs_is_null(t)) |
| 1172 | continue; | 1187 | continue; |
| 1173 | 1188 | ||
| 1174 | if (xs_startswith(t, "image/")) { | 1189 | if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) { |
| 1175 | char *url = xs_dict_get(v, "url"); | 1190 | char *url = xs_dict_get(v, "url"); |
| 1176 | char *name = xs_dict_get(v, "name"); | 1191 | char *name = xs_dict_get(v, "name"); |
| 1177 | 1192 | ||
| @@ -1248,24 +1263,6 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1248 | } | 1263 | } |
| 1249 | } | 1264 | } |
| 1250 | 1265 | ||
| 1251 | /* if the message has an image, add it */ | ||
| 1252 | if (!xs_is_null(image)) { | ||
| 1253 | if (!xs_is_null(image = xs_dict_get(image, "url"))) { | ||
| 1254 | xs *es1; | ||
| 1255 | if (!xs_is_null(v = xs_dict_get(msg, "name"))) | ||
| 1256 | es1 = encode_html(v); | ||
| 1257 | else | ||
| 1258 | es1 = xs_str_new(NULL); | ||
| 1259 | |||
| 1260 | xs *s1 = xs_fmt( | ||
| 1261 | "<a href=\"%s\" target=\"_blank\">" | ||
| 1262 | "<img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n", | ||
| 1263 | image, image, es1, es1); | ||
| 1264 | |||
| 1265 | s = xs_str_cat(s, s1); | ||
| 1266 | } | ||
| 1267 | } | ||
| 1268 | |||
| 1269 | s = xs_str_cat(s, "</p>\n"); | 1266 | s = xs_str_cat(s, "</p>\n"); |
| 1270 | } | 1267 | } |
| 1271 | 1268 | ||