소스 검색

Started working on a notification list.

default 3 년 전
부모
커밋
2d5d63554c
2개의 변경된 파일17개의 추가작업 그리고 15개의 파일을 삭제
  1. 12 15
      activitypub.c
  2. 5 0
      mastoapi.c

+ 12 - 15
activitypub.c

@@ -846,8 +846,6 @@ xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
 void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg)
 /* notifies the user of relevant events */
 {
-    xs_val *object = NULL;
-
     if (strcmp(type, "Create") == 0) {
         /* only notify of notes specifically for us */
         xs *rcpts = recipient_list(snac, msg, 0);
@@ -859,21 +857,20 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
     if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") != 0)
         return;
 
-    if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) {
-        object = xs_dict_get(msg, "object");
+    /* get the object id */
+    const char *objid = xs_dict_get(msg, "object");
 
-        if (xs_is_null(object))
-            return;
-        else {
-            if (xs_type(object) == XSTYPE_DICT)
-                object = xs_dict_get(object, "id");
+    if (xs_type(objid) == XSTYPE_DICT)
+        objid = xs_dict_get(objid, "id");
 
-            /* if it's not an admiration about something by us, done */
-            if (xs_is_null(object) || !xs_startswith(object, snac->actor))
-                return;
-        }
+    if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) {
+        /* if it's not an admiration about something by us, done */
+        if (xs_is_null(objid) || !xs_startswith(objid, snac->actor))
+            return;
     }
 
+    /* user will love to know about this! */
+
     /* prepare message body */
     xs *body = xs_fmt("User  : @%s@%s\n",
         xs_dict_get(snac->config, "uid"),
@@ -894,8 +891,8 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
         body = xs_str_cat(body, s1);
     }
 
-    if (object != NULL) {
-        xs *s1 = xs_fmt("Object: %s\n", object);
+    if (objid != NULL) {
+        xs *s1 = xs_fmt("Object: %s\n", objid);
         body = xs_str_cat(body, s1);
     }
 

+ 5 - 0
mastoapi.c

@@ -855,6 +855,11 @@ 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;