diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-10-05 12:36:42 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-10-05 17:36:50 +0200 |
commit | b00a8b7a06980271cb68c983733038ace0647f0f (patch) | |
tree | 3c0ef823c723451170d342e9482465c1eff1075b /schema.sql | |
parent | ca92b1505f2fc92cd728757d7ae07cfb23cd6df2 (diff) | |
download | server-b00a8b7a06980271cb68c983733038ace0647f0f.tar.gz |
Track forum thread read/unread status for logged in users.
Diffstat (limited to 'schema.sql')
-rw-r--r-- | schema.sql | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -164,6 +164,12 @@ create table if not exists posts ( body text ); +create table if not exists read_threads ( + user_id integer, + thread_id integer, + primary key (user_id, thread_id) +) without rowid; + drop view if exists thread_view; create view thread_view as select @@ -383,6 +389,7 @@ begin delete from tokens where user_id = old.user_id; delete from user_last_seen where user_id = old.user_id; delete from last_notified where user_id = old.user_id; + delete from read_threads where user_id = old.user_id; delete from contacts where me = old.user_id or you = old.user_id; delete from messages where from_id = old.user_id or to_id = old.user_id; delete from posts where author_id = old.user_id; @@ -396,4 +403,17 @@ drop trigger if exists trigger_delete_on_threads; create trigger trigger_delete_on_threads after delete on threads begin delete from posts where thread_id = old.thread_id; -end + delete from read_threads where thread_id = old.thread_id; +end; + +drop trigger if exists trigger_mark_threads_as_unread1; +create trigger trigger_mark_threads_as_unread1 after insert on posts +begin + delete from read_threads where user_id != new.author_id and thread_id = new.thread_id; +end; + +drop trigger if exists trigger_mark_threads_as_unread2; +create trigger trigger_mark_threads_as_unread2 after update on posts +begin + delete from read_threads where user_id != new.author_id and thread_id = new.thread_id; +end; |