commit 35c611b

default  ·  2023-04-14 06:37:33 +0000 UTC
parent 815c39d
Fixed crash in notification list.
2 files changed,  +13, -10
M data.c
M data.c
+2, -4
 1@@ -1558,7 +1558,7 @@ xs_dict *notify_get(snac *snac, const char *id)
 2 
 3 
 4 xs_list *notify_list(snac *snac, int new_only)
 5-/* returns a list of notifications, optionally only the new ones */
 6+/* returns a list of notification ids, optionally only the new ones */
 7 {
 8     xs *t = NULL;
 9 
10@@ -1579,9 +1579,7 @@ xs_list *notify_list(snac *snac, int new_only)
11         if (t != NULL && strcmp(id, t) < 0)
12             continue;
13 
14-        xs *noti = notify_get(snac, id);
15-
16-        out = xs_list_append(out, noti);
17+        out = xs_list_append(out, id);
18     }
19 
20     return out;
+11, -6
 1@@ -866,12 +866,17 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2             xs_dict *v;
 3 
 4             while (xs_list_iter(&p, &v)) {
 5-                const char *type = xs_dict_get(v, "type");
 6-                const char *objid = xs_dict_get(v, "objid");
 7+                xs *noti = notify_get(&snac1, v);
 8+
 9+                if (noti == NULL)
10+                    continue;
11+
12+                const char *type  = xs_dict_get(noti, "type");
13+                const char *objid = xs_dict_get(noti, "objid");
14                 xs *actor = NULL;
15                 xs *entry = NULL;
16 
17-                if (!valid_status(object_get(xs_dict_get(v, "actor"), &actor)))
18+                if (!valid_status(object_get(xs_dict_get(noti, "actor"), &actor)))
19                     continue;
20 
21                 if (objid != NULL && !valid_status(object_get(objid, &entry)))
22@@ -896,15 +901,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
23 
24                 mn = xs_dict_append(mn, "type", type);
25 
26-                xs *id = xs_replace(xs_dict_get(v, "id"), ".", "");
27+                xs *id = xs_replace(xs_dict_get(noti, "id"), ".", "");
28                 mn = xs_dict_append(mn, "id", id);
29 
30-                mn = xs_dict_append(mn, "created_at", xs_dict_get(v, "date"));
31+                mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date"));
32 
33                 xs *acct = mastoapi_account(actor);
34                 mn = xs_dict_append(mn, "account", acct);
35 
36-                if (objid != NULL) {
37+                if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) {
38                     xs *st = mastoapi_status(&snac1, entry);
39                     mn = xs_dict_append(mn, "status", st);
40                 }