From 72ffa2abedf1e3d6d41375344a0b032539aaf1a0 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sat, 13 Aug 2022 05:01:19 +0000 Subject: [PATCH] Mark all as read, fix CSS FossilOrigin-Name: 115f3020f24f12be0b54fcfff7088ab483fccd5029a36506e02051ec715e5b65 --- dist/treebird.css | 29 ++++++++++++++++++++++--- src/main.c | 3 +++ src/notifications.c | 43 +++++++++++++++++++++++++++++++++++-- src/notifications.h | 1 + templates/content_notifs.tt | 2 ++ templates/status.tt | 5 +++-- 6 files changed, 76 insertions(+), 7 deletions(-) diff --git a/dist/treebird.css b/dist/treebird.css index ea7b454..147b82c 100644 --- a/dist/treebird.css +++ b/dist/treebird.css @@ -838,14 +838,37 @@ input[type=checkbox].hidden:not(:checked) + .reply-form /* vertical-align: middle; */ /* } */ -.status.status-notification .status-content +.status.status-notification:not(.status-notification-mention) .status-content { color: #808080; } -.status.status-notification .status-interact +.notification-unread { - float: right; + position: relative; +} + + +.notification-unread::before +{ + content:""; + position: absolute; + top: 0px; + left: 0px; + width: 15px; + height: 15px; + background: linear-gradient(135deg, rgba(255,0,0,1) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0) 100%); +} + +.notification-unread::after +{ + content:""; + position: absolute; + top: 0px; + left: 0px; + width: 65px; + height: 65px; + background: linear-gradient(135deg, rgba(255,0,0,.2) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0) 100%); } /*************************** diff --git a/src/main.c b/src/main.c index 7c0c757..cf05e20 100644 --- a/src/main.c +++ b/src/main.c @@ -103,6 +103,9 @@ static struct path_info paths[] = { { "/blocked", content_account_blocked }, { "/muted", content_account_muted }, { "/notifications_compact", content_notifications_compact }, + { "/notification/:/read", content_notifications_read }, + { "/notification/:/delete", content_notifications_clear }, + { "/notifications/read", content_notifications_read }, { "/notifications/clear", content_notifications_clear }, { "/notifications", content_notifications }, { "/tag/:", content_tl_tag }, diff --git a/src/notifications.c b/src/notifications.c index 3fe93a5..ca5915c 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -340,12 +340,51 @@ void content_notifications_clear(PATH_ARGS) set_mstdnt_args(&m_args, ssn); struct mstdnt_storage storage = { 0 }; - mastodont_notifications_clear(api, &m_args, &storage); + if (data) + { + mastodont_notification_dismiss(api, &m_args, &storage, data[0]); + } + else { + mastodont_notifications_clear(api, &m_args, &storage); + } mastodont_storage_cleanup(&storage); redirect(req, REDIRECT_303, referer); } +void content_notifications_read(PATH_ARGS) +{ + char* referer = GET_ENV("HTTP_REFERER", req); + struct mstdnt_args m_args; + set_mstdnt_args(&m_args, ssn); + struct mstdnt_storage storage = { 0 }; + + if (data) + { + struct mstdnt_notifications_args args = { .id = data[0] }; + mastodont_notifications_read(api, &m_args, &args, &storage, NULL); + } + else { + mastodont_notifications_read(api, &m_args, NULL, &storage, NULL); + } + + mastodont_storage_cleanup(&storage); + redirect(req, REDIRECT_303, referer); +} + +// Converts it into a perl struct +static HV* perlify_notification_pleroma(struct mstdnt_notification_pleroma* notif) +{ + if (!notif) return NULL; + HV* notif_pl_hv = newHV(); + + hvstores_int(notif_pl_hv, "is_muted", notif->is_muted); + hvstores_int(notif_pl_hv, "is_seen", notif->is_seen); + + return notif_pl_hv; +} + + // Converts it into a perl struct HV* perlify_notification(struct mstdnt_notification* notif) { @@ -357,6 +396,7 @@ HV* perlify_notification(struct mstdnt_notification* notif) hvstores_str(notif_hv, "emoji", notif->emoji); hvstores_str(notif_hv, "type", mstdnt_notification_t_to_str(notif->type)); hvstores_ref(notif_hv, "account", perlify_account(notif->account)); + hvstores_ref(notif_hv, "pleroma", perlify_notification_pleroma(notif->pleroma)); hvstores_ref(notif_hv, "status", perlify_status(notif->status)); return notif_hv; @@ -380,5 +420,4 @@ AV* perlify_notifications(struct mstdnt_notification* notifs, size_t len) void api_notifications(PATH_ARGS) { send_result(req, NULL, "application/json", "{\"status\":0}", 0); - } diff --git a/src/notifications.h b/src/notifications.h index 8a51b3b..9ceed69 100644 --- a/src/notifications.h +++ b/src/notifications.h @@ -50,6 +50,7 @@ char* construct_notifications_compact(struct session* ssn, void content_notifications(PATH_ARGS); void content_notifications_compact(PATH_ARGS); void content_notifications_clear(PATH_ARGS); +void content_notifications_read(PATH_ARGS); void api_notifications(PATH_ARGS); diff --git a/templates/content_notifs.tt b/templates/content_notifs.tt index cf710c1..8b9797f 100644 --- a/templates/content_notifs.tt +++ b/templates/content_notifs.tt @@ -3,8 +3,10 @@ [% IF notifs %] diff --git a/templates/status.tt b/templates/status.tt index a73f9a5..501123e 100644 --- a/templates/status.tt +++ b/templates/status.tt @@ -1,6 +1,7 @@
@@ -115,7 +116,7 @@
[% END %]
- [% UNLESS notif || is_statusey_notif %] + [% IF !notif || is_statusey_notif %]