forked from MirrorHub/mautrix-whatsapp
Implement "Delete for me" support for messages (#530)
This commit is contained in:
parent
45ed657ab1
commit
180c8996a8
2 changed files with 27 additions and 0 deletions
22
portal.go
22
portal.go
|
@ -1664,6 +1664,28 @@ func (portal *Portal) HandleMessageRevoke(user *User, info *types.MessageInfo, k
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) deleteForMe(user *User, content *events.DeleteForMe) bool {
|
||||||
|
matrixUsers, err := portal.GetMatrixUsers()
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to get Matrix users in portal to see if DeleteForMe should be handled:", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(matrixUsers) == 1 && matrixUsers[0] == user.MXID {
|
||||||
|
msg := portal.bridge.DB.Message.GetByJID(portal.Key, content.MessageID)
|
||||||
|
if msg == nil || msg.IsFakeMXID() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err := portal.MainIntent().RedactEvent(portal.MXID, msg.MXID)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to redact %s: %v", msg.JID, err)
|
||||||
|
} else {
|
||||||
|
msg.Delete()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendMainIntentMessage(content *event.MessageEventContent) (*mautrix.RespSendEvent, error) {
|
func (portal *Portal) sendMainIntentMessage(content *event.MessageEventContent) (*mautrix.RespSendEvent, error) {
|
||||||
return portal.sendMessage(portal.MainIntent(), event.EventMessage, content, nil, 0)
|
return portal.sendMessage(portal.MainIntent(), event.EventMessage, content, nil, 0)
|
||||||
}
|
}
|
||||||
|
|
5
user.go
5
user.go
|
@ -921,6 +921,11 @@ func (user *User) HandleEvent(event interface{}) {
|
||||||
if user.bridge.Config.Bridge.SyncManualMarkedUnread {
|
if user.bridge.Config.Bridge.SyncManualMarkedUnread {
|
||||||
user.markUnread(user.GetPortalByJID(v.JID), !v.Action.GetRead())
|
user.markUnread(user.GetPortalByJID(v.JID), !v.Action.GetRead())
|
||||||
}
|
}
|
||||||
|
case *events.DeleteForMe:
|
||||||
|
portal := user.GetPortalByJID(v.ChatJID)
|
||||||
|
if portal != nil {
|
||||||
|
portal.deleteForMe(user, v)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
user.log.Debugfln("Unknown type of event in HandleEvent: %T", v)
|
user.log.Debugfln("Unknown type of event in HandleEvent: %T", v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue