From 3451a4888275a876b2dda47e93a3ef61ceb9de52 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 24 Feb 2022 19:12:01 +0000 Subject: [PATCH] Prepend users in reply box FossilOrigin-Name: af5d1c04617c94c640c0b5788624750bd728ac112f3492eeba81bef54b4389b6 --- src/reply.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ src/reply.h | 33 ++++++++++++++++++++ src/status.c | 30 +++++-------------- static/post.html | 2 +- 4 files changed, 120 insertions(+), 23 deletions(-) create mode 100644 src/reply.c create mode 100644 src/reply.h diff --git a/src/reply.c b/src/reply.c new file mode 100644 index 0000000..5b99e89 --- /dev/null +++ b/src/reply.c @@ -0,0 +1,78 @@ +/* + * RatFE - 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 . + */ + +#include +#include +#include "reply.h" +#include "easprintf.h" + +// Pages +#include "../static/post.chtml" + +#define ID_REPLY_SIZE 256 +#define ID_RESPONSE "" + +char* construct_post_box(char* reply_id, + char* default_content, + int* size) +{ + char* reply_html; + char id_reply[ID_REPLY_SIZE]; + + // Put hidden post request + snprintf(id_reply, ID_REPLY_SIZE, ID_RESPONSE, reply_id); + + // Construct box + size_t s = easprintf(&reply_html, data_post_html, reply_id ? id_reply : "", + default_content); + if (size) *size = s; + return reply_html; +} + +char* reply_status(char* id, + struct mstdnt_status* statuses_before, + size_t before_len, + struct mstdnt_status* status) +{ + char* stat_reply; + + // Replies + size_t replies_size, replies_size_orig; + char* replies = malloc(replies_size = strlen(status->account.acct)+2); + replies[0] = '@'; + strcpy(replies+1, status->account.acct); + replies[replies_size-1] = ' '; + + for (int i = before_len-1; i >= 1; --i) + { + replies_size_orig = replies_size; + replies_size += strlen(statuses_before[i].account.acct)+2; + + // Realloc string + replies = realloc(replies, replies_size+1); + + replies[replies_size_orig] = '@'; + strcpy(replies + replies_size_orig + 1, statuses_before[i].account.acct); + replies[replies_size-1] = ' '; + + } + + stat_reply = construct_post_box(id, replies, NULL); + if (replies) free(replies); + return stat_reply; +} diff --git a/src/reply.h b/src/reply.h new file mode 100644 index 0000000..09c8629 --- /dev/null +++ b/src/reply.h @@ -0,0 +1,33 @@ +/* + * RatFE - 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 . + */ + +#ifndef REPLY_H +#define REPLY_H +#include + +char* construct_post_box(char* reply_id, + char* default_content, + int* size); + +char* reply_status(char* id, + struct mstdnt_status* statuses_before, + size_t before_len, + struct mstdnt_status* status); + + +#endif // REPLY_H diff --git a/src/status.c b/src/status.c index f163ccd..1aff811 100644 --- a/src/status.c +++ b/src/status.c @@ -24,14 +24,11 @@ #include "query.h" #include "cookie.h" #include "string_helpers.h" +#include "reply.h" #include "../config.h" // Pages #include "../static/status.chtml" -#include "../static/post.chtml" - -#define ID_REPLY_SIZE 256 -#define ID_RESPONSE "" int try_post_status(mastodont_t* api) { @@ -82,23 +79,6 @@ int try_interact_status(mastodont_t* api, char* id) return 0; } -char* construct_post_box(char* reply_id, - char* default_content, - int* size) -{ - char* reply_html; - char id_reply[ID_REPLY_SIZE]; - - // Put hidden post request - snprintf(id_reply, ID_REPLY_SIZE, ID_RESPONSE, reply_id); - - // Construct box - size_t s = easprintf(&reply_html, data_post_html, reply_id ? id_reply : "", - default_content); - if (size) *size = s; - return reply_html; -} - char* construct_status(struct mstdnt_status* status, int* size) { char* stat_html; @@ -181,7 +161,13 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl // Current status stat_html = construct_status(&status, NULL); - if (is_reply) stat_reply = construct_post_box(data[0], "", NULL); + if (is_reply) + { + stat_reply = reply_status(data[0], + statuses_before, + stat_before_len, + &status); + } // After... after_html = construct_statuses(statuses_after, stat_after_len, NULL); diff --git a/static/post.html b/static/post.html index fd2fafc..79b637c 100644 --- a/static/post.html +++ b/static/post.html @@ -1,7 +1,7 @@
%s
- +