diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 55 |
1 files changed, 52 insertions, 3 deletions
| @@ -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 | } |