mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-29 11:59:06 +00:00
update
This commit is contained in:
@@ -5,6 +5,17 @@ module Simplex.Chat.Store.SQLite.Migrations.M20251016_chat_relays where
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
-- - chat_relays - user's list of chat relays to choose from (similar to protocol_servers)
|
||||
-- - users.is_user_chat_relay - indicates that the user can serve as a chat relay
|
||||
-- (TBC usage, e.g. agree to invitations to be relay)
|
||||
-- - group_relays - group owner's list of relays for a group
|
||||
-- - group_relays.relay_link - links for all relays of a group are included in GroupShortLinkData
|
||||
-- - group_relays.relay_status - group owner's status for each relay (GroupRelayStatus)
|
||||
-- - group_members.is_chat_relay - indicates that the member is a chat relay (to all group members)
|
||||
-- - group_members.group_relay_id - associates group_members record with a group_relays record for a group owner;
|
||||
-- receiving event to member connection, owner can match it to the relay
|
||||
-- - TBC also inverse link from group_relays to group_members? (group_relays.group_member_id)
|
||||
-- - groups.relay_own_status - indicates for a relay client that it is chat relay for the group (GroupRelayOwnStatus)
|
||||
m20251016_chat_relays :: Query
|
||||
m20251016_chat_relays =
|
||||
[sql|
|
||||
@@ -22,39 +33,41 @@ CREATE TABLE chat_relays(
|
||||
UNIQUE(user_id, address),
|
||||
UNIQUE(user_id, name)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_chat_relays_user_id ON chat_relays(user_id);
|
||||
|
||||
ALTER TABLE users ADD COLUMN is_user_chat_relay INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE group_members ADD COLUMN is_chat_relay INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- Relay's link for group
|
||||
ALTER TABLE groups ADD COLUMN relay_link BLOB;
|
||||
|
||||
-- Owner's list of relays for group
|
||||
-- TBC relay_status: invited/accepted/added/notified/confirmed
|
||||
-- relay_link: links for all relays are included in GroupShortLinkData
|
||||
CREATE TABLE group_relays(
|
||||
group_relay_id INTEGER PRIMARY KEY,
|
||||
group_id INTEGER NOT NULL REFERENCES groups ON DELETE CASCADE,
|
||||
relay_status TEXT NOT NULL,
|
||||
relay_link BLOB
|
||||
);
|
||||
CREATE INDEX idx_group_relays_group_id ON group_relays(group_id);
|
||||
|
||||
ALTER TABLE group_members ADD COLUMN is_chat_relay INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE group_members ADD COLUMN group_relay_id INTEGER REFERENCES group_relays ON DELETE SET NULL;
|
||||
CREATE INDEX idx_group_members_group_relay_id ON group_members(group_relay_id);
|
||||
|
||||
ALTER TABLE groups ADD COLUMN relay_own_status TEXT;
|
||||
|]
|
||||
|
||||
down_m20251016_chat_relays :: Query
|
||||
down_m20251016_chat_relays =
|
||||
[sql|
|
||||
DROP TABLE group_relays;
|
||||
|
||||
ALTER TABLE groups DROP COLUMN relay_link;
|
||||
|
||||
ALTER TABLE group_members DROP COLUMN is_chat_relay;
|
||||
DROP INDEX idx_chat_relays_user_id;
|
||||
DROP TABLE chat_relays;
|
||||
|
||||
ALTER TABLE users DROP COLUMN is_user_chat_relay;
|
||||
|
||||
DROP INDEX idx_chat_relays_user_id;
|
||||
DROP INDEX idx_group_relays_group_id;
|
||||
DROP TABLE group_relays;
|
||||
|
||||
DROP TABLE chat_relays;
|
||||
ALTER TABLE group_members DROP COLUMN is_chat_relay;
|
||||
|
||||
DROP INDEX idx_group_members_group_relay_id;
|
||||
ALTER TABLE group_members DROP COLUMN group_relay_id;
|
||||
|
||||
ALTER TABLE groups DROP COLUMN relay_own_status;
|
||||
|]
|
||||
|
||||
+10
-10
@@ -958,7 +958,7 @@ data GroupMember = GroupMember
|
||||
updatedAt :: UTCTime,
|
||||
supportChat :: Maybe GroupSupportChat,
|
||||
isChatRelay :: BoolDef,
|
||||
relayStatus :: Maybe RelayStatusInGroup
|
||||
relayStatus :: Maybe GroupRelayOwnStatus
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
@@ -967,17 +967,17 @@ data GroupMember = GroupMember
|
||||
-- TODO - GroupMember?
|
||||
-- TODO - separate list of relays in GroupInfo?
|
||||
-- TODO - only on request?
|
||||
data ChatRelayStatus
|
||||
= CRSNew
|
||||
| CRSInvited
|
||||
| CRSAccepted
|
||||
| CRSAdded
|
||||
| CRSNotified
|
||||
| CRSConfirmed
|
||||
data GroupRelayStatus
|
||||
= GRSNew
|
||||
| GRSInvited
|
||||
| GRSAccepted
|
||||
| GRSAdded
|
||||
| GRSNotified
|
||||
| GRSConfirmed
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- Own status tracked by relay in group
|
||||
data RelayStatusInGroup
|
||||
-- Own status tracked by relay in a group
|
||||
data GroupRelayOwnStatus
|
||||
= RSGInvited
|
||||
| RSGLinkCreated
|
||||
| RSGAccepted
|
||||
|
||||
Reference in New Issue
Block a user