mirror of https://gitlab.com/litecord/litecord.git
storage: add Storage.get_guild_settings
- gateway.websocket: use Storage.get_guild_settings - schema.sql: chande defaults on message_notifications to 0
This commit is contained in:
parent
3a9bc22c60
commit
a926ed47ae
|
|
@ -218,11 +218,11 @@ class GatewayWebsocket:
|
|||
'relationships': relationships,
|
||||
'presences': friend_presences,
|
||||
'read_state': await self.storage.get_read_state(user_id),
|
||||
'user_guild_settings': await self.storage.get_guild_settings(
|
||||
user_id),
|
||||
|
||||
'friend_suggestion_count': 0,
|
||||
|
||||
# TODO
|
||||
'user_guild_settings': [],
|
||||
|
||||
'connected_accounts': [],
|
||||
'experiments': [],
|
||||
|
|
|
|||
|
|
@ -908,3 +908,44 @@ class Storage:
|
|||
parties.remove(user_id)
|
||||
|
||||
return parties[0]
|
||||
|
||||
async def get_guild_settings(self, user_id: int):
|
||||
"""Get the specific User Guild Settings,
|
||||
for all guilds a user is on."""
|
||||
|
||||
res = {}
|
||||
|
||||
settings = await self.db.fetch("""
|
||||
SELECT guild_id, suppress_everyone, muted
|
||||
message_notifications, mobile_push
|
||||
FROM guild_settings
|
||||
WHERE user_id = $1
|
||||
""", user_id)
|
||||
|
||||
for row in settings:
|
||||
gid = row['guild_id']
|
||||
drow = dict(row)
|
||||
drow.pop('guild_id')
|
||||
|
||||
chan_ids = await self.get_channel_ids(gid)
|
||||
|
||||
chan_overrides = {}
|
||||
|
||||
for chan_id in chan_ids:
|
||||
chan_row = await self.db.fetchrow("""
|
||||
SELECT muted, message_notifications
|
||||
FROM guild_setting_channel_overrides
|
||||
WHERE
|
||||
guild_id = $1
|
||||
AND user_id = $2
|
||||
AND channel_id = $3
|
||||
""", gid, user_id, chan_id)
|
||||
|
||||
chan_overrides[str(chan_id)] = dict(chan_row)
|
||||
|
||||
res[str(gid)] = {**drow, **{
|
||||
'channel_overrides': chan_overrides
|
||||
}}
|
||||
|
||||
return res
|
||||
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ CREATE TABLE IF NOT EXISTS guild_settings (
|
|||
|
||||
suppress_everyone bool DEFAULT false,
|
||||
muted bool DEFAULT false,
|
||||
message_notifications int DEFAULT 3,
|
||||
message_notifications int DEFAULT 0,
|
||||
mobile_push bool DEFAULT true,
|
||||
|
||||
PRIMARY KEY (user_id, guild_id)
|
||||
|
|
@ -287,7 +287,7 @@ CREATE TABLE IF NOT EXISTS guild_settings_channel_overrides (
|
|||
channel_id bigint REFERENCES channels (id) ON DELETE CASCADE,
|
||||
|
||||
muted bool DEFAULT false,
|
||||
message_notifications bool DEFAULT 3, -- ??
|
||||
message_notifications bool DEFAULT 0,
|
||||
|
||||
PRIMARY KEY (user_id, guild_id, channel_id)
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue