diff --git a/html.c b/html.c index e448cd8..c9d9c86 100644 --- a/html.c +++ b/html.c @@ -289,14 +289,15 @@ d_char *html_user_header(snac *snac, d_char *s, int local) /* show the notification number, if there are any */ if (n_len) - n_str = xs_fmt(" %d ", n_len); + n_str = xs_fmt(" %d ", n_len); else n_str = xs_str_new(""); s1 = xs_fmt( "%s - " "%s - " - "%s%s - " + "%s%s - " "%s\n", snac->actor, L("public"), snac->actor, L("private"), @@ -1184,6 +1185,76 @@ d_char *html_people(snac *snac) } +xs_str *html_notifications(snac *snac) +{ + xs_str *s = xs_str_new(NULL); + xs *n_list = notify_list(snac, 0); + xs *n_time = notify_check_time(snac, 0); + xs_list *p = n_list; + xs_str *v; + enum { NHDR_NONE, NHDR_NEW, NHDR_OLD } stage = NHDR_NONE; + + s = html_user_header(snac, s, 0); + + while (xs_list_iter(&p, &v)) { + xs *noti = notify_get(snac, v); + + if (noti == NULL) + continue; + + xs *obj = NULL; + const char *type = xs_dict_get(noti, "type"); + const char *id = xs_dict_get(noti, strcmp(type, "Follow") == 0 ? "actor" : "objid"); + + if (!valid_status(object_get(id, &obj))) + continue; + + if (is_hidden(snac, id)) + continue; + + if (strcmp(v, n_time) > 0) { + /* unseen notification */ + if (stage == NHDR_NONE) { + xs *s1 = xs_fmt("

%s

\n", L("New")); + s = xs_str_cat(s, s1); + + stage = NHDR_NEW; + } + } + else { + /* already seen notification */ + if (stage != NHDR_OLD) { + xs *s1 = xs_fmt("

%s

\n", L("Older")); + s = xs_str_cat(s, s1); + + stage = NHDR_OLD; + } + } + + s = xs_str_cat(s, "
\n"); + + xs *s1 = xs_fmt("

%s:

\n", strcmp("Create", type) == 0 ? "Mention" : type); + s = xs_str_cat(s, s1); + + xs *md5 = xs_md5_hex(id, strlen(id)); + s = html_entry(snac, s, obj, 0, 0, md5); + + s = xs_str_cat(s, "
\n"); + } + + if (stage == NHDR_NONE) { + xs *s1 = xs_fmt("

%s

\n", L("None")); + s = xs_str_cat(s, s1); + } + + s = html_user_footer(snac, s); + + s = xs_str_cat(s, "\n\n"); + + return s; +} + + int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) { char *accept = xs_dict_get(req, "accept"); @@ -1305,6 +1376,18 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * } } else + if (strcmp(p_path, "notifications") == 0) { + /* the list of notifications */ + + if (!login(&snac, req)) + status = 401; + else { + *body = html_notifications(&snac); + *b_size = strlen(*body); + status = 200; + } + } + else if (xs_startswith(p_path, "p/")) { /* a timeline with just one entry */ xs *id = xs_fmt("%s/%s", snac.actor, p_path); diff --git a/mastoapi.c b/mastoapi.c index 4ec9000..f9141d0 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -882,6 +882,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (objid != NULL && !valid_status(object_get(objid, &entry))) continue; + if (is_hidden(&snac1, objid)) + continue; + /* convert the type */ if (strcmp(type, "Like") == 0) type = "favourite";