Add WhatsApp->Matrix typing notifications and presence

This commit is contained in:
Tulir Asokan
2018-08-24 20:02:38 +03:00
parent 1f87deb317
commit a7f7295528
4 changed files with 33 additions and 3 deletions

19
user.go
View File

@ -261,6 +261,25 @@ func (user *User) HandleConnInfo(info whatsapp_ext.ConnInfo) {
}
}
func (user *User) HandlePresence(info whatsapp_ext.Presence) {
puppet := user.GetPuppetByJID(info.SenderJID)
switch info.Status {
case whatsapp_ext.PresenceUnavailable:
puppet.Intent().SetPresence("offline")
case whatsapp_ext.PresenceAvailable:
if len(puppet.typingIn) > 0 {
puppet.Intent().UserTyping(puppet.typingIn, false, 0)
puppet.typingIn = ""
} else {
puppet.Intent().SetPresence("online")
}
case whatsapp_ext.PresenceComposing:
portal := user.GetPortalByJID(info.JID)
puppet.typingIn = portal.MXID
puppet.Intent().UserTyping(portal.MXID, true, 15 * 1000)
}
}
func (user *User) HandleMsgInfo(info whatsapp_ext.MsgInfo) {
if (info.Command == whatsapp_ext.MsgInfoCommandAck || info.Command == whatsapp_ext.MsgInfoCommandAcks) && info.Acknowledgement == whatsapp_ext.AckMessageRead {
portal := user.GetPortalByJID(info.ToJID)