FossilOrigin-Name: d0746c463cfc117130572a2d835585703541e21174e78433f42f586b18138110
This commit is contained in:
me@ow.nekobit.net 2022-04-20 15:07:46 +00:00
parent 716809aa0a
commit e10053155d
5 changed files with 97 additions and 4 deletions

1
dist/treebird20.css vendored
View file

@ -62,7 +62,6 @@ ul
border-radius: 5px;
}
.hidden
{
display: none;

53
src/emoji.c Normal file
View file

@ -0,0 +1,53 @@
/*
* 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/>.
*/
#include <stdlib.h>
#include <string.h>
#include "string.h"
#include "emoji.h"
#include "easprintf.h"
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len)
{
size_t sc_len;
char* oldres;
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);
coloned = malloc(sc_len+3);
coloned[0] = ':';
strncpy(coloned + 1, emos[i].shortcode, sc_len);
coloned[sc_len-1] = ':';
coloned[sc_len] = '\0';
easprintf(&emoji_url_str, "<img class=\"emoji\" src=\"%s\">", emos[i].url);
res = strrepl(res, coloned, emoji_url_str, STRREPL_ALL);
if (oldres != content) free(oldres);
// Cleanup
free(emoji_url_str);
free(coloned);
}
return res;
}

25
src/emoji.h Normal file
View file

@ -0,0 +1,25 @@
/*
* 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_H
#define EMOJI_H
#include <mastodont.h>
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len);
#endif // EMOJI_H

View file

@ -33,6 +33,7 @@
#include "../config.h"
#include "type_string.h"
#include "string.h"
#include "emoji.h"
// Pages
#include "../static/status.chtml"
@ -164,7 +165,21 @@ char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size
#define REGEX_GREENTEXT "((?:^|<br/?>|\\s)&gt;.*?)(?:<br/?>|$)"
#define REGEX_GREENTEXT_LEN 6
char* reformat_status(char* content)
char* reformat_status(char* content, struct mstdnt_emoji* emos, size_t emos_len)
{
char* gt_res;
char* emo_res;
gt_res = greentextify(content);
if (emos)
{
emo_res = emojify(gt_res, emos, emos_len);
free(gt_res);
return emo_res;
}
return gt_res;
}
char* greentextify(char* content)
{
const char* error;
int erroffset;
@ -247,7 +262,7 @@ char* construct_status(mastodont_t* api,
notif_reblog.type = MSTDNT_NOTIFICATION_REBLOG;
notif = &notif_reblog;
}
char* parse_content = reformat_status(status->content);
char* parse_content = reformat_status(status->content, status->emojis, status->emojis_len);
if (status->replies_count)
easprintf(&reply_count, NUM_STR, status->replies_count);

View file

@ -36,7 +36,8 @@ void content_status_create(struct session* ssn, mastodont_t* api, char** data);
char* construct_post_box(char* reply_id,
char* default_content,
int* size);
char* reformat_status(char* content);
char* reformat_status(char* content, struct mstdnt_emoji* emos, size_t emos_len);
char* greentextify(char* content);
char* construct_status(mastodont_t* api, struct mstdnt_status* status, int* size, struct mstdnt_notification* notif, uint8_t flags);
char* construct_statuses(mastodont_t* api, struct mstdnt_status* statuses, size_t size, size_t* ret_size);