diff options
author | default <nobody@localhost> | 2023-04-13 17:56:00 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-04-13 17:56:00 +0200 |
commit | 51208b10c168e9b15ccae255d73fae38ae717fdf (patch) | |
tree | 82067d9d1fe0023c69ada2e9dc705125ef096d42 | |
parent | 1a27e67ed9e4c4b12d9ee4d151c7647043b54647 (diff) |
Implemented mastoapi notifications.
-rw-r--r-- | data.c | 4 | ||||
-rw-r--r-- | mastoapi.c | 55 |
2 files changed, 55 insertions, 4 deletions
@@ -1525,9 +1525,11 @@ void notify_add(snac *snac, const char *type, const char *utype, 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 (!xs_is_null(objid)) + noti = xs_dict_append(noti, "objid", objid); + if ((f = fopen(fn, "w")) != NULL) { xs *j = xs_json_dumps_pp(noti, 4); @@ -854,11 +854,60 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/notifications") == 0) { - /* TBD */ if (logged_in) { - xs *l = notify_list(&snac1, 0); + xs *l = notify_list(&snac1, 0); + xs *out = xs_list_new(); + xs_list *p = l; + xs_dict *v; + + while (xs_list_iter(&p, &v)) { + const char *type = xs_dict_get(v, "type"); + const char *objid = xs_dict_get(v, "objid"); + xs *actor = NULL; + xs *entry = NULL; + + if (!valid_status(object_get(xs_dict_get(v, "actor"), &actor))) + continue; - *body = xs_dup("[]"); + if (objid != NULL && !valid_status(object_get(objid, &entry))) + continue; + + /* convert the type */ + if (strcmp(type, "Like") == 0) + type = "favourite"; + else + if (strcmp(type, "Announce") == 0) + type = "reblog"; + else + if (strcmp(type, "Follow") == 0) + type = "follow"; + else + if (strcmp(type, "Create") == 0) + type = "mention"; + else + continue; + + xs *mn = xs_dict_new(); + + mn = xs_dict_append(mn, "type", type); + + xs *id = xs_replace(xs_dict_get(v, "id"), ".", ""); + mn = xs_dict_append(mn, "id", id); + + mn = xs_dict_append(mn, "created_at", xs_dict_get(v, "date")); + + xs *acct = mastoapi_account(actor); + mn = xs_dict_append(mn, "account", acct); + + if (objid != NULL) { + xs *st = mastoapi_status(&snac1, entry); + mn = xs_dict_append(mn, "status", st); + } + + out = xs_list_append(out, mn); + } + + *body = xs_json_dumps_pp(out, 4); *ctype = "application/json"; status = 200; } |