mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-17 19:03:46 +01:00
Add last typing update timestamp to check intended action of available presence properly
This commit is contained in:
parent
0b7d23e897
commit
5eacaafc93
2 changed files with 4 additions and 1 deletions
|
@ -133,6 +133,7 @@ type Puppet struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
typingIn types.MatrixRoomID
|
typingIn types.MatrixRoomID
|
||||||
|
typingAt int64
|
||||||
|
|
||||||
MXID types.MatrixUserID
|
MXID types.MatrixUserID
|
||||||
}
|
}
|
||||||
|
|
4
user.go
4
user.go
|
@ -267,15 +267,17 @@ func (user *User) HandlePresence(info whatsapp_ext.Presence) {
|
||||||
case whatsapp_ext.PresenceUnavailable:
|
case whatsapp_ext.PresenceUnavailable:
|
||||||
puppet.Intent().SetPresence("offline")
|
puppet.Intent().SetPresence("offline")
|
||||||
case whatsapp_ext.PresenceAvailable:
|
case whatsapp_ext.PresenceAvailable:
|
||||||
if len(puppet.typingIn) > 0 {
|
if len(puppet.typingIn) > 0 && puppet.typingAt + 15 > time.Now().Unix() {
|
||||||
puppet.Intent().UserTyping(puppet.typingIn, false, 0)
|
puppet.Intent().UserTyping(puppet.typingIn, false, 0)
|
||||||
puppet.typingIn = ""
|
puppet.typingIn = ""
|
||||||
|
puppet.typingAt = 0
|
||||||
} else {
|
} else {
|
||||||
puppet.Intent().SetPresence("online")
|
puppet.Intent().SetPresence("online")
|
||||||
}
|
}
|
||||||
case whatsapp_ext.PresenceComposing:
|
case whatsapp_ext.PresenceComposing:
|
||||||
portal := user.GetPortalByJID(info.JID)
|
portal := user.GetPortalByJID(info.JID)
|
||||||
puppet.typingIn = portal.MXID
|
puppet.typingIn = portal.MXID
|
||||||
|
puppet.typingAt = time.Now().Unix()
|
||||||
puppet.Intent().UserTyping(portal.MXID, true, 15 * 1000)
|
puppet.Intent().UserTyping(portal.MXID, true, 15 * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue