Forráskód Böngészése

New function notify_add().

default 3 éve
szülő
commit
bcde97c2d5
4 módosított fájl, 42 hozzáadás és 6 törlés
  1. 3 0
      activitypub.c
  2. 35 0
      data.c
  3. 0 5
      mastoapi.c
  4. 4 1
      snac.h

+ 3 - 0
activitypub.c

@@ -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 - 0
data.c

@@ -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)

+ 0 - 5
mastoapi.c

@@ -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;

+ 4 - 1
snac.h

@@ -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);