Direct messages

FossilOrigin-Name: 17cdd2763618af17467ca3246959b28026e24c1a695722c488a2b0e627a861cc
This commit is contained in:
me@ow.nekobit.net 2022-04-19 19:17:55 +00:00
parent 057112d1d6
commit e16397dd03
6 changed files with 87 additions and 2 deletions

View file

@ -88,6 +88,8 @@ $(PAGES_DIR)/search.chtml: $(PAGES_DIR)/search.html
./filec $< data_search_html > $@
$(PAGES_DIR)/scrobble.chtml: $(PAGES_DIR)/scrobble.html
./filec $< data_scrobble_html > $@
$(PAGES_DIR)/directs_page.chtml: $(PAGES_DIR)/directs_page.html
./filec $< data_directs_page_html > $@
$(MASTODONT_DIR):
git clone $(MASTODONT_URL) || true

View file

@ -297,7 +297,7 @@ input[type=textbox]
{
background: linear-gradient(#520000, #290000);
border-color: #400000;
color: #a68f8f;
color: #ffdddd;
cursor: pointer;
}

View file

@ -98,6 +98,7 @@ int main(void)
{ "/lists/for/:", content_tl_list },
{ "/lists", content_lists },
{ "/federated", content_tl_federated },
{ "/direct", content_tl_direct },
{ "/local", content_tl_local },
{ "/notifications", content_notifications },
};

View file

@ -30,7 +30,9 @@
#include "string_helpers.h"
#include "../static/navigation.chtml"
#include "../static/directs_page.chtml"
/* TODO Clean these up and make a meta function, i'm just lazy */
void tl_home(struct session* ssn, mastodont_t* api, int local)
{
@ -48,7 +50,7 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
.max_id = ssn->post.max_id,
.since_id = NULL,
.min_id = ssn->post.min_id,
.limit = 10,
.limit = 20
};
try_post_status(ssn, api);
@ -99,6 +101,72 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
if (output) free(output);
}
void tl_direct(struct session* ssn, mastodont_t* api)
{
size_t status_count = 0, statuses_html_count = 0;
struct mstdnt_status* statuses = NULL;
struct mstdnt_storage storage = { 0 };
char* status_format = NULL,
*navigation_box = NULL,
*output = NULL,
*page = NULL;
char* start_id;
struct mstdnt_timeline_args args = {
.with_muted = 0,
.max_id = ssn->post.max_id,
.since_id = NULL,
.min_id = ssn->post.min_id,
.limit = 20,
};
if (mastodont_timeline_direct(api, &args, &storage, &statuses, &status_count))
{
status_format = construct_error(storage.error, E_ERROR, 1, NULL);
}
else {
// Construct statuses into HTML
status_format = construct_statuses(api, statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = construct_error("Couldn't load posts", E_ERROR, 1, NULL);
}
// Create post box
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
NULL);
}
easprintf(&page, "%s%s",
STR_NULL_EMPTY(status_format),
STR_NULL_EMPTY(navigation_box));
easprintf(&output, data_directs_page_html, page);
struct base_page b = {
.category = BASE_CAT_DIRECT,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
// Output
render_base_page(&b, ssn, api);
// Cleanup
mastodont_storage_cleanup(&storage);
mstdnt_cleanup_statuses(statuses, status_count);
if (status_format) free(status_format);
if (navigation_box) free(navigation_box);
if (output) free(output);
if (page) free(page);
}
void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_category cat)
{
size_t status_count = 0, statuses_html_count = 0;
@ -229,6 +297,12 @@ void content_tl_home(struct session* ssn, mastodont_t* api, char** data)
content_tl_federated(ssn, api, data);
}
void content_tl_direct(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;
tl_direct(ssn, api);
}
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;

View file

@ -25,11 +25,13 @@
// Federated and local are here
void tl_home(struct session* ssn, mastodont_t* api, int local);
void tl_direct(struct session* ssn, mastodont_t* api);
void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_category cat);
void tl_list(struct session* ssn, mastodont_t* api, char* list_id);
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data);
void content_tl_home(struct session* ssn, mastodont_t* api, char** data);
void content_tl_direct(struct session* ssn, mastodont_t* api, char** data);
void content_tl_local(struct session* ssn, mastodont_t* api, char** data);
void content_tl_list(struct session* ssn, mastodont_t* api, char** data);

6
static/directs_page.html Normal file
View file

@ -0,0 +1,6 @@
<div class="simple-page">
<h1>Direct Messages</h1>
<div class="direct-container">
%s
</div>
</div>