Notifications embed

FossilOrigin-Name: 9ceac560758f39950f7edeaa79580d7cd0b212108a197efd7f57b24413c42dac
This commit is contained in:
nekobit 2022-08-19 03:52:26 +00:00
parent 5f32afa0cd
commit c9eaaac234
14 changed files with 220 additions and 181 deletions

25
perl/embed.pm Normal file
View File

@ -0,0 +1,25 @@
package embed;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( generate_embedded_page );
use template_helpers 'to_template';
sub generate_embedded_page
{
my ($ssn, $data, $content) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
content => $content,
);
to_template(\%vars, \$data->{'embed.tt'});
}
1;

View File

@ -13,6 +13,7 @@ use lists;
use search;
use chat;
use config;
use embed;
# my $template = Template->new(
# {

View File

@ -3,12 +3,13 @@ use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( generate_notification content_notifications );
our @EXPORT = qw( generate_notification content_notifications embed_notifications );
use template_helpers 'to_template';
use status 'generate_status';
use string_helpers qw( random_error_kaomoji );
use icons 'get_icon';
use embed 'generate_embedded_page';
sub generate_notification
{
@ -43,4 +44,19 @@ sub content_notifications
to_template(\%vars, \$data->{'content_notifs.tt'});
}
return 1;
sub embed_notifications
{
my ($ssn, $data, $notifs) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
notifs => $notifs,
notification => sub { generate_notification($ssn, $data, shift, 1); },
random_error_kaomoji => \&random_error_kaomoji,
);
generate_embedded_page($ssn, $data, to_template(\%vars, \$data->{'notifs_embed.tt'}));
}
1;

View File

@ -44,6 +44,8 @@
#include "../templates/chat.ctt"
#include "../templates/config_general.ctt"
#include "../templates/config_appearance.ctt"
#include "../templates/embed.ctt"
#include "../templates/notifs_embed.ctt"
PerlInterpreter* my_perl;
HV* template_files;
@ -78,6 +80,8 @@ void init_template_files(pTHX)
hv_stores(template_files, "chat.tt", newSVpv(data_chat_tt, data_chat_tt_size));
hv_stores(template_files, "config_general.tt", newSVpv(data_config_general_tt, data_config_general_tt_size));
hv_stores(template_files, "config_appearance.tt", newSVpv(data_config_appearance_tt, data_config_appearance_tt_size));
hv_stores(template_files, "embed.tt", newSVpv(data_embed_tt, data_embed_tt_size));
hv_stores(template_files, "notifs_embed.tt", newSVpv(data_notifs_embed_tt, data_notifs_embed_tt_size));
}
void cleanup_template_files()

View File

@ -27,7 +27,6 @@ HV* perlify_config(struct local_config* config)
hv_stores(ssn_config_hv, "theme", newSVpv(config->theme, 0));
hv_stores(ssn_config_hv, "background_url", newSVpv(config->background_url, 0));
hv_stores(ssn_config_hv, "lang", newSViv(config->lang));
hv_stores(ssn_config_hv, "themeclr", newSViv(config->themeclr));
hv_stores(ssn_config_hv, "jsactions", newSViv(config->jsactions));
hv_stores(ssn_config_hv, "jslive", newSViv(config->jslive));
hv_stores(ssn_config_hv, "js", newSViv(config->js));

View File

@ -27,7 +27,6 @@ struct local_config
char* theme;
char* background_url;
int lang;
int themeclr;
int jsactions;
int jsreply;
int jslive;

View File

