View status

FossilOrigin-Name: 5f272da1e3bec03bb54e2ccbc6dc56459f6503a74b0f33b177239d6983ca45c0
This commit is contained in:
me@ow.nekobit.net 2022-02-21 20:40:41 +00:00
parent c7daed2bd7
commit 6ae4d8cd12
3 changed files with 49 additions and 9 deletions

View file

@ -29,6 +29,7 @@
#include "local_config.h"
#include "cookie.h"
#include "query.h"
#include "status.h"
int main(void)
{
@ -58,6 +59,7 @@ int main(void)
{ "/config", content_config },
{ "/login", content_login },
{ "/@:", content_account },
{ "/status/:", content_status }
};
handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0]));

View file

@ -18,6 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include "base_page.h"
#include "status.h"
#include "easprintf.h"
#include "query.h"
@ -73,6 +74,22 @@ int try_interact_status(mastodont_t* api)
return 0;
}
char* construct_status(struct mstdnt_status* status, int* size)
{
char* stat_html;
size_t s = easprintf(&stat_html, data_status_html,
status->account.avatar,
status->account.display_name, /* Username */
status->account.acct, /* Account */
"Public", /* visibility */
status->content,
status->reblogged ? "nobutton-active" : "",
status->id,
status->favourited ? "nobutton-active" : "");
if (size) *size = s;
return stat_html;
}
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size)
{
char* stat_html, *result = NULL;
@ -80,15 +97,8 @@ char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* re
for (size_t i = 0; i < size; ++i)
{
parse_size = easprintf(&stat_html, data_status_html,
statuses[i].account.avatar,
statuses[i].account.display_name, /* Username */
statuses[i].account.acct, /* Account */
"Public", /* visibility */
statuses[i].content,
statuses[i].reblogged ? "nobutton-active" : "",
statuses[i].id,
statuses[i].favourited ? "nobutton-active" : "");
stat_html = construct_status(statuses + i, &parse_size);
if (parse_size == -1) /* Malloc error */
{
if (result) free(result);
@ -118,3 +128,29 @@ char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* re
return result;
}
void content_status(mastodont_t* api, char** data, size_t data_size)
{
struct mstdnt_storage storage;
struct mstdnt_status* statuses_before, *statuses_after;
size_t stat_before_len, stat_after_len;
char* before_html = NULL, *after_html = NULL;
mastodont_status_context(api, data[0], &storage, &statuses_before, &statuses_after,
&stat_before_len, &stat_after_len);
before_html = construct_statuses(statuses_before, stat_before_len, NULL);
// after_html = construct_statuses(statuses_after, stat_after_len, NULL);
struct base_page b = {
.locale = L10N_EN_US,
.content = before_html,
.sidebar_right = NULL
};
// Output
render_base_page(&b);
// Cleanup
if (before_html) free(before_html);
if (after_html) free(after_html);
mastodont_storage_cleanup(&storage);
}

View file

@ -22,6 +22,8 @@
int try_post_status(mastodont_t* api);
int try_interact_status(mastodont_t* api);
char* construct_status(struct mstdnt_status* status, int* size);
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
void content_status(mastodont_t* api, char** data, size_t data_size);
#endif // STATUS_H