Prepend users in reply box

FossilOrigin-Name: af5d1c04617c94c640c0b5788624750bd728ac112f3492eeba81bef54b4389b6
This commit is contained in:
me@ow.nekobit.net 2022-02-24 19:12:01 +00:00
parent 574955db2f
commit 3451a48882
4 changed files with 120 additions and 23 deletions

78
src/reply.c Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include "reply.h"
#include "easprintf.h"
// Pages
#include "../static/post.chtml"
#define ID_REPLY_SIZE 256
#define ID_RESPONSE "<input type=\"hidden\" name=\"replyid\" value=\"%s\">"
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;
}

33
src/reply.h Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef REPLY_H
#define REPLY_H
#include <mastodont.h>
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

View file

@ -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 "<input type=\"hidden\" name=\"replyid\" value=\"%s\">"
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);

View file

@ -1,7 +1,7 @@
<form action="." method="post">
%s
<div class="statusbox">
<textarea name="content" placeholder="Just landed in N.Y." rows="5"></textarea>
<textarea name="content" placeholder="Just landed in N.Y." rows="5">%s</textarea>
<div class="statusfooter">
<div class="statusfooter-left">
<!-- Put text here -->