forked from MirrorHub/mautrix-whatsapp
Don't try to set WA presence before PushName is known
This commit is contained in:
parent
f5ae637ffd
commit
8e25088d8b
2 changed files with 19 additions and 13 deletions
|
@ -240,9 +240,12 @@ func (puppet *Puppet) handlePresenceEvent(event *event.Event) {
|
|||
} else {
|
||||
puppet.customUser.log.Debugln("Marking online")
|
||||
}
|
||||
err := puppet.customUser.Client.SendPresence(presence)
|
||||
if err != nil {
|
||||
puppet.customUser.log.Warnln("Failed to set presence:", err)
|
||||
puppet.customUser.lastPresence = presence
|
||||
if puppet.customUser.Client.Store.PushName != "" {
|
||||
err := puppet.customUser.Client.SendPresence(presence)
|
||||
if err != nil {
|
||||
puppet.customUser.log.Warnln("Failed to set presence:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
user.go
23
user.go
|
@ -60,9 +60,9 @@ type User struct {
|
|||
mgmtCreateLock sync.Mutex
|
||||
connLock sync.Mutex
|
||||
|
||||
historySyncs chan *events.HistorySync
|
||||
|
||||
historySyncs chan *events.HistorySync
|
||||
prevBridgeStatus *BridgeState
|
||||
lastPresence types.Presence
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetUserByMXID(userID id.UserID) *User {
|
||||
|
@ -158,6 +158,7 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
|||
log: bridge.Log.Sub("User").Sub(string(dbUser.MXID)),
|
||||
|
||||
historySyncs: make(chan *events.HistorySync, 32),
|
||||
lastPresence: types.PresenceUnavailable,
|
||||
}
|
||||
user.RelayWhitelisted = user.bridge.Config.Bridge.Permissions.IsRelayWhitelisted(user.MXID)
|
||||
user.Whitelisted = user.bridge.Config.Bridge.Permissions.IsWhitelisted(user.MXID)
|
||||
|
@ -370,16 +371,18 @@ func (user *User) HandleEvent(event interface{}) {
|
|||
go user.sendBridgeState(BridgeState{StateEvent: StateConnected})
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, true)
|
||||
user.bridge.Metrics.TrackLoginState(user.JID, true)
|
||||
go func() {
|
||||
err := user.Client.SendPresence(types.PresenceUnavailable)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to send initial presence:", err)
|
||||
}
|
||||
}()
|
||||
if len(user.Client.Store.PushName) > 0 {
|
||||
go func() {
|
||||
err := user.Client.SendPresence(user.lastPresence)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to send initial presence:", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
go user.tryAutomaticDoublePuppeting()
|
||||
case *events.AppStateSyncComplete:
|
||||
if len(user.Client.Store.PushName) > 0 && v.Name == appstate.WAPatchCriticalBlock {
|
||||
err := user.Client.SendPresence(types.PresenceUnavailable)
|
||||
err := user.Client.SendPresence(user.lastPresence)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to send presence after app state sync:", err)
|
||||
}
|
||||
|
@ -389,7 +392,7 @@ func (user *User) HandleEvent(event interface{}) {
|
|||
case *events.PushNameSetting:
|
||||
// Send presence available when connecting and when the pushname is changed.
|
||||
// This makes sure that outgoing messages always have the right pushname.
|
||||
err := user.Client.SendPresence(types.PresenceUnavailable)
|
||||
err := user.Client.SendPresence(user.lastPresence)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to send presence after push name update:", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue