summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-10-13 16:58:00 +0200
committerYorhel <git@yorhel.nl>2020-10-13 16:58:00 +0200
commit7430acd68bf99585e461ef4fad4b40be45466d70 (patch)
tree81ace6e00ba0d5f636502f6126abb42304a42eca /lib
parenta25ef5a7313b95873d6db50f658331026b965bc7 (diff)
notifications: Add subscribing for (un)applications of traits
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm1
-rw-r--r--lib/VNWeb/HTML.pm28
-rw-r--r--lib/VNWeb/User/Notifications.pm6
3 files changed, 23 insertions, 12 deletions
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index a18542f8..7d070f94 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -35,6 +35,7 @@ sub htmlFooter { # %options => { pref_code => 1 }
noscript id => 'pref_code', title => $self->authGetCode('/xml/prefs.xml'), ''
if $o{pref_code} && $self->authInfo->{id};
script type => 'text/javascript', src => $self->{url_static}.'/f/vndb.js?'.$self->{version}, '';
+ VNWeb::HTML::_scripts_({});
end 'body';
end 'html';
}
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index d9098ffe..3cc13494 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -338,7 +338,7 @@ sub _footer_ {
sub _maintabs_subscribe_ {
my($o, $id) = @_;
- return if !auth || $id !~ /^[twvrpcsd]/;
+ return if !auth || $id !~ /^[twvrpcsdi]/;
my $noti =
$id =~ /^t/ ? tuwf->dbVali('SELECT SUM(x) FROM (
@@ -351,9 +351,10 @@ sub _maintabs_subscribe_ {
UNION SELECT 1+1 FROM reviews w, users u WHERE u.id =', \auth->uid, 'AND w.uid =', \auth->uid, 'AND w.id =', \$id, 'AND u.notify_comment
) x(x)')
- : auth->pref('notify_dbedit') && tuwf->dbVali('SELECT 1 FROM changes WHERE type = vndbid_type(', \$id, ')::dbentry_type AND itemid = vndbid_num(', \$id, ') AND requester =', \auth->uid);
+ : $id =~ /^[vrpcsd]/ && auth->pref('notify_dbedit') && tuwf->dbVali('
+ SELECT 1 FROM changes WHERE type = vndbid_type(', \$id, ')::dbentry_type AND itemid = vndbid_num(', \$id, ') AND requester =', \auth->uid);
- my $sub = tuwf->dbRowi('SELECT subnum, subreview FROM notification_subs WHERE uid =', \auth->uid, 'AND iid =', \$id);
+ my $sub = tuwf->dbRowi('SELECT subnum, subreview, subapply FROM notification_subs WHERE uid =', \auth->uid, 'AND iid =', \$id);
li_ id => 'subscribe', sub {
elm_ Subscribe => $VNWeb::User::Notifications::SUB, {
@@ -361,8 +362,9 @@ sub _maintabs_subscribe_ {
noti => $noti||0,
subnum => $sub->{subnum},
subreview => $sub->{subreview}||0,
+ subapply => $sub->{subapply}||0,
}, sub {
- a_ href => '#', class => ($noti && (!defined $sub->{subnum} || $sub->{subnum})) || $sub->{subnum} || $sub->{subreview} ? 'active' : 'inactive', '🔔';
+ a_ href => '#', class => ($noti && (!defined $sub->{subnum} || $sub->{subnum})) || $sub->{subnum} || $sub->{subreview} || $sub->{subapply} ? 'active' : 'inactive', '🔔';
};
};
}
@@ -459,6 +461,17 @@ sub _hidden_msg_ {
}
+sub _scripts_ {
+ my($o) = @_;
+ script_ type => 'application/json', id => 'pagevars', sub {
+ # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape().
+ lit_(JSON::XS->new->canonical->encode(tuwf->req->{pagevars}) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg);
+ } if keys tuwf->req->{pagevars}->%*;
+ script_ type => 'application/javascript', src => config->{url_static}.'/f/elm.js?'.config->{version}, '' if tuwf->req->{pagevars}{elm};
+ script_ type => 'application/javascript', src => config->{url_static}.'/f/plain.js?'.config->{version}, '' if $o->{js} || tuwf->req->{pagevars}{elm};
+}
+
+
# Options:
# title => $title
# index => 1/0, default 0
@@ -489,12 +502,7 @@ sub framework_ {
$cont->() unless $o{hiddenmsg} && _hidden_msg_ \%o;
div_ id => 'footer', \&_footer_;
};
- script_ type => 'application/json', id => 'pagevars', sub {
- # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape().
- lit_(JSON::XS->new->canonical->encode(tuwf->req->{pagevars}) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg);
- } if keys tuwf->req->{pagevars}->%*;
- script_ type => 'application/javascript', src => config->{url_static}.'/f/elm.js?'.config->{version}, '' if tuwf->req->{pagevars}{elm};
- script_ type => 'application/javascript', src => config->{url_static}.'/f/plain.js?'.config->{version}, '' if $o{js} || tuwf->req->{pagevars}{elm};
+ _scripts_ \%o;
}
}
}
diff --git a/lib/VNWeb/User/Notifications.pm b/lib/VNWeb/User/Notifications.pm
index 18ddb9f5..aa97b064 100644
--- a/lib/VNWeb/User/Notifications.pm
+++ b/lib/VNWeb/User/Notifications.pm
@@ -13,6 +13,7 @@ my %ntypes = (
subpost => 'Reply to a thread you subscribed to',
subedit => 'Entry you subscribed to has been edited',
subreview => 'New review for a VN you subscribed to',
+ subapply => 'Trait you subscribed to has been (un)applied',
);
@@ -214,9 +215,10 @@ TUWF::hook before => sub {
our $SUB = form_compile any => {
- id => { vndbid => [qw|t w v r p c s d|] },
+ id => { vndbid => [qw|t w v r p c s d i|] },
subnum => { required => 0, jsonbool => 1 },
subreview => { anybool => 1 },
+ subapply => { anybool => 1 },
noti => { uint => 1 }, # Whether the user already gets 'subnum' notifications for this entry (see HTML.pm for possible values)
};
@@ -228,7 +230,7 @@ elm_api Subscribe => undef, $SUB, sub {
$data->{subreview} = 0 if $data->{id} !~ /^v/;
my %where = (iid => delete $data->{id}, uid => auth->uid);
- if(!defined $data->{subnum} && !$data->{subreview}) {
+ if(!defined $data->{subnum} && !$data->{subreview} && !$data->{subapply}) {
tuwf->dbExeci('DELETE FROM notification_subs WHERE', \%where);
} else {
tuwf->dbExeci('INSERT INTO notification_subs', {%where, %$data}, 'ON CONFLICT (iid,uid) DO UPDATE SET', $data);