Implement "Delete for me" support for messages (#530)

This commit is contained in:
vurpo 2022-07-18 16:08:52 +03:00 committed by GitHub
parent 45ed657ab1
commit 180c8996a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -1664,6 +1664,28 @@ func (portal *Portal) HandleMessageRevoke(user *User, info *types.MessageInfo, k
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) {
return portal.sendMessage(portal.MainIntent(), event.EventMessage, content, nil, 0)
}

View file

@ -921,6 +921,11 @@ func (user *User) HandleEvent(event interface{}) {
if user.bridge.Config.Bridge.SyncManualMarkedUnread {
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:
user.log.Debugfln("Unknown type of event in HandleEvent: %T", v)
}