diff options
author | default <nobody@localhost> | 2023-08-20 16:03:46 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-08-20 16:03:46 +0200 |
commit | cf0aa96a3533fb521f76d17230496613d5e6deee (patch) | |
tree | ef7e5a30cfecea931e830893434bca540630cd36 | |
parent | b9f4bea0c9ba5f4cd60843a7ee5f93bc1658d613 (diff) |
mastoapi: some tweaks for posts from lemmy.
-rw-r--r-- | mastoapi.c | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -669,10 +669,16 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) const char *name = xs_dict_get(msg, "name"); xs *s1 = NULL; - if (name) + if (name && content) s1 = xs_fmt("%s<br><br>%s", name, content); else + if (name) + s1 = xs_dup(name); + else + if (content) s1 = xs_dup(content); + else + s1 = xs_str_new(NULL); st = xs_dict_append(st, "content", s1); } @@ -716,6 +722,22 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) if (xs_is_null(mtype)) mtype = xs_dict_get(aobj, "type"); + const char *url = xs_dict_get(aobj, "url"); + if (xs_is_null(url)) + url = xs_dict_get(aobj, "href"); + if (xs_is_null(url)) + continue; + + /* if it's a plain Link, check if it can be "rewritten" */ + if (xs_list_len(attr_list) < 2 && strcmp(mtype, "Link") == 0) { + const char *mt = xs_mime_by_ext(url); + + if (xs_startswith(mt, "image/") || + xs_startswith(mt, "audio/") || + xs_startswith(mt, "video/")) + mtype = mt; + } + if (!xs_is_null(mtype)) { if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") || strcmp(mtype, "Image") == 0) { @@ -724,9 +746,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) matte = xs_dict_append(matte, "id", matteid); matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image"); - matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); - matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); - matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); + matte = xs_dict_append(matte, "url", url); + matte = xs_dict_append(matte, "preview_url", url); + matte = xs_dict_append(matte, "remote_url", url); const char *name = xs_dict_get(aobj, "name"); if (xs_is_null(name)) |