Emoji picker progress

FossilOrigin-Name: d99bbf4e3c5908213f91b25b102f175b22843aee254acdc7d5b60fba86b74c0b
This commit is contained in:
me@ow.nekobit.net 2022-05-09 01:46:34 +00:00
parent 9412c33062
commit 2c0c69e765
15 changed files with 267 additions and 12 deletions

View file

@ -4,13 +4,13 @@
Alas, it becomes a social project too...
* Nekobit <@neko@desuposter.club>
* Nekobit <@neko@rdrama.cc>
Created the Treebird frontend, created mastodont-c (A pleroma C library)
Originally, this was called RatFE, but the name changed.
[ Producer ]
* Grumbulon <@grumbulon@freecumextremist.com>
Creator of the Logo and owns treebird.dev
Creator of the Logo and owns treebird.dev, made dark theme
[ Camera support ]
* SamTherapy <@sam@froth.zone>
@ -27,4 +27,5 @@
* ICONSVG Project
* cJSON developers
* Pleroma developers
* Alex Gleason - For API assistance
* You! :)

View file

@ -110,6 +110,10 @@ $(PAGES_DIR)/bar_graph.chtml: $(PAGES_DIR)/bar_graph.html
./filec $< data_bar_graph_html > $@
$(PAGES_DIR)/bar.chtml: $(PAGES_DIR)/bar.html
./filec $< data_bar_html > $@
$(PAGES_DIR)/emoji_picker.chtml: $(PAGES_DIR)/emoji_picker.html
./filec $< data_emoji_picker_html > $@
$(PAGES_DIR)/emoji.chtml: $(PAGES_DIR)/emoji.html
./filec $< data_emoji_html > $@
$(MASTODONT_DIR):
git clone $(MASTODONT_URL) || true

1
dist/svg/emoji.svg vendored Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="8" y1="12" x2="16" y2="12"></line></svg>

After

Width:  |  Height:  |  Size: 266 B

1
meta/emoji.json Normal file

File diff suppressed because one or more lines are too long

0
scripts/emoji-to.c Normal file
View file

View file

@ -21,6 +21,11 @@
#include "string.h"
#include "emoji.h"
#include "easprintf.h"
#include "string_helpers.h"
// Pages
#include "../static/emoji.chtml"
#include "../static/emoji_picker.chtml"
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len)
{
@ -52,3 +57,33 @@ char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len)
}
return res;
}
char* construct_emoji(struct emoji_info* emoji, size_t* size)
{
char* emoji_html;
size_t s = easprintf(&emoji_html, data_emoji_html, emoji->codes);
if (size) *size = s;
return emoji_html;
}
static char* construct_emoji_voidwrap(void* passed, size_t index, int* res)
{
return construct_emoji((struct emoji_info*)passed + index, 0);
}
char* construct_emoji_picker(enum emoji_picker_cat cat, unsigned index, size_t* size)
{
char* emoji_picker_html;
char* emojis;
emojis = construct_func_strings(construct_emoji_voidwrap, emojos, 8, NULL);
size_t s = easprintf(&emoji_picker_html, data_emoji_picker_html,
emojis);
free(emojis);
if (size) *size = s;
return emoji_picker_html;
}

View file

@ -19,7 +19,17 @@
#ifndef EMOJI_H
#define EMOJI_H
#include <mastodont.h>
#include "emoji_codes.h"
enum emoji_picker_cat
{
EMOJI_CAT_CUSTOM,
EMOJI_CAT_FACES,
};
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len);
char* construct_emoji(struct emoji_info* emoji, size_t* size);
char* construct_emoji_picker(enum emoji_picker_cat cat, unsigned index, size_t* size);
#endif // EMOJI_H

142
src/emoji_codes.h Normal file
View file

@ -0,0 +1,142 @@
// Not generated, but will be generated
#ifndef EMOJOS_H
#define EMOJOS_H
#include "emoji_info.h"
struct emoji_info emojos[] = {
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ "☺️", "smile", "Smiles" },
{ NULL, NULL, NULL },
};
#endif

29
src/emoji_info.h Normal file
View file

@ -0,0 +1,29 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef EMOJI_INFO_H
#define EMOJI_INFO_H
struct emoji_info
{
char* codes;
char* name;
char* group;
};
#endif /* EMOJI_INFO_H */

View file

@ -91,6 +91,7 @@ int main(void)
{ "/@:/media", content_account_media },
{ "/@:", content_account_statuses },
{ "/status/:/react/:", content_status_react },
{ "/status/:/react", status_emoji },
{ "/status/create", content_status_create },
{ "/status/:/interact", status_interact },
{ "/status/:/reply", status_reply },

View file

