diff options
| author | 2023-04-13 16:59:17 +0200 | |
|---|---|---|
| committer | 2023-04-13 16:59:17 +0200 | |
| commit | bcde97c2d53f9c94c6ced2717945affa4ede554c (patch) | |
| tree | e57442ff4bd0f2bc25ae516241ca5bcdaa0c3878 | |
| parent | Started working on a notification list. (diff) | |
| download | snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.gz snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.xz snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.zip | |
New function notify_add().
| -rw-r--r-- | activitypub.c | 3 | ||||
| -rw-r--r-- | data.c | 35 | ||||
| -rw-r--r-- | mastoapi.c | 5 | ||||
| -rw-r--r-- | snac.h | 5 |
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 | ||
| @@ -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 | |||
| 1480 | void 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 | ||
| 1479 | static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) | 1514 | static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) |
| @@ -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; |
| @@ -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 | ||
| 138 | void lastlog_write(snac *snac); | 138 | void lastlog_write(snac *snac); |
| 139 | 139 | ||
| 140 | void notify_add(snac *snac, const char *type, const char *utype, | ||
| 141 | const char *actor, const char *objid); | ||
| 142 | |||
| 140 | void inbox_add(const char *inbox); | 143 | void inbox_add(const char *inbox); |
| 141 | void inbox_add_by_actor(const xs_dict *actor); | 144 | void inbox_add_by_actor(const xs_dict *actor); |
| 142 | xs_list *inbox_list(void); | 145 | xs_list *inbox_list(void); |