summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-11-29 09:36:03 +0100
committerGravatar default2023-11-29 09:36:03 +0100
commit9af9f29d3313226500f65aab7e569c7de6a01280 (patch)
tree68e0f47aff213538cea9f1694e3d505edbe809a4
parentFixed crash in activitypub_request() when there is no payload. (diff)
downloadsnac2-9af9f29d3313226500f65aab7e569c7de6a01280.tar.gz
snac2-9af9f29d3313226500f65aab7e569c7de6a01280.tar.xz
snac2-9af9f29d3313226500f65aab7e569c7de6a01280.zip
html_notifications() is now fully xs_html.
-rw-r--r--html.c174
1 files changed, 87 insertions, 87 deletions
diff --git a/html.c b/html.c
index 1271a7e..5ccc8db 100644
--- a/html.c
+++ b/html.c
@@ -2331,85 +2331,60 @@ xs_str *html_people(snac *user)
2331} 2331}
2332 2332
2333 2333
2334xs_str *html_notifications(snac *snac) 2334xs_str *html_notifications(snac *user)
2335{ 2335{
2336 xs_str *s = xs_str_new(NULL); 2336 xs *n_list = notify_list(user, 0);
2337 xs *n_list = notify_list(snac, 0); 2337 xs *n_time = notify_check_time(user, 0);
2338 xs *n_time = notify_check_time(snac, 0);
2339 xs_list *p = n_list;
2340 xs_str *v;
2341 enum { NHDR_NONE, NHDR_NEW, NHDR_OLD } stage = NHDR_NONE;
2342 2338
2343 s = html_user_header(snac, s, 0); 2339 xs_html *body = html_user_body(user, 0);
2344 2340
2345 xs *clear_all_action = xs_fmt("%s/admin/clear-notifications", snac->actor); 2341 xs_html *html = xs_html_tag("html",
2346 xs_html *clear_all_form = xs_html_tag("form", 2342 html_user_head(user),
2347 xs_html_attr("autocomplete", "off"), 2343 body);
2348 xs_html_attr("method", "post"),
2349 xs_html_attr("action", clear_all_action),
2350 xs_html_attr("id", "clear"),
2351 xs_html_sctag("input",
2352 xs_html_attr("type", "submit"),
2353 xs_html_attr("class", "snac-btn-like"),
2354 xs_html_attr("value", L("Clear all"))));
2355 2344
2356 { 2345 xs *clear_all_action = xs_fmt("%s/admin/clear-notifications", user->actor);
2357 xs *s1 = xs_html_render(clear_all_form);
2358 s = xs_str_cat(s, s1);
2359 }
2360 2346
2347 xs_html_add(body,
2348 xs_html_tag("form",
2349 xs_html_attr("autocomplete", "off"),
2350 xs_html_attr("method", "post"),
2351 xs_html_attr("action", clear_all_action),
2352 xs_html_attr("id", "clear"),
2353 xs_html_sctag("input",
2354 xs_html_attr("type", "submit"),
2355 xs_html_attr("class", "snac-btn-like"),
2356 xs_html_attr("value", L("Clear all")))));
2357
2358 xs_html *noti_new = NULL;
2359 xs_html *noti_seen = NULL;
2360
2361 xs_list *p = n_list;
2362 xs_str *v;
2361 while (xs_list_iter(&p, &v)) { 2363 while (xs_list_iter(&p, &v)) {
2362 xs *noti = notify_get(snac, v); 2364 xs *noti = notify_get(user, v);
2363 2365
2364 if (noti == NULL) 2366 if (noti == NULL)
2365 continue; 2367 continue;
2366 2368
2367 xs *obj = NULL; 2369 xs *obj = NULL;
2368 const char *type = xs_dict_get(noti, "type"); 2370 char *type = xs_dict_get(noti, "type");
2369 const char *utype = xs_dict_get(noti, "utype"); 2371 char *utype = xs_dict_get(noti, "utype");
2370 const char *id = xs_dict_get(noti, "objid"); 2372 char *id = xs_dict_get(noti, "objid");
2371 2373
2372 if (xs_is_null(id) || !valid_status(object_get(id, &obj))) 2374 if (xs_is_null(id) || !valid_status(object_get(id, &obj)))
2373 continue; 2375 continue;
2374 2376
2375 if (is_hidden(snac, id)) 2377 if (is_hidden(user, id))
2376 continue; 2378 continue;
2377 2379
2378 const char *actor_id = xs_dict_get(noti, "actor"); 2380 char *actor_id = xs_dict_get(noti, "actor");
2379 xs *actor = NULL; 2381 xs *actor = NULL;
2380 2382
2381 if (!valid_status(actor_get(actor_id, &actor))) 2383 if (!valid_status(actor_get(actor_id, &actor)))
2382 continue; 2384 continue;
2383 2385
2384 xs *a_name = actor_name(actor); 2386 xs *a_name = actor_name(actor);
2385 2387 char *label = type;
2386 if (strcmp(v, n_time) > 0) {
2387 /* unseen notification */
2388 if (stage == NHDR_NONE) {
2389 xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n", L("New"));
2390 s = xs_str_cat(s, s1);
2391
2392 s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
2393
2394 stage = NHDR_NEW;
2395 }
2396 }
2397 else {
2398 /* already seen notification */
2399 if (stage != NHDR_OLD) {
2400 if (stage == NHDR_NEW)
2401 s = xs_str_cat(s, "</div>\n");
2402
2403 xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n", L("Already seen"));
2404 s = xs_str_cat(s, s1);
2405
2406 s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
2407
2408 stage = NHDR_OLD;
2409 }
2410 }
2411
2412 const char *label = type;
2413 2388
2414 if (strcmp(type, "Create") == 0) 2389 if (strcmp(type, "Create") == 0)
2415 label = L("Mention"); 2390 label = L("Mention");
@@ -2420,56 +2395,81 @@ xs_str *html_notifications(snac *snac)
2420 if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0) 2395 if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0)
2421 label = L("Unfollow"); 2396 label = L("Unfollow");
2422 2397
2423 xs *es1 = encode_html(label); 2398 xs_html *entry = xs_html_tag("div",
2424 xs *s1 = xs_fmt("<div class=\"snac-post-with-desc\">\n" 2399 xs_html_attr("class", "snac-post-with-desc"),
2425 "<p><b>%s by <a href=\"%s\">%s</a></b>:</p>\n", 2400 xs_html_tag("p",
2426 es1, actor_id, a_name); 2401 xs_html_tag("b",
2427 s = xs_str_cat(s, s1); 2402 xs_html_text(label),
2403 xs_html_text(" by "),
2404 xs_html_tag("a",
2405 xs_html_attr("href", actor_id),
2406 xs_html_raw(a_name))))); /* a_name is already sanitized */
2428 2407
2429 if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0) { 2408 if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0) {
2430 xs_html *div = xs_html_tag("div", 2409 xs_html_add(entry,
2431 xs_html_attr("class", "snac-post"), 2410 xs_html_tag("div",
2432 html_actor_icon(actor, NULL, NULL, NULL, 0)); 2411 xs_html_attr("class", "snac-post"),
2433 2412 html_actor_icon(actor, NULL, NULL, NULL, 0)));
2434 xs *s1 = xs_html_render(div);
2435 s = xs_str_cat(s, s1);
2436 } 2413 }
2437 else { 2414 else {
2438 xs *md5 = xs_md5_hex(id, strlen(id)); 2415 xs *md5 = xs_md5_hex(id, strlen(id));
2439 2416
2440 xs_html *entry = html_entry(snac, obj, 0, 0, md5, 1); 2417 xs_html *h = html_entry(user, obj, 0, 0, md5, 1);
2441 2418
2442 if (entry != NULL) { 2419 if (h != NULL) {
2443 xs *s1 = xs_html_render(entry); 2420 xs_html_add(entry,
2444 s = xs_str_cat(s, s1); 2421 h);
2445 } 2422 }
2446 } 2423 }
2447 2424
2448 s = xs_str_cat(s, "</div>\n"); 2425 if (strcmp(v, n_time) > 0) {
2449 } 2426 /* unseen notification */
2427 if (noti_new == NULL) {
2428 noti_new = xs_html_tag("div",
2429 xs_html_tag("h2",
2430 xs_html_attr("class", "snac-header"),
2431 xs_html_text(L("New"))));
2432
2433 xs_html_add(body,
2434 noti_new);
2435 }
2450 2436
2451 if (stage == NHDR_NONE) { 2437 xs_html_add(noti_new,
2452 xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n", L("None")); 2438 entry);
2453 s = xs_str_cat(s, s1); 2439 }
2454 } 2440 else {
2455 else 2441 /* already seen notification */
2456 s = xs_str_cat(s, "</div>\n"); 2442 if (noti_seen == NULL) {
2443 noti_seen = xs_html_tag("div",
2444 xs_html_tag("h2",
2445 xs_html_attr("class", "snac-header"),
2446 xs_html_text(L("Already seen"))));
2447
2448 xs_html_add(body,
2449 noti_seen);
2450 }
2457 2451
2458 { 2452 xs_html_add(noti_seen,
2459 xs_html *h = html_footer(); 2453 entry);
2460 xs *s1 = xs_html_render(h); 2454 }
2461 s = xs_str_cat(s, s1);
2462 } 2455 }
2463 2456
2464 s = xs_str_cat(s, "</body>\n</html>\n"); 2457 if (noti_new == NULL && noti_seen == NULL)
2458 xs_html_add(body,
2459 xs_html_tag("hd",
2460 xs_html_attr("class", "snac-header"),
2461 xs_html_text(L("None"))));
2462
2463 xs_html_add(body,
2464 html_footer());
2465 2465
2466 /* set the check time to now */ 2466 /* set the check time to now */
2467 xs *dummy = notify_check_time(snac, 1); 2467 xs *dummy = notify_check_time(user, 1);
2468 dummy = xs_free(dummy); 2468 dummy = xs_free(dummy);
2469 2469
2470 timeline_touch(snac); 2470 timeline_touch(user);
2471 2471
2472 return s; 2472 return xs_html_render_s(html, "<!DOCTYPE html>\n");
2473} 2473}
2474 2474
2475 2475