Notifications

FossilOrigin-Name: ce21a66f8c12ceea330a9dfa87ad5bfbd1241feced93851afe10a7c630fe5ef6
This commit is contained in:
me@ow.nekobit.net 2022-03-29 13:03:02 +00:00
parent 2bca7e5f60
commit d41f1e404a
12 changed files with 169 additions and 25 deletions

29
dist/treebird20.css vendored
View file

@ -257,6 +257,24 @@ ul li:first-child a.sidebarbtn
font-size: 10px;
}
.notification-info
{
margin-top: 7px;
}
.notification-info img
{
margin-left: 36px;
width: 24px;
}
.notification-info .notification-user
{
display: inline;
position: relative;
top: -8px;
}
/***************************
* Statuses *
**************************/
@ -268,6 +286,11 @@ ul li:first-child a.sidebarbtn
border-spacing: 0px;
}
.notification-info + .status
{
padding-top: 0;
}
.status .profile-picture
{
display: inline-block;
@ -692,6 +715,7 @@ ul li:first-child a.sidebarbtn
display: block;
padding: 0;
margin-top: 8px;
padding-left: 0px !important;
margin-bottom: 6px;
}
@ -703,6 +727,11 @@ ul li:first-child a.sidebarbtn
margin: 0 4px;
}
.emoji
{
font-family: Emoji;
}
/*************************************************
* LISTS *
*************************************************/

View file

