Started working on a notification list.

This commit is contained in:
default 2023-04-13 15:32:13 +02:00
parent c2f5748a9d
commit 2d5d63554c
2 changed files with 17 additions and 15 deletions

View file

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

View file

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