summaryrefslogtreecommitdiff
path: root/schema.sql
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-04-04 12:00:54 +0200
committerTor Andersson <tor@ccxvii.net>2025-04-04 12:05:13 +0200
commitdd7cafe49acc87fd6a1f7b675b2dbb40dd1e2514 (patch)
treec301848c6fb46a30679b0786cac011f11a51f33d /schema.sql
parent6138d98f4dd9b58febedb64f1a565b50c234f37f (diff)
downloadserver-dd7cafe49acc87fd6a1f7b675b2dbb40dd1e2514.tar.gz
Track "unseen" finished games.
Count unseen and unread chats in "waiting" games badge. Don't count resignation and timeouts as a move.
Diffstat (limited to 'schema.sql')
-rw-r--r--schema.sql16
1 files changed, 15 insertions, 1 deletions
diff --git a/schema.sql b/schema.sql
index 2840934..65edadf 100644
--- a/schema.sql
+++ b/schema.sql
@@ -254,7 +254,12 @@ create view user_dynamic_view as
owner_id = users.user_id
and status = 0
and join_count = 0
- ) as waiting,
+ ) + (
+ select count(1) from unseen_games where user_id = users.user_id
+ ) + (
+ select count(1) from unread_chats where user_id = users.user_id
+ )
+ as waiting,
is_banned
from
users
@@ -506,6 +511,12 @@ create table if not exists unread_chats (
primary key (user_id, game_id)
) without rowid;
+create table if not exists unseen_games (
+ user_id integer,
+ game_id integer,
+ primary key (user_id, game_id)
+) without rowid;
+
drop view if exists game_chat_view;
create view game_chat_view as
select
@@ -1055,6 +1066,7 @@ begin
delete from game_snap where game_id = old.game_id;
delete from game_notes where game_id = old.game_id;
delete from unread_chats where game_id = old.game_id;
+ delete from unseen_games where game_id = old.game_id;
end;
-- Triggers to clean up without relying on foreign key cascades
@@ -1068,6 +1080,7 @@ begin
delete from game_snap where game_id = old.game_id;
delete from game_notes where game_id = old.game_id;
delete from unread_chats where game_id = old.game_id;
+ delete from unseen_games where game_id = old.game_id;
delete from players where game_id = old.game_id;
end;
@@ -1085,6 +1098,7 @@ begin
delete from tokens where user_id = old.user_id;
delete from read_threads where user_id = old.user_id;
delete from unread_chats where user_id = old.user_id;
+ delete from unseen_games 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;