commit 2bea378
default
·
2023-08-14 18:11:03 +0000 UTC
parent 8f09e4c
mastoapi: Some tweaks to process posts with 'name' and 'image' fields.
2 files changed,
+33,
-4
M
data.c
M
data.c
+1,
-1
1@@ -591,7 +591,7 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
2 /* returns a stored object, optionally of the requested type */
3 {
4 int status = 404;
5- xs *fn = _object_fn_by_md5(md5, "object_get_my_md5");
6+ xs *fn = _object_fn_by_md5(md5, "object_get_by_md5");
7 FILE *f;
8
9 if ((f = fopen(fn, "r")) != NULL) {
+32,
-3
1@@ -662,7 +662,19 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
2 st = xs_dict_append(st, "url", id);
3 st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published"));
4 st = xs_dict_append(st, "account", acct);
5- st = xs_dict_append(st, "content", xs_dict_get(msg, "content"));
6+
7+ {
8+ const char *content = xs_dict_get(msg, "content");
9+ const char *name = xs_dict_get(msg, "name");
10+ xs *s1 = NULL;
11+
12+ if (name)
13+ s1 = xs_fmt("%s<br><br>%s", name, content);
14+ else
15+ s1 = xs_dup(content);
16+
17+ st = xs_dict_append(st, "content", s1);
18+ }
19
20 st = xs_dict_append(st, "visibility",
21 is_msg_public(msg) ? "public" : "private");
22@@ -683,17 +695,34 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
23 xs *matt = xs_list_new();
24 xs_list *att = xs_dict_get(msg, "attachment");
25 xs_str *aobj;
26+ xs *attr_list = NULL;
27+
28+ if (xs_type(att) == XSTYPE_DICT) {
29+ attr_list = xs_list_new();
30+ attr_list = xs_list_append(attr_list, att);
31+ }
32+ else
33+ attr_list = xs_dup(att);
34+
35+ /* if it has an image, add it as an attachment */
36+ xs_dict *image = xs_dict_get(msg, "image");
37+ if (!xs_is_null(image))
38+ attr_list = xs_list_append(attr_list, image);
39
40+ att = attr_list;
41 while (xs_list_iter(&att, &aobj)) {
42 const char *mtype = xs_dict_get(aobj, "mediaType");
43+ if (xs_is_null(mtype))
44+ mtype = xs_dict_get(aobj, "type");
45
46 if (!xs_is_null(mtype)) {
47- if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/")) {
48+ if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") ||
49+ strcmp(mtype, "Image") == 0) {
50 xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
51 xs *matte = xs_dict_new();
52
53 matte = xs_dict_append(matte, "id", matteid);
54- matte = xs_dict_append(matte, "type", *mtype == 'i' ? "image" : "video");
55+ matte = xs_dict_append(matte, "type", *mtype == 'v' ? "video" : "image");
56 matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url"));
57 matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url"));
58 matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url"));