summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-08-14 20:11:03 +0200
committerGravatar default2023-08-14 20:11:03 +0200
commit2bea378610c6402f201a9b01b9d22c19ceb2a215 (patch)
tree31f97e048d0b52904baee52a2142d481b38c281e
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-2bea378610c6402f201a9b01b9d22c19ceb2a215.tar.gz
snac2-2bea378610c6402f201a9b01b9d22c19ceb2a215.tar.xz
snac2-2bea378610c6402f201a9b01b9d22c19ceb2a215.zip
mastoapi: Some tweaks to process posts with 'name' and 'image' fields.
-rw-r--r--data.c2
-rw-r--r--mastoapi.c35
2 files changed, 33 insertions, 4 deletions
diff --git a/data.c b/data.c
index 73192ba..c2d69c8 100644
--- a/data.c
+++ b/data.c
@@ -591,7 +591,7 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
591/* returns a stored object, optionally of the requested type */ 591/* returns a stored object, optionally of the requested type */
592{ 592{
593 int status = 404; 593 int status = 404;
594 xs *fn = _object_fn_by_md5(md5, "object_get_my_md5"); 594 xs *fn = _object_fn_by_md5(md5, "object_get_by_md5");
595 FILE *f; 595 FILE *f;
596 596
597 if ((f = fopen(fn, "r")) != NULL) { 597 if ((f = fopen(fn, "r")) != NULL) {
diff --git a/mastoapi.c b/mastoapi.c
index e7d9b60..73b4d9f 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -662,7 +662,19 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
662 st = xs_dict_append(st, "url", id); 662 st = xs_dict_append(st, "url", id);
663 st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published")); 663 st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published"));
664 st = xs_dict_append(st, "account", acct); 664 st = xs_dict_append(st, "account", acct);
665 st = xs_dict_append(st, "content", xs_dict_get(msg, "content")); 665
666 {
667 const char *content = xs_dict_get(msg, "content");
668 const char *name = xs_dict_get(msg, "name");
669 xs *s1 = NULL;
670
671 if (name)
672 s1 = xs_fmt("%s<br><br>%s", name, content);
673 else
674 s1 = xs_dup(content);
675
676 st = xs_dict_append(st, "content", s1);
677 }
666 678
667 st = xs_dict_append(st, "visibility", 679 st = xs_dict_append(st, "visibility",
668 is_msg_public(msg) ? "public" : "private"); 680 is_msg_public(msg) ? "public" : "private");
@@ -683,17 +695,34 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
683 xs *matt = xs_list_new(); 695 xs *matt = xs_list_new();
684 xs_list *att = xs_dict_get(msg, "attachment"); 696 xs_list *att = xs_dict_get(msg, "attachment");
685 xs_str *aobj; 697 xs_str *aobj;
698 xs *attr_list = NULL;
699
700 if (xs_type(att) == XSTYPE_DICT) {
701 attr_list = xs_list_new();
702 attr_list = xs_list_append(attr_list, att);
703 }
704 else
705 attr_list = xs_dup(att);
706
707 /* if it has an image, add it as an attachment */
708 xs_dict *image = xs_dict_get(msg, "image");
709 if (!xs_is_null(image))
710 attr_list = xs_list_append(attr_list, image);
686 711
712 att = attr_list;
687 while (xs_list_iter(&att, &aobj)) { 713 while (xs_list_iter(&att, &aobj)) {
688 const char *mtype = xs_dict_get(aobj, "mediaType"); 714 const char *mtype = xs_dict_get(aobj, "mediaType");
715 if (xs_is_null(mtype))
716 mtype = xs_dict_get(aobj, "type");
689 717
690 if (!xs_is_null(mtype)) { 718 if (!xs_is_null(mtype)) {
691 if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/")) { 719 if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") ||
720 strcmp(mtype, "Image") == 0) {
692 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt)); 721 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
693 xs *matte = xs_dict_new(); 722 xs *matte = xs_dict_new();
694 723
695 matte = xs_dict_append(matte, "id", matteid); 724 matte = xs_dict_append(matte, "id", matteid);
696 matte = xs_dict_append(matte, "type", *mtype == 'i' ? "image" : "video"); 725 matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image");
697 matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); 726 matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url"));
698 matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); 727 matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url"));
699 matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); 728 matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url"));