diff --git a/Makefile b/Makefile index 28d3a25..ad94e82 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dist/treebird20-dark.css b/dist/treebird20-dark.css index e934b9b..dbb67c4 100644 --- a/dist/treebird20-dark.css +++ b/dist/treebird20-dark.css @@ -297,7 +297,7 @@ input[type=textbox] { background: linear-gradient(#520000, #290000); border-color: #400000; - color: #a68f8f; + color: #ffdddd; cursor: pointer; } diff --git a/src/main.c b/src/main.c index 12ee1e2..74ebdf9 100644 --- a/src/main.c +++ b/src/main.c @@ -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 }, }; diff --git a/src/timeline.c b/src/timeline.c index 362a837..39658d3 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -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; diff --git a/src/timeline.h b/src/timeline.h index 0f48e92..f3af763 100644 --- a/src/timeline.h +++ b/src/timeline.h @@ -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); diff --git a/static/directs_page.html b/static/directs_page.html new file mode 100644 index 0000000..6373543 --- /dev/null +++ b/static/directs_page.html @@ -0,0 +1,6 @@ +
+

Direct Messages

+
+ %s +
+