Notification types

FossilOrigin-Name: ac2b37f01821bf40987bb501a736e25bb8486a8cfef8ac7c2e25cf06e7d1f16b
This commit is contained in:
me@ow.nekobit.net 2022-03-24 03:21:39 +00:00
parent 0779ca5060
commit 6aecb7226f
4 changed files with 67 additions and 4 deletions

14
dist/treebird20.css vendored
View file

@ -213,11 +213,25 @@ ul li:first-child a.sidebarbtn
border-bottom: 1px solid #dadada;
}
.pfp-compact-td
{
width: 16px;
}
.pfp-compact-td img
{
border-radius: 3px;
}
.notification-compact
{
min-width: 100%;
}
.notification-compact p
{
margin: 0;
}
.notification-compact .notification-info
{
font-size: 12px;

View file

@ -88,12 +88,14 @@ enum l10n_string
L10N_NOTIF_REPEATED,
L10N_NOTIF_FOLLOW,
L10N_NOTIF_FOLLOW_REQUEST,
L10N_NOTIF_POLL,
L10N_NOTIF_COMPACT_LIKED,
L10N_NOTIF_COMPACT_REACTED_WITH,
L10N_NOTIF_COMPACT_REPEATED,
L10N_NOTIF_COMPACT_FOLLOW,
L10N_NOTIF_COMPACT_FOLLOW_REQUEST,
L10N_NOTIF_COMPACT_POLL,
_L10N_LEN,
};
@ -149,7 +151,7 @@ static const char* const L10N[][_L10N_LEN] = {
/* LOGIN */
"Login",
"Register"
"Register",
"Username",
"Password",
"Login",
@ -162,12 +164,14 @@ static const char* const L10N[][_L10N_LEN] = {
"repeated your status",
"followed you",
"wants to follow you",
"poll results",
"liked",
"reacted",
"repeated",
"followed",
"follows?"
"follows?",
"poll",
},
// ES_ES
@ -220,7 +224,7 @@ static const char* const L10N[][_L10N_LEN] = {
/* LOGIN */
"Login",
"Register"
"Register",
"Username",
"Password",
"Login",
@ -233,12 +237,14 @@ static const char* const L10N[][_L10N_LEN] = {
"repeated your status",
"followed you",
"wants to follow you",
"poll results",
"liked",
"reacted",
"repeated",
"followed",
"follows?",
"poll",
},
};

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
#include "notifications.h"
#include "base_page.h"
@ -34,11 +35,52 @@ char* construct_notification(struct mstdnt_notification* notif, int* size)
return notif_html;
}
/* https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightLinear */
static unsigned trail_bits(unsigned int v)
{
unsigned int c; // output: c will count v's trailing zero bits,
// so if v is 1101000 (base 2), then c will be 3
if (v)
{
v = (v ^ (v - 1)) >> 1; // Set v's trailing 0s to 1s and zero rest
for (c = 0; v; c++)
{
v >>= 1;
}
}
else
{
c = CHAR_BIT * sizeof(v);
}
return c;
}
const char* notification_type_str(mstdnt_notification_t type)
{
/* Taking advantage of the bitshift in the definitions,
* we create a table based on the index
* See: mastodont_c/include/mastodont_notif_types.h */
char* notif_type_table[] = {
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW],
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_FOLLOW_REQUEST],
"",
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REPEATED],
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_LIKED],
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_POLL],
"",
L10N[L10N_EN_US][L10N_NOTIF_COMPACT_REACTED_WITH],
};
return notif_type_table[trail_bits((unsigned)type)];
}
char* construct_notification_compact(struct mstdnt_notification* notif, int* size)
{
char* notif_html;
char* notif_stats = NULL;
const char* type_str = notification_type_str(notif->type);
if (notif->status)
easprintf(&notif_stats, "%d - %d - %d",
notif->status->replies_count,
@ -49,7 +91,7 @@ char* construct_notification_compact(struct mstdnt_notification* notif, int* siz
size_t s = easprintf(&notif_html, data_notification_compact_html,
notif->account->avatar,
notif->account->display_name,
"interacted",
type_str,
notif->status ? notif->status->content : "",
notif_stats ? notif_stats : "");

View file

@ -20,6 +20,7 @@
#define NOTIFICATIONS_H
#include <mastodont.h>
const char* notification_type_str(mstdnt_notification_t type);
char* construct_notification(struct mstdnt_notification* notif, int* size);
char* construct_notification_compact(struct mstdnt_notification* notif, int* size);