Fixed crash in notification list.

This commit is contained in:
default 2023-04-14 08:37:33 +02:00
parent 815c39d0c6
commit 35c611b8b9
2 changed files with 13 additions and 10 deletions

6
data.c
View File

@ -1558,7 +1558,7 @@ xs_dict *notify_get(snac *snac, const char *id)
xs_list *notify_list(snac *snac, int new_only) xs_list *notify_list(snac *snac, int new_only)
/* returns a list of notifications, optionally only the new ones */ /* returns a list of notification ids, optionally only the new ones */
{ {
xs *t = NULL; xs *t = NULL;
@ -1579,9 +1579,7 @@ xs_list *notify_list(snac *snac, int new_only)
if (t != NULL && strcmp(id, t) < 0) if (t != NULL && strcmp(id, t) < 0)
continue; continue;
xs *noti = notify_get(snac, id); out = xs_list_append(out, id);
out = xs_list_append(out, noti);
} }
return out; return out;

View File

@ -866,12 +866,17 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
xs_dict *v; xs_dict *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
const char *type = xs_dict_get(v, "type"); xs *noti = notify_get(&snac1, v);
const char *objid = xs_dict_get(v, "objid");
if (noti == NULL)
continue;
const char *type = xs_dict_get(noti, "type");
const char *objid = xs_dict_get(noti, "objid");
xs *actor = NULL; xs *actor = NULL;
xs *entry = NULL; xs *entry = NULL;
if (!valid_status(object_get(xs_dict_get(v, "actor"), &actor))) if (!valid_status(object_get(xs_dict_get(noti, "actor"), &actor)))
continue; continue;
if (objid != NULL && !valid_status(object_get(objid, &entry))) if (objid != NULL && !valid_status(object_get(objid, &entry)))
@ -896,15 +901,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
mn = xs_dict_append(mn, "type", type); mn = xs_dict_append(mn, "type", type);
xs *id = xs_replace(xs_dict_get(v, "id"), ".", ""); xs *id = xs_replace(xs_dict_get(noti, "id"), ".", "");
mn = xs_dict_append(mn, "id", id); mn = xs_dict_append(mn, "id", id);
mn = xs_dict_append(mn, "created_at", xs_dict_get(v, "date")); mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date"));
xs *acct = mastoapi_account(actor); xs *acct = mastoapi_account(actor);
mn = xs_dict_append(mn, "account", acct); mn = xs_dict_append(mn, "account", acct);
if (objid != NULL) { if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) {
xs *st = mastoapi_status(&snac1, entry); xs *st = mastoapi_status(&snac1, entry);
mn = xs_dict_append(mn, "status", st); mn = xs_dict_append(mn, "status", st);
} }