summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-02-05 10:24:44 +0100
committerYorhel <git@yorhel.nl>2010-02-05 10:24:44 +0100
commitb541d72849cd859580e7e6d7232165c92aa3a40b (patch)
tree2a6d3c47b4679387d89488fcd23ec9833c963155
parent004d60b64d80506944fd069c89c589302b5ae313 (diff)
Notifications: Added 'announce' notification
This one is also configurable, but mainly because I want to avoid generating several thousands of notifications for a single action...
-rw-r--r--ChangeLog1
-rw-r--r--data/lang.txt12
-rw-r--r--lib/VNDB/DB/Users.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm19
-rw-r--r--util/sql/all.sql3
-rw-r--r--util/sql/func.sql20
-rw-r--r--util/sql/schema.sql3
-rw-r--r--util/updates/update_2.11.sql4
8 files changed, 54 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 026a90bd..91109e9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@ git - ?
- Notifying users of a deletion of an entry they contributed to
- Notifying users of a deletion they have in their (wish)list
- Notifying users of an edit of an entry they contributed to
+ - Notifying users of site announcements
- Removed the ?l10n= paremeter
- Remove sessions that haven't been used for more than a month
- Properly copy over search string on switching with the searchtabs
diff --git a/data/lang.txt b/data/lang.txt
index 3cc9c1da..b86e1c53 100644
--- a/data/lang.txt
+++ b/data/lang.txt
@@ -4702,6 +4702,12 @@ ru*:
cs*:
hu*:
+:_usern_type_announce
+en : Site announcement
+ru*:
+cs*:
+hu*:
+
:_usern_n_t_new
en : New thread [_1] by [_2]
ru*:
@@ -4750,6 +4756,12 @@ ru*:
cs*:
hu*:
+:_usern_set_announce
+en : Notify me about site announcements
+ru*:
+cs*:
+hu*:
+
:_usern_set_submit
en : Save
ru*:
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index 20278688..41f9f25a 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -54,7 +54,7 @@ sub dbUserGet {
qw|id username c_votes c_changes show_list c_tags|,
q|extract('epoch' from registered) as registered|,
$o{what} =~ /extended/ ? (
- qw|mail rank salt skin customcss show_nsfw ign_votes notify_dbedit|,
+ qw|mail rank salt skin customcss show_nsfw ign_votes notify_dbedit notify_announce|,
q|encode(passwd, 'hex') AS passwd|
) : (),
$o{what} =~ /notifycount/ ?
@@ -100,7 +100,7 @@ sub dbUserEdit {
my %h;
defined $o{$_} && ($h{$_.' = ?'} = $o{$_})
- for (qw| username mail rank show_nsfw show_list skin customcss salt ign_votes notify_dbedit |);
+ for (qw| username mail rank show_nsfw show_list skin customcss salt ign_votes notify_dbedit notify_announce |);
$h{'passwd = decode(?, \'hex\')'} = $o{passwd}
if defined $o{passwd};
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index e7822f6e..f68f9db9 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -537,11 +537,14 @@ sub notifies {
my $saved;
if($self->reqMethod() eq 'POST' && $self->reqParam('set')) {
my $frm = $self->formValidate(
- { name => 'notify_dbedit', required => 0 }
+ { name => 'notify_dbedit', required => 0 },
+ { name => 'notify_announce', required => 0 }
);
return 404 if $frm->{_err};
- $frm->{notify_dbedit} = $frm->{notify_dbedit} ? 1 : 0;
- $self->authInfo->{notify_dbedit} = $frm->{notify_dbedit};
+ for ('notify_dbedit', 'notify_announce') {
+ $frm->{$_} = $frm->{$_} ? 1 : 0;
+ $self->authInfo->{$_} = $frm->{$_};
+ }
$self->dbUserEdit($uid, %$frm);
$saved = 1;
@@ -628,10 +631,12 @@ sub notifies {
h1 mt '_usern_set_title';
div class => 'notice', mt '_usern_set_saved' if $saved;
p;
- input type => 'checkbox', name => 'notify_dbedit', id => 'notify_dbedit', value => 1,
- $self->authInfo->{notify_dbedit} ? (checked => 'checked') : ();
- label for => 'notify_dbedit', ' '.mt('_usern_set_dbedit');
- br;
+ for('dbedit', 'announce') {
+ input type => 'checkbox', name => "notify_$_", id => "notify_$_", value => 1,
+ $self->authInfo->{"notify_$_"} ? (checked => 'checked') : ();
+ label for => "notify_$_", ' '.mt("_usern_set_$_");
+ br;
+ }
input type => 'submit', name => 'set', value => mt '_usern_set_submit';
end;
end;
diff --git a/util/sql/all.sql b/util/sql/all.sql
index 5bd314f5..9a9eace0 100644
--- a/util/sql/all.sql
+++ b/util/sql/all.sql
@@ -11,7 +11,7 @@ CREATE TYPE dbentry_type AS ENUM ('v', 'r', 'p');
CREATE TYPE edit_rettype AS (iid integer, cid integer, rev integer);
CREATE TYPE language AS ENUM('cs', 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt', 'ru', 'sk', 'sv', 'tr', 'vi', 'zh');
CREATE TYPE medium AS ENUM ('cd', 'dvd', 'gdr', 'blr', 'flp', 'mrt', 'mem', 'umd', 'nod', 'in', 'otc');
-CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit');
+CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit', 'announce');
CREATE TYPE notification_ltype AS ENUM ('v', 'r', 'p', 't');
CREATE TYPE producer_relation AS ENUM ('old', 'new', 'sub', 'par', 'imp', 'ipa', 'spa', 'ori');
CREATE TYPE release_type AS ENUM ('complete', 'partial', 'trial');
@@ -72,6 +72,7 @@ CREATE TRIGGER notify_listdel AFTER UPDATE ON releases
CREATE TRIGGER notify_dbedit AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
CREATE TRIGGER notify_dbedit AFTER UPDATE ON producers FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
CREATE TRIGGER notify_dbedit AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_announce AFTER INSERT ON threads_posts FOR EACH ROW EXECUTE PROCEDURE notify_announce();
-- Sequences used for ID generation of items not in the DB
diff --git a/util/sql/func.sql b/util/sql/func.sql
index 8a27a32c..a58bce9e 100644
--- a/util/sql/func.sql
+++ b/util/sql/func.sql
@@ -718,3 +718,23 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
+
+-- called on INSERT INTO threads_posts
+CREATE OR REPLACE FUNCTION notify_announce() RETURNS trigger AS $$
+BEGIN
+ -- new thread?
+ IF NEW.num = 1 THEN
+ INSERT INTO notifications (ntype, ltype, uid, iid, subid, c_title, c_byuser)
+ SELECT 'announce', 't', u.id, t.id, 1, t.title, NEw.uid
+ FROM threads t
+ JOIN threads_boards tb ON tb.tid = t.id
+ -- get the users who want this announcement
+ JOIN users u ON u.notify_announce
+ WHERE t.id = NEW.tid
+ AND tb.type = 'an' -- announcement board
+ AND NOT t.hidden;
+ END IF;
+ RETURN NULL;
+END;
+$$ LANGUAGE plpgsql;
+
diff --git a/util/sql/schema.sql b/util/sql/schema.sql
index 91d7f9bf..a9da0cbb 100644
--- a/util/sql/schema.sql
+++ b/util/sql/schema.sql
@@ -276,7 +276,8 @@ CREATE TABLE users (
c_tags integer NOT NULL DEFAULT 0,
salt character(9) NOT NULL DEFAULT '',
ign_votes boolean NOT NULL DEFAULT FALSE,
- notify_dbedit boolean NOT NULL DEFAULT TRUE
+ notify_dbedit boolean NOT NULL DEFAULT TRUE,
+ notify_announce boolean NOT NULL DEFAULT FALSE
);
-- vn
diff --git a/util/updates/update_2.11.sql b/util/updates/update_2.11.sql
index 9184dec9..65571fa9 100644
--- a/util/updates/update_2.11.sql
+++ b/util/updates/update_2.11.sql
@@ -1,6 +1,6 @@
-CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit');
+CREATE TYPE notification_ntype AS ENUM ('pm', 'dbdel', 'listdel', 'dbedit', 'announce');
CREATE TYPE notification_ltype AS ENUM ('v', 'r', 'p', 't');
CREATE TABLE notifications (
@@ -28,6 +28,7 @@ INSERT INTO notifications (uid, date, ntype, ltype, iid, subid, c_title, c_byuse
ALTER TABLE threads_boards DROP COLUMN lastread;
ALTER TABLE users ADD COLUMN notify_dbedit boolean NOT NULL DEFAULT true;
+ALTER TABLE users ADD COLUMN notify_announce boolean NOT NULL DEFAULT false;
UPDATE users SET notify_dbedit = false WHERE id IN(0,1);
@@ -115,4 +116,5 @@ CREATE TRIGGER notify_listdel AFTER UPDATE ON releases
CREATE TRIGGER notify_dbedit AFTER UPDATE ON vn FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
CREATE TRIGGER notify_dbedit AFTER UPDATE ON producers FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
CREATE TRIGGER notify_dbedit AFTER UPDATE ON releases FOR EACH ROW EXECUTE PROCEDURE notify_dbedit();
+CREATE TRIGGER notify_announce AFTER INSERT ON threads_posts FOR EACH ROW EXECUTE PROCEDURE notify_announce();