More perl stuff
FossilOrigin-Name: 7a4d25bfdd0b7eb8e20e91c6f01d719c8e9fb43e0d35c0d46027876b6fab8659
This commit is contained in:
parent
e038ff9b82
commit
2e21b6fea3
11 changed files with 121 additions and 50 deletions
|
@ -11,4 +11,4 @@ config.h
|
|||
treebird
|
||||
test/tests
|
||||
scripts/*.o
|
||||
perl/*.ctt
|
||||
templates/*.ctt
|
|
@ -14,7 +14,7 @@ my $template = Template->new(
|
|||
|
||||
sub base_page
|
||||
{
|
||||
my ($ssn, $data, $main, $acct) = @_;
|
||||
my ($ssn, $data, $main) = @_;
|
||||
my $result;
|
||||
|
||||
my %vars = (
|
||||
|
@ -24,7 +24,7 @@ sub base_page
|
|||
lang => sub { $L10N{'EN_US'}->{shift(@_)} },
|
||||
main => $main,
|
||||
sidebar_opacity => $ssn->{config}->{sidebar_opacity} / 255,
|
||||
acct => $acct
|
||||
acct => $ssn->{account}
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -878,9 +878,8 @@ void content_account_favourites(PATH_ARGS)
|
|||
|
||||
HV* perlify_account(const struct mstdnt_account* acct)
|
||||
{
|
||||
HV* acct_hv = newHV();
|
||||
|
||||
if (!acct) return NULL;
|
||||
HV* acct_hv = newHV();
|
||||
|
||||
hvstores_str(acct_hv, "id", acct->id);
|
||||
hvstores_str(acct_hv, "username", acct->username);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
#include "l10n.h"
|
||||
|
||||
#define ACCOUNT_NOP 0
|
||||
|
|
|
@ -44,53 +44,51 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
||||
HV* session_hv = perlify_session(ssn);
|
||||
HV* acct_hv = perlify_account(&(ssn->acct));
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)session_hv)));
|
||||
XPUSHs(sv_2mortal(newSVpv(data_main_tt, 0)));
|
||||
XPUSHs(sv_2mortal(newSVpv(page->content, 0)));
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)acct_hv)));
|
||||
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
/* // If user is logged in */
|
||||
/* if (keystr(ssn->cookies.logged_in) && keystr(ssn->cookies.access_token)) */
|
||||
/* { */
|
||||
/* account_sidebar_str = construct_account_sidebar(&(ssn->acct), NULL); */
|
||||
|
||||
/* // Get / Show notifications on sidebar */
|
||||
/* if (ssn->config.notif_embed) */
|
||||
/* { */
|
||||
/* main_sidebar_str = (char*)sidebar_embed; */
|
||||
/* } */
|
||||
/* else { */
|
||||
/* struct mstdnt_get_notifications_args args = { */
|
||||
/* .exclude_types = 0, */
|
||||
/* .account_id = NULL, */
|
||||
/* .exclude_visibilities = 0, */
|
||||
/* .include_types = 0, */
|
||||
/* .with_muted = 1, */
|
||||
/* .max_id = NULL, */
|
||||
/* .min_id = NULL, */
|
||||
/* .since_id = NULL, */
|
||||
/* .offset = 0, */
|
||||
/* .limit = 8, */
|
||||
/* }; */
|
||||
if (keystr(ssn->cookies.logged_in) && keystr(ssn->cookies.access_token))
|
||||
{
|
||||
// Get / Show notifications on sidebar
|
||||
if (!ssn->config.notif_embed)
|
||||
{
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_notification* notifs = NULL;
|
||||
size_t notifs_len = 0;
|
||||
struct mstdnt_get_notifications_args args = {
|
||||
.exclude_types = 0,
|
||||
.account_id = NULL,
|
||||
.exclude_visibilities = 0,
|
||||
.include_types = 0,
|
||||
.with_muted = 1,
|
||||
.max_id = NULL,
|
||||
.min_id = NULL,
|
||||
.since_id = NULL,
|
||||
.offset = 0,
|
||||
.limit = 8,
|
||||
};
|
||||
|
||||
/* if (mastodont_get_notifications(api, */
|
||||
/* &m_args, */
|
||||
/* &args, */
|
||||
/* &storage, */
|
||||
/* ¬ifs, */
|
||||
/* ¬ifs_len) == 0) */
|
||||
/* { */
|
||||
/* main_sidebar_str = construct_notifications_compact(ssn, api, notifs, notifs_len, NULL); */
|
||||
/* } */
|
||||
if (mastodont_get_notifications(api,
|
||||
&m_args,
|
||||
&args,
|
||||
&storage,
|
||||
¬ifs,
|
||||
¬ifs_len) == 0)
|
||||
{
|
||||
AV* notifs_av = perlify_notifications(notifs, notifs_len);
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)notifs_av)));
|
||||
}
|
||||
|
||||
/* mstdnt_cleanup_notifications(notifs, notifs_len); */
|
||||
/* mastodont_storage_cleanup(&storage); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
mstdnt_cleanup_notifications(notifs, notifs_len);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
}
|
||||
|
||||
// Run function
|
||||
PUTBACK;
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
#include <perl.h>
|
||||
|
||||
// hv_stores(ssn_hv, "id", newSVpv(acct->id, 0));
|
||||
#define hvstores_str(hv, key, val) hv_stores((hv), key, newSVpv((val), 0))
|
||||
#define hvstores_str(hv, key, val) hv_stores((hv), key, ((val) ? newSVpv((val), 0) : &PL_sv_undef))
|
||||
#define hvstores_int(hv, key, val) hv_stores((hv), key, newSViv((val)))
|
||||
#define hvstores_ref(hv, key, val) hv_stores((hv), key, \
|
||||
((val) ? newRV_inc((SV* const)(val)) : &PL_sv_undef))
|
||||
|
||||
static PerlInterpreter* perl;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "status.h"
|
||||
#include "error.h"
|
||||
#include "emoji.h"
|
||||
#include "account.h"
|
||||
#include "../config.h"
|
||||
|
||||
// Pages
|
||||
|
@ -336,6 +337,35 @@ void content_notifications_compact(PATH_ARGS)
|
|||
free(theme_str);
|
||||
}
|
||||
|
||||
// Converts it into a perl struct
|
||||
HV* perlify_notification(struct mstdnt_notification* notif)
|
||||
{
|
||||
if (!notif) return NULL;
|
||||
HV* notif_hv = newHV();
|
||||
|
||||
hvstores_str(notif_hv, "id", notif->id);
|
||||
hvstores_str(notif_hv, "created_at", notif->created_at);
|
||||
hvstores_ref(notif_hv, "account", perlify_account(notif->account));
|
||||
hvstores_ref(notif_hv, "status", perlify_status(notif->status));
|
||||
|
||||
return notif_hv;
|
||||
}
|
||||
|
||||
// The same as above, but for multiple
|
||||
AV* perlify_notifications(struct mstdnt_notification* notifs, size_t len)
|
||||
{
|
||||
if (!(notifs && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_notification(notifs + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
void api_notifications(PATH_ARGS)
|
||||
{
|
||||
send_result(req, NULL, "application/json", "{\"status\":0}", 0);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "session.h"
|
||||
#include "path.h"
|
||||
#include "type_string.h"
|
||||
#include "global_perl.h"
|
||||
|
||||
char* construct_notification(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
|
@ -51,4 +52,7 @@ void content_notifications_compact(PATH_ARGS);
|
|||
|
||||
void api_notifications(PATH_ARGS);
|
||||
|
||||
HV* perlify_notification(struct mstdnt_notification* notif);
|
||||
AV* perlify_notifications(struct mstdnt_notification* notif, size_t len);
|
||||
|
||||
#endif // NOTIFICATION_H
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "account.h"
|
||||
#include "session.h"
|
||||
#include "../config.h"
|
||||
|
||||
|
@ -37,12 +38,14 @@ HV* perlify_session(struct session* ssn)
|
|||
HV* ssn_post_values = perlify_post_values(&(ssn->post));
|
||||
HV* ssn_get_values = perlify_get_values(&(ssn->query));
|
||||
HV* ssn_cookie_values = perlify_cookies(&(ssn->cookies));
|
||||
HV* acct_hv = perlify_account(&(ssn->acct));
|
||||
// Config
|
||||
HV* ssn_config = perlify_config(&(ssn->config));
|
||||
hv_stores(ssn_hv, "config", newRV_inc((SV*)ssn_config));
|
||||
hv_stores(ssn_hv, "cookies", newRV_inc((SV*)ssn_cookie_values));
|
||||
hv_stores(ssn_hv, "query", newRV_inc((SV*)ssn_get_values));
|
||||
hv_stores(ssn_hv, "post", newRV_inc((SV*)ssn_post_values));
|
||||
hvstores_ref(ssn_hv, "config", ssn_config);
|
||||
hvstores_ref(ssn_hv, "cookies", ssn_cookie_values);
|
||||
hvstores_ref(ssn_hv, "query", ssn_get_values);
|
||||
hvstores_ref(ssn_hv, "post", ssn_post_values);
|
||||
hvstores_ref(ssn_hv, "account", acct_hv);
|
||||
|
||||
return ssn_hv;
|
||||
}
|
||||
|
|
30
src/status.c
30
src/status.c
|
@ -1149,3 +1149,33 @@ void notice_redirect(PATH_ARGS)
|
|||
redirect(req, REDIRECT_303, url);
|
||||
free(url);
|
||||
}
|
||||
|
||||
HV* perlify_status(const struct mstdnt_status* status)
|
||||
{
|
||||
if (!status) return NULL;
|
||||
|
||||
HV* status_hv = newHV();
|
||||
hvstores_str(status_hv, "id", status->id);
|
||||
hvstores_str(status_hv, "uri", status->uri);
|
||||
hvstores_str(status_hv, "created_at", status->id);
|
||||
hvstores_ref(status_hv, "account", perlify_account(&(status->account)));
|
||||
hvstores_str(status_hv, "content", status->content);
|
||||
hvstores_str(status_hv, "spoiler_text", status->spoiler_text);
|
||||
hvstores_str(status_hv, "url", status->url);
|
||||
hvstores_str(status_hv, "in_reply_to_id", status->in_reply_to_id);
|
||||
hvstores_str(status_hv, "in_reply_to_account_id", status->in_reply_to_account_id);
|
||||
hvstores_str(status_hv, "language", status->language);
|
||||
hvstores_str(status_hv, "text", status->text);
|
||||
|
||||
hvstores_int(status_hv, "favourited", status->favourited);
|
||||
hvstores_int(status_hv, "reblogged", status->reblogged);
|
||||
hvstores_int(status_hv, "muted", status->muted);
|
||||
hvstores_int(status_hv, "bookmarked", status->bookmarked);
|
||||
hvstores_int(status_hv, "pinned", status->pinned);
|
||||
hvstores_int(status_hv, "reblogs_count", status->reblogs_count);
|
||||
hvstores_int(status_hv, "favourites_count", status->favourites_count);
|
||||
hvstores_int(status_hv, "replies_count", status->replies_count);
|
||||
hvstores_ref(status_hv, "status", perlify_status(status->reblog));
|
||||
|
||||
return status_hv;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "l10n.h"
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
#include "global_perl.h"
|
||||
|
||||
// Flags
|
||||
#define STATUS_NOOP 0
|
||||
|
@ -134,4 +135,7 @@ void notice_redirect(PATH_ARGS);
|
|||
// API
|
||||
void api_status_interact(PATH_ARGS);
|
||||
|
||||
// Perl
|
||||
HV* perlify_status(const struct mstdnt_status* status);
|
||||
|
||||
#endif // STATUS_H
|
||||
|
|
Loading…
Reference in a new issue