From 9412c330624198bba936f0e4192297d3a9e8bd6d Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Sun, 8 May 2022 06:11:41 +0000 Subject: [PATCH] Emoji reaction FossilOrigin-Name: 3024cb51e152637daaad2d91294f81ad3a91a5b1b7df2105735d13e02a309d30 --- dist/treebird20.css | 17 ++++++++++++++++- src/emoji_reaction.c | 22 +++++++++++++++++----- src/emoji_reaction.h | 4 ++-- src/main.c | 1 + src/status.c | 23 ++++++++++++++++++++++- src/status.h | 1 + static/emoji_reaction.html | 2 +- 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/dist/treebird20.css b/dist/treebird20.css index 978a2ad..4e7b58e 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -323,6 +323,13 @@ table.present th, table.present td cursor: pointer; } +.btn.active +{ + background: initial; + background-color: #eeaaaa; + border-color: #cc0000; +} + .btn-disabled { color: #cacaca !important; @@ -1172,14 +1179,22 @@ svg.in-reply-to-icon display: inline-block; list-style-type: none; padding: 3px 7px; - margin: 2px 4px; + margin: 1px 2px; + vertical-align: middle; + } .emoji { + vertical-align: middle; font-family: Emoji; } +.emoji-num +{ + vertical-align: middle; +} + /************************************************* * LISTS * *************************************************/ diff --git a/src/emoji_reaction.c b/src/emoji_reaction.c index a81d5b0..2b6f99d 100644 --- a/src/emoji_reaction.c +++ b/src/emoji_reaction.c @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "../config.h" #include "string_helpers.h" #include "emoji_reaction.h" #include @@ -25,25 +26,36 @@ #include "../static/emoji_reaction.chtml" #include "../static/emoji_reactions.chtml" -char* construct_emoji_reaction(struct mstdnt_emoji_reaction* emo, int* str_size) +struct construct_emoji_reactions_args +{ + struct mstdnt_emoji_reaction* emojis; + char* id; +}; + +char* construct_emoji_reaction(char* id, struct mstdnt_emoji_reaction* emo, int* str_size) { char* emo_html; size_t s = easprintf(&emo_html, data_emoji_reaction_html, - emo->name, emo->count); + config_url_prefix, id, emo->name, emo->me ? "active" : "", emo->name, emo->count); if (str_size) *str_size = s; return emo_html; } static char* construct_emoji_reactions_voidwrap(void* passed, size_t index, int* res) { - return construct_emoji_reaction((struct mstdnt_emoji_reaction*)passed + index, res); + struct construct_emoji_reactions_args* args = passed; + return construct_emoji_reaction(args->id, args->emojis + index, res); } -char* construct_emoji_reactions(struct mstdnt_emoji_reaction* emos, size_t emos_len, size_t* str_size) +char* construct_emoji_reactions(char* id, struct mstdnt_emoji_reaction* emos, size_t emos_len, size_t* str_size) { size_t elements_size; - char* elements = construct_func_strings(construct_emoji_reactions_voidwrap, emos, emos_len, &elements_size); + struct construct_emoji_reactions_args args = { + .emojis = emos, + .id = id + }; + char* elements = construct_func_strings(construct_emoji_reactions_voidwrap, &args, emos_len, &elements_size); char* emos_view; size_t s = easprintf(&emos_view, data_emoji_reactions_html, elements); diff --git a/src/emoji_reaction.h b/src/emoji_reaction.h index a8ffae9..88b57ce 100644 --- a/src/emoji_reaction.h +++ b/src/emoji_reaction.h @@ -20,7 +20,7 @@ #define EMOJI_REACTION_H #include -char* construct_emoji_reaction(struct mstdnt_emoji_reaction* emo, int* str_len); -char* construct_emoji_reactions(struct mstdnt_emoji_reaction* emos, size_t emos_len, size_t* str_len); +char* construct_emoji_reaction(char* id, struct mstdnt_emoji_reaction* emo, int* str_len); +char* construct_emoji_reactions(char* id, struct mstdnt_emoji_reaction* emos, size_t emos_len, size_t* str_len); #endif // EMOJI_REACTION_H diff --git a/src/main.c b/src/main.c index dc9ba80..7262614 100644 --- a/src/main.c +++ b/src/main.c @@ -90,6 +90,7 @@ int main(void) { "/@:/pinned", content_account_pinned }, { "/@:/media", content_account_media }, { "/@:", content_account_statuses }, + { "/status/:/react/:", content_status_react }, { "/status/create", content_status_create }, { "/status/:/interact", status_interact }, { "/status/:/reply", status_reply }, diff --git a/src/status.c b/src/status.c index 02304a9..ace4103 100644 --- a/src/status.c +++ b/src/status.c @@ -96,6 +96,18 @@ int try_post_status(struct session* ssn, mastodont_t* api) return 0; } +int try_react_status(struct session* ssn, mastodont_t* api, char* id, char* emoji) +{ + struct mstdnt_storage storage = { 0 }; + struct mstdnt_status status = { 0 }; + + mastodont_status_emoji_react(api, id, emoji, &storage, &status); + + mstdnt_cleanup_status(&status); + mastodont_storage_cleanup(&storage); + return 1; +} + void content_status_create(struct session* ssn, mastodont_t* api, char** data) { char* referer = getenv("HTTP_REFERER"); @@ -105,6 +117,15 @@ void content_status_create(struct session* ssn, mastodont_t* api, char** data) redirect(REDIRECT_303, referer); } +void content_status_react(struct session* ssn, mastodont_t* api, char** data) +{ + char* referer = getenv("HTTP_REFERER"); + + try_react_status(ssn, api, data[0], data[1]); + + redirect(REDIRECT_303, referer); +} + int try_interact_status(struct session* ssn, mastodont_t* api, char* id) { struct mstdnt_storage storage = { 0 }; @@ -439,7 +460,7 @@ char* construct_status(mastodont_t* api, if (status->media_attachments_len) 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); + emoji_reactions = construct_emoji_reactions(status->id, status->pleroma.emoji_reactions, status->pleroma.emoji_reactions_len, NULL); if (notif && notif->type != MSTDNT_NOTIFICATION_MENTION) easprintf(¬if_info, data_notification_html, notif->account->avatar, diff --git a/src/status.h b/src/status.h index 24082df..d0a568b 100644 --- a/src/status.h +++ b/src/status.h @@ -43,6 +43,7 @@ struct interact_profile_args int try_post_status(struct session* ssn, mastodont_t* api); int try_interact_status(struct session* ssn, mastodont_t* api, char* id); void content_status_create(struct session* ssn, mastodont_t* api, char** data); +void content_status_react(struct session* ssn, mastodont_t* api, char** data); // HTML Builders char* construct_post_box(char* reply_id, diff --git a/static/emoji_reaction.html b/static/emoji_reaction.html index a08a2ca..dd4aa38 100644 --- a/static/emoji_reaction.html +++ b/static/emoji_reaction.html @@ -1 +1 @@ -
  • %s %u
  • +%s %u