Browse Source

Add last typing update timestamp to check intended action of available presence properly

Tulir Asokan 6 năm trước cách đây
mục cha
commit
5eacaafc93
2 tập tin đã thay đổi với 4 bổ sung1 xóa
  1. 1 0
      puppet.go
  2. 3 1
      user.go

+ 1 - 0
puppet.go

@@ -133,6 +133,7 @@ type Puppet struct {
 	log    log.Logger
 
 	typingIn types.MatrixRoomID
+	typingAt int64
 
 	MXID types.MatrixUserID
 }

+ 3 - 1
user.go

@@ -267,15 +267,17 @@ func (user *User) HandlePresence(info whatsapp_ext.Presence) {
 	case whatsapp_ext.PresenceUnavailable:
 		puppet.Intent().SetPresence("offline")
 	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.typingIn = ""
+			puppet.typingAt = 0
 		} else {
 			puppet.Intent().SetPresence("online")
 		}
 	case whatsapp_ext.PresenceComposing:
 		portal := user.GetPortalByJID(info.JID)
 		puppet.typingIn = portal.MXID
+		puppet.typingAt = time.Now().Unix()
 		puppet.Intent().UserTyping(portal.MXID, true, 15 * 1000)
 	}
 }