@ -93,7 +93,6 @@ struct mstdnt_storage* load_config(FCGX_Request* req,
set_config_str(req, ssn, &(ssn->config.background_url), "background_url", &(atm), &(ssn->cookies.background_url), page, CONFIG_APPEARANCE);
set_config_int(LOAD_CFG_SIM("sidebaropacity", sidebar_opacity), CONFIG_APPEARANCE);
set_config_str(LOAD_CFG_SIM("theme", theme), CONFIG_APPEARANCE);
set_config_int(LOAD_CFG_SIM("themeclr", themeclr), CONFIG_APPEARANCE);
set_config_int(LOAD_CFG_SIM("jsactions", jsactions), CONFIG_GENERAL);
set_config_int(LOAD_CFG_SIM("jsreply", jsreply), CONFIG_GENERAL);
set_config_int(LOAD_CFG_SIM("jslive", jslive), CONFIG_GENERAL);

View File

@ -123,7 +123,6 @@ static void application(mastodont_t* api, FCGX_Request* req)
struct session ssn = {
.config = {
.theme = "treebird20",
.themeclr = 0,
.lang = L10N_EN_US,
.jsactions = 1,
.jsreply = 1,

View File

@ -244,15 +244,12 @@ void content_notifications(PATH_ARGS)
void content_notifications_compact(PATH_ARGS)
{
char* theme_str = NULL;
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
char* page, *notif_html = NULL;
char* page;
struct mstdnt_storage storage = { 0 };
struct mstdnt_notification* notifs = NULL;
size_t notifs_len = 0;
char* start_id = NULL;
char* navigation_box = NULL;
if (keystr(ssn->cookies.logged_in))
{
@ -269,56 +266,24 @@ void content_notifications_compact(PATH_ARGS)
.limit = 20,
};
if (mastodont_get_notifications(api,
&m_args,
&args,
&storage,
&notifs,
&notifs_len) == 0)
{
if (notifs && notifs_len)
{
notif_html = construct_notifications_compact(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);
mastodont_get_notifications(api, &m_args, &args, &storage, &notifs, &notifs_len);
}
// Set theme
if (ssn->config.theme && !(strcmp(ssn->config.theme, "treebird") == 0 &&
ssn->config.themeclr == 0))
{
easprintf(&theme_str, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/%s%s.css\">",
ssn->config.theme,
ssn->config.themeclr ? "-dark" : "");
}
PERL_STACK_INIT;
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
if (notifs)
XPUSHs(newRV_noinc((SV*)perlify_notifications(notifs, notifs_len)));
size_t len;
struct notifications_embed_template tdata = {
.theme_str = theme_str,
.notifications = notif_html,
.navigation_box = navigation_box
};
PERL_STACK_SCALAR_CALL("notifications::embed_notifications");
page = tmpl_gen_notifications_embed(&tdata, &len);
page = PERL_GET_STACK_EXIT;
send_result(req, NULL, NULL, page, len);
send_result(req, NULL, NULL, page, 0);
mastodont_storage_cleanup(&storage);
free(notif_html);
free(navigation_box);
free(page);
free(theme_str);
mstdnt_cleanup_notifications(notifs, notifs_len);
}
void content_notifications_clear(PATH_ARGS)

View File

@ -1,42 +1,33 @@
<div class="simple-page">
<form action="appearance" method="post" enctype="multipart/form-data">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>Appearance</h1>
<input class="btn btn-single" type="submit" value="Save">
<h3>Theme variant</h3>
<ul>
<li>
<label for="cfgthemevar">Theme variant</label>
<select name="theme" id="cfgthemevar">
<option value="treebird" title="Created by nekobit (@neko@rdrama.cc) | Former dark variant created by Grumbulon (@grumbulon@freecumextremist.com)">Treebird - Default, simple theme</option>
<option value="solarized" title="Created by coyote (@coyote@pl.lain.sh)">Solarized - Solarized colors for pleasant viewing</option>
</select>
</li>
</ul>
<h3>Color Scheme</h3>
<ul>
<li>
<input type="radio" id="cfglight" name="themeclr" value="0" checked>
<label for="cfglight">Light</label>
</li>
<li>
<input type="radio" id="cfgdark" name="themeclr" value="1">
<label for="cfgdark">Dark</label>
</li>
</ul>
<h3>Background</h3>
<ul>
<li>
<input type="file" name="file">
</li>
</ul>
<ul>
<li>
Sidebar opacity: <input type="range" name="sidebaropacity" min="0" max="255" value="255">
</li>
</ul>
<input class="btn btn-single" type="submit" value="Save">
</form>
<form action="appearance" method="post" enctype="multipart/form-data">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>Appearance</h1>
<input class="btn btn-single" type="submit" value="Save">
<h3>Theme variant</h3>
<ul>
<li>
<label for="cfgthemevar">Theme variant</label>
<select name="theme" id="cfgthemevar">
<option value="treebird" title="Created by nekobit (@neko@rdrama.cc)">Treebird - Default, simple theme</option>
<option value="treebird-dark" title="Created by nekobit (@neko@rdrama.cc) | Former dark variant created by Grumbulon (@grumbulon@freecumextremist.com)">Treebird Dark - Dark variant</option>
<option value="solarized" title="Created by coyote (@coyote@pl.lain.sh)">Solarized - Solarized colors for pleasant viewing</option>
<option value="solarized-dark" title="Created by coyote (@coyote@pl.lain.sh)">Solarized Dark - Solarized dark variant</option>
</select>
</li>
</ul>
<h3>Background</h3>
<ul>
<li>
<input type="file" name="file">
</li>
</ul>
<ul>
<li>
Sidebar opacity: <input type="range" name="sidebaropacity" min="0" max="255" value="255">
</li>
</ul>
<input class="btn btn-single" type="submit" value="Save">
</form>
</div>

View File

@ -1,94 +1,94 @@
<div class="simple-page">
<form action="general" method="post">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<form action="general" method="post">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>General</h1>
<input class="btn btn-single" type="submit" value="Save">
<h3>Locales</h3>
<ul>
<li>
<label for="cfglang">Language:</label>
<select name="lang" id="cfglang">
<option value="0">English</option>
<option value="1">Spanish</option>
<option value="2">Chinese (Traditional)</option>
</select>
</li>
</ul>
<h1>General</h1>
<input class="btn btn-single" type="submit" value="Save">
<h3>Locales</h3>
<ul>
<li>
<label for="cfglang">Language:</label>
<select name="lang" id="cfglang">
<option value="0">English</option>
<option value="1">Spanish</option>
<option value="2">Chinese (Traditional)</option>
</select>
</li>
</ul>
<h3>JavaScript</h3>
<ul>
<li>
<input type="checkbox" id="cfgjs" name="js" value="1" {{%s:js_on}}>
<label for="cfgjs">Enable JavaScript - If disabled, overrides options below</label>
</li>
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjsactions" name="jsactions" value="1" {{%s:jsactions_on}}> -->
<!-- <label for="cfgjsactions">Quick actions - Likes, Boosts, etc done in background</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjsreply" name="jsreply" value="1" {{%s:jsreply_on}}> -->
<!-- <label for="cfgjsreply">Quick reply - Replies don't require redirects</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjslive" name="jslive" value="1" {{%s:jslive_on}}> -->
<!-- <label for="cfgjslive">Live update - Statuses, chats, and reactions fetch on the fly</label> -->
<!-- </li> -->
</ul>
<h3>JavaScript</h3>
<ul>
<li>
<input type="checkbox" id="cfgjs" name="js" value="1"[% IF ssn.config.js %] checked[% END %]>
<label for="cfgjs">Enable JavaScript - If disabled, overrides options below</label>
</li>
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjsactions" name="jsactions" value="1" {{%s:jsactions_on}}> -->
<!-- <label for="cfgjsactions">Quick actions - Likes, Boosts, etc done in background</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjsreply" name="jsreply" value="1" {{%s:jsreply_on}}> -->
<!-- <label for="cfgjsreply">Quick reply - Replies don't require redirects</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgjslive" name="jslive" value="1" {{%s:jslive_on}}> -->
<!-- <label for="cfgjslive">Live update - Statuses, chats, and reactions fetch on the fly</label> -->
<!-- </li> -->
</ul>
<h3>Statuses</h3>
<ul>
<li>
<input type="checkbox" id="cfgstatattachments" name="statattachments" value="1" {{%s:status_attachments_on}}>
<label for="cfgstatattachments">Show attachments - If disabled, attachments are links instead</label>
</li>
<li>
<input type="checkbox" id="cfgstatgreentexts" name="statgreentexts" value="1" {{%s:status_greentexts_on}}>
<label for="cfgstatgreentexts">Show greentexts</label>
</li>
<li>
<input type="checkbox" id="cfgstatdope" name="statdope" value="1" {{%s:status_dopameme_on}}>
<label for="cfgstatdope">Show dopameme numbers - Likes, comments, and boost counts</label>
</li>
<li>
<input type="checkbox" id="cfgstatoneclicksoftware" name="statoneclicksoftware" value="1" {{%s:status_oneclicksoftware_on}}>
<label for="cfgstatoneclicksoftware">Show Like-Boost button - Show a button in the status which likes and boosts a post</label>
</li>
<li>
<input type="checkbox" id="interactimg" name="interact_img" value="1" {{%s:status_interact_img_on}}>
<label for="interactimg">Use IMG for interaction buttons - Compatibility</label>
</li>
<!-- <li> -->
<!-- <input type="checkbox" id="cfgstatemojolikes" name="statemojolikes" value="1" {{%s:status_emojo_likes_on}}> -->
<!-- <label for="cfgstatemojolikes">Convert Emoji reacts to likes - Also disables the emoji reaction button</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgstathidemuted" name="stathidemuted" value="1" {{%s:status_hide_muted_on}}> -->
<!-- <label for="cfgstathidemuted">Hide statuses from muted users and threads - If disabled, statuses will appear collapsed</label> -->
<!-- </li> -->
</ul>
<h3>Statuses</h3>
<ul>
<li>
<input type="checkbox" id="cfgstatattachments" name="statattachments" value="1" [% IF ssn.config.stat_attachments %] checked[% END %]>
<label for="cfgstatattachments">Show attachments - If disabled, attachments are links instead</label>
</li>
<li>
<input type="checkbox" id="cfgstatgreentexts" name="statgreentexts" value="1" [% IF ssn.config.stat_greentexts %] checked[% END %]>
<label for="cfgstatgreentexts">Show greentexts</label>
</li>
<li>
<input type="checkbox" id="cfgstatdope" name="statdope" value="1" [% IF ssn.config.stat_dope %] checked[% END %]>
<label for="cfgstatdope">Show dopameme numbers - Likes, comments, and boost counts</label>
</li>
<li>
<input type="checkbox" id="cfgstatoneclicksoftware" name="statoneclicksoftware" value="1" [% IF ssn.config.stat_oneclicksoftware %] checked[% END %]>
<label for="cfgstatoneclicksoftware">Show Like-Boost button - Show a button in the status which likes and boosts a post</label>
</li>
<li>
<input type="checkbox" id="interactimg" name="interact_img" value="1" [% IF ssn.config.interact_img %] checked[% END %]>
<label for="interactimg">Use IMG for interaction buttons - Compatibility</label>
</li>
<!-- <li> -->
<!-- <input type="checkbox" id="cfgstatemojolikes" name="statemojolikes" value="1" {{%s:status_emojo_likes_on}}> -->
<!-- <label for="cfgstatemojolikes">Convert Emoji reacts to likes - Also disables the emoji reaction button</label> -->
<!-- </li> -->
<!-- <li> -->
<!-- <input type="checkbox" id="cfgstathidemuted" name="stathidemuted" value="1" {{%s:status_hide_muted_on}}> -->
<!-- <label for="cfgstathidemuted">Hide statuses from muted users and threads - If disabled, statuses will appear collapsed</label> -->
<!-- </li> -->
</ul>
<h3>Instance</h3>
<ul>
<!-- <li> -->
<!-- <input type="checkbox" id="cfginstanceshowshoutbox" name="instanceshowshoutbox" value="1" {{%s:instance_show_shoutbox_on}}> -->
<!-- <label for="cfginstanceshowshoutbox">Show instance shoutbox (JS required)</label> -->
<!-- </li> -->
<li>
<input type="checkbox" id="cfginstancepanel" name="instancepanel" value="1" {{%s:instance_panel_on}}>
<label for="cfginstancepanel">Show instance panel - <em>Admins should <strong>not</strong> use the instance panel for major announcements</em></label>
</li>
</ul>
<h3>Instance</h3>
<ul>
<!-- <li> -->
<!-- <input type="checkbox" id="cfginstanceshowshoutbox" name="instanceshowshoutbox" value="1" {{%s:instance_show_shoutbox_on}}> -->
<!-- <label for="cfginstanceshowshoutbox">Show instance shoutbox (JS required)</label> -->
<!-- </li> -->
<li>
<input type="checkbox" id="cfginstancepanel" name="instancepanel" value="1" [% IF ssn.config.instance_panel %] checked[% END %]>
<label for="cfginstancepanel">Show instance panel - <em>Admins should <strong>not</strong> use the instance panel for major announcements</em></label>
</li>
</ul>
<h3>Notifications</h3>
<ul>
<li>
<input type="checkbox" id="cfgnotifembed" name="notifembed" value="1" {{%s:notifications_embed_on}}>
<label for="cfgnotifembed">Display notifications in iFrame - iFrames separate loading from the main page</label>
</li>
</ul>
<h3>Notifications</h3>
<ul>
<li>
<input type="checkbox" id="cfgnotifembed" name="notifembed" value="1" [% IF ssn.config.notif_embed %] checked[% END %]>
<label for="cfgnotifembed">Display notifications in iFrame - iFrames separate loading from the main page</label>
</li>
</ul>
<input class="btn btn-single" type="submit" value="Save">
</form>
<input class="btn btn-single" type="submit" value="Save">
</form>
</div>

29
templates/embed.tt Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Embed</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/treebird.css">
[% UNLESS ssn.config.theme == "treebird" %]
<link
rel="stylesheet"
type="text/css"
href="/[% ssn.config.theme %].css">
[% END %]
<style>
/* Overrides */
html, body
{
margin: 0;
padding: 0;
background-color: unset;
}
</style>
</head>
<body>
<div class="embed">
[% content %]
</div>
</body>
</html>

View File

@ -5,11 +5,11 @@
<title>$title</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/treebird.css">
[% IF !(ssn.config.theme == "treebird" && ssn.config.themeclr == 0) %]
[% UNLESS ssn.config.theme == "treebird" %]
<link
rel="stylesheet"
type="text/css"
href="/[% ssn.config.theme %][% IF ssn.config.themeclr %]-dark[% END %].css">
href="/[% ssn.config.theme %].css">
[% END %]
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ %s : title }} is a decentralized social media platform">

12
templates/notifs_embed.tt Normal file
View File

@ -0,0 +1,12 @@
<div class="notifications-compact">
[% IF notifs %]
[% FOREACH notif IN notifs %]
[% notification(notif, 1) %]
[% END %]
[% ELSE %]
<div class="fancy-error">
<span class="fancy-error-text">No notifications.</span>
</div>
[% END %]
</div>