diff options
| author | 2023-08-20 16:03:46 +0200 | |
|---|---|---|
| committer | 2023-08-20 16:03:46 +0200 | |
| commit | cf0aa96a3533fb521f76d17230496613d5e6deee (patch) | |
| tree | ef7e5a30cfecea931e830893434bca540630cd36 | |
| parent | Only use a Link as an attachment if there are no other. (diff) | |
| download | snac2-cf0aa96a3533fb521f76d17230496613d5e6deee.tar.gz snac2-cf0aa96a3533fb521f76d17230496613d5e6deee.tar.xz snac2-cf0aa96a3533fb521f76d17230496613d5e6deee.zip | |
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) | |||
| 669 | const char *name = xs_dict_get(msg, "name"); | 669 | const char *name = xs_dict_get(msg, "name"); |
| 670 | xs *s1 = NULL; | 670 | xs *s1 = NULL; |
| 671 | 671 | ||
| 672 | if (name) | 672 | if (name && content) |
| 673 | s1 = xs_fmt("%s<br><br>%s", name, content); | 673 | s1 = xs_fmt("%s<br><br>%s", name, content); |
| 674 | else | 674 | else |
| 675 | if (name) | ||
| 676 | s1 = xs_dup(name); | ||
| 677 | else | ||
| 678 | if (content) | ||
| 675 | s1 = xs_dup(content); | 679 | s1 = xs_dup(content); |
| 680 | else | ||
| 681 | s1 = xs_str_new(NULL); | ||
| 676 | 682 | ||
| 677 | st = xs_dict_append(st, "content", s1); | 683 | st = xs_dict_append(st, "content", s1); |
| 678 | } | 684 | } |
| @@ -716,6 +722,22 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 716 | if (xs_is_null(mtype)) | 722 | if (xs_is_null(mtype)) |
| 717 | mtype = xs_dict_get(aobj, "type"); | 723 | mtype = xs_dict_get(aobj, "type"); |
| 718 | 724 | ||
| 725 | const char *url = xs_dict_get(aobj, "url"); | ||
| 726 | if (xs_is_null(url)) | ||
| 727 | url = xs_dict_get(aobj, "href"); | ||
| 728 | if (xs_is_null(url)) | ||
| 729 | continue; | ||
| 730 | |||
| 731 | /* if it's a plain Link, check if it can be "rewritten" */ | ||
| 732 | if (xs_list_len(attr_list) < 2 && strcmp(mtype, "Link") == 0) { | ||
| 733 | const char *mt = xs_mime_by_ext(url); | ||
| 734 | |||
| 735 | if (xs_startswith(mt, "image/") || | ||
| 736 | xs_startswith(mt, "audio/") || | ||
| 737 | xs_startswith(mt, "video/")) | ||
| 738 | mtype = mt; | ||
| 739 | } | ||
| 740 | |||
| 719 | if (!xs_is_null(mtype)) { | 741 | if (!xs_is_null(mtype)) { |
| 720 | if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") || | 742 | if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") || |
| 721 | strcmp(mtype, "Image") == 0) { | 743 | strcmp(mtype, "Image") == 0) { |
| @@ -724,9 +746,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 724 | 746 | ||
| 725 | matte = xs_dict_append(matte, "id", matteid); | 747 | matte = xs_dict_append(matte, "id", matteid); |
| 726 | matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image"); | 748 | matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image"); |
| 727 | matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); | 749 | matte = xs_dict_append(matte, "url", url); |
| 728 | matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); | 750 | matte = xs_dict_append(matte, "preview_url", url); |
| 729 | matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); | 751 | matte = xs_dict_append(matte, "remote_url", url); |
| 730 | 752 | ||
| 731 | const char *name = xs_dict_get(aobj, "name"); | 753 | const char *name = xs_dict_get(aobj, "name"); |
| 732 | if (xs_is_null(name)) | 754 | if (xs_is_null(name)) |