@ -384,6 +384,7 @@ char* construct_status(mastodont_t* api,
char* notif_info = NULL;
char* in_reply_to_str = NULL;
char* interactions_html = NULL;
char* emoji_picker_html = NULL;
struct mstdnt_status* status = local_status;
// Create a "fake" notification header which contains information for
// the reblogged status
@ -398,6 +399,12 @@ char* construct_status(mastodont_t* api,
if (!status) return NULL;
// Emojo picker
if ((flags & STATUS_EMOJI_PICKER) == STATUS_EMOJI_PICKER)
{
emoji_picker_html = construct_emoji_picker(EMOJI_CAT_FACES, 0, NULL);
}
// If focused, show status interactions
if ((flags & STATUS_FOCUSED) == STATUS_FOCUSED &&
(status->reblogs_count || status->favourites_count))
@ -519,7 +526,10 @@ char* construct_status(mastodont_t* api,
status->id,
config_url_prefix,
status->id,
status->id);
config_url_prefix,
status->id,
status->id,
emoji_picker_html);
if (size) *size = s;
// Cleanup
@ -531,6 +541,7 @@ char* construct_status(mastodont_t* api,
if (emoji_reactions) free(emoji_reactions);
if (notif) free(notif_info);
if (interactions_html) free(interactions_html);
if (emoji_picker_html) free(emoji_picker_html);
if (parse_content != status->content) free(parse_content);
return stat_html;
}
@ -572,15 +583,20 @@ void status_interact(struct session* ssn, mastodont_t* api, char** data)
void status_view(struct session* ssn, mastodont_t* api, char** data)
{
content_status(ssn, api, data, 0);
content_status(ssn, api, data, STATUS_FOCUSED);
}
void status_emoji(struct session* ssn, mastodont_t* api, char** data)
{
content_status(ssn, api, data, STATUS_FOCUSED | STATUS_EMOJI_PICKER);
}
void status_reply(struct session* ssn, mastodont_t* api, char** data)
{
content_status(ssn, api, data, 1);
content_status(ssn, api, data, STATUS_FOCUSED | STATUS_REPLY);
}
void content_status(struct session* ssn, mastodont_t* api, char** data, int is_reply)
void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t flags)
{
char* output;
// Status context
@ -604,8 +620,8 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r
before_html = construct_statuses(api, statuses_before, stat_before_len, NULL, 0);
// Current status
stat_html = construct_status(api, &status, NULL, NULL, NULL, STATUS_FOCUSED);
if (is_reply)
stat_html = construct_status(api, &status, NULL, NULL, NULL, flags);
if ((flags & STATUS_REPLY) == STATUS_REPLY)
{
stat_reply = reply_status(data[0],
&status);
@ -636,7 +652,7 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r
if (stat_html) free(stat_html);
if (after_html) free(after_html);
if (output) free(output);
if (is_reply) free(stat_reply);
if ((flags & STATUS_REPLY) == STATUS_REPLY) free(stat_reply);
mstdnt_cleanup_statuses(statuses_before, stat_before_len);
mstdnt_cleanup_statuses(statuses_after, stat_after_len);
mstdnt_cleanup_status(&status);

View file

@ -24,8 +24,9 @@
// Flags
#define STATUS_NOOP 0
#define STATUS_FOCUSED (1<<0)
#define STATUS_EMOJI_PICKER (1<<1)
#define STATUS_REPLY (1<<0)
#define STATUS_FOCUSED (1<<1)
#define STATUS_EMOJI_PICKER (1<<2)
struct construct_statuses_args
{
@ -89,8 +90,9 @@ char* greentextify(char* content);
void status_view(struct session* ssn, mastodont_t* api, char** data);
void status_reply(struct session* ssn, mastodont_t* api, char** data);
void status_interact(struct session* ssn, mastodont_t* api, char** data);
void status_emoji(struct session* ssn, mastodont_t* api, char** data);
// Above wraps to the below function
void content_status(struct session* ssn, mastodont_t* api, char** data, int is_reply);
void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t flags);
// Cleanup
void cleanup_media_ids(struct session* ssn, char** media_ids);

1
static/emoji.html Normal file
View file

@ -0,0 +1 @@
<span class="emoji">%s</span>

3
static/emoji_picker.html Normal file
View file

@ -0,0 +1,3 @@
<div class="emoji-picker">
%s
</div>

View file

@ -85,6 +85,14 @@
</label>
</form>
</td>
<td>
<form action="%s/status/%s/react" method="post">
<label class="pointer">
<svg class="emoji-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="8" y1="12" x2="16" y2="12"></line></svg>
<input class="hidden" type="submit" value="Emoji">
</label>
</form>
</td>
<td>
<form action="%s/status/%s#id-%s" method="post">
<label class="pointer">
@ -102,3 +110,4 @@
</td>
</tr>
</table>
%s