Re-add support for deleting attachments
This commit is contained in:
@@ -169,12 +169,10 @@ func (m *Message) Insert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Delete() {
|
func (m *Message) Delete() {
|
||||||
query := "DELETE FROM message WHERE dcid=$1 AND dc_chan_id=$2 AND dc_chan_receiver=$3"
|
query := "DELETE FROM message WHERE dcid=$1 AND dc_chan_id=$2 AND dc_chan_receiver=$3 AND dc_attachment_id=$4"
|
||||||
|
_, err := m.db.Exec(query, m.DiscordID, m.Channel.ChannelID, m.Channel.Receiver, m.AttachmentID)
|
||||||
_, err := m.db.Exec(query, m.DiscordID, m.Channel.ChannelID, m.Channel.Receiver)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Warnfln("Failed to delete %s@%s: %v", m.DiscordID, m.Channel, err)
|
m.log.Warnfln("Failed to delete %q of %s@%s: %v", m.AttachmentID, m.DiscordID, m.Channel, err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
portal.go
22
portal.go
@@ -690,8 +690,27 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
|
|
||||||
intent := portal.bridge.GetPuppetByID(msg.Author.ID).IntentFor(portal)
|
intent := portal.bridge.GetPuppetByID(msg.Author.ID).IntentFor(portal)
|
||||||
|
|
||||||
|
attachmentMap := map[string]*database.Message{}
|
||||||
|
for _, existingPart := range existing {
|
||||||
|
if existingPart.AttachmentID != "" {
|
||||||
|
attachmentMap[existingPart.AttachmentID] = existingPart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, attachment := range msg.Attachments {
|
||||||
|
if _, found := attachmentMap[attachment.ID]; found {
|
||||||
|
delete(attachmentMap, attachment.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, attachment := range attachmentMap {
|
||||||
|
_, err := intent.RedactEvent(portal.MXID, attachment.MXID)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Warnfln("Failed to remove attachment %s: %v", attachment.MXID, err)
|
||||||
|
}
|
||||||
|
attachment.Delete()
|
||||||
|
}
|
||||||
|
|
||||||
if msg.Content == "" || existing[0].AttachmentID != "" {
|
if msg.Content == "" || existing[0].AttachmentID != "" {
|
||||||
portal.log.Debugfln("Dropping non-text edit to %s", msg.ID)
|
portal.log.Debugfln("Dropping non-text edit to %s (message on matrix: %t, text on discord: %t)", msg.ID, existing[0].AttachmentID == "", len(msg.Content) > 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content := renderDiscordMarkdown(msg.Content)
|
content := renderDiscordMarkdown(msg.Content)
|
||||||
@@ -1297,6 +1316,7 @@ func (portal *Portal) handleMatrixRedaction(sender *User, evt *event.Event) {
|
|||||||
portal.log.Debugfln("Failed to delete discord message %s: %v", message.DiscordID, err)
|
portal.log.Debugfln("Failed to delete discord message %s: %v", message.DiscordID, err)
|
||||||
portal.bridge.SendMessageErrorCheckpoint(evt, bridge.MsgStepRemote, err, true, 0)
|
portal.bridge.SendMessageErrorCheckpoint(evt, bridge.MsgStepRemote, err, true, 0)
|
||||||
} else {
|
} else {
|
||||||
|
// TODO add support for deleting individual attachments from messages
|
||||||
message.Delete()
|
message.Delete()
|
||||||
portal.bridge.SendMessageSuccessCheckpoint(evt, bridge.MsgStepRemote, 0)
|
portal.bridge.SendMessageSuccessCheckpoint(evt, bridge.MsgStepRemote, 0)
|
||||||
portal.sendDeliveryReceipt(evt.ID)
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user