summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-14 12:23:32 +0200
committerGravatar default2023-04-14 12:23:32 +0200
commitcb616d6eb53af387e128bb7ce624f161907f4ed9 (patch)
tree5aa931a0288123640f5ccfd947b29aec75584817
parentShow a top link to the (future) notifications area, including a count of new ... (diff)
downloadsnac2-cb616d6eb53af387e128bb7ce624f161907f4ed9.tar.gz
snac2-cb616d6eb53af387e128bb7ce624f161907f4ed9.tar.xz
snac2-cb616d6eb53af387e128bb7ce624f161907f4ed9.zip
New notifications web page.
-rw-r--r--html.c87
-rw-r--r--mastoapi.c3
2 files changed, 88 insertions, 2 deletions
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)
289 289
290 /* show the notification number, if there are any */ 290 /* show the notification number, if there are any */
291 if (n_len) 291 if (n_len)
292 n_str = xs_fmt("<sup style=\"background-color: red; color: white;\"> %d </sup> ", n_len); 292 n_str = xs_fmt("<sup style=\"background-color: red; "
293 "color: white;\"> %d </sup> ", n_len);
293 else 294 else
294 n_str = xs_str_new(""); 295 n_str = xs_str_new("");
295 296
296 s1 = xs_fmt( 297 s1 = xs_fmt(
297 "<a href=\"%s\">%s</a> - " 298 "<a href=\"%s\">%s</a> - "
298 "<a href=\"%s/admin\">%s</a> - " 299 "<a href=\"%s/admin\">%s</a> - "
299 "<a href=\"%s/admin\">%s</a>%s - " 300 "<a href=\"%s/notifications\">%s</a>%s - "
300 "<a href=\"%s/people\">%s</a></nav>\n", 301 "<a href=\"%s/people\">%s</a></nav>\n",
301 snac->actor, L("public"), 302 snac->actor, L("public"),
302 snac->actor, L("private"), 303 snac->actor, L("private"),
@@ -1184,6 +1185,76 @@ d_char *html_people(snac *snac)
1184} 1185}
1185 1186
1186 1187
1188xs_str *html_notifications(snac *snac)
1189{
1190 xs_str *s = xs_str_new(NULL);
1191 xs *n_list = notify_list(snac, 0);
1192 xs *n_time = notify_check_time(snac, 0);
1193 xs_list *p = n_list;
1194 xs_str *v;
1195 enum { NHDR_NONE, NHDR_NEW, NHDR_OLD } stage = NHDR_NONE;
1196
1197 s = html_user_header(snac, s, 0);
1198
1199 while (xs_list_iter(&p, &v)) {
1200 xs *noti = notify_get(snac, v);
1201
1202 if (noti == NULL)
1203 continue;
1204
1205 xs *obj = NULL;
1206 const char *type = xs_dict_get(noti, "type");
1207 const char *id = xs_dict_get(noti, strcmp(type, "Follow") == 0 ? "actor" : "objid");
1208
1209 if (!valid_status(object_get(id, &obj)))
1210 continue;
1211
1212 if (is_hidden(snac, id))
1213 continue;
1214
1215 if (strcmp(v, n_time) > 0) {
1216 /* unseen notification */
1217 if (stage == NHDR_NONE) {
1218 xs *s1 = xs_fmt("<h2>%s</h2>\n", L("New"));
1219 s = xs_str_cat(s, s1);
1220
1221 stage = NHDR_NEW;
1222 }
1223 }
1224 else {
1225 /* already seen notification */
1226 if (stage != NHDR_OLD) {
1227 xs *s1 = xs_fmt("<h2>%s</h2>\n", L("Older"));
1228 s = xs_str_cat(s, s1);
1229
1230 stage = NHDR_OLD;
1231 }
1232 }
1233
1234 s = xs_str_cat(s, "<div>\n");
1235
1236 xs *s1 = xs_fmt("<p><b>%s</b>:</p>\n", strcmp("Create", type) == 0 ? "Mention" : type);
1237 s = xs_str_cat(s, s1);
1238
1239 xs *md5 = xs_md5_hex(id, strlen(id));
1240 s = html_entry(snac, s, obj, 0, 0, md5);
1241
1242 s = xs_str_cat(s, "</div>\n");
1243 }
1244
1245 if (stage == NHDR_NONE) {
1246 xs *s1 = xs_fmt("<h2>%s</h2>\n", L("None"));
1247 s = xs_str_cat(s, s1);
1248 }
1249
1250 s = html_user_footer(snac, s);
1251
1252 s = xs_str_cat(s, "</body>\n</html>\n");
1253
1254 return s;
1255}
1256
1257
1187int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) 1258int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
1188{ 1259{
1189 char *accept = xs_dict_get(req, "accept"); 1260 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 *
1305 } 1376 }
1306 } 1377 }
1307 else 1378 else
1379 if (strcmp(p_path, "notifications") == 0) {
1380 /* the list of notifications */
1381
1382 if (!login(&snac, req))
1383 status = 401;
1384 else {
1385 *body = html_notifications(&snac);
1386 *b_size = strlen(*body);
1387 status = 200;
1388 }
1389 }
1390 else
1308 if (xs_startswith(p_path, "p/")) { 1391 if (xs_startswith(p_path, "p/")) {
1309 /* a timeline with just one entry */ 1392 /* a timeline with just one entry */
1310 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 1393 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,
882 if (objid != NULL && !valid_status(object_get(objid, &entry))) 882 if (objid != NULL && !valid_status(object_get(objid, &entry)))
883 continue; 883 continue;
884 884
885 if (is_hidden(&snac1, objid))
886 continue;
887
885 /* convert the type */ 888 /* convert the type */
886 if (strcmp(type, "Like") == 0) 889 if (strcmp(type, "Like") == 0)
887 type = "favourite"; 890 type = "favourite";