-- Phase 10: notifications counted per thread. -- -- thread_id is the thread an event that notified a user belongs to: the -- root its m.relates_to names when rel_type is m.thread, and '' for an -- event on the main timeline. A read receipt for a thread clears that -- thread's rows and a receipt for the main timeline clears the '' rows, -- which is what lets reading one thread leave the rest of the room unread. ALTER TABLE push_notifications ADD COLUMN thread_id TEXT NOT NULL DEFAULT ''; -- The notifications already stored, from the relation 0012 projected onto -- their events. A notification whose event has gone stays on the main -- timeline, where an unthreaded or main receipt still clears it. UPDATE push_notifications SET thread_id = COALESCE(( SELECT e.relates_to_id FROM roomserver_events e WHERE e.event_id = push_notifications.event_id AND e.rel_type = 'm.thread' ), ''); -- A threaded receipt marks one thread's rows read; the per-thread counts a -- sync asks for group a room's unread rows by thread. CREATE INDEX IF NOT EXISTS push_notifications_thread_idx ON push_notifications (user_id, room_id, thread_id, is_read, event_pos);