forked from mirrors/treebird
Emoji reaction
FossilOrigin-Name: 3024cb51e152637daaad2d91294f81ad3a91a5b1b7df2105735d13e02a309d30
This commit is contained in:
parent
238b2bcd19
commit
9412c33062
7 changed files with 60 additions and 10 deletions
17
dist/treebird20.css
vendored
17
dist/treebird20.css
vendored
|
@ -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 *
|
||||
*************************************************/
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "string_helpers.h"
|
||||
#include "emoji_reaction.h"
|
||||
#include <stdlib.h>
|
||||
|
@ -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);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define EMOJI_REACTION_H
|
||||
#include <mastodont.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -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 },
|
||||
|
|
23
src/status.c
23
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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1 +1 @@
|
|||
<li class="emoji-react-box btn"><span class="emoji">%s</span> %u</li>
|
||||
<a href="%s/status/%s/react/%s" class="emoji-react-box btn %s"><span class="emoji">%s</span> <span class="emoji-num">%u<span></a>
|
||||
|
|
Loading…
Reference in a new issue