Bookmarks and favorites page
FossilOrigin-Name: 9af3f8d27ddd84caab9c72e74c591a1969eb3b422fcaae2f512605b836a7ff43
This commit is contained in:
parent
a0240a63db
commit
ca444fde1d
6 changed files with 48 additions and 124 deletions
|
@ -13,7 +13,7 @@ use navigation 'generate_navigation';
|
|||
|
||||
sub content_timeline
|
||||
{
|
||||
my ($ssn, $data, $statuses, $title, $show_post_box) = @_;
|
||||
my ($ssn, $data, $statuses, $title, $show_post_box, $fake_timeline) = @_;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
|
@ -21,10 +21,12 @@ sub content_timeline
|
|||
data => $data,
|
||||
statuses => $statuses,
|
||||
title => $title,
|
||||
fake_timeline => $fake_timeline,
|
||||
show_post_box => $show_post_box,
|
||||
postbox => \&generate_postbox,
|
||||
create_status => sub { generate_status($ssn, $data, shift); },
|
||||
nav => generate_navigation($ssn, $data, $statuses->[0]->{id}, $statuses->[-1]->{id}),
|
||||
# Don't autovivify statuses
|
||||
nav => sub { generate_navigation($ssn, $data, $statuses->[0]->{id}, $statuses->[-1]->{id}) },
|
||||
);
|
||||
|
||||
to_template(\%vars, \$data->{'timeline.tt'});
|
||||
|
|
110
src/account.c
110
src/account.c
|
@ -33,6 +33,7 @@
|
|||
#include "string_helpers.h"
|
||||
#include "navigation.h"
|
||||
#include "emoji.h"
|
||||
#include "timeline.h"
|
||||
|
||||
// Files
|
||||
#include "../static/account.ctmpl"
|
||||
|
@ -685,14 +686,9 @@ void content_account_action(PATH_ARGS)
|
|||
|
||||
void content_account_bookmarks(PATH_ARGS)
|
||||
{
|
||||
size_t status_count = 0, statuses_html_count = 0;
|
||||
size_t statuses_len = 0;
|
||||
struct mstdnt_status* statuses = NULL;
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
char* status_format = NULL,
|
||||
*navigation_box = NULL,
|
||||
*output = NULL;
|
||||
char* start_id;
|
||||
|
||||
struct mstdnt_bookmarks_args args = {
|
||||
.max_id = keystr(ssn->post.max_id),
|
||||
.since_id = NULL,
|
||||
|
@ -702,49 +698,9 @@ void content_account_bookmarks(PATH_ARGS)
|
|||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
||||
if (mastodont_get_bookmarks(api, &m_args, &args, &storage, &statuses, &status_count))
|
||||
{
|
||||
status_format = construct_error(storage.error, E_ERROR, 1, NULL);
|
||||
}
|
||||
else {
|
||||
// Construct statuses into HTML
|
||||
status_format = construct_statuses(ssn, api, statuses, status_count, NULL, &statuses_html_count);
|
||||
if (!status_format)
|
||||
status_format = construct_error("Couldn't load posts", E_ERROR, 1, NULL);
|
||||
}
|
||||
mastodont_get_bookmarks(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
// Create post box
|
||||
if (statuses)
|
||||
{
|
||||
// If not set, set it
|
||||
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
|
||||
navigation_box = construct_navigation_box(start_id,
|
||||
statuses[0].id,
|
||||
statuses[status_count-1].id,
|
||||
NULL);
|
||||
}
|
||||
|
||||
struct bookmarks_page_template tdata = {
|
||||
.statuses = status_format,
|
||||
.navigation = navigation_box
|
||||
};
|
||||
output = tmpl_gen_bookmarks_page(&tdata, NULL);
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_BOOKMARKS,
|
||||
.content = output,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mstdnt_cleanup_statuses(statuses, status_count);
|
||||
free(status_format);
|
||||
free(navigation_box);
|
||||
free(output);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_BOOKMARKS, "Bookmarks", 0, 1);
|
||||
}
|
||||
|
||||
static void accounts_page(FCGX_Request* req,
|
||||
|
@ -828,66 +784,20 @@ void content_account_muted(PATH_ARGS)
|
|||
|
||||
void content_account_favourites(PATH_ARGS)
|
||||
{
|
||||
size_t status_count = 0, statuses_html_count = 0;
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
size_t statuses_len = 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_favourites_args args = {
|
||||
|
||||
.min_id = keystr(ssn->post.min_id),
|
||||
.limit = 20,
|
||||
};
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
||||
if (mastodont_get_favourites(api, &m_args, &args, &storage, &statuses, &status_count))
|
||||
{
|
||||
status_format = construct_error(storage.error, E_ERROR, 1, NULL);
|
||||
}
|
||||
else {
|
||||
// Construct statuses into HTML
|
||||
status_format = construct_statuses(ssn, api, statuses, status_count, NULL, &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 = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
|
||||
navigation_box = construct_navigation_box(start_id,
|
||||
statuses[0].id,
|
||||
statuses[status_count-1].id,
|
||||
NULL);
|
||||
}
|
||||
|
||||
struct favourites_page_template tdata = {
|
||||
.statuses = status_format,
|
||||
.navigation = navigation_box
|
||||
};
|
||||
output = tmpl_gen_favourites_page(&tdata, NULL);
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_FAVOURITES,
|
||||
.content = output,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, req, 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);
|
||||
mastodont_get_favourites(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_BOOKMARKS, "Favorites", 0, 1);
|
||||
}
|
||||
|
||||
HV* perlify_account(const struct mstdnt_account* acct)
|
||||
|
|
|
@ -43,7 +43,8 @@ void content_timeline(FCGX_Request* req,
|
|||
size_t statuses_len,
|
||||
enum base_category cat,
|
||||
char* header_text,
|
||||
int show_post_box)
|
||||
int show_post_box,
|
||||
int fake_timeline)
|
||||
{
|
||||
perl_lock();
|
||||
dSP;
|
||||
|
@ -63,6 +64,7 @@ void content_timeline(FCGX_Request* req,
|
|||
else ARG_UNDEFINED();
|
||||
|
||||
mXPUSHi(show_post_box);
|
||||
mXPUSHi(fake_timeline);
|
||||
|
||||
PUTBACK;
|
||||
call_pv("timeline::content_timeline", G_SCALAR);
|
||||
|
@ -120,7 +122,7 @@ void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local
|
|||
|
||||
mastodont_timeline_home(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_HOME, NULL, 1);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_HOME, NULL, 1, 0);
|
||||
}
|
||||
|
||||
void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
||||
|
@ -148,7 +150,7 @@ void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
|||
|
||||
mastodont_timeline_direct(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0, 0);
|
||||
}
|
||||
|
||||
void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local, enum base_category cat)
|
||||
|
@ -178,7 +180,7 @@ void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int loc
|
|||
|
||||
mastodont_timeline_public(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, cat, NULL, 1);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, cat, NULL, 1, 0);
|
||||
}
|
||||
|
||||
void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* list_id)
|
||||
|
@ -205,7 +207,7 @@ void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* lis
|
|||
|
||||
mastodont_timeline_list(api, &m_args, list_id, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_LISTS, "List timeline", 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_LISTS, "List timeline", 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -234,7 +236,7 @@ void tl_tag(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* tag_
|
|||
|
||||
easprintf(&header, "Hashtag - #%s", tag_id);
|
||||
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_NONE, header, 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_NONE, header, 0, 0);
|
||||
free(header);
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ void content_timeline(FCGX_Request* req,
|
|||
size_t statuses_len,
|
||||
enum base_category cat,
|
||||
char* header,
|
||||
int show_post_box);
|
||||
int show_post_box,
|
||||
int fake_timeline);
|
||||
|
||||
#endif // TIMELINE_H
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<tr>
|
||||
<td class="nav-up btn">
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="only_media" value="[% IF ssn.post.only_media %]1[% ELSE %]0[% END %]">
|
||||
<label class="pointer">
|
||||
<span class="nav-btn">Up</span>
|
||||
<input type="submit" class="hidden">
|
||||
|
@ -10,6 +11,7 @@
|
|||
</td>
|
||||
<td class="nav-prev btn">
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="only_media" value="[% IF ssn.post.only_media %]1[% ELSE %]0[% END %]">
|
||||
<label class="pointer">
|
||||
[% UNLESS prev_id == start_id %]
|
||||
<input type="hidden" name="start_id" value="[% start_id %]">
|
||||
|
@ -22,6 +24,7 @@
|
|||
</td>
|
||||
<td class="nav-next btn">
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="only_media" value="[% IF ssn.post.only_media %]1[% ELSE %]0[% END %]">
|
||||
<label class="pointer">
|
||||
<input type="hidden" name="start_id" value="[% start_id %]">
|
||||
<input type="hidden" name="max_id" value="[% next_id %]">
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
[% IF title %]
|
||||
<h1 class="text-header">$title</h1>
|
||||
[% END %]
|
||||
|
||||
[% IF show_post_box %]
|
||||
[% postbox(ssn, data, undef) %]
|
||||
[% END %]
|
||||
|
||||
<div class="menubar">
|
||||
<form action="." method="post">
|
||||
Only media:
|
||||
<input type="checkbox" name="only_media" value="1" [% ssn.post.only_media %]>
|
||||
<span class="bullet-separate">•</span>
|
||||
Replies:
|
||||
<select name="replies_only">
|
||||
<option value="0">Show replies</option>
|
||||
<option value="1">Self</option>
|
||||
<option value="2">Following</option>
|
||||
</select>
|
||||
<input type="submit" class="btn btn-single" value="Filter">
|
||||
</form>
|
||||
</div>
|
||||
[% UNLESS fake_timeline %]
|
||||
<div class="menubar">
|
||||
<form action="." method="post">
|
||||
Only media:
|
||||
<input type="checkbox" name="only_media" value="1" [% ssn.post.only_media %]>
|
||||
<span class="bullet-separate">•</span>
|
||||
Replies:
|
||||
<select name="replies_only">
|
||||
<option value="0">Show replies</option>
|
||||
<option value="1">Self</option>
|
||||
<option value="2">Following</option>
|
||||
</select>
|
||||
<input type="submit" class="btn btn-single" value="Filter">
|
||||
</form>
|
||||
</div>
|
||||
[% END %]
|
||||
|
||||
[% FOREACH i IN statuses %]
|
||||
[% create_status(i) %]
|
||||
[% END %]
|
||||
|
||||
[%# TODO navigation %]
|
||||
[% nav %]
|
||||
[% nav() %]
|
||||
|
|
Loading…
Reference in a new issue