In reply to

FossilOrigin-Name: 75dcc9ecb835e4b8e2c6c3ca2b2fdfa1de6c326a52c7e7de63d60d7745105d11
This commit is contained in:
me@ow.nekobit.net 2022-04-04 13:53:49 +00:00
parent 3ffead15ab
commit 6f4dbb5710
11 changed files with 117 additions and 31 deletions

View file

@ -79,12 +79,17 @@ $(PAGES_DIR)/config_general.chtml: $(PAGES_DIR)/config_general.html
./filec $< data_config_general_html > $@
$(PAGES_DIR)/config_appearance.chtml: $(PAGES_DIR)/config_appearance.html
./filec $< data_config_appearance_html > $@
$(PAGES_DIR)/in_reply_to.chtml: $(PAGES_DIR)/in_reply_to.html
./filec $< data_in_reply_to_html > $@
$(MASTODONT_DIR):
git clone $(MASTODONT_URL) || true
@echo -e "\033[38;5;13mRun 'make update' to update mastodont-c\033[0m"
install:
@echo "lol"
apache_start:
./scripts/fcgistarter.sh

View file

@ -28,7 +28,8 @@
#include "../static/index.chtml"
#include "../static/account.chtml"
char* construct_account_page(struct mstdnt_account* acct,
char* construct_account_page(mastodont_t* api,
struct mstdnt_account* acct,
struct mstdnt_status* statuses,
size_t statuses_len,
size_t* res_size)
@ -39,7 +40,7 @@ char* construct_account_page(struct mstdnt_account* acct,
char* result;
// Load statuses html
statuses_html = construct_statuses(statuses, statuses_len, NULL);
statuses_html = construct_statuses(api, statuses, statuses_len, NULL);
if (!statuses_html)
statuses_html = "Error in malloc!";
else
@ -83,7 +84,8 @@ void content_account(struct session* ssn, mastodont_t* api, char** data)
account_page = construct_error("Couldn't load account info", NULL);
}
else {
account_page = construct_account_page(&acct,
account_page = construct_account_page(api,
&acct,
statuses,
status_len,
NULL);

View file

@ -22,7 +22,8 @@
#include <mastodont.h>
#include "session.h"
char* construct_account_page(struct mstdnt_account* acct,
char* construct_account_page(mastodont_t* api,
struct mstdnt_account* acct,
struct mstdnt_status* statuses,
size_t statuses_len,
size_t* res_size);

View file

@ -61,6 +61,7 @@ enum l10n_string
L10N_LIKE,
L10N_QUICK,
L10N_VIEW,
L10N_IN_REPLY_TO,
/* ERRORS */
L10N_PAGE_NOT_FOUND,
@ -138,6 +139,7 @@ static const char* const L10N[][_L10N_LEN] = {
"Like",
"Quick",
"View",
"In reply to",
/* ERRORS */
"Content not found",
@ -211,7 +213,8 @@ static const char* const L10N[][_L10N_LEN] = {
"Impulso",
"Me gusta",
"Rápido",
"View (Translate me)",
"View",
"In reply to",
/* ERRORS */
"Content not found",

View file

@ -36,7 +36,15 @@
#include "../static/like_svg.chtml"
#include "../static/repeat_svg.chtml"
char* construct_notification(struct mstdnt_notification* notif, int* size)
struct notification_args
{
mastodont_t* api;
struct mstdnt_notification* notifs;
};
char* construct_notification(mastodont_t* api,
struct mstdnt_notification* notif,
int* size)
{
char* notif_html;
int s = 0;
@ -44,7 +52,7 @@ char* construct_notification(struct mstdnt_notification* notif, int* size)
if (notif->status)
{
// Construct status with notification_info
notif_html = construct_status(notif->status, &s, notif, 0);
notif_html = construct_status(api, notif->status, &s, notif, 0);
}
else {
notif_html = construct_notification_action(notif, &s);
@ -73,7 +81,9 @@ char* construct_notification_action(struct mstdnt_notification* notif, int* size
return notif_html;
}
char* construct_notification_compact(struct mstdnt_notification* notif, int* size)
char* construct_notification_compact(mastodont_t* api,
struct mstdnt_notification* notif,
int* size)
{
char* notif_html;
char* notif_stats = NULL;
@ -110,27 +120,39 @@ char* construct_notification_compact(struct mstdnt_notification* notif, int* siz
static char* construct_notification_voidwrap(void* passed, size_t index, int* res)
{
return construct_notification((struct mstdnt_notification*)passed + index, res);
struct notification_args* args = passed;
return construct_notification(args->api, args->notifs + index, res);
}
static char* construct_notification_compact_voidwrap(void* passed, size_t index, int* res)
{
return construct_notification_compact((struct mstdnt_notification*)passed + index, res);
struct notification_args* args = passed;
return construct_notification_compact(args->api, args->notifs + index, res);
}
char* construct_notifications(struct mstdnt_notification* notifs,
char* construct_notifications(mastodont_t* api,
struct mstdnt_notification* notifs,
size_t size,
size_t* ret_size)
{
return construct_func_strings(construct_notification_voidwrap, notifs, size, ret_size);
struct notification_args args = {
.api = api,
.notifs = notifs
};
return construct_func_strings(construct_notification_voidwrap, &args, size, ret_size);
}
char* construct_notifications_compact(struct mstdnt_notification* notifs,
char* construct_notifications_compact(mastodont_t* api,
struct mstdnt_notification* notifs,
size_t size,
size_t* ret_size)
{
struct notification_args args = {
.api = api,
.notifs = notifs
};
return construct_func_strings(construct_notification_compact_voidwrap,
notifs,
&args,
size,
ret_size);
}
@ -159,7 +181,7 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
if (mastodont_get_notifications(api, &args, &storage, &notifs, &notifs_len) == 0)
{
notif_html = construct_notifications(notifs, notifs_len, NULL);
notif_html = construct_notifications(api, notifs, notifs_len, NULL);
mstdnt_cleanup_notifications(notifs, notifs_len);
}
else

View file

@ -22,13 +22,19 @@
#include "session.h"
#include "type_string.h"
char* construct_notification(struct mstdnt_notification* notif, int* size);
char* construct_notification(mastodont_t* api,
struct mstdnt_notification* notif,
int* size);
char* construct_notification_action(struct mstdnt_notification* notif, int* size);
char* construct_notification_compact(struct mstdnt_notification* notif, int* size);
char* construct_notifications(struct mstdnt_notification* notifs,
char* construct_notification_compact(mastodont_t* api,
struct mstdnt_notification* notif,
int* size);
char* construct_notifications(mastodont_t* api,
struct mstdnt_notification* notifs,
size_t size,
size_t* ret_size);
char* construct_notifications_compact(struct mstdnt_notification* notifs,
char* construct_notifications_compact(mastodont_t* api,
struct mstdnt_notification* notifs,
size_t size,
size_t* ret_size);

View file

@ -34,9 +34,16 @@
// Pages
#include "../static/status.chtml"
#include "../static/notification.chtml"
#include "../static/in_reply_to.chtml"
#define NUM_STR "%u"
struct status_args
{
mastodont_t* api;
struct mstdnt_status* status;
};
int try_post_status(struct session* ssn, mastodont_t* api)
{
if (!(ssn->post.content)) return 1;
@ -109,7 +116,32 @@ int try_interact_status(struct session* ssn, mastodont_t* api, char* id)
return 0;
}
char* construct_status(struct mstdnt_status* status,
char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size_t* size)
{
char* irt_html;
size_t s;
struct mstdnt_storage storage;
struct mstdnt_account acct;
mastodont_get_account(api,
config_experimental_lookup,
status->in_reply_to_account_id,
&acct,
&storage,
NULL);
s = easprintf(&irt_html, data_in_reply_to_html,
config_url_prefix,
status->in_reply_to_id,
L10N[L10N_EN_US][L10N_IN_REPLY_TO],
status->in_reply_to_account_id);
if (size) *size = s;
return irt_html;
}
char* construct_status(mastodont_t* api,
struct mstdnt_status* status,
int* size,
struct mstdnt_notification* notif,
uint8_t flags)
@ -123,6 +155,7 @@ char* construct_status(struct mstdnt_status* status,
char* attachments = NULL;
char* emoji_reactions = NULL;
char* notif_info = NULL;
char* in_reply_to_str = NULL;
if (status->replies_count)
easprintf(&reply_count, NUM_STR, status->replies_count);
if (status->reblogs_count)
@ -139,7 +172,9 @@ char* construct_status(struct mstdnt_status* status,
notif->account->display_name,
notification_type_str(notif->type),
notification_type_svg(notif->type));
if (status->in_reply_to_id && status->in_reply_to_account_id)
in_reply_to_str = construct_in_reply_to(api, status, NULL);
size_t s = easprintf(&stat_html, data_status_html,
status->id,
@ -164,6 +199,7 @@ char* construct_status(struct mstdnt_status* status,
status->id,
status->bookmarked ? "un" : "",
status->bookmarked ? "Remove Bookmark" : "Bookmark",
in_reply_to_str ? in_reply_to_str : "",
status->content,
attachments ? attachments : "",
emoji_reactions ? emoji_reactions : "",
@ -189,6 +225,7 @@ char* construct_status(struct mstdnt_status* status,
if (reply_count) free(reply_count);
if (repeat_count) free(repeat_count);
if (favourites_count) free(favourites_count);
if (in_reply_to_str) free(in_reply_to_str);
if (attachments) free(attachments);
if (emoji_reactions) free(emoji_reactions);
if (notif) free(notif_info);
@ -197,12 +234,17 @@ char* construct_status(struct mstdnt_status* status,
static char* construct_status_voidwrap(void* passed, size_t index, int* res)
{
return construct_status((struct mstdnt_status*)passed + index, res, NULL, 0);
struct status_args* args = passed;
return construct_status(args->api, args->status + index, res, NULL, 0);
}
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size)
char* construct_statuses(mastodont_t* api, struct mstdnt_status* statuses, size_t size, size_t* ret_size)
{
return construct_func_strings(construct_status_voidwrap, statuses, size, ret_size);
struct status_args args = {
.api = api,
.status = statuses,
};
return construct_func_strings(construct_status_voidwrap, &args, size, ret_size);
}
void status_interact(struct session* ssn, mastodont_t* api, char** data)
@ -245,10 +287,10 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r
mastodont_get_status(api, data[0], &status_storage, &status);
// Before...
before_html = construct_statuses(statuses_before, stat_before_len, NULL);
before_html = construct_statuses(api, statuses_before, stat_before_len, NULL);
// Current status
stat_html = construct_status(&status, NULL, NULL, STATUS_FOCUSED);
stat_html = construct_status(api, &status, NULL, NULL, STATUS_FOCUSED);
if (is_reply)
{
stat_reply = reply_status(data[0],
@ -256,7 +298,7 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r
}
// After...
after_html = construct_statuses(statuses_after, stat_after_len, NULL);
after_html = construct_statuses(api, statuses_after, stat_after_len, NULL);
easprintf(&output, "%s%s%s%s",
before_html ? before_html : "",

View file

@ -27,6 +27,7 @@
#define STATUS_FOCUSED (1<<0)
#define STATUS_EMOJI_PICKER (1<<1)
char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size_t* size);
int try_post_status(struct session* ssn, mastodont_t* api);
int try_interact_status(struct session* ssn, mastodont_t* api, char* id);
void content_status_create(struct session* ssn, mastodont_t* api, char** data);
@ -35,8 +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* construct_status(struct mstdnt_status* status, int* size, struct mstdnt_notification* notif, uint8_t flags);
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
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);
// Status frontends
void status_view(struct session* ssn, mastodont_t* api, char** data);

View file

@ -60,7 +60,7 @@ void tl_public(struct session* ssn, mastodont_t* api, int local)
}
else {
// Construct statuses into HTML
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
status_format = construct_statuses(api, statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
}
@ -124,7 +124,7 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
}
else {
// Construct statuses into HTML
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
status_format = construct_statuses(api, statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;

3
static/in_reply_to.html Normal file
View file

@ -0,0 +1,3 @@
<span class="in-reply-to">
<a class="in-reply-to-id" href="%s/status/%s"><span class="in-reply-to-text">%s</span></a> <span class="acct">%s</span>
</span>

View file

@ -37,6 +37,7 @@
</div>
</span>
</div>
%s
<span class="status-content">
%s
</span>