diff options
| author | 2024-12-19 19:55:56 +0000 | |
|---|---|---|
| committer | 2024-12-20 00:18:32 +0000 | |
| commit | fa253f008a0f4d028dbb9ef14c83d6699a133614 (patch) | |
| tree | 1a5f52d469327385bfc7890de5926768801ef6ed /data.c | |
| parent | Updated documentation. (diff) | |
| download | penes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.tar.gz penes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.tar.xz penes-snac2-fa253f008a0f4d028dbb9ef14c83d6699a133614.zip | |
Implement mastoapi markers for notifications and home.
Diffstat (limited to '')
| -rw-r--r-- | data.c | 66 |
1 files changed, 66 insertions, 0 deletions
| @@ -2840,6 +2840,72 @@ xs_str *notify_check_time(snac *snac, int reset) | |||
| 2840 | return t; | 2840 | return t; |
| 2841 | } | 2841 | } |
| 2842 | 2842 | ||
| 2843 | xs_dict *markers_get(snac *snac, const xs_list *markers) | ||
| 2844 | { | ||
| 2845 | xs_dict *data = NULL; | ||
| 2846 | xs_dict *returns = xs_dict_new(); | ||
| 2847 | xs *fn = xs_fmt("%s/markers.json", snac->basedir); | ||
| 2848 | const xs_str *v = NULL; | ||
| 2849 | FILE *f; | ||
| 2850 | |||
| 2851 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 2852 | data = xs_json_load(f); | ||
| 2853 | fclose(f); | ||
| 2854 | } | ||
| 2855 | |||
| 2856 | if (xs_is_null(data)) | ||
| 2857 | data = xs_dict_new(); | ||
| 2858 | |||
| 2859 | xs_list_foreach(markers, v) { | ||
| 2860 | const xs_dict *mark = xs_dict_get(data, v); | ||
| 2861 | if (!xs_is_null(mark)) { | ||
| 2862 | returns = xs_dict_append(returns, v, mark); | ||
| 2863 | } | ||
| 2864 | } | ||
| 2865 | return returns; | ||
| 2866 | } | ||
| 2867 | |||
| 2868 | xs_dict *markers_set(snac *snac, const char *home_marker, const char *notify_marker) | ||
| 2869 | /* gets or sets notification marker */ | ||
| 2870 | { | ||
| 2871 | xs_dict *data = NULL; | ||
| 2872 | xs_dict *written = xs_dict_new(); | ||
| 2873 | xs *fn = xs_fmt("%s/markers.json", snac->basedir); | ||
| 2874 | FILE *f; | ||
| 2875 | |||
| 2876 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 2877 | data = xs_json_load(f); | ||
| 2878 | fclose(f); | ||
| 2879 | } | ||
| 2880 | |||
| 2881 | if (xs_is_null(data)) | ||
| 2882 | data = xs_dict_new(); | ||
| 2883 | |||
| 2884 | if (!xs_is_null(home_marker)) { | ||
| 2885 | xs_dict *home = xs_dict_new(); | ||
| 2886 | home = xs_dict_append(home, "last_read_id", home_marker); | ||
| 2887 | home = xs_dict_append(home, "version", xs_stock(0)); | ||
| 2888 | home = xs_dict_append(home, "updated_at", tid(0)); | ||
| 2889 | data = xs_dict_set(data, "home", home); | ||
| 2890 | written = xs_dict_append(written, "home", home); | ||
| 2891 | } | ||
| 2892 | |||
| 2893 | if (!xs_is_null(notify_marker)) { | ||
| 2894 | xs_dict *notify = xs_dict_new(); | ||
| 2895 | notify = xs_dict_append(notify, "last_read_id", notify_marker); | ||
| 2896 | notify = xs_dict_append(notify, "version", xs_stock(0)); | ||
| 2897 | notify = xs_dict_append(notify, "updated_at", tid(0)); | ||
| 2898 | data = xs_dict_set(data, "notifications", notify); | ||
| 2899 | written = xs_dict_append(written, "notifications", notify); | ||
| 2900 | } | ||
| 2901 | |||
| 2902 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 2903 | xs_json_dump(data, 4, f); | ||
| 2904 | fclose(f); | ||
| 2905 | } | ||
| 2906 | |||
| 2907 | return written; | ||
| 2908 | } | ||
| 2843 | 2909 | ||
| 2844 | void notify_add(snac *snac, const char *type, const char *utype, | 2910 | void notify_add(snac *snac, const char *type, const char *utype, |
| 2845 | const char *actor, const char *objid, const xs_dict *msg) | 2911 | const char *actor, const char *objid, const xs_dict *msg) |