Notifications perl template
FossilOrigin-Name: 7f5ff955aa478f571019fe9d6cf992f229e421dd7bac1b8ea689594baca3621f
This commit is contained in:
parent
388f4fadf4
commit
937301e307
|
@ -3,7 +3,7 @@ use warnings;
|
|||
# Modules
|
||||
use Template;
|
||||
use l10n qw( &lang %L10N );
|
||||
use notifications qw( generate_notification_compact );
|
||||
use notifications qw( generate_notification_compact content_notifications );
|
||||
use template_helpers qw( &to_template );
|
||||
use timeline;
|
||||
use status;
|
||||
|
|
|
@ -3,7 +3,7 @@ use strict;
|
|||
use warnings;
|
||||
use Exporter 'import';
|
||||
|
||||
our @EXPORT = qw( generate_notification_compact );
|
||||
our @EXPORT = qw( generate_notification_compact content_notifications );
|
||||
|
||||
use template_helpers 'to_template';
|
||||
|
||||
|
@ -19,3 +19,16 @@ sub generate_notification_compact
|
|||
|
||||
to_template(\%vars, \$data->{'notif_compact.tt'});
|
||||
}
|
||||
|
||||
sub content_notifications
|
||||
{
|
||||
my ($ssn, $data, $notifs) = @_;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
ssn=> $ssn,
|
||||
notif => $notif
|
||||
);
|
||||
|
||||
to_template(\%vars, \$data->{'content_notifs.tt'});
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../templates/account.ctt"
|
||||
#include "../templates/account_statuses.ctt"
|
||||
#include "../templates/account_scrobbles.ctt"
|
||||
#include "../templates/content_notifs.ctt"
|
||||
|
||||
HV* template_files;
|
||||
pthread_mutex_t perl_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
@ -51,6 +52,7 @@ void init_template_files()
|
|||
hv_stores(template_files, "account.tt", newSVpv(data_account_tt, data_account_tt_size));
|
||||
hv_stores(template_files, "account_statuses.tt", newSVpv(data_account_statuses_tt, data_account_statuses_tt_size));
|
||||
hv_stores(template_files, "account_scrobbles.tt", newSVpv(data_account_scrobbles_tt, data_account_scrobbles_tt_size));
|
||||
hv_stores(template_files, "content_notifs.tt", newSVpv(data_content_notifs_tt, data_content_notifs_tt_size));
|
||||
}
|
||||
|
||||
void cleanup_template_files()
|
||||
|
|
|
@ -195,67 +195,61 @@ void content_notifications(PATH_ARGS)
|
|||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
char* page, *notif_html = NULL;
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_notification* notifs = NULL;
|
||||
size_t notifs_len = 0;
|
||||
char* start_id;
|
||||
char* navigation_box = NULL;
|
||||
|
||||
if (keystr(ssn->cookies.logged_in))
|
||||
{
|
||||
struct mstdnt_get_notifications_args args = {
|
||||
.exclude_types = 0,
|
||||
.account_id = NULL,
|
||||
.exclude_visibilities = 0,
|
||||
.include_types = 0,
|
||||
.with_muted = 1,
|
||||
.max_id = keystr(ssn->post.max_id),
|
||||
.min_id = keystr(ssn->post.min_id),
|
||||
.since_id = NULL,
|
||||
.offset = 0,
|
||||
.limit = 20,
|
||||
};
|
||||
|
||||
if (mastodont_get_notifications(api, &m_args, &args, &storage, ¬ifs, ¬ifs_len) == 0)
|
||||
{
|
||||
if (notifs && notifs_len)
|
||||
{
|
||||
notif_html = construct_notifications(ssn, api, notifs, notifs_len, NULL);
|
||||
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id;
|
||||
navigation_box = construct_navigation_box(start_id,
|
||||
notifs[0].id,
|
||||
notifs[notifs_len-1].id,
|
||||
NULL);
|
||||
mstdnt_cleanup_notifications(notifs, notifs_len);
|
||||
}
|
||||
else
|
||||
notif_html = construct_error("No notifications", E_NOTICE, 1, NULL);
|
||||
}
|
||||
else
|
||||
notif_html = construct_error(storage.error, E_ERROR, 1, NULL);
|
||||
|
||||
}
|
||||
|
||||
struct notifications_page_template tdata = {
|
||||
.notifications = notif_html,
|
||||
.navigation = navigation_box
|
||||
|
||||
struct mstdnt_get_notifications_args args = {
|
||||
.exclude_types = 0,
|
||||
.account_id = NULL,
|
||||
.exclude_visibilities = 0,
|
||||
.include_types = 0,
|
||||
.with_muted = 1,
|
||||
.max_id = keystr(ssn->post.max_id),
|
||||
.min_id = keystr(ssn->post.min_id),
|
||||
.since_id = NULL,
|
||||
.offset = 0,
|
||||
.limit = 20,
|
||||
};
|
||||
|
||||
page = tmpl_gen_notifications_page(&tdata, NULL);
|
||||
if (keystr(ssn->cookies.logged_in))
|
||||
mastodont_get_notifications(api, &m_args, &args, &storage, ¬ifs, ¬ifs_len);
|
||||
|
||||
// Call perl
|
||||
perl_lock();
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
|
||||
HV* session_hv = perlify_session(ssn);
|
||||
XPUSHs(newRV_noinc((SV*)session_hv));
|
||||
XPUSHs(newRV_noinc((SV*)template_files));
|
||||
XPUSHs(newRV_noinc((SV*)perlify_notifications(notifs, notifs_len)));
|
||||
|
||||
// ARGS
|
||||
PUTBACK;
|
||||
call_pv("notifications::content_notifications", G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
// Duplicate so we can free the TMPs
|
||||
char* dup = savesharedsvpv(POPs);
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
perl_unlock();
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_NOTIFICATIONS,
|
||||
.content = page,
|
||||
.content = dup,
|
||||
.session = session_hv,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, req, ssn, api);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
if (notif_html) free(notif_html);
|
||||
if (navigation_box) free(navigation_box);
|
||||
if (page) free(page);
|
||||
Safefree(dup);
|
||||
}
|
||||
|
||||
void content_notifications_compact(PATH_ARGS)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<h1>Notifications</h1>
|
Loading…
Reference in New Issue