commit 9e7a77c
default
·
2023-04-14 17:39:31 +0000 UTC
parent 58b2a47
New mastoapi to clear all notifications.
3 files changed,
+27,
-0
M
data.c
+13,
-0
1@@ -1595,6 +1595,19 @@ xs_list *notify_list(snac *snac, int new_only)
2 }
3
4
5+void notify_clear(snac *snac)
6+/* clears all notifications */
7+{
8+ xs *spec = xs_fmt("%s/notify/" "*", snac->basedir);
9+ xs *lst = xs_glob(spec, 0, 0);
10+ xs_list *p = lst;
11+ xs_str *v;
12+
13+ while (xs_list_iter(&p, &v))
14+ unlink(v);
15+}
16+
17+
18 /** the queue **/
19
20 static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
+13,
-0
1@@ -1290,6 +1290,19 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2 else
3 status = 401;
4 }
5+ else
6+ if (strcmp(cmd, "/notifications/clear") == 0) {
7+ if (logged_in) {
8+ notify_clear(&snac);
9+ timeline_touch(&snac);
10+
11+ *body = xs_dup("{}");
12+ *ctype = "application/json";
13+ status = 200;
14+ }
15+ else
16+ status = 401;
17+ }
18
19 /* user cleanup */
20 if (logged_in)
M
snac.h
+1,
-0
1@@ -143,6 +143,7 @@ void notify_add(snac *snac, const char *type, const char *utype,
2 const char *actor, const char *objid);
3 xs_dict *notify_get(snac *snac, const char *id);
4 xs_list *notify_list(snac *snac, int new_only);
5+void notify_clear(snac *snac);
6
7 void inbox_add(const char *inbox);
8 void inbox_add_by_actor(const xs_dict *actor);