mastoapi: Some tweaks to process posts with 'name' and 'image' fields.

This commit is contained in:
default 2023-08-14 20:11:03 +02:00
parent 8f09e4cb78
commit 2bea378610
2 changed files with 33 additions and 4 deletions

2
data.c
View File

@ -591,7 +591,7 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
/* returns a stored object, optionally of the requested type */ /* returns a stored object, optionally of the requested type */
{ {
int status = 404; int status = 404;
xs *fn = _object_fn_by_md5(md5, "object_get_my_md5"); xs *fn = _object_fn_by_md5(md5, "object_get_by_md5");
FILE *f; FILE *f;
if ((f = fopen(fn, "r")) != NULL) { if ((f = fopen(fn, "r")) != NULL) {

View File

@ -662,7 +662,19 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
st = xs_dict_append(st, "url", id); st = xs_dict_append(st, "url", id);
st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published")); st = xs_dict_append(st, "created_at", xs_dict_get(msg, "published"));
st = xs_dict_append(st, "account", acct); st = xs_dict_append(st, "account", acct);
st = xs_dict_append(st, "content", xs_dict_get(msg, "content"));
{
const char *content = xs_dict_get(msg, "content");
const char *name = xs_dict_get(msg, "name");
xs *s1 = NULL;
if (name)
s1 = xs_fmt("%s<br><br>%s", name, content);
else
s1 = xs_dup(content);
st = xs_dict_append(st, "content", s1);
}
st = xs_dict_append(st, "visibility", st = xs_dict_append(st, "visibility",
is_msg_public(msg) ? "public" : "private"); is_msg_public(msg) ? "public" : "private");
@ -683,17 +695,34 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
xs *matt = xs_list_new(); xs *matt = xs_list_new();
xs_list *att = xs_dict_get(msg, "attachment"); xs_list *att = xs_dict_get(msg, "attachment");
xs_str *aobj; xs_str *aobj;
xs *attr_list = NULL;
if (xs_type(att) == XSTYPE_DICT) {
attr_list = xs_list_new();
attr_list = xs_list_append(attr_list, att);
}
else
attr_list = xs_dup(att);
/* if it has an image, add it as an attachment */
xs_dict *image = xs_dict_get(msg, "image");
if (!xs_is_null(image))
attr_list = xs_list_append(attr_list, image);
att = attr_list;
while (xs_list_iter(&att, &aobj)) { while (xs_list_iter(&att, &aobj)) {
const char *mtype = xs_dict_get(aobj, "mediaType"); const char *mtype = xs_dict_get(aobj, "mediaType");
if (xs_is_null(mtype))
mtype = xs_dict_get(aobj, "type");
if (!xs_is_null(mtype)) { if (!xs_is_null(mtype)) {
if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/")) { if (xs_startswith(mtype, "image/") || xs_startswith(mtype, "video/") ||
strcmp(mtype, "Image") == 0) {
xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt)); xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
xs *matte = xs_dict_new(); xs *matte = xs_dict_new();
matte = xs_dict_append(matte, "id", matteid); matte = xs_dict_append(matte, "id", matteid);
matte = xs_dict_append(matte, "type", *mtype == 'i' ? "image" : "video"); 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, "url", xs_dict_get(aobj, "url"));
matte = xs_dict_append(matte, "preview_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, "remote_url", xs_dict_get(aobj, "url"));