summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-13 17:34:48 +0200
committerGravatar default2023-04-13 17:34:48 +0200
commit1a27e67ed9e4c4b12d9ee4d151c7647043b54647 (patch)
treeee59fbe612da767a7f21db117d41b711b7a763ad
parentNew function notify_check_time(). (diff)
downloadsnac2-1a27e67ed9e4c4b12d9ee4d151c7647043b54647.tar.gz
snac2-1a27e67ed9e4c4b12d9ee4d151c7647043b54647.tar.xz
snac2-1a27e67ed9e4c4b12d9ee4d151c7647043b54647.zip
New functions notify_get() and notify_list().
-rw-r--r--data.c49
-rw-r--r--mastoapi.c12
-rw-r--r--snac.h2
3 files changed, 60 insertions, 3 deletions
diff --git a/data.c b/data.c
index cf66b9a..939ede6 100644
--- a/data.c
+++ b/data.c
@@ -1537,6 +1537,55 @@ void notify_add(snac *snac, const char *type, const char *utype,
1537} 1537}
1538 1538
1539 1539
1540xs_dict *notify_get(snac *snac, const char *id)
1541/* gets a notification */
1542{
1543 xs *fn = xs_fmt("%s/notify/%s.json", snac->basedir);
1544 FILE *f;
1545 xs_dict *out = NULL;
1546
1547 if ((f = fopen(fn, "r")) != NULL) {
1548 xs *j = xs_readall(f);
1549 fclose(f);
1550
1551 out = xs_json_loads(j);
1552 }
1553
1554 return out;
1555}
1556
1557
1558xs_list *notify_list(snac *snac, int new_only)
1559/* returns a list of notifications, optionally only the new ones */
1560{
1561 xs *t = NULL;
1562
1563 /* if only new ones are requested, get the last time */
1564 if (new_only)
1565 t = notify_check_time(snac, 0);
1566
1567 xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
1568 xs *lst = xs_glob(spec, 1, 0);
1569 xs_list *out = xs_list_new();
1570 xs_list *p = lst;
1571 xs_str *v;
1572
1573 while (xs_list_iter(&p, &v)) {
1574 xs *id = xs_replace(v, ".json", "");
1575
1576 /* old? */
1577 if (t != NULL && strcmp(id, t) < 0)
1578 continue;
1579
1580 xs *noti = notify_get(snac, id);
1581
1582 out = xs_list_append(out, noti);
1583 }
1584
1585 return out;
1586}
1587
1588
1540/** the queue **/ 1589/** the queue **/
1541 1590
1542static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) 1591static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
diff --git a/mastoapi.c b/mastoapi.c
index 7029dfb..fc636a9 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -855,9 +855,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
855 else 855 else
856 if (strcmp(cmd, "/notifications") == 0) { 856 if (strcmp(cmd, "/notifications") == 0) {
857 /* TBD */ 857 /* TBD */
858 *body = xs_dup("[]"); 858 if (logged_in) {
859 *ctype = "application/json"; 859 xs *l = notify_list(&snac1, 0);
860 status = 200; 860
861 *body = xs_dup("[]");
862 *ctype = "application/json";
863 status = 200;
864 }
865 else
866 status = 401;
861 } 867 }
862 else 868 else
863 if (strcmp(cmd, "/filters") == 0) { 869 if (strcmp(cmd, "/filters") == 0) {
diff --git a/snac.h b/snac.h
index e201801..f1fe13f 100644
--- a/snac.h
+++ b/snac.h
@@ -140,6 +140,8 @@ void lastlog_write(snac *snac);
140xs_str *notify_check_time(snac *snac, int reset); 140xs_str *notify_check_time(snac *snac, int reset);
141void notify_add(snac *snac, const char *type, const char *utype, 141void notify_add(snac *snac, const char *type, const char *utype,
142 const char *actor, const char *objid); 142 const char *actor, const char *objid);
143xs_dict *notify_get(snac *snac, const char *id);
144xs_list *notify_list(snac *snac, int new_only);
143 145
144void inbox_add(const char *inbox); 146void inbox_add(const char *inbox);
145void inbox_add_by_actor(const xs_dict *actor); 147void inbox_add_by_actor(const xs_dict *actor);