diff --git a/Makefile b/Makefile index 709d3b0..1774638 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,10 @@ $(PAGES_DIR)/status_interaction_profile.chtml: $(PAGES_DIR)/status_interaction_p ./filec $< data_status_interaction_profile_html > $@ $(PAGES_DIR)/account_follow_btn.chtml: $(PAGES_DIR)/account_follow_btn.html ./filec $< data_account_follow_btn_html > $@ +$(PAGES_DIR)/bookmarks_page.chtml: $(PAGES_DIR)/bookmarks_page.html + ./filec $< data_bookmarks_page_html > $@ +$(PAGES_DIR)/favourites_page.chtml: $(PAGES_DIR)/favourites_page.html + ./filec $< data_favourites_page_html > $@ $(MASTODONT_DIR): git clone $(MASTODONT_URL) || true diff --git a/src/account.c b/src/account.c index 07c2dbf..2932a3b 100644 --- a/src/account.c +++ b/src/account.c @@ -25,13 +25,17 @@ #include "easprintf.h" #include "status.h" #include "http.h" +#include "base_page.h" #include "scrobble.h" #include "string_helpers.h" +#include "navigation.h" // Files #include "../static/account.chtml" #include "../static/account_info.chtml" #include "../static/account_follow_btn.chtml" +#include "../static/favourites_page.chtml" +#include "../static/bookmarks_page.chtml" #define FOLLOWS_YOU_HTML "%s" #define MAKE_FOCUSED_IF(tab, test_tab) ((tab) == test_tab ? "focused" : "") @@ -346,3 +350,135 @@ void content_account_action(struct session* ssn, mastodont_t* api, char** data) redirect(REDIRECT_303, referer); } + +void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** data) +{ + 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_bookmarks_args args = { + .with_muted = 0, + .max_id = ssn->post.max_id, + .since_id = NULL, + .min_id = ssn->post.min_id, + .limit = 20, + }; + + if (mastodont_get_bookmarks(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_bookmarks_page_html, page); + + struct base_page b = { + .category = BASE_CAT_BOOKMARKS, + .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 content_account_favourites(struct session* ssn, mastodont_t* api, char** data) +{ + 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_get_favourites(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_favourites_page_html, page); + + struct base_page b = { + .category = BASE_CAT_FAVOURITES, + .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); +} diff --git a/src/account.h b/src/account.h index 7d1d546..776a89e 100644 --- a/src/account.h +++ b/src/account.h @@ -62,12 +62,11 @@ char* load_account_info(struct mstdnt_account* acct, size_t* size); void content_account_statuses(struct session* ssn, mastodont_t* api, char** data); - void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data); - void content_account_pinned(struct session* ssn, mastodont_t* api, char** data); - void content_account_media(struct session* ssn, mastodont_t* api, char** data); - void content_account_action(struct session* ssn, mastodont_t* api, char** data); +void content_account_favourites(struct session* ssn, mastodont_t* api, char** data); +void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** data); + #endif // ACCOUNT_H diff --git a/src/base_page.c b/src/base_page.c index 60e58a4..6a7f2ef 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -103,6 +103,12 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* CAT_TEXT(page->category, BASE_CAT_LISTS), config_url_prefix, L10N[locale][L10N_LISTS], + CAT_TEXT(page->category, BASE_CAT_FAVOURITES), + config_url_prefix, + L10N[locale][L10N_LISTS], + CAT_TEXT(page->category, BASE_CAT_BOOKMARKS), + config_url_prefix, + L10N[locale][L10N_LISTS], CAT_TEXT(page->category, BASE_CAT_DIRECT), config_url_prefix, L10N[locale][L10N_DIRECT], diff --git a/src/base_page.h b/src/base_page.h index 6ce2b6e..7dc0091 100644 --- a/src/base_page.h +++ b/src/base_page.h @@ -31,6 +31,8 @@ enum base_category BASE_CAT_FEDERATED, BASE_CAT_NOTIFICATIONS, BASE_CAT_LISTS, + BASE_CAT_FAVOURITES, + BASE_CAT_BOOKMARKS, BASE_CAT_DIRECT, BASE_CAT_CONFIG, }; diff --git a/src/l10n.h b/src/l10n.h index 86709f6..8c1ab3b 100644 --- a/src/l10n.h +++ b/src/l10n.h @@ -34,6 +34,8 @@ enum l10n_string L10N_FEDERATED, L10N_NOTIFICATIONS, L10N_LISTS, + L10N_FAVOURITES, + L10N_BOOKMARKS, L10N_DIRECT, L10N_CONFIG, L10N_SEARCH_PLACEHOLDER, @@ -132,6 +134,8 @@ static const char* const L10N[][_L10N_LEN] = { "Federated", "Notifications", "Lists", + "Favorites", + "Bookmarks", "Direct", "Config", "Search", @@ -227,6 +231,8 @@ static const char* const L10N[][_L10N_LEN] = { "Federado", "Notificaciones", "Listas", + "Favourites", + "Bookmarks", "Directo", "Configuración", "Búsqueda", diff --git a/src/main.c b/src/main.c index 74ebdf9..babeeec 100644 --- a/src/main.c +++ b/src/main.c @@ -100,6 +100,8 @@ int main(void) { "/federated", content_tl_federated }, { "/direct", content_tl_direct }, { "/local", content_tl_local }, + { "/bookmarks", content_account_bookmarks }, + { "/favourites", content_account_favourites }, { "/notifications", content_notifications }, }; diff --git a/static/bookmarks_page.html b/static/bookmarks_page.html new file mode 100644 index 0000000..7d08ba4 --- /dev/null +++ b/static/bookmarks_page.html @@ -0,0 +1,6 @@ +