summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-01-24 19:58:51 +0100
committerGravatar default2024-01-24 19:58:51 +0100
commit2d4860d57ecdb07f7f9006328f6241676c34fe97 (patch)
tree187228acb21aa78afb3f2d0da3f46adb5073825c
parentUse get_attachments() in html_entry(). (diff)
downloadsnac2-2d4860d57ecdb07f7f9006328f6241676c34fe97.tar.gz
snac2-2d4860d57ecdb07f7f9006328f6241676c34fe97.tar.xz
snac2-2d4860d57ecdb07f7f9006328f6241676c34fe97.zip
Use get_attachments() in mastoapi_status().
-rw-r--r--mastoapi.c80
1 files changed, 23 insertions, 57 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 19db3cd..9f6c383 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -768,72 +768,38 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
768 st = xs_dict_append(st, "spoiler_text", tmp); 768 st = xs_dict_append(st, "spoiler_text", tmp);
769 769
770 /* create the list of attachments */ 770 /* create the list of attachments */
771 xs *matt = xs_list_new(); 771 xs *attach = get_attachments(msg);
772 xs_list *att = xs_dict_get(msg, "attachment"); 772
773 xs_str *aobj; 773 {
774 xs *attr_list = NULL; 774 xs_list *p = attach;
775 775 xs_dict *v;
776 if (xs_type(att) == XSTYPE_DICT) {
777 attr_list = xs_list_new();
778 attr_list = xs_list_append(attr_list, att);
779 }
780 else
781 if (xs_type(att) == XSTYPE_LIST)
782 attr_list = xs_dup(att);
783 else
784 attr_list = xs_list_new();
785
786 /* if it has an image, add it as an attachment */
787 xs_dict *image = xs_dict_get(msg, "image");
788 if (!xs_is_null(image))
789 attr_list = xs_list_append(attr_list, image);
790
791 att = attr_list;
792 while (xs_list_iter(&att, &aobj)) {
793 const char *mtype = xs_dict_get(aobj, "mediaType");
794 if (xs_is_null(mtype))
795 mtype = xs_dict_get(aobj, "type");
796
797 const char *url = xs_dict_get(aobj, "url");
798 if (xs_is_null(url))
799 url = xs_dict_get(aobj, "href");
800 if (xs_is_null(url))
801 continue;
802
803 /* if it's a plain Link, check if it can be "rewritten" */
804 if (xs_list_len(attr_list) < 2 && strcmp(mtype, "Link") == 0) {
805 const char *mt = xs_mime_by_ext(url);
806
807 if (xs_startswith(mt, "image/") ||
808 xs_startswith(mt, "audio/") ||
809 xs_startswith(mt, "video/"))
810 mtype = mt;
811 }
812 776
813 if (!xs_is_null(mtype)) { 777 xs *matt = xs_list_new();
814 if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") || 778
815 strcmp(mtype, "Image") == 0 || strcmp(mtype, "Document") == 0) { 779 while (xs_list_iter(&p, &v)) {
780 char *type = xs_dict_get(v, "type");
781 char *href = xs_dict_get(v, "href");
782 char *name = xs_dict_get(v, "name");
783
784 if (xs_match(type, "image/*|video/*|Image|Video")) { /* */
816 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt)); 785 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
817 xs *matte = xs_dict_new();
818 786
819 matte = xs_dict_append(matte, "id", matteid); 787 xs *d = xs_dict_new();
820 matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image");
821 matte = xs_dict_append(matte, "url", url);
822 matte = xs_dict_append(matte, "preview_url", url);
823 matte = xs_dict_append(matte, "remote_url", url);
824 788
825 const char *name = xs_dict_get(aobj, "name"); 789 d = xs_dict_append(d, "id", matteid);
826 if (xs_is_null(name)) 790 d = xs_dict_append(d, "url", href);
827 name = ""; 791 d = xs_dict_append(d, "preview_url", href);
792 d = xs_dict_append(d, "remote_url", href);
793 d = xs_dict_append(d, "description", name);
828 794
829 matte = xs_dict_append(matte, "description", name); 795 d = xs_dict_append(d, "type", (*type == 'v' || *type == 'V') ? "video" : "image");
830 796
831 matt = xs_list_append(matt, matte); 797 matt = xs_list_append(matt, d);
832 } 798 }
833 } 799 }
834 }
835 800
836 st = xs_dict_append(st, "media_attachments", matt); 801 st = xs_dict_append(st, "media_attachments", matt);
802 }
837 803
838 { 804 {
839 xs *ml = xs_list_new(); 805 xs *ml = xs_list_new();