Emoji picker and refactoring bullshit still
FossilOrigin-Name: 8ac12640e4940972a2528fb690e7a1736208275dcb053edc9bf418642a82867c
This commit is contained in:
parent
aae83c2bd9
commit
d033f363c3
11 changed files with 23 additions and 602 deletions
|
@ -22,4 +22,12 @@ sub generate_emoji
|
|||
to_template(\%vars, \$data->{'emoji.tt'});
|
||||
}
|
||||
|
||||
sub emoji_picker
|
||||
{
|
||||
my ($ssn, $data, $emojis) = @_;
|
||||
|
||||
|
||||
to_template(\%vars, \$data->{'emoji_picker.tt'});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
#include "base_page.h"
|
||||
#include "about.h"
|
||||
|
||||
#include "../static/about.ctmpl"
|
||||
#include "../static/license.ctmpl"
|
||||
|
||||
void content_about(PATH_ARGS)
|
||||
{
|
||||
PERL_STACK_INIT;
|
||||
|
|
272
src/account.c
272
src/account.c
|
@ -35,17 +35,6 @@
|
|||
#include "emoji.h"
|
||||
#include "timeline.h"
|
||||
|
||||
// Files
|
||||
#include "../static/account.ctmpl"
|
||||
#include "../static/account_info.ctmpl"
|
||||
#include "../static/account_follow_btn.ctmpl"
|
||||
#include "../static/favourites_page.ctmpl"
|
||||
#include "../static/bookmarks_page.ctmpl"
|
||||
#include "../static/account_stub.ctmpl"
|
||||
#include "../static/account_sidebar.ctmpl"
|
||||
#include "../static/account_current_menubar.ctmpl"
|
||||
#include "../static/basic_page.ctmpl"
|
||||
|
||||
#define FOLLOWS_YOU_HTML "<span class=\"acct-badge\">%s</span>"
|
||||
|
||||
struct account_args
|
||||
|
@ -55,22 +44,6 @@ struct account_args
|
|||
uint8_t flags;
|
||||
};
|
||||
|
||||
char* load_account_info(struct mstdnt_account* acct,
|
||||
size_t* size)
|
||||
{
|
||||
char* info_html;
|
||||
char* note = emojify(acct->note,
|
||||
acct->emojis,
|
||||
acct->emojis_len);
|
||||
struct account_info_template data = {
|
||||
.acct_note = note
|
||||
};
|
||||
info_html = tmpl_gen_account_info(&data, size);
|
||||
if (note != acct->note)
|
||||
free(note);
|
||||
return info_html;
|
||||
}
|
||||
|
||||
static char* accounts_page(HV* session_hv,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_account* acct,
|
||||
|
@ -109,42 +82,6 @@ static char* accounts_page(HV* session_hv,
|
|||
return output;
|
||||
}
|
||||
|
||||
char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size)
|
||||
{
|
||||
char* result = NULL;
|
||||
char* sanitized_display_name = NULL;
|
||||
char* display_name = NULL;
|
||||
char* header_css = NULL;
|
||||
if (acct->display_name)
|
||||
{
|
||||
sanitized_display_name = sanitize_html(acct->display_name);
|
||||
display_name = emojify(sanitized_display_name,
|
||||
acct->emojis,
|
||||
acct->emojis_len);
|
||||
}
|
||||
easprintf(&header_css, "style=\"background: linear-gradient(var(--account-overlay-gradient-top), var(--account-overlay-gradient-bottom)), url(%s);\"", acct->header);
|
||||
struct account_sidebar_template data = {
|
||||
.prefix = config_url_prefix,
|
||||
.avatar = acct->avatar,
|
||||
.username = display_name,
|
||||
.header = acct->header ? header_css : "",
|
||||
.statuses_text = L10N[L10N_EN_US][L10N_TAB_STATUSES],
|
||||
.following_text = L10N[L10N_EN_US][L10N_TAB_FOLLOWING],
|
||||
.followers_text = L10N[L10N_EN_US][L10N_TAB_FOLLOWERS],
|
||||
.statuses_count = acct->statuses_count,
|
||||
.following_count = acct->following_count,
|
||||
.followers_count = acct->followers_count,
|
||||
.acct = acct->acct,
|
||||
};
|
||||
result = tmpl_gen_account_sidebar(&data, size);
|
||||
if (sanitized_display_name != acct->display_name) free(sanitized_display_name);
|
||||
if (display_name != sanitized_display_name &&
|
||||
display_name != acct->display_name)
|
||||
free(display_name);
|
||||
free(header_css);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char* account_followers_cb(HV* session_hv,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
|
@ -350,215 +287,6 @@ static void fetch_account_page(FCGX_Request* req,
|
|||
Safefree(data);
|
||||
}
|
||||
|
||||
size_t construct_account_page(struct session* ssn,
|
||||
char** result,
|
||||
struct account_page* page,
|
||||
char* content)
|
||||
{
|
||||
if (!page->account)
|
||||
{
|
||||
*result = NULL;
|
||||
return 0;
|
||||
}
|
||||
size_t size;
|
||||
struct mstdnt_relationship* rel = page->relationship;
|
||||
int is_same_user = ssn->logged_in && strcmp(ssn->acct.acct, page->acct) == 0;
|
||||
char* follow_btn = NULL,
|
||||
* follow_btn_text = NULL,
|
||||
* follows_you = NULL,
|
||||
* info_html = NULL,
|
||||
* is_blocked = NULL,
|
||||
* menubar = NULL,
|
||||
* display_name = NULL,
|
||||
* sanitized_display_name = NULL;
|
||||
|
||||
sanitized_display_name = sanitize_html(page->display_name);
|
||||
display_name = emojify(sanitized_display_name,
|
||||
page->account->emojis,
|
||||
page->account->emojis_len);
|
||||
|
||||
// Check if note is not empty
|
||||
if (page->note && strcmp(page->note, "") != 0)
|
||||
{
|
||||
info_html = load_account_info(page->account, NULL);
|
||||
}
|
||||
|
||||
// Display follow button only if not the same user
|
||||
if (rel && !is_same_user)
|
||||
{
|
||||
if (MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_FOLLOWED_BY))
|
||||
easprintf(&follows_you, FOLLOWS_YOU_HTML, L10N[page->locale][L10N_FOLLOWS_YOU]);
|
||||
|
||||
if (MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_BLOCKED_BY))
|
||||
is_blocked = construct_error(L10N[page->locale][L10N_BLOCKED], E_NOTICE, 0, NULL);
|
||||
|
||||
if (MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_REQUESTED))
|
||||
follow_btn_text = L10N[page->locale][L10N_FOLLOW_PENDING];
|
||||
else if (MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_FOLLOWING))
|
||||
follow_btn_text = L10N[page->locale][L10N_FOLLOWING];
|
||||
else
|
||||
follow_btn_text = L10N[page->locale][L10N_FOLLOW];
|
||||
|
||||
struct account_follow_btn_template data = {
|
||||
.prefix = config_url_prefix,
|
||||
.active = (rel && MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_FOLLOWING)
|
||||
? "active" : ""),
|
||||
.follow_text = follow_btn_text,
|
||||
.unfollow = (rel && (MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_FOLLOWING) ||
|
||||
MSTDNT_FLAG_ISSET(rel->flags, MSTDNT_RELATIONSHIP_REQUESTED))
|
||||
? "un" : ""),
|
||||
.userid = page->id,
|
||||
};
|
||||
|
||||
follow_btn = tmpl_gen_account_follow_btn(&data, NULL);
|
||||
}
|
||||
|
||||
// Display menubar with extra options for access if same user
|
||||
if (is_same_user)
|
||||
{
|
||||
struct account_current_menubar_template acmdata = {
|
||||
.prefix = config_url_prefix,
|
||||
.blocked_str = "Blocks",
|
||||
.muted_str = "Mutes",
|
||||
.favourited_str = "Favorites",
|
||||
};
|
||||
|
||||
menubar = tmpl_gen_account_current_menubar(&acmdata, NULL);
|
||||
}
|
||||
|
||||
struct account_template acct_data = {
|
||||
.is_blocked = STR_NULL_EMPTY(is_blocked),
|
||||
.header = page->header_image,
|
||||
.menubar = menubar,
|
||||
.display_name = display_name,
|
||||
.acct = page->acct,
|
||||
.prefix = config_url_prefix,
|
||||
.userid = page->id,
|
||||
.follows_you = follows_you,
|
||||
.unsubscribe = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_NOTIFYING)
|
||||
? "un" : ""),
|
||||
.subscribe_text = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_NOTIFYING)
|
||||
? L10N[page->locale][L10N_UNSUBSCRIBE] : L10N[page->locale][L10N_SUBSCRIBE]),
|
||||
.unblock = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_BLOCKING)
|
||||
? "un" : ""),
|
||||
.block_text = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_BLOCKING)
|
||||
? L10N[page->locale][L10N_UNBLOCK] : L10N[page->locale][L10N_BLOCK]),
|
||||
.unmute = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_MUTING)
|
||||
? "un" : ""),
|
||||
.mute_text = (rel && MSTDNT_FLAG_ISSET(rel->flags,
|
||||
MSTDNT_RELATIONSHIP_MUTING)
|
||||
? L10N[page->locale][L10N_UNMUTE] : L10N[page->locale][L10N_MUTE]),
|
||||
.tab_statuses_text = L10N[page->locale][L10N_TAB_STATUSES],
|
||||
.statuses_count = page->statuses_count,
|
||||
.tab_following_text = L10N[page->locale][L10N_TAB_FOLLOWING],
|
||||
.following_count = page->following_count,
|
||||
.tab_followers_text = L10N[page->locale][L10N_TAB_FOLLOWERS],
|
||||
.followers_count = page->followers_count,
|
||||
.follow_btn = follow_btn,
|
||||
.avatar = page->profile_image,
|
||||
.info = info_html,
|
||||
.tab_statuses_focused = MAKE_FOCUSED_IF(page->tab, ACCT_TAB_STATUSES),
|
||||
.tab_statuses_text = L10N[page->locale][L10N_TAB_STATUSES],
|
||||
.tab_scrobbles_focused = MAKE_FOCUSED_IF(page->tab, ACCT_TAB_SCROBBLES),
|
||||
.tab_scrobbles_text = L10N[page->locale][L10N_TAB_SCROBBLES],
|
||||
.tab_media_focused = MAKE_FOCUSED_IF(page->tab, ACCT_TAB_MEDIA),
|
||||
.tab_media_text = L10N[page->locale][L10N_TAB_MEDIA],
|
||||
.tab_pinned_focused = MAKE_FOCUSED_IF(page->tab, ACCT_TAB_PINNED),
|
||||
.tab_pinned_text = L10N[page->locale][L10N_TAB_PINNED],
|
||||
.acct_content = content
|
||||
};
|
||||
|
||||
*result = tmpl_gen_account(&acct_data, &size);
|
||||
|
||||
free(info_html);
|
||||
free(follows_you);
|
||||
free(follow_btn);
|
||||
free(is_blocked);
|
||||
free(menubar);
|
||||
if (sanitized_display_name != page->display_name) free(sanitized_display_name);
|
||||
if (display_name != page->display_name &&
|
||||
display_name != sanitized_display_name)
|
||||
free(display_name);
|
||||
return size;
|
||||
}
|
||||
|
||||
char* construct_account(mastodont_t* api,
|
||||
struct mstdnt_account* acct,
|
||||
uint8_t flags,
|
||||
size_t* size)
|
||||
{
|
||||
char* result;
|
||||
char* sanitized_display_name = sanitize_html(acct->display_name);
|
||||
struct account_stub_template data = {
|
||||
.prefix = config_url_prefix,
|
||||
.acct = acct->acct,
|
||||
.avatar = acct->avatar,
|
||||
.display_name = sanitized_display_name,
|
||||
};
|
||||
|
||||
result = tmpl_gen_account_stub(&data, size);
|
||||
if (sanitized_display_name != acct->display_name) free(sanitized_display_name);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char* construct_account_voidwrap(void* passed, size_t index, size_t* res)
|
||||
{
|
||||
struct account_args* args = passed;
|
||||
return construct_account(args->api, args->accts + index, args->flags, res);
|
||||
}
|
||||
|
||||
char* construct_accounts(mastodont_t* api,
|
||||
struct mstdnt_account* accounts,
|
||||
size_t size,
|
||||
uint8_t flags,
|
||||
size_t* ret_size)
|
||||
{
|
||||
if (!(accounts && size)) return NULL;
|
||||
struct account_args acct_args = {
|
||||
.api = api,
|
||||
.accts = accounts,
|
||||
.flags = flags,
|
||||
};
|
||||
return construct_func_strings(construct_account_voidwrap, &acct_args, size, ret_size);
|
||||
}
|
||||
|
||||
char* load_account_page(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_relationship* relationship,
|
||||
enum account_tab tab,
|
||||
char* content,
|
||||
size_t* res_size)
|
||||
{
|
||||
size_t size;
|
||||
char* result;
|
||||
struct account_page page = {
|
||||
.locale = l10n_normalize(ssn->config.lang),
|
||||
.account = acct,
|
||||
.header_image = acct->header,
|
||||
.profile_image = acct->avatar,
|
||||
.acct = acct->acct,
|
||||
.display_name = acct->display_name,
|
||||
.statuses_count = acct->statuses_count,
|
||||
.following_count = acct->following_count,
|
||||
.followers_count = acct->followers_count,
|
||||
.note = acct->note,
|
||||
.id = acct->id,
|
||||
.tab = tab,
|
||||
.relationship = relationship,
|
||||
};
|
||||
|
||||
size = construct_account_page(ssn, &result, &page, content);
|
||||
|
||||
if (res_size) *res_size = size;
|
||||
return result;
|
||||
}
|
||||
|
||||
void content_account_statuses(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_statuses_args args = {
|
||||
|
|
|
@ -57,33 +57,6 @@ struct account_page
|
|||
};
|
||||
|
||||
void get_account_info(mastodont_t* api, struct session* ssn);
|
||||
char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size);
|
||||
|
||||
char* construct_account(mastodont_t* api,
|
||||
struct mstdnt_account* account,
|
||||
uint8_t flags,
|
||||
size_t* size);
|
||||
char* construct_accounts(mastodont_t* api,
|
||||
struct mstdnt_account* accounts,
|
||||
size_t size,
|
||||
uint8_t flags,
|
||||
size_t* ret_size);
|
||||
|
||||
size_t construct_account_page(struct session *ssn,
|
||||
char** result,
|
||||
struct account_page* page,
|
||||
char* content);
|
||||
|
||||
char* load_account_page(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_relationship* relationship,
|
||||
enum account_tab tab,
|
||||
char* content,
|
||||
size_t* res_size);
|
||||
|
||||
char* load_account_info(struct mstdnt_account* acct,
|
||||
size_t* size);
|
||||
|
||||
void content_account_followers(PATH_ARGS);
|
||||
void content_account_following(PATH_ARGS);
|
||||
|
|
|
@ -24,13 +24,6 @@
|
|||
#include "attachments.h"
|
||||
#include "string_helpers.h"
|
||||
|
||||
// Pages
|
||||
#include "../static/attachments.ctmpl"
|
||||
#include "../static/attachment_image.ctmpl"
|
||||
#include "../static/attachment_gifv.ctmpl"
|
||||
#include "../static/attachment_video.ctmpl"
|
||||
#include "../static/attachment_link.ctmpl"
|
||||
#include "../static/attachment_audio.ctmpl"
|
||||
|
||||
struct attachments_args
|
||||
{
|
||||
|
@ -123,80 +116,6 @@ void cleanup_media_ids(struct session* ssn, char** media_ids)
|
|||
free(media_ids);
|
||||
}
|
||||
|
||||
char* construct_attachment(struct session* ssn,
|
||||
mstdnt_bool sensitive,
|
||||
struct mstdnt_attachment* att,
|
||||
size_t* str_size)
|
||||
{
|
||||
// Due to how similar the attachment templates are, we're just going to use their data files
|
||||
// and not generate any templates, saves some LOC!
|
||||
char* att_html;
|
||||
size_t s;
|
||||
const char* attachment_str;
|
||||
if (!att) return NULL;
|
||||
|
||||
if (ssn->config.stat_attachments)
|
||||
switch (att->type)
|
||||
{
|
||||
case MSTDNT_ATTACHMENT_IMAGE:
|
||||
attachment_str = data_attachment_image; break;
|
||||
case MSTDNT_ATTACHMENT_GIFV:
|
||||
attachment_str = data_attachment_gifv; break;
|
||||
case MSTDNT_ATTACHMENT_VIDEO:
|
||||
attachment_str = data_attachment_video; break;
|
||||
case MSTDNT_ATTACHMENT_AUDIO:
|
||||
attachment_str = data_attachment_audio; break;
|
||||
case MSTDNT_ATTACHMENT_UNKNOWN: // Fall through
|
||||
default:
|
||||
attachment_str = data_attachment_link; break;
|
||||
}
|
||||
else
|
||||
attachment_str = data_attachment_link;
|
||||
|
||||
// Images/visible content displays sensitive placeholder after
|
||||
if ((att->type == MSTDNT_ATTACHMENT_IMAGE ||
|
||||
att->type == MSTDNT_ATTACHMENT_GIFV ||
|
||||
att->type == MSTDNT_ATTACHMENT_VIDEO) &&
|
||||
ssn->config.stat_attachments)
|
||||
{
|
||||
s = easprintf(&att_html, attachment_str,
|
||||
att->url,
|
||||
sensitive ? "<div class=\"sensitive-contain sensitive\"></div>" : "");
|
||||
}
|
||||
else {
|
||||
s = easprintf(&att_html, attachment_str,
|
||||
sensitive ? "sensitive" : "",
|
||||
att->url);
|
||||
}
|
||||
|
||||
if (str_size) *str_size = s;
|
||||
return att_html;
|
||||
}
|
||||
|
||||
static char* construct_attachments_voidwrap(void* passed, size_t index, size_t* res)
|
||||
{
|
||||
struct attachments_args* args = passed;
|
||||
return construct_attachment(args->ssn, args->sensitive, args->atts + index, res);
|
||||
}
|
||||
|
||||
char* construct_attachments(struct session* ssn,
|
||||
mstdnt_bool sensitive,
|
||||
struct mstdnt_attachment* atts,
|
||||
size_t atts_len,
|
||||
size_t* str_size)
|
||||
{
|
||||
size_t elements_size;
|
||||
struct attachments_args args = { ssn, atts, sensitive };
|
||||
char* elements = construct_func_strings(construct_attachments_voidwrap, &args, atts_len, &elements_size);
|
||||
char* att_view;
|
||||
|
||||
size_t s = easprintf(&att_view, data_attachments, elements);
|
||||
if (str_size) *str_size = s;
|
||||
// Cleanup
|
||||
free(elements);
|
||||
return att_view;
|
||||
}
|
||||
|
||||
HV* perlify_attachment(struct mstdnt_attachment* const attachment)
|
||||
{
|
||||
if (!attachment) return NULL;
|
||||
|
|
|
@ -34,8 +34,6 @@ int try_upload_media(struct mstdnt_storage** storage,
|
|||
char*** media_ids);
|
||||
void cleanup_media_storages(struct session* ssn, struct mstdnt_storage* storage);
|
||||
void cleanup_media_ids(struct session* ssn, char** media_ids);
|
||||
char* construct_attachment(struct session* ssn, mstdnt_bool sensitive, struct mstdnt_attachment* att, size_t* str_size);
|
||||
char* construct_attachments(struct session* ssn, mstdnt_bool sensitive, struct mstdnt_attachment* atts, size_t atts_len, size_t* str_size);
|
||||
void api_attachment_create(PATH_ARGS);
|
||||
|
||||
// Perl
|
||||
|
|
|
@ -30,11 +30,6 @@
|
|||
#include <fcgi_stdio.h>
|
||||
#include "global_cache.h"
|
||||
|
||||
// Files
|
||||
#include "../static/index.ctmpl"
|
||||
#include "../static/quick_login.ctmpl"
|
||||
#include "../templates/main.ctt"
|
||||
|
||||
#define BODY_STYLE "style=\"background:url('%s');\""
|
||||
|
||||
void render_base_page(struct base_page* page, FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
||||
|
|
|
@ -26,138 +26,6 @@
|
|||
#include "error.h"
|
||||
#include "base_page.h"
|
||||
|
||||
// Files
|
||||
#include "../static/chat.ctmpl"
|
||||
#include "../static/chats_page.ctmpl"
|
||||
#include "../static/message.ctmpl"
|
||||
#include "../static/chat_view.ctmpl"
|
||||
#include "../static/embed.ctmpl"
|
||||
|
||||
struct construct_message_args
|
||||
{
|
||||
struct mstdnt_message* msg;
|
||||
struct mstdnt_account* you;
|
||||
struct mstdnt_account* them;
|
||||
size_t msg_size; // Read messages backwards
|
||||
};
|
||||
|
||||
struct construct_chats_args
|
||||
{
|
||||
mastodont_t* api;
|
||||
struct mstdnt_args* args;
|
||||
struct mstdnt_chat* chats;
|
||||
};
|
||||
|
||||
char* construct_chat(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chat* chat,
|
||||
size_t* size)
|
||||
{
|
||||
char* result;
|
||||
char* msg_id = NULL;
|
||||
char* last_message = "<span class=\"empty-chat-text\">Chat created</span>";
|
||||
|
||||
// Get latest message
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_message* messages = NULL;
|
||||
size_t messages_len = 0;
|
||||
|
||||
struct mstdnt_chats_args args = {
|
||||
.with_muted = MSTDNT_TRUE,
|
||||
.offset = 0,
|
||||
.limit = 1,
|
||||
};
|
||||
|
||||
if (mastodont_get_chat_messages(api, m_args, chat->id, &args, &storage,
|
||||
&messages, &messages_len) == 0 && messages_len == 1)
|
||||
{
|
||||
last_message = messages[0].content;
|
||||
msg_id = messages[0].id;
|
||||
}
|
||||
|
||||
struct chat_template data = {
|
||||
.id = chat->id,
|
||||
.prefix = config_url_prefix,
|
||||
.acct = chat->account.acct,
|
||||
.avatar = chat->account.avatar,
|
||||
.display_name = chat->account.display_name,
|
||||
.message_id = msg_id,
|
||||
.last_message = last_message,
|
||||
};
|
||||
result = tmpl_gen_chat(&data, size);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
// TODO cleanup messages
|
||||
return result;
|
||||
}
|
||||
|
||||
static char* construct_chat_voidwrap(void* passed, size_t index, size_t* res)
|
||||
{
|
||||
struct construct_chats_args* args = passed;
|
||||
return construct_chat(args->api, args->args, args->chats + index, res);
|
||||
}
|
||||
|
||||
char* construct_chats(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chat* chats,
|
||||
size_t size,
|
||||
size_t* ret_size)
|
||||
{
|
||||
struct construct_chats_args args = {
|
||||
.api = api,
|
||||
.args = m_args,
|
||||
.chats = chats,
|
||||
};
|
||||
|
||||
return construct_func_strings(construct_chat_voidwrap, &args, size, ret_size);
|
||||
}
|
||||
|
||||
char* construct_message(struct mstdnt_message* msg,
|
||||
struct mstdnt_account* you,
|
||||
struct mstdnt_account* them,
|
||||
size_t* size)
|
||||
{
|
||||
char* result;
|
||||
if (!(you && them)) return NULL;
|
||||
int is_you = strcmp(you->id, msg->account_id) == 0;
|
||||
struct message_template data = {
|
||||
.id = msg->id,
|
||||
.content = msg->content,
|
||||
.is_you = is_you ? "message-you" : NULL,
|
||||
.avatar = is_you ? you->avatar : them->avatar
|
||||
};
|
||||
result = tmpl_gen_message(&data, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char* construct_message_voidwrap(void* passed, size_t index, size_t* res)
|
||||
{
|
||||
struct construct_message_args* args = passed;
|
||||
return construct_message(args->msg + (args->msg_size - index - 1), args->you, args->them, res);
|
||||
}
|
||||
|
||||
char* construct_messages(struct mstdnt_message* messages,
|
||||
struct mstdnt_account* you,
|
||||
struct mstdnt_account* them,
|
||||
size_t size,
|
||||
size_t* ret_size)
|
||||
{
|
||||
struct construct_message_args args = {
|
||||
.msg = messages,
|
||||
.you = you,
|
||||
.them = them,
|
||||
.msg_size = size
|
||||
};
|
||||
return construct_func_strings(construct_message_voidwrap, &args, size, ret_size);
|
||||
}
|
||||
|
||||
char* construct_chats_view(char* lists_string, size_t* size)
|
||||
{
|
||||
struct chats_page_template data = {
|
||||
.content = lists_string,
|
||||
};
|
||||
return tmpl_gen_chats_page(&data, size);
|
||||
}
|
||||
|
||||
void content_chats(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
|
|
|
@ -23,27 +23,6 @@
|
|||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
|
||||
char* construct_chat(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chat* chat,
|
||||
size_t* size);
|
||||
char* construct_chats(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chat* chats,
|
||||
size_t size,
|
||||
size_t* ret_size);
|
||||
char* construct_chats_view(char* lists_string, size_t* size);
|
||||
// Message
|
||||
char* construct_message(struct mstdnt_message* message,
|
||||
struct mstdnt_account* your_profile,
|
||||
struct mstdnt_account* their_profile,
|
||||
size_t* size);
|
||||
char* construct_messages(struct mstdnt_message* message,
|
||||
struct mstdnt_account* your_profile,
|
||||
struct mstdnt_account* their_profile,
|
||||
size_t size,
|
||||
size_t* ret_size);
|
||||
|
||||
void content_chats(PATH_ARGS);
|
||||
void content_chat_view(PATH_ARGS);
|
||||
|
||||
|
|
73
src/emoji.c
73
src/emoji.c
|
@ -24,11 +24,6 @@
|
|||
#include "easprintf.h"
|
||||
#include "string_helpers.h"
|
||||
|
||||
// Pages
|
||||
#include "../static/emoji.ctmpl"
|
||||
#include "../static/emoji_plain.ctmpl"
|
||||
#include "../static/emoji_picker.ctmpl"
|
||||
|
||||
enum emoji_categories
|
||||
{
|
||||
EMO_CAT_SMILEYS,
|
||||
|
@ -42,38 +37,6 @@ enum emoji_categories
|
|||
EMO_CAT_LEN
|
||||
};
|
||||
|
||||
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len)
|
||||
{
|
||||
if (!content) return NULL;
|
||||
size_t sc_len;
|
||||
char* oldres = NULL;
|
||||
char* res = content;
|
||||
char* emoji_url_str;
|
||||
char* coloned;
|
||||
for (size_t i = 0; i < emos_len; ++i)
|
||||
{
|
||||
oldres = res;
|
||||
|
||||
// Add colons around string
|
||||
sc_len = strlen(emos[i].shortcode);
|
||||
// 3 = \0 and two :
|
||||
coloned = malloc(sc_len+3);
|
||||
coloned[0] = ':';
|
||||
strncpy(coloned + 1, emos[i].shortcode, sc_len);
|
||||
coloned[sc_len+1] = ':';
|
||||
coloned[sc_len+2] = '\0';
|
||||
|
||||
easprintf(&emoji_url_str, "<img class=\"emoji\" src=\"%s\" loading=\"lazy\">", emos[i].url);
|
||||
|
||||
res = strrepl(res, coloned, emoji_url_str, STRREPL_ALL);
|
||||
if (oldres != content && res != oldres) free(oldres);
|
||||
// Cleanup
|
||||
free(emoji_url_str);
|
||||
free(coloned);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
struct construct_emoji_picker_args
|
||||
{
|
||||
char* status_id;
|
||||
|
@ -84,21 +47,14 @@ char* construct_emoji(struct emoji_info* emoji, char* status_id, size_t* size)
|
|||
{
|
||||
if (!emoji)
|
||||
return NULL;
|
||||
char* emoji_str;
|
||||
|
||||
if (status_id)
|
||||
{
|
||||
struct emoji_template data = {
|
||||
.status_id = status_id,
|
||||
.emoji = emoji->codes
|
||||
};
|
||||
return tmpl_gen_emoji(&data, size);
|
||||
}
|
||||
else {
|
||||
struct emoji_plain_template data = {
|
||||
.emoji = emoji->codes
|
||||
};
|
||||
return tmpl_gen_emoji_plain(&data, size);
|
||||
}
|
||||
easprintf(&emoji_str, "<a href=\"/status/%s/react/%s\" class=\"emoji\">%s</a>",
|
||||
status_id, emoji->codes, emoji->codes);
|
||||
else
|
||||
easprintf(&emoji_str, "<span class=\"emoji\">%s</span>", emoji->codes);
|
||||
return emoji_str;
|
||||
}
|
||||
|
||||
static char* construct_emoji_voidwrap(void* passed, size_t index, size_t* res)
|
||||
|
@ -136,16 +92,17 @@ char* construct_emoji_picker(char* status_id, size_t* size)
|
|||
};
|
||||
|
||||
char* emojis[EMO_CAT_LEN];
|
||||
size_t len[EMO_CAT_LEN];
|
||||
|
||||
// TODO refactor to use #define lol
|
||||
emojis[EMO_CAT_SMILEYS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_SMILEYS, EMOJO_CAT_ANIMALS - EMOJO_CAT_SMILEY, NULL);
|
||||
emojis[EMO_CAT_ANIMALS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_ANIMALS, EMOJO_CAT_FOOD - EMOJO_CAT_ANIMALS, NULL);
|
||||
emojis[EMO_CAT_FOOD] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_FOOD, EMOJO_CAT_TRAVEL - EMOJO_CAT_FOOD, NULL);
|
||||
emojis[EMO_CAT_TRAVEL] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_TRAVEL, EMOJO_CAT_ACTIVITIES - EMOJO_CAT_TRAVEL, NULL);
|
||||
emojis[EMO_CAT_ACTIVITIES] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_ACTIVITIES, EMOJO_CAT_OBJECTS - EMOJO_CAT_ACTIVITIES, NULL);
|
||||
emojis[EMO_CAT_OBJECTS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_OBJECTS, EMOJO_CAT_SYMBOLS - EMOJO_CAT_OBJECTS, NULL);
|
||||
emojis[EMO_CAT_SYMBOLS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_SYMBOLS, EMOJO_CAT_FLAGS - EMOJO_CAT_SYMBOLS, NULL);
|
||||
emojis[EMO_CAT_FLAGS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_FLAGS, EMOJO_CAT_MAX - EMOJO_CAT_FLAGS, NULL);
|
||||
emojis[EMO_CAT_SMILEYS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_SMILEYS, EMOJO_CAT_ANIMALS - EMOJO_CAT_SMILEY, len);
|
||||
emojis[EMO_CAT_ANIMALS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_ANIMALS, EMOJO_CAT_FOOD - EMOJO_CAT_ANIMALS, len + 1);
|
||||
emojis[EMO_CAT_FOOD] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_FOOD, EMOJO_CAT_TRAVEL - EMOJO_CAT_FOOD, len + 2);
|
||||
emojis[EMO_CAT_TRAVEL] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_TRAVEL, EMOJO_CAT_ACTIVITIES - EMOJO_CAT_TRAVEL, len + 3);
|
||||
emojis[EMO_CAT_ACTIVITIES] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_ACTIVITIES, EMOJO_CAT_OBJECTS - EMOJO_CAT_ACTIVITIES, len + 4);
|
||||
emojis[EMO_CAT_OBJECTS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_OBJECTS, EMOJO_CAT_SYMBOLS - EMOJO_CAT_OBJECTS, len + 5);
|
||||
emojis[EMO_CAT_SYMBOLS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_SYMBOLS, EMOJO_CAT_FLAGS - EMOJO_CAT_SYMBOLS, len + 6);
|
||||
emojis[EMO_CAT_FLAGS] = construct_func_strings(construct_emoji_voidwrap, args + EMO_CAT_FLAGS, EMOJO_CAT_MAX - EMOJO_CAT_FLAGS, len + 6);
|
||||
|
||||
struct emoji_picker_template data = {
|
||||
.emojis_smileys = emojis[EMO_CAT_SMILEYS],
|
||||
|
|
|
@ -33,7 +33,6 @@ enum emoji_picker_cat
|
|||
EMOJI_CAT_FACES,
|
||||
};
|
||||
|
||||
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len);
|
||||
char* construct_emoji(struct emoji_info* emoji, char* status_id, size_t* size);
|
||||
void content_emoji_picker(PATH_ARGS);
|
||||
char* construct_emoji_picker(char* status_id, size_t* size);
|
||||
|
|
Loading…
Reference in a new issue