diff --git a/src/notifications.c b/src/notifications.c index 09b4eb4..9d721cc 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -35,43 +35,18 @@ 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)]; + 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)