@ -22,6 +22,7 @@
#include "base_page.h"
#include "string_helpers.h"
#include "easprintf.h"
#include "status.h"
// Pages
#include "../static/notifications_page.chtml"
@ -32,22 +33,21 @@
char* construct_notification(struct mstdnt_notification* notif, int* size)
{
char* notif_html;
int s = 0;
if (notif->status)
{
// Construct status with notification_info
notif_html = construct_status(notif->status, &s, notif);
}
else {
notif_html = NULL;
}
if (size) *size = s;
return notif_html;
}
const char* notification_type_str(mstdnt_notification_t type)
{
switch (type)
{
case MSTDNT_NOTIFICATION_FOLLOW: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW];
case MSTDNT_NOTIFICATION_FOLLOW_REQUEST: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW_REQUEST];
case MSTDNT_NOTIFICATION_REBLOG: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REPEATED];
case MSTDNT_NOTIFICATION_FAVOURITE: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_LIKED];
case MSTDNT_NOTIFICATION_POLL: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_POLL];
case MSTDNT_NOTIFICATION_EMOJI_REACT: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REACTED_WITH];
default: return "";
}
}
char* construct_notification_compact(struct mstdnt_notification* notif, int* size)
{
@ -109,13 +109,44 @@ char* construct_notifications_compact(struct mstdnt_notification* notifs,
void content_notifications(mastodont_t* api, char** data, size_t data_size)
{
char* page, *notif_html = NULL;
struct mstdnt_storage storage;
struct mstdnt_notification* notifs;
size_t notifs_len;
if (cookies.logged_in)
{
struct mstdnt_get_notifications_args args = {
.exclude_types = 0,
.account_id = NULL,
.exclude_visibilities = 0,
.include_types = 0,
.with_muted = 1,
.max_id = NULL,
.min_id = NULL,
.since_id = NULL,
.offset = 0,
.limit = 20,
};
if (mastodont_get_notifications(api, &args, &storage, &notifs, &notifs_len) == 0)
notif_html = construct_notifications(notifs, notifs_len, NULL);
mstdnt_cleanup_notifications(notifs, notifs_len);
}
easprintf(&page, data_notifications_page_html,
notif_html ? notif_html : "Not logged in");
struct base_page b = {
.locale = L10N_EN_US,
.content = data_notifications_page_html,
.content = page,
.sidebar_left = NULL
};
// Output
render_base_page(&b, api);
if (notif_html) free(notif_html);
if (page) free(page);
}

View file

@ -19,8 +19,8 @@
#ifndef NOTIFICATIONS_H
#define NOTIFICATIONS_H
#include <mastodont.h>
const char* notification_type_str(mstdnt_notification_t type);
#include "cookie.h"
#include "type_string.h"
char* construct_notification(struct mstdnt_notification* notif, int* size);
char* construct_notification_compact(struct mstdnt_notification* notif, int* size);

View file

@ -28,9 +28,11 @@
#include "attachments.h"
#include "emoji_reaction.h"
#include "../config.h"
#include "type_string.h"
// Pages
#include "../static/status.chtml"
#include "../static/notification.chtml"
#define NUM_STR "%u"
@ -97,7 +99,9 @@ int try_interact_status(mastodont_t* api, char* id)
return 0;
}
char* construct_status(struct mstdnt_status* status, int* size)
char* construct_status(struct mstdnt_status* status,
int* size,
struct mstdnt_notification* notif)
{
char* stat_html;
@ -107,6 +111,7 @@ char* construct_status(struct mstdnt_status* status, int* size)
char* favourites_count = NULL;
char* attachments = NULL;
char* emoji_reactions = NULL;
char* notif_info = NULL;
if (status->replies_count)
easprintf(&reply_count, NUM_STR, status->replies_count);
if (status->reblogs_count)
@ -117,9 +122,15 @@ char* construct_status(struct mstdnt_status* status, int* size)
attachments = construct_attachments(status->sensitive, status->media_attachments, status->media_attachments_len, NULL);
if (status->pleroma.emoji_reactions_len)
emoji_reactions = construct_emoji_reactions(status->pleroma.emoji_reactions, status->pleroma.emoji_reactions_len, NULL);
if (notif && notif->type != MSTDNT_NOTIFICATION_MENTION)
easprintf(&notif_info, data_notification_html,
notif->account->avatar,
notif->account->display_name,
notification_type_str(notif->type));
size_t s = easprintf(&stat_html, data_status_html,
notif_info ? notif_info : "",
status->account.avatar,
status->account.display_name, /* Username */
config_url_prefix,
@ -151,12 +162,13 @@ char* construct_status(struct mstdnt_status* status, int* size)
if (favourites_count) free(favourites_count);
if (attachments) free(attachments);
if (emoji_reactions) free(emoji_reactions);
if (notif) free(notif_info);
return stat_html;
}
static char* construct_status_voidwrap(void* passed, size_t index, int* res)
{
return construct_status((struct mstdnt_status*)passed + index, res);
return construct_status((struct mstdnt_status*)passed + index, res, NULL);
}
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size)
@ -210,7 +222,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
before_html = construct_statuses(statuses_before, stat_before_len, NULL);
// Current status
stat_html = construct_status(&status, NULL);
stat_html = construct_status(&status, NULL, NULL);
if (is_reply)
{
stat_reply = reply_status(data[0],

View file

@ -28,7 +28,7 @@ void content_status_create(mastodont_t* api, char** data, size_t data_size);
char* construct_post_box(char* reply_id,
char* default_content,
int* size);
char* construct_status(struct mstdnt_status* status, int* size);
char* construct_status(struct mstdnt_status* status, int* size, struct mstdnt_notification* notif);
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
// Status frontends

View file

@ -35,6 +35,10 @@ char* construct_func_strings(char* (*func)(void*, size_t, int*),
for (size_t i = 0; i < strings_len; ++i)
{
res_html = func(strings, i, &parse_size);
// Don't bother if it returns null
// Null is equivalent to ""
if (!res_html) continue;
if (parse_size == -1) /* Malloc error */
{
@ -52,9 +56,9 @@ char* construct_func_strings(char* (*func)(void*, size_t, int*),
return NULL;
}
/* Copy res_html to result in correct position */
// Copy res_html to result in correct position
strncpy(result + last_parse_size, res_html, parse_size);
/* Cleanup */
// Cleanup
free(res_html);
}

33
src/type_string.c Normal file
View file

@ -0,0 +1,33 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "type_string.h"
const char* notification_type_str(mstdnt_notification_t type)
{
switch (type)
{
case MSTDNT_NOTIFICATION_FOLLOW: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW];
case MSTDNT_NOTIFICATION_FOLLOW_REQUEST: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW_REQUEST];
case MSTDNT_NOTIFICATION_REBLOG: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REPEATED];
case MSTDNT_NOTIFICATION_FAVOURITE: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_LIKED];
case MSTDNT_NOTIFICATION_POLL: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_POLL];
case MSTDNT_NOTIFICATION_EMOJI_REACT: return L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REACTED_WITH];
default: return "";
}
}

26
src/type_string.h Normal file
View file

@ -0,0 +1,26 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TYPE_STRING_H
#define TYPE_STRING_H
#include <mastodont.h>
#include "l10n.h"
const char* notification_type_str(mstdnt_notification_t type);
#endif // TYPE_STRING_H

View file

@ -1 +1,7 @@
notif
<div class="notification-info">
<img src="%s">
<div class="notification-user">
<span class="username">%s</span>
<span class="action">%s</span>
</div>
</div>

View file

@ -1,3 +1,3 @@
<div class="notifications-container">
%s
</div>

View file

@ -1,4 +1,6 @@
<div class="simple-page">
<h1>Notifications</h1>
%s
<div class="notifications-container">
%s
</div>
</div>

View file

@ -1,4 +1,5 @@
<table class="status ui-table">
%s
<tr>
<td class="pfp-td">
<img src="%s" width="56">