From e251c61382d4cd39ed89876a37962acab1122f84 Mon Sep 17 00:00:00 2001 From: green Date: Tue, 1 Apr 2025 23:08:48 +0200 Subject: allow emoji urls with no extension --- format.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'format.c') diff --git a/format.c b/format.c index b2b585d..43dd638 100644 --- a/format.c +++ b/format.c @@ -385,7 +385,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag 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 (xs_startswith(v, "https:/" "/") && + (xs_startswith((t = xs_mime_by_ext(v)), "image/") || strrchr(v, '.') == NULL)) { if (tag && xs_str_in(s, k) != -1) { /* add the emoji to the tag list */ xs *e = xs_dict_new(); -- cgit v1.2.3 From 15100ad81941c967ce34cc7534bf9b6d7b585e91 Mon Sep 17 00:00:00 2001 From: green Date: Tue, 1 Apr 2025 23:12:21 +0200 Subject: check the extension in a different way --- format.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 43dd638..1bb2cf1 100644 --- a/format.c +++ b/format.c @@ -10,6 +10,7 @@ #include "xs_match.h" #include "snac.h" +#include /* emoticons, people laughing and such */ const char *smileys[] = { @@ -382,11 +383,11 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag const char *k, *v; while (xs_dict_next(d, &k, &v, &c)) { - const char *t = NULL; + const char *t = xs_mime_by_ext(v); /* is it an URL to an image? */ if (xs_startswith(v, "https:/" "/") && - (xs_startswith((t = xs_mime_by_ext(v)), "image/") || strrchr(v, '.') == NULL)) { + (xs_startswith(t, "image/") || strcmp(t, "application/octet-stream") == 0)) { if (tag && xs_str_in(s, k) != -1) { /* add the emoji to the tag list */ xs *e = xs_dict_new(); -- cgit v1.2.3 From 0c03e6c9d9a6b65fede94cc9eab34a05746f8d5e Mon Sep 17 00:00:00 2001 From: green Date: Sun, 13 Apr 2025 15:44:24 +0200 Subject: cleaned up old changes and outdated comments --- format.c | 1 - 1 file changed, 1 deletion(-) (limited to 'format.c') diff --git a/format.c b/format.c index 1bb2cf1..3089955 100644 --- a/format.c +++ b/format.c @@ -10,7 +10,6 @@ #include "xs_match.h" #include "snac.h" -#include /* emoticons, people laughing and such */ const char *smileys[] = { -- cgit v1.2.3 From 6878e3fc939c3dac9853a3a33bfab7a289c7648b Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 3 May 2025 18:55:10 +0200 Subject: Also add direct and markdown links in posts as attachments. --- format.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index b2b585d..525edb0 100644 --- a/format.c +++ b/format.c @@ -154,10 +154,22 @@ static xs_str *format_line(const char *line, xs_list **attach) xs *l = xs_split_n(w, "](", 1); if (xs_list_len(l) == 2) { - xs *link = xs_fmt("%s", - xs_list_get(l, 1), xs_list_get(l, 0)); + const char *name = xs_list_get(l, 0); + const char *url = xs_list_get(l, 1); + + xs *link = xs_fmt("%s", url, name); s = xs_str_cat(s, link); + + /* also add the link as an attachment */ + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", url); + d = xs_dict_append(d, "name", name); + d = xs_dict_append(d, "type", "Link"); + + *attach = xs_list_append(*attach, d); } else s = xs_str_cat(s, v); @@ -208,6 +220,7 @@ static xs_str *format_line(const char *line, xs_list **attach) } else if (xs_str_in(v, ":/" "/") != -1) { + /* direct URLs in the post body */ xs *u = xs_replace_i(xs_replace(v, "#", "#"), "@", "@"); xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)"); @@ -240,6 +253,16 @@ static xs_str *format_line(const char *line, xs_list **attach) else { xs *s1 = xs_fmt("%s", v2, u); s = xs_str_cat(s, s1); + + /* also add the link as an attachment */ + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", v2); + d = xs_dict_append(d, "name", ""); + d = xs_dict_append(d, "type", "Link"); + + *attach = xs_list_append(*attach, d); } } else -- cgit v1.2.3 From 7f38c744dc6ead2ccac83ae979c99ef521aad23a Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 3 May 2025 19:03:51 +0200 Subject: Revert adding links as attachments. --- format.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 525edb0..f5c66da 100644 --- a/format.c +++ b/format.c @@ -160,16 +160,6 @@ static xs_str *format_line(const char *line, xs_list **attach) xs *link = xs_fmt("%s", url, name); s = xs_str_cat(s, link); - - /* also add the link as an attachment */ - xs *d = xs_dict_new(); - - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", url); - d = xs_dict_append(d, "name", name); - d = xs_dict_append(d, "type", "Link"); - - *attach = xs_list_append(*attach, d); } else s = xs_str_cat(s, v); @@ -253,16 +243,6 @@ static xs_str *format_line(const char *line, xs_list **attach) else { xs *s1 = xs_fmt("%s", v2, u); s = xs_str_cat(s, s1); - - /* also add the link as an attachment */ - xs *d = xs_dict_new(); - - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", v2); - d = xs_dict_append(d, "name", ""); - d = xs_dict_append(d, "type", "Link"); - - *attach = xs_list_append(*attach, d); } } else -- cgit v1.2.3 From 90e9a0aeef500f11528a326ee676caa7da5ef2db Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 3 May 2025 19:31:05 +0200 Subject: Added back again links as attachments. --- format.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'format.c') diff --git a/format.c b/format.c index f5c66da..525edb0 100644 --- a/format.c +++ b/format.c @@ -160,6 +160,16 @@ static xs_str *format_line(const char *line, xs_list **attach) xs *link = xs_fmt("%s", url, name); s = xs_str_cat(s, link); + + /* also add the link as an attachment */ + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", url); + d = xs_dict_append(d, "name", name); + d = xs_dict_append(d, "type", "Link"); + + *attach = xs_list_append(*attach, d); } else s = xs_str_cat(s, v); @@ -243,6 +253,16 @@ static xs_str *format_line(const char *line, xs_list **attach) else { xs *s1 = xs_fmt("%s", v2, u); s = xs_str_cat(s, s1); + + /* also add the link as an attachment */ + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", v2); + d = xs_dict_append(d, "name", ""); + d = xs_dict_append(d, "type", "Link"); + + *attach = xs_list_append(*attach, d); } } else -- cgit v1.2.3 From 12107401ea2721edbfb8affacefb242409dd271f Mon Sep 17 00:00:00 2001 From: default Date: Tue, 6 May 2025 07:28:43 +0200 Subject: Fixed crash. --- format.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 862d766..b3764ef 100644 --- a/format.c +++ b/format.c @@ -161,15 +161,17 @@ static xs_str *format_line(const char *line, xs_list **attach) s = xs_str_cat(s, link); - /* also add the link as an attachment */ - xs *d = xs_dict_new(); + if (attach) { + /* also add the link as an attachment */ + xs *d = xs_dict_new(); - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", url); - d = xs_dict_append(d, "name", name); - d = xs_dict_append(d, "type", "Link"); + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", url); + d = xs_dict_append(d, "name", name); + d = xs_dict_append(d, "type", "Link"); - *attach = xs_list_append(*attach, d); + *attach = xs_list_append(*attach, d); + } } else s = xs_str_cat(s, v); @@ -254,15 +256,17 @@ static xs_str *format_line(const char *line, xs_list **attach) xs *s1 = xs_fmt("%s", v2, u); s = xs_str_cat(s, s1); - /* also add the link as an attachment */ - xs *d = xs_dict_new(); + if (attach) { + /* also add the link as an attachment */ + xs *d = xs_dict_new(); - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", v2); - d = xs_dict_append(d, "name", ""); - d = xs_dict_append(d, "type", "Link"); + d = xs_dict_append(d, "mediaType", "text/html"); + d = xs_dict_append(d, "url", v2); + d = xs_dict_append(d, "name", ""); + d = xs_dict_append(d, "type", "Link"); - *attach = xs_list_append(*attach, d); + *attach = xs_list_append(*attach, d); + } } } else -- cgit v1.2.3 From c166e05f7d3ba1efe9b16290bf3da2b06fdae8ea Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 9 May 2025 15:31:58 +0200 Subject: As they look ugly in some platforms, links are no longer shown as attachments. --- format.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index b3764ef..2f30a0d 100644 --- a/format.c +++ b/format.c @@ -160,18 +160,6 @@ static xs_str *format_line(const char *line, xs_list **attach) xs *link = xs_fmt("%s", url, name); s = xs_str_cat(s, link); - - if (attach) { - /* also add the link as an attachment */ - xs *d = xs_dict_new(); - - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", url); - d = xs_dict_append(d, "name", name); - d = xs_dict_append(d, "type", "Link"); - - *attach = xs_list_append(*attach, d); - } } else s = xs_str_cat(s, v); @@ -255,18 +243,6 @@ static xs_str *format_line(const char *line, xs_list **attach) else { xs *s1 = xs_fmt("%s", v2, u); s = xs_str_cat(s, s1); - - if (attach) { - /* also add the link as an attachment */ - xs *d = xs_dict_new(); - - d = xs_dict_append(d, "mediaType", "text/html"); - d = xs_dict_append(d, "url", v2); - d = xs_dict_append(d, "name", ""); - d = xs_dict_append(d, "type", "Link"); - - *attach = xs_list_append(*attach, d); - } } } else -- cgit v1.2.3