summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--migrations/4_add_user_default_target.sql12
-rw-r--r--schema.sql8
-rw-r--r--src/mulk/benki/lazychat.clj6
3 files changed, 23 insertions, 3 deletions
diff --git a/migrations/4_add_user_default_target.sql b/migrations/4_add_user_default_target.sql
new file mode 100644
index 0000000..89d0b25
--- /dev/null
+++ b/migrations/4_add_user_default_target.sql
@@ -0,0 +1,12 @@
+CREATE TABLE user_default_target(
+ "user" INTEGER NOT NULL,
+ target INTEGER NOT NULL,
+ PRIMARY KEY("user", target),
+ FOREIGN KEY("user") REFERENCES users,
+ FOREIGN KEY(target) REFERENCES roles
+);
+
+INSERT INTO user_default_target
+ SELECT users.id, roles.id
+ FROM users
+ INNER JOIN roles ON (roles."name" = 'Inner Circle');
diff --git a/schema.sql b/schema.sql
index 984fdea..ae843f8 100644
--- a/schema.sql
+++ b/schema.sql
@@ -165,6 +165,14 @@ CREATE TABLE lazychat_references(
FOREIGN KEY(referee) REFERENCES lazychat_messages
);
+CREATE TABLE user_default_target(
+ "user" INTEGER NOT NULL,
+ target INTEGER NOT NULL,
+ PRIMARY KEY("user", target),
+ FOREIGN KEY("user") REFERENCES users,
+ FOREIGN KEY(target) REFERENCES roles
+);
+
CREATE VIEW effective_role_subroles AS
WITH RECURSIVE t(superrole, subrole) AS (
SELECT id, id
diff --git a/src/mulk/benki/lazychat.clj b/src/mulk/benki/lazychat.clj
index 5986264..2b0db68 100644
--- a/src/mulk/benki/lazychat.clj
+++ b/src/mulk/benki/lazychat.clj
@@ -69,13 +69,13 @@
("public")
(sql/do-prepared
"INSERT INTO lazychat_targets
- SELECT ?, role FROM role_tags WHERE tag = 'world'"
+ SELECT ?, role FROM role_tags WHERE tag = 'world'"
[id])
("protected")
(sql/do-prepared
"INSERT INTO lazychat_targets
- SELECT ?, role FROM role_tags WHERE tag = 'inner_circle'"
- [id])
+ SELECT ?, target FROM user_default_target WHERE (\"user\" = ?)"
+ [id user])
("private")
(do))
(enqueue lafargue-events