summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-13 16:59:17 +0200
committerGravatar default2023-04-13 16:59:17 +0200
commitbcde97c2d53f9c94c6ced2717945affa4ede554c (patch)
treee57442ff4bd0f2bc25ae516241ca5bcdaa0c3878
parentStarted working on a notification list. (diff)
downloadsnac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.gz
snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.xz
snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.zip
New function notify_add().
-rw-r--r--activitypub.c3
-rw-r--r--data.c35
-rw-r--r--mastoapi.c5
-rw-r--r--snac.h5
4 files changed, 42 insertions, 6 deletions
diff --git a/activitypub.c b/activitypub.c
index 792080d..851699a 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -935,6 +935,9 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
935 935
936 if (!xs_is_null(bot) && !xs_is_null(chat_id) && *bot && *chat_id) 936 if (!xs_is_null(bot) && !xs_is_null(chat_id) && *bot && *chat_id)
937 enqueue_telegram(body, bot, chat_id); 937 enqueue_telegram(body, bot, chat_id);
938
939 /* finally, store it in the notification folder */
940 notify_add(snac, type, utype, actor, objid);
938} 941}
939 942
940 943
diff --git a/data.c b/data.c
index b375cb2..a98e9e5 100644
--- a/data.c
+++ b/data.c
@@ -7,6 +7,7 @@
7#include "xs_openssl.h" 7#include "xs_openssl.h"
8#include "xs_glob.h" 8#include "xs_glob.h"
9#include "xs_set.h" 9#include "xs_set.h"
10#include "xs_time.h"
10 11
11#include "snac.h" 12#include "snac.h"
12 13
@@ -1474,6 +1475,40 @@ xs_list *inbox_list(void)
1474} 1475}
1475 1476
1476 1477
1478/** notifications **/
1479
1480void notify_add(snac *snac, const char *type, const char *utype,
1481 const char *actor, const char *objid)
1482/* adds a new notification */
1483{
1484 xs *ntid = tid(0);
1485 xs *fn = xs_fmt("%s/notify/", snac->basedir);
1486 xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
1487 FILE *f;
1488
1489 /* create the directory */
1490 mkdirx(fn);
1491 fn = xs_str_cat(fn, ntid);
1492 fn = xs_str_cat(fn, ".json");
1493
1494 xs *noti = xs_dict_new();
1495
1496 noti = xs_dict_append(noti, "id", ntid);
1497 noti = xs_dict_append(noti, "type", type);
1498 noti = xs_dict_append(noti, "utype", utype);
1499 noti = xs_dict_append(noti, "actor", actor);
1500 noti = xs_dict_append(noti, "objid", objid);
1501 noti = xs_dict_append(noti, "date", date);
1502
1503 if ((f = fopen(fn, "w")) != NULL) {
1504 xs *j = xs_json_dumps_pp(noti, 4);
1505
1506 fwrite(j, strlen(j), 1, f);
1507 fclose(f);
1508 }
1509}
1510
1511
1477/** the queue **/ 1512/** the queue **/
1478 1513
1479static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) 1514static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
diff --git a/mastoapi.c b/mastoapi.c
index 80f1619..7029dfb 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -855,11 +855,6 @@ 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 {
859 xs *j = xs_json_dumps_pp(args, 4);
860 printf("notification args:\n%s\n", j);
861 }
862
863 *body = xs_dup("[]"); 858 *body = xs_dup("[]");
864 *ctype = "application/json"; 859 *ctype = "application/json";
865 status = 200; 860 status = 200;
diff --git a/snac.h b/snac.h
index 02ddfb1..a707f16 100644
--- a/snac.h
+++ b/snac.h
@@ -1,7 +1,7 @@
1/* snac - A simple, minimalistic ActivityPub instance */ 1/* snac - A simple, minimalistic ActivityPub instance */
2/* copyright (c) 2022 - 2023 grunfink / MIT license */ 2/* copyright (c) 2022 - 2023 grunfink / MIT license */
3 3
4#define VERSION "2.27" 4#define VERSION "2.28-dev"
5 5
6#define USER_AGENT "snac/" VERSION 6#define USER_AGENT "snac/" VERSION
7 7
@@ -137,6 +137,9 @@ d_char *history_list(snac *snac);
137 137
138void lastlog_write(snac *snac); 138void lastlog_write(snac *snac);
139 139
140void notify_add(snac *snac, const char *type, const char *utype,
141 const char *actor, const char *objid);
142
140void inbox_add(const char *inbox); 143void inbox_add(const char *inbox);
141void inbox_add_by_actor(const xs_dict *actor); 144void inbox_add_by_actor(const xs_dict *actor);
142xs_list *inbox_list(void); 145xs_list *inbox_list(void);