Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow message deletes from any platform #1991

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bridge/whatsappmulti/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
return "", nil
}

_, err := b.wc.RevokeMessage(groupJID, msg.ID)
_, err := b.wc.SendMessage(context.Background(), groupJID, b.wc.BuildRevoke(groupJID, extendedMsgID.Sender, extendedMsgID.MessageID))

return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ func (gw *Gateway) SendMessage(

// exclude file delete event as the msg ID here is the native file ID that needs to be deleted
if msg.Event != config.EventFileDelete {
msg.ID = gw.getDestMsgID(rmsg.Protocol+" "+rmsg.ID, dest, channel)
canonicalMsgID := gw.FindCanonicalMsgID(rmsg.Protocol, rmsg.ID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest this is a bit of a hacky workaround and I don't necessarily like doing this pretty expensive operation on basically every message recived.

Hypothetically we can work around this

In practice this inefficiency would only matter in really large message caches (and we're mostly limited by I/O bandwidth).

I still don't really like it though.
I'd rather it be more of a graph-like structure where any message maps to the rest of the messages rather than 1 canonical message to the sent mesages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is less of an issue with the persistent message maps in #1996

msg.ID = gw.getDestMsgID(canonicalMsgID, dest, channel)
}

// for api we need originchannel as channel
Expand Down
8 changes: 7 additions & 1 deletion gateway/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ func (r *Router) handleReceive() {
r.handleEventFailure(&msg)
r.handleEventRejoinChannels(&msg)

srcBridge := r.getBridge(msg.Account)
// Set message protocol based on the account it came from
msg.Protocol = r.getBridge(msg.Account).Protocol
msg.Protocol = srcBridge.Protocol

filesHandled := false
for _, gw := range r.Gateways {
Expand Down Expand Up @@ -163,6 +164,11 @@ func (r *Router) handleReceive() {
// This is necessary as msgIDs will change if a bridge returns
// a different ID in response to edits.
if !exists {
// we're adding the original message as a "dest message"
// as when we get the dest messages for a delete the source message isnt in the list
// therefore the delete doesnt happen on the source platform.
msgIDs = append(msgIDs, &BrMsgID{srcBridge, srcBridge.Protocol + " " + msg.ID, msg.Channel + srcBridge.Account})

gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs)
}
}
Expand Down