summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-13 17:56:00 +0200
committerGravatar default2023-04-13 17:56:00 +0200
commit51208b10c168e9b15ccae255d73fae38ae717fdf (patch)
tree82067d9d1fe0023c69ada2e9dc705125ef096d42
parentNew functions notify_get() and notify_list(). (diff)
downloadsnac2-51208b10c168e9b15ccae255d73fae38ae717fdf.tar.gz
snac2-51208b10c168e9b15ccae255d73fae38ae717fdf.tar.xz
snac2-51208b10c168e9b15ccae255d73fae38ae717fdf.zip
Implemented mastoapi notifications.
-rw-r--r--data.c4
-rw-r--r--mastoapi.c55
2 files changed, 55 insertions, 4 deletions
diff --git a/data.c b/data.c
index 939ede6..026ae7b 100644
--- a/data.c
+++ b/data.c
@@ -1525,9 +1525,11 @@ void notify_add(snac *snac, const char *type, const char *utype,
1525 noti = xs_dict_append(noti, "type", type); 1525 noti = xs_dict_append(noti, "type", type);
1526 noti = xs_dict_append(noti, "utype", utype); 1526 noti = xs_dict_append(noti, "utype", utype);
1527 noti = xs_dict_append(noti, "actor", actor); 1527 noti = xs_dict_append(noti, "actor", actor);
1528 noti = xs_dict_append(noti, "objid", objid);
1529 noti = xs_dict_append(noti, "date", date); 1528 noti = xs_dict_append(noti, "date", date);
1530 1529
1530 if (!xs_is_null(objid))
1531 noti = xs_dict_append(noti, "objid", objid);
1532
1531 if ((f = fopen(fn, "w")) != NULL) { 1533 if ((f = fopen(fn, "w")) != NULL) {
1532 xs *j = xs_json_dumps_pp(noti, 4); 1534 xs *j = xs_json_dumps_pp(noti, 4);
1533 1535
diff --git a/mastoapi.c b/mastoapi.c
index fc636a9..74b62ba 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -854,11 +854,60 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
854 } 854 }
855 else 855 else
856 if (strcmp(cmd, "/notifications") == 0) { 856 if (strcmp(cmd, "/notifications") == 0) {
857 /* TBD */
858 if (logged_in) { 857 if (logged_in) {
859 xs *l = notify_list(&snac1, 0); 858 xs *l = notify_list(&snac1, 0);
859 xs *out = xs_list_new();
860 xs_list *p = l;
861 xs_dict *v;
862
863 while (xs_list_iter(&p, &v)) {
864 const char *type = xs_dict_get(v, "type");
865 const char *objid = xs_dict_get(v, "objid");
866 xs *actor = NULL;
867 xs *entry = NULL;
868
869 if (!valid_status(object_get(xs_dict_get(v, "actor"), &actor)))
870 continue;
860 871
861 *body = xs_dup("[]"); 872 if (objid != NULL && !valid_status(object_get(objid, &entry)))
873 continue;
874
875 /* convert the type */
876 if (strcmp(type, "Like") == 0)
877 type = "favourite";
878 else
879 if (strcmp(type, "Announce") == 0)
880 type = "reblog";
881 else
882 if (strcmp(type, "Follow") == 0)
883 type = "follow";
884 else
885 if (strcmp(type, "Create") == 0)
886 type = "mention";
887 else
888 continue;
889
890 xs *mn = xs_dict_new();
891
892 mn = xs_dict_append(mn, "type", type);
893
894 xs *id = xs_replace(xs_dict_get(v, "id"), ".", "");
895 mn = xs_dict_append(mn, "id", id);
896
897 mn = xs_dict_append(mn, "created_at", xs_dict_get(v, "date"));
898
899 xs *acct = mastoapi_account(actor);
900 mn = xs_dict_append(mn, "account", acct);
901
902 if (objid != NULL) {
903 xs *st = mastoapi_status(&snac1, entry);
904 mn = xs_dict_append(mn, "status", st);
905 }
906
907 out = xs_list_append(out, mn);
908 }
909
910 *body = xs_json_dumps_pp(out, 4);
862 *ctype = "application/json"; 911 *ctype = "application/json";
863 status = 200; 912 status = 200;
864 } 913 }