diff options
| -rw-r--r-- | data.c | 35 | ||||
| -rw-r--r-- | html.c | 5 | ||||
| -rw-r--r-- | mastoapi.c | 2 | ||||
| -rw-r--r-- | snac.h | 3 |
4 files changed, 30 insertions, 15 deletions
| @@ -2064,15 +2064,34 @@ xs_dict *notify_get(snac *snac, const char *id) | |||
| 2064 | } | 2064 | } |
| 2065 | 2065 | ||
| 2066 | 2066 | ||
| 2067 | xs_list *notify_list(snac *snac, int new_only) | 2067 | int notify_new_num(snac *snac) |
| 2068 | /* returns a list of notification ids, optionally only the new ones */ | 2068 | /* counts the number of new notifications */ |
| 2069 | { | 2069 | { |
| 2070 | xs *t = NULL; | 2070 | xs *t = notify_check_time(snac, 0); |
| 2071 | xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); | ||
| 2072 | xs *lst = xs_glob(spec, 1, 1); | ||
| 2073 | int cnt = 0; | ||
| 2074 | |||
| 2075 | xs_list *p = lst; | ||
| 2076 | xs_str *v; | ||
| 2077 | |||
| 2078 | while (xs_list_iter(&p, &v)) { | ||
| 2079 | xs *id = xs_replace(v, ".json", ""); | ||
| 2071 | 2080 | ||
| 2072 | /* if only new ones are requested, get the last time */ | 2081 | /* old? count no more */ |
| 2073 | if (new_only) | 2082 | if (strcmp(id, t) < 0) |
| 2074 | t = notify_check_time(snac, 0); | 2083 | break; |
| 2075 | 2084 | ||
| 2085 | cnt++; | ||
| 2086 | } | ||
| 2087 | |||
| 2088 | return cnt; | ||
| 2089 | } | ||
| 2090 | |||
| 2091 | |||
| 2092 | xs_list *notify_list(snac *snac) | ||
| 2093 | /* returns a list of notification ids, optionally only the new ones */ | ||
| 2094 | { | ||
| 2076 | xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); | 2095 | xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); |
| 2077 | xs *lst = xs_glob(spec, 1, 1); | 2096 | xs *lst = xs_glob(spec, 1, 1); |
| 2078 | xs_list *out = xs_list_new(); | 2097 | xs_list *out = xs_list_new(); |
| @@ -2082,10 +2101,6 @@ xs_list *notify_list(snac *snac, int new_only) | |||
| 2082 | while (xs_list_iter(&p, &v)) { | 2101 | while (xs_list_iter(&p, &v)) { |
| 2083 | xs *id = xs_replace(v, ".json", ""); | 2102 | xs *id = xs_replace(v, ".json", ""); |
| 2084 | 2103 | ||
| 2085 | /* old? */ | ||
| 2086 | if (t != NULL && strcmp(id, t) < 0) | ||
| 2087 | continue; | ||
| 2088 | |||
| 2089 | out = xs_list_append(out, id); | 2104 | out = xs_list_append(out, id); |
| 2090 | } | 2105 | } |
| 2091 | 2106 | ||
| @@ -673,8 +673,7 @@ static xs_html *html_user_body(snac *user, int local) | |||
| 673 | xs_html_text(L("private")))); | 673 | xs_html_text(L("private")))); |
| 674 | } | 674 | } |
| 675 | else { | 675 | else { |
| 676 | xs *n_list = notify_list(user, 1); | 676 | int n_len = notify_new_num(user); |
| 677 | int n_len = xs_list_len(n_list); | ||
| 678 | xs_html *notify_count = NULL; | 677 | xs_html *notify_count = NULL; |
| 679 | 678 | ||
| 680 | /* show the number of new notifications, if there are any */ | 679 | /* show the number of new notifications, if there are any */ |
| @@ -2138,7 +2137,7 @@ xs_str *html_people(snac *user) | |||
| 2138 | 2137 | ||
| 2139 | xs_str *html_notifications(snac *user) | 2138 | xs_str *html_notifications(snac *user) |
| 2140 | { | 2139 | { |
| 2141 | xs *n_list = notify_list(user, 0); | 2140 | xs *n_list = notify_list(user); |
| 2142 | xs *n_time = notify_check_time(user, 0); | 2141 | xs *n_time = notify_check_time(user, 0); |
| 2143 | 2142 | ||
| 2144 | xs_html *body = html_user_body(user, 0); | 2143 | xs_html *body = html_user_body(user, 0); |
| @@ -1542,7 +1542,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1542 | else | 1542 | else |
| 1543 | if (strcmp(cmd, "/v1/notifications") == 0) { /** **/ | 1543 | if (strcmp(cmd, "/v1/notifications") == 0) { /** **/ |
| 1544 | if (logged_in) { | 1544 | if (logged_in) { |
| 1545 | xs *l = notify_list(&snac1, 0); | 1545 | xs *l = notify_list(&snac1); |
| 1546 | xs *out = xs_list_new(); | 1546 | xs *out = xs_list_new(); |
| 1547 | xs_list *p = l; | 1547 | xs_list *p = l; |
| 1548 | xs_dict *v; | 1548 | xs_dict *v; |
| @@ -187,7 +187,8 @@ xs_str *notify_check_time(snac *snac, int reset); | |||
| 187 | void notify_add(snac *snac, const char *type, const char *utype, | 187 | void notify_add(snac *snac, const char *type, const char *utype, |
| 188 | const char *actor, const char *objid); | 188 | const char *actor, const char *objid); |
| 189 | xs_dict *notify_get(snac *snac, const char *id); | 189 | xs_dict *notify_get(snac *snac, const char *id); |
| 190 | xs_list *notify_list(snac *snac, int new_only); | 190 | int notify_new_num(snac *snac); |
| 191 | xs_list *notify_list(snac *snac); | ||
| 191 | void notify_clear(snac *snac); | 192 | void notify_clear(snac *snac); |
| 192 | 193 | ||
| 193 | void inbox_add(const char *inbox); | 194 | void inbox_add(const char *inbox); |