feat: Add channel notification event tracking.

Bumps schema version to 2.
Adds Profiles module version dep on schema init.
Add notice_events, notice_sub_events, and notice_resub_events tables.
Add corresponding event manager.
Add ChatNotificationWithPayload event payload extension.
Add ChannelNotification subscription.
This commit is contained in:
2026-07-22 12:21:16 +03:00
parent 7744aaab0e
commit dd6fc013ee
4 changed files with 304 additions and 109 deletions
+61 -3
View File
@@ -1,8 +1,11 @@
BEGIN;
INSERT INTO version_history (component, from_version, to_version, author) VALUES ('EVENT_TRACKER', 0, 1, 'Initial Creation');
-- Version dependency checks
DO $$
ASSERT current_module_version('PROFILES') = 1, 'Dependency version mismatch: PROFILES';
$$ LANGUAGE plpgsql;
-- TODO: Assert profiles data version
INSERT INTO version_history (component, from_version, to_version, author) VALUES ('EVENT_TRACKER', 0, 2, 'Initial Creation');
-- Twitch tracked event data {{{
@@ -23,6 +26,8 @@ CREATE TABLE events(
profileid INTEGER REFERENCES user_profiles (profileid),
user_id TEXT,
occurred_at TIMESTAMPTZ,
event_payload JSONB,
parent_event_id INTEGER REFERENCES events (event_id),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (event_id, event_type)
);
@@ -180,6 +185,37 @@ CREATE TABLE raid_in_events(
FOREIGN KEY (event_id, event_type) REFERENCES events (event_id, event_type)
);
CREATE TABLE notice_events(
event_id INTEGER PRIMARY KEY REFERENCES events (event_id),
event_type TEXT NOT NULL DEFAULT 'notice',
message_id TEXT NOT NULL,
system_message TEXT NOT NULL,
FOREIGN KEY (event_id, event_type) REFERENCES events (event_id, event_type)
);
CREATE TABLE notice_sub_events(
event_id INTEGER PRIMARY KEY REFERENCES events (event_id),
event_type TEXT NOT NULL DEFAULT 'notice_sub',
tier INTEGER NOT NULL,
is_prime BOOLEAN NOT NULL,
duration_months INTEGER NOT NULL,
FOREIGN KEY (event_id, event_type) REFERENCES events (event_id, event_type)
);
CREATE TABLE notice_resub_events(
event_id INTEGER PRIMARY KEY REFERENCES events (event_id),
event_type TEXT NOT NULL DEFAULT 'notice_resub',
tier INTEGER NOT NULL,
is_prime BOOLEAN,
is_gift BOOLEAN NOT NULL,
cumulative_months INTEGER NOT NULL,
duration_months INTEGER NOT NULL,
streak_months INTEGER,
gifter_is_anonymous BOOLEAN,
gifter_user_id TEXT,
FOREIGN KEY (event_id, event_type) REFERENCES events (event_id, event_type)
);
CREATE VIEW event_info AS
SELECT
@@ -189,6 +225,9 @@ SELECT
events.channel_id AS event_channel_id,
events.profileid AS user_profileid,
events.user_id AS user_id,
events.event_payload AS event_payload,
events.parent_event_id AS parent_event_id,
user_profiles.nickname AS user_nickname,
user_profiles.timezone AS user_timezone,
user_profiles.locale_hint AS user_localehint,
@@ -258,6 +297,22 @@ SELECT
raid_in_events.source_name AS raidin_sourcename,
raid_in_events.viewer_count AS raidin_viewers
notice_events.message_id AS notice_message_id,
notice_events.system_message AS notice_system_message,
notice_sub_events.tier AS notice_sub_tier,
notice_sub_events.is_prime AS notice_sub_is_prime,
notice_sub_events.duration_months AS notice_sub_duration_months,
notice_resub_events.tier AS notice_resub_tier,
notice_resub_events.is_prime AS notice_resub_is_prime,
notice_resub_events.is_gift AS notice_resub_is_gift,
notice_resub_events.cumulative_months AS notice_resub_cumulative_months,
notice_resub_events.duration_months AS notice_resub_duration_months,
notice_resub_events.streak_months AS notice_resub_streak_months,
notice_resub_events.gifter_is_anonymous AS notice_resub_gifter_is_anonymous,
notice_resub_events.gifter_user_id AS notice_resub_gifter_user_id,
FROM events
LEFT JOIN user_profiles USING (profileid)
LEFT JOIN follow_events USING (event_id, event_type)
@@ -276,7 +331,10 @@ LEFT JOIN vip_add_events USING (event_id, event_type)
LEFT JOIN vip_remove_events USING (event_id, event_type)
LEFT JOIN message_events USING (event_id, event_type)
LEFT JOIN raid_out_events USING (event_id, event_type)
LEFT JOIN raid_in_events USING (event_id, event_type);
LEFT JOIN raid_in_events USING (event_id, event_type)
LEFT JOIN notice_events USING (event_id, event_type)
LEFT JOIN notice_sub_events USING (event_id, event_type)
LEFT JOIN notice_resub_events USING (event_id, event_type);
-- }}}