If an emoji in emojis.json is an URL to an image, it's stored in the tag list.

This commit is contained in:
default 2024-03-25 16:15:09 +01:00
parent bc752b7d67
commit adf0a13992
6 changed files with 34 additions and 9 deletions

View File

@ -1190,7 +1190,7 @@ xs_dict *msg_actor(snac *snac)
msg = xs_dict_set(msg, "preferredUsername", snac->uid);
msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published"));
xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL);
xs *f_bio_2 = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL, NULL);
f_bio = process_tags(snac, f_bio_2, &tags);
msg = xs_dict_set(msg, "summary", f_bio);
msg = xs_dict_set(msg, "tag", tags);
@ -1398,7 +1398,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
}
/* format the content */
fc2 = not_really_markdown(content, &atls);
fc2 = not_really_markdown(content, &atls, &tag);
if (in_reply_to != NULL && *in_reply_to) {
xs *p_msg = NULL;

View File

@ -6,6 +6,7 @@
#include "xs_mime.h"
#include "xs_html.h"
#include "xs_json.h"
#include "xs_time.h"
#include "snac.h"
@ -140,7 +141,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
}
xs_str *not_really_markdown(const char *content, xs_list **attach)
xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag)
/* formats a content using some Markdown rules */
{
xs_str *s = xs_str_new(NULL);
@ -229,7 +230,31 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
char *k, *v;
while (xs_dict_next(d, &k, &v, &c)) {
s = xs_replace_i(s, k, v);
const char *t = NULL;
/* is it an URL to an image? */
if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) {
if (tag) {
/* add the emoji to the tag list */
xs *e = xs_dict_new();
xs *i = xs_dict_new();
xs *u = xs_str_utctime(0, ISO_DATE_SPEC);
e = xs_dict_append(e, "id", v);
e = xs_dict_append(e, "type", "Emoji");
e = xs_dict_append(e, "name", k);
e = xs_dict_append(e, "updated", u);
i = xs_dict_append(i, "type", "Image");
i = xs_dict_append(i, "mediaType", t);
i = xs_dict_append(i, "url", v);
e = xs_dict_append(e, "icon", i);
*tag = xs_list_append(*tag, e);
}
}
else
s = xs_replace_i(s, k, v);
}
}

4
html.c
View File

@ -775,7 +775,7 @@ static xs_html *html_user_body(snac *user, int read_only)
if (read_only) {
xs *es1 = encode_html(xs_dict_get(user->config, "bio"));
xs *bio1 = not_really_markdown(es1, NULL);
xs *bio1 = not_really_markdown(es1, NULL, NULL);
xs *tags = xs_list_new();
xs *bio2 = process_tags(user, bio1, &tags);
@ -2657,7 +2657,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
return 403;
xs *elems = timeline_simple_list(&snac, "public", 0, 20);
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL, NULL);
xs *rss_title = xs_fmt("%s (@%s@%s)",
xs_dict_get(snac.config, "name"),

2
main.c
View File

@ -98,7 +98,7 @@ int main(int argc, char *argv[])
if (strcmp(cmd, "markdown") == 0) { /** **/
/* undocumented, for testing only */
xs *c = xs_readall(stdin);
xs *fc = not_really_markdown(c, NULL);
xs *fc = not_really_markdown(c, NULL, NULL);
printf("<html>\n%s\n</html>\n", fc);
return 0;

View File

@ -2717,7 +2717,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) {
const char *content = xs_dict_get(args, "status");
xs *atls = xs_list_new();
xs *f_content = not_really_markdown(content, &atls);
xs *f_content = not_really_markdown(content, &atls, NULL);
/* replace fields with new content */
msg = xs_dict_set(msg, "sourceContent", content);

2
snac.h
View File

@ -305,7 +305,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype);
xs_dict *emojis(void);
xs_str *not_really_markdown(const char *content, xs_list **attach);
xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
xs_str *sanitize(const char *content);
xs_str *encode_html(const char *str);