Support both WhatsApp read receipt event types
This commit is contained in:
parent
25a99c4464
commit
dd8b5097cb
2
go.mod
2
go.mod
@ -19,4 +19,4 @@ require (
|
||||
maunium.net/go/mautrix v0.6.1
|
||||
)
|
||||
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.5
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.6
|
||||
|
2
go.sum
2
go.sum
@ -119,6 +119,8 @@ github.com/tulir/go-whatsapp v0.3.4 h1:MnfKMj8QOZpZ0SBRXOzhTmoMRF+KqsSDLI+R/glw3
|
||||
github.com/tulir/go-whatsapp v0.3.4/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
|
||||
github.com/tulir/go-whatsapp v0.3.5 h1:cFw8MWhoLTqR0h2kSkSvz866rggRIAx4X2l8I65gARk=
|
||||
github.com/tulir/go-whatsapp v0.3.5/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
|
||||
github.com/tulir/go-whatsapp v0.3.6 h1:RtyNh8TFX48ClMvi2J8oS3qmH7b1t9SIKA5jucG2lbk=
|
||||
github.com/tulir/go-whatsapp v0.3.6/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||
|
38
user.go
38
user.go
@ -871,9 +871,22 @@ func (user *User) HandleMsgInfo(info whatsappExt.MsgInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) HandleReceivedMessage(received whatsapp.ReceivedMessage) {
|
||||
if received.Type == "read" {
|
||||
user.markSelfRead(received.Jid, received.Index)
|
||||
} else {
|
||||
user.log.Debugfln("Unknown received message type: %+v", received)
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) HandleReadMessage(read whatsapp.ReadMessage) {
|
||||
if strings.HasSuffix(read.Jid, whatsappExt.OldUserSuffix) {
|
||||
read.Jid = strings.Replace(read.Jid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, -1)
|
||||
user.log.Debugfln("Received chat read message: %+v", read)
|
||||
user.markSelfRead(read.Jid, "")
|
||||
}
|
||||
|
||||
func (user *User) markSelfRead(jid, messageID string) {
|
||||
if strings.HasSuffix(jid, whatsappExt.OldUserSuffix) {
|
||||
jid = strings.Replace(jid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, -1)
|
||||
}
|
||||
puppet := user.bridge.GetPuppetByJID(user.JID)
|
||||
if puppet == nil {
|
||||
@ -883,18 +896,27 @@ func (user *User) HandleReadMessage(read whatsapp.ReadMessage) {
|
||||
if intent == nil {
|
||||
return
|
||||
}
|
||||
portal := user.GetPortalByJID(read.Jid)
|
||||
portal := user.GetPortalByJID(jid)
|
||||
if portal == nil {
|
||||
return
|
||||
}
|
||||
message := user.bridge.DB.Message.GetLastInChat(portal.Key)
|
||||
if message == nil {
|
||||
return
|
||||
var message *database.Message
|
||||
if messageID == "" {
|
||||
message = user.bridge.DB.Message.GetLastInChat(portal.Key)
|
||||
if message == nil {
|
||||
return
|
||||
}
|
||||
user.log.Debugfln("User read chat %s/%s in WhatsApp mobile (last known event: %s/%s)", portal.Key.JID, portal.MXID, message.JID, message.MXID)
|
||||
} else {
|
||||
message = user.bridge.DB.Message.GetByJID(portal.Key, messageID)
|
||||
if message == nil {
|
||||
return
|
||||
}
|
||||
user.log.Debugfln("User read message %s/%s in %s/%s in WhatsApp mobile", message.JID, message.MXID, portal.Key.JID, portal.MXID)
|
||||
}
|
||||
user.log.Debugfln("User read %s/%s in %s/%s in WhatsApp mobile", message.JID, message.MXID, portal.Key.JID, portal.MXID)
|
||||
err := intent.MarkRead(portal.MXID, message.MXID)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to bridge own read receipt in %s: %v", read.Jid, err)
|
||||
user.log.Warnfln("Failed to bridge own read receipt in %s: %v", jid, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user