mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 09:35:04 +00:00
Emojis are now read from ~/emojis.json.
This commit is contained in:
parent
5a8c4cac80
commit
bc752b7d67
3 changed files with 43 additions and 4 deletions
3
data.c
3
data.c
|
@ -132,6 +132,9 @@ int srv_open(char *basedir, int auto_upgrade)
|
|||
}
|
||||
#endif /* __OpenBSD__ */
|
||||
|
||||
/* read (and drop) emojis.json, possibly creating it */
|
||||
xs_free(emojis());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
43
format.c
43
format.c
|
@ -5,6 +5,7 @@
|
|||
#include "xs_regex.h"
|
||||
#include "xs_mime.h"
|
||||
#include "xs_html.h"
|
||||
#include "xs_json.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
@ -36,6 +37,39 @@ const char *smileys[] = {
|
|||
};
|
||||
|
||||
|
||||
xs_dict *emojis(void)
|
||||
/* returns a dict with the emojis */
|
||||
{
|
||||
xs *fn = xs_fmt("%s/emojis.json", srv_basedir);
|
||||
FILE *f;
|
||||
|
||||
if (mtime(fn) == 0) {
|
||||
/* file does not exist; create it with the defaults */
|
||||
xs *d = xs_dict_new();
|
||||
const char **emo = smileys;
|
||||
|
||||
while (*emo) {
|
||||
d = xs_dict_append(d, emo[0], emo[1]);
|
||||
emo += 2;
|
||||
}
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump(d, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
xs_dict *d = NULL;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
d = xs_json_load(f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
static xs_str *format_line(const char *line, xs_list **attach)
|
||||
/* formats a line */
|
||||
{
|
||||
|
@ -190,11 +224,12 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
|
|||
|
||||
{
|
||||
/* traditional emoticons */
|
||||
const char **emo = smileys;
|
||||
xs *d = emojis();
|
||||
int c = 0;
|
||||
char *k, *v;
|
||||
|
||||
while (*emo) {
|
||||
s = xs_replace_i(s, emo[0], emo[1]);
|
||||
emo += 2;
|
||||
while (xs_dict_next(d, &k, &v, &c)) {
|
||||
s = xs_replace_i(s, k, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1
snac.h
1
snac.h
|
@ -304,6 +304,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
|
|||
char *payload, int p_size,
|
||||
char **body, int *b_size, char **ctype);
|
||||
|
||||
xs_dict *emojis(void);
|
||||
xs_str *not_really_markdown(const char *content, xs_list **attach);
|
||||
xs_str *sanitize(const char *content);
|
||||
xs_str *encode_html(const char *str);
|
||||
|
|
Loading…
Reference in a new issue