Browse Source

mastoapi: more tweaks to notifications code.

default 4 months ago
parent
commit
437829a833
1 changed files with 12 additions and 4 deletions
  1. 12 4
      mastoapi.c

+ 12 - 4
mastoapi.c

@@ -1727,11 +1727,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
         if (logged_in) {
             xs *l      = notify_list(&snac1, 0, 64);
             xs *out    = xs_list_new();
-            xs_list *p = l;
             const xs_dict *v;
             const xs_list *excl = xs_dict_get(args, "exclude_types[]");
+            const char *max_id = xs_dict_get(args, "max_id");
 
-            while (xs_list_iter(&p, &v)) {
+            xs_list_foreach(l, v) {
                 xs *noti = notify_get(&snac1, v);
 
                 if (noti == NULL)
@@ -1740,6 +1740,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
                 const char *type  = xs_dict_get(noti, "type");
                 const char *utype = xs_dict_get(noti, "utype");
                 const char *objid = xs_dict_get(noti, "objid");
+                const char *id    = xs_dict_get(noti, "id");
+                xs *fid = xs_replace(id, ".", "");
                 xs *actor = NULL;
                 xs *entry = NULL;
 
@@ -1752,6 +1754,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
                 if (is_hidden(&snac1, objid))
                     continue;
 
+                if (max_id) {
+                    if (strcmp(fid, max_id) == 0)
+                        max_id = NULL;
+
+                    continue;
+                }
+
                 /* convert the type */
                 if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0)
                     type = "favourite";
@@ -1778,8 +1787,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 
                 mn = xs_dict_append(mn, "type", type);
 
-                xs *id = xs_replace(xs_dict_get(noti, "id"), ".", "");
-                mn = xs_dict_append(mn, "id", id);
+                mn = xs_dict_append(mn, "id", fid);
 
                 mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date"));