Always wait for offline sync to finish before sending connected state

This commit is contained in:
Tulir Asokan 2022-02-18 13:18:29 +02:00
parent b389354bcc
commit be68203056

View file

@ -545,7 +545,6 @@ func (user *User) HandleEvent(event interface{}) {
user.bridge.Metrics.TrackConnectionState(user.JID, false) user.bridge.Metrics.TrackConnectionState(user.JID, false)
user.bridge.Metrics.TrackLoginState(user.JID, false) user.bridge.Metrics.TrackLoginState(user.JID, false)
case *events.Connected: case *events.Connected:
go user.sendBridgeState(BridgeState{StateEvent: StateConnected})
user.bridge.Metrics.TrackConnectionState(user.JID, true) user.bridge.Metrics.TrackConnectionState(user.JID, true)
user.bridge.Metrics.TrackLoginState(user.JID, true) user.bridge.Metrics.TrackLoginState(user.JID, true)
if len(user.Client.Store.PushName) > 0 { if len(user.Client.Store.PushName) > 0 {
@ -567,8 +566,10 @@ func (user *User) HandleEvent(event interface{}) {
if !user.PhoneRecentlySeen(true) { if !user.PhoneRecentlySeen(true) {
user.log.Infofln("Offline sync completed, but phone last seen date is still %s - sending phone offline bridge status", user.PhoneLastSeen) user.log.Infofln("Offline sync completed, but phone last seen date is still %s - sending phone offline bridge status", user.PhoneLastSeen)
go user.sendBridgeState(BridgeState{StateEvent: StateTransientDisconnect, Error: WAPhoneOffline}) go user.sendBridgeState(BridgeState{StateEvent: StateTransientDisconnect, Error: WAPhoneOffline})
} else if user.GetPrevBridgeState().StateEvent == StateBackfilling { } else {
if user.GetPrevBridgeState().StateEvent == StateBackfilling {
user.log.Infoln("Offline sync completed") user.log.Infoln("Offline sync completed")
}
go user.sendBridgeState(BridgeState{StateEvent: StateConnected}) go user.sendBridgeState(BridgeState{StateEvent: StateConnected})
} }
case *events.AppStateSyncComplete: case *events.AppStateSyncComplete: