commit 2d5d635
default
·
2023-04-13 13:32:13 +0000 UTC
parent c2f5748
Started working on a notification list.
2 files changed,
+17,
-15
+12,
-15
1@@ -846,8 +846,6 @@ xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
2 void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg)
3 /* notifies the user of relevant events */
4 {
5- xs_val *object = NULL;
6-
7 if (strcmp(type, "Create") == 0) {
8 /* only notify of notes specifically for us */
9 xs *rcpts = recipient_list(snac, msg, 0);
10@@ -859,21 +857,20 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
11 if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") != 0)
12 return;
13
14- if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) {
15- object = xs_dict_get(msg, "object");
16+ /* get the object id */
17+ const char *objid = xs_dict_get(msg, "object");
18
19- if (xs_is_null(object))
20- return;
21- else {
22- if (xs_type(object) == XSTYPE_DICT)
23- object = xs_dict_get(object, "id");
24+ if (xs_type(objid) == XSTYPE_DICT)
25+ objid = xs_dict_get(objid, "id");
26
27- /* if it's not an admiration about something by us, done */
28- if (xs_is_null(object) || !xs_startswith(object, snac->actor))
29- return;
30- }
31+ if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) {
32+ /* if it's not an admiration about something by us, done */
33+ if (xs_is_null(objid) || !xs_startswith(objid, snac->actor))
34+ return;
35 }
36
37+ /* user will love to know about this! */
38+
39 /* prepare message body */
40 xs *body = xs_fmt("User : @%s@%s\n",
41 xs_dict_get(snac->config, "uid"),
42@@ -894,8 +891,8 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
43 body = xs_str_cat(body, s1);
44 }
45
46- if (object != NULL) {
47- xs *s1 = xs_fmt("Object: %s\n", object);
48+ if (objid != NULL) {
49+ xs *s1 = xs_fmt("Object: %s\n", objid);
50 body = xs_str_cat(body, s1);
51 }
52
+5,
-0
1@@ -855,6 +855,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 else
3 if (strcmp(cmd, "/notifications") == 0) {
4 /* TBD */
5+ {
6+ xs *j = xs_json_dumps_pp(args, 4);
7+ printf("notification args:\n%s\n", j);
8+ }
9+
10 *body = xs_dup("[]");
11 *ctype = "application/json";
12 status = 200;