mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-12-04 16:13:04 -08:00
fix(gateway): keep the sync nonce off the guild handoff (#4395)
This commit is contained in:
1 parent
d81acc7b88
commit
2d0168f8d2
4 files changed
+30
-20
No files matched your search
@@ -235,6 +235,7 @@ fn add_session(
|
||||
let key = id.user_id_to_int(user)
|
||||
let state =
|
||||
visitors.remove_session(state, session.session_id_to_string(ref.id))
|
||||
|> guild_state.drop_sync_nonce(session.session_id_to_string(ref.id))
|
||||
let created =
|
||||
entry.new(
|
||||
ref:,
|
||||
@@ -363,6 +364,7 @@ fn remove(state: GuildState, found: Entry) -> GuildState {
|
||||
let sessions = table.track_connected(sessions, key, -1)
|
||||
let state =
|
||||
guild_state.set_sessions(state, sessions)
|
||||
|> guild_state.drop_sync_nonce(entry.key(found))
|
||||
|> guild_threads.session_left(entry.key(found))
|
||||
case
|
||||
member_list.unsubscribe(guild_state.member_list(state), entry.id(found))
|
||||
|
||||
@@ -25,7 +25,6 @@ pub opaque type Entry {
|
||||
staff: Option(Bool),
|
||||
mode: Mode,
|
||||
synced: Bool,
|
||||
sync_nonce: Int,
|
||||
typing: Option(Bool),
|
||||
seen_messages: Dict(Int, Int),
|
||||
seen_voice: Dict(VoiceKey, VoiceState),
|
||||
@@ -52,7 +51,6 @@ pub fn new(
|
||||
staff:,
|
||||
mode:,
|
||||
synced: False,
|
||||
sync_nonce: 0,
|
||||
typing: None,
|
||||
seen_messages: dict.new(),
|
||||
seen_voice: dict.new(),
|
||||
@@ -109,10 +107,6 @@ pub fn is_synced(entry: Entry) -> Bool {
|
||||
entry.synced
|
||||
}
|
||||
|
||||
pub fn sync_nonce(entry: Entry) -> Int {
|
||||
entry.sync_nonce
|
||||
}
|
||||
|
||||
pub fn typing(entry: Entry) -> Option(Bool) {
|
||||
entry.typing
|
||||
}
|
||||
@@ -141,7 +135,6 @@ pub fn routing(entry: Entry) -> Entry {
|
||||
Entry(
|
||||
..entry,
|
||||
synced: False,
|
||||
sync_nonce: 0,
|
||||
seen_messages: dict.new(),
|
||||
seen_voice: dict.new(),
|
||||
dm_eligible: [],
|
||||
@@ -165,10 +158,6 @@ pub fn set_synced(entry: Entry, synced: Bool) -> Entry {
|
||||
Entry(..entry, synced:)
|
||||
}
|
||||
|
||||
pub fn set_sync_nonce(entry: Entry, sync_nonce: Int) -> Entry {
|
||||
Entry(..entry, sync_nonce:)
|
||||
}
|
||||
|
||||
pub fn set_typing(entry: Entry, typing: Option(Bool)) -> Entry {
|
||||
Entry(..entry, typing:)
|
||||
}
|
||||
|
||||
@@ -143,15 +143,16 @@ pub fn renew_sync(
|
||||
session: SessionId,
|
||||
nonce: Int,
|
||||
) -> GuildState {
|
||||
update(state, session, fn(found) {
|
||||
case entry.sync_nonce(found) == nonce {
|
||||
True -> found
|
||||
False ->
|
||||
found
|
||||
|> entry.set_synced(False)
|
||||
|> entry.set_sync_nonce(nonce)
|
||||
}
|
||||
})
|
||||
let key = session_id_to_string(session)
|
||||
case
|
||||
table.get(guild_state.sessions(state), session),
|
||||
guild_state.sync_nonce(state, key) == nonce
|
||||
{
|
||||
Some(_), False ->
|
||||
update(state, session, entry.set_synced(_, False))
|
||||
|> guild_state.set_sync_nonce(key, nonce)
|
||||
_, _ -> state
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_guild_sync(state: GuildState, session: SessionId) -> GuildState {
|
||||
|
||||
@@ -55,6 +55,7 @@ pub opaque type GuildState {
|
||||
thread_inbox: Subject(ThreadMsg),
|
||||
push: push_dispatch.GuildPush,
|
||||
sessions: Sessions,
|
||||
sync_nonces: Dict(String, Int),
|
||||
version: Int,
|
||||
public_online: Option(Int),
|
||||
list_flush: Option(Timer),
|
||||
@@ -107,6 +108,7 @@ pub fn new(
|
||||
thread_inbox:,
|
||||
push:,
|
||||
sessions:,
|
||||
sync_nonces: dict.new(),
|
||||
version: 1,
|
||||
public_online: None,
|
||||
list_flush: None,
|
||||
@@ -243,6 +245,22 @@ pub fn set_sessions(state: GuildState, sessions: Sessions) -> GuildState {
|
||||
GuildState(..state, sessions:)
|
||||
}
|
||||
|
||||
pub fn sync_nonce(state: GuildState, key: String) -> Int {
|
||||
dict.get(state.sync_nonces, key) |> result.unwrap(0)
|
||||
}
|
||||
|
||||
pub fn set_sync_nonce(
|
||||
state: GuildState,
|
||||
key: String,
|
||||
nonce: Int,
|
||||
) -> GuildState {
|
||||
GuildState(..state, sync_nonces: dict.insert(state.sync_nonces, key, nonce))
|
||||
}
|
||||
|
||||
pub fn drop_sync_nonce(state: GuildState, key: String) -> GuildState {
|
||||
GuildState(..state, sync_nonces: dict.delete(state.sync_nonces, key))
|
||||
}
|
||||
|
||||
pub fn self_ref(state: GuildState) -> GuildRef {
|
||||
state.self_ref
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user