New function notify_add().

This commit is contained in:
default 2023-04-13 16:59:17 +02:00
parent 2d5d63554c
commit bcde97c2d5
4 changed files with 42 additions and 6 deletions

View file

@ -935,6 +935,9 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
if (!xs_is_null(bot) && !xs_is_null(chat_id) && *bot && *chat_id)
enqueue_telegram(body, bot, chat_id);
/* finally, store it in the notification folder */
notify_add(snac, type, utype, actor, objid);
}

35
data.c
View file

@ -7,6 +7,7 @@
#include "xs_openssl.h"
#include "xs_glob.h"
#include "xs_set.h"
#include "xs_time.h"
#include "snac.h"
@ -1474,6 +1475,40 @@ xs_list *inbox_list(void)
}
/** notifications **/
void notify_add(snac *snac, const char *type, const char *utype,
const char *actor, const char *objid)
/* adds a new notification */
{
xs *ntid = tid(0);
xs *fn = xs_fmt("%s/notify/", snac->basedir);
xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
FILE *f;
/* create the directory */
mkdirx(fn);
fn = xs_str_cat(fn, ntid);
fn = xs_str_cat(fn, ".json");
xs *noti = xs_dict_new();
noti = xs_dict_append(noti, "id", ntid);
noti = xs_dict_append(noti, "type", type);
noti = xs_dict_append(noti, "utype", utype);
noti = xs_dict_append(noti, "actor", actor);
noti = xs_dict_append(noti, "objid", objid);
noti = xs_dict_append(noti, "date", date);
if ((f = fopen(fn, "w")) != NULL) {
xs *j = xs_json_dumps_pp(noti, 4);
fwrite(j, strlen(j), 1, f);
fclose(f);
}
}
/** the queue **/
static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)

View file

@ -855,11 +855,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
else
if (strcmp(cmd, "/notifications") == 0) {
/* TBD */
{
xs *j = xs_json_dumps_pp(args, 4);
printf("notification args:\n%s\n", j);
}
*body = xs_dup("[]");
*ctype = "application/json";
status = 200;

5
snac.h
View file

@ -1,7 +1,7 @@
/* snac - A simple, minimalistic ActivityPub instance */
/* copyright (c) 2022 - 2023 grunfink / MIT license */
#define VERSION "2.27"
#define VERSION "2.28-dev"
#define USER_AGENT "snac/" VERSION
@ -137,6 +137,9 @@ d_char *history_list(snac *snac);
void lastlog_write(snac *snac);
void notify_add(snac *snac, const char *type, const char *utype,
const char *actor, const char *objid);
void inbox_add(const char *inbox);
void inbox_add_by_actor(const xs_dict *actor);
xs_list *inbox_list(void);