From e11feb13a2ee61a7c0a68babaaf44ff0757cd880 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Sat, 14 Sep 2024 11:20:17 -0400 Subject: [PATCH] fix(replies): fix replies from Status and to Status messages (#18) Needed for https://github.com/status-im/status-desktop/issues/16323 There were multiple problems. 1. The ParentID was not set correctly when a message was sent from Status 2. We didn't send back the ID of messages that we sent, so the gateway couldn't associate the new messages to the old ones 3. Missing param in the toml config `PreserveThreading` 4. Discord messages are weirdly formatted when a reply is send. It cannot use webhooks, so we need to pass the username directly in the message (it's ugly, but it works) Finally, there was an issue on the status-go side. We tried to use the discord message ID to find the replies, but the bridge already converts it to the right ID, so we could just use it directly --- bridge/discord/discord.go | 2 +- bridge/status/status.go | 15 ++++++++++++--- status.toml | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 51dbe6bc71..8c2c4a3ec9 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -337,7 +337,7 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st } m := discordgo.MessageSend{ - Content: msg.Username + msg.Text, + Content: msg.Username + ": " + msg.Text, AllowedMentions: b.getAllowedMentions(), } diff --git a/bridge/status/status.go b/bridge/status/status.go index a39dcc5bd6..6c6b1e4f18 100644 --- a/bridge/status/status.go +++ b/bridge/status/status.go @@ -219,6 +219,7 @@ func (b *Bstatus) propagateMessage(msg *common.Message) { Text: msg.Text, Channel: msg.ChatId, ID: msg.ID, + ParentID: msg.ResponseTo, Account: b.Account, } } @@ -245,6 +246,10 @@ func (b *Bstatus) toStatusMsg(msg config.Message) *common.Message { } } + if msg.ParentID != "" { + originalParentID = msg.ParentID + } + message.Payload = &protobuf.ChatMessage_BridgeMessage{ BridgeMessage: &protobuf.BridgeMessage{ BridgeName: msg.Protocol, @@ -297,6 +302,8 @@ func (b *Bstatus) Send(msg config.Message) (string, error) { return "", errors.Wrap(err, "failed to get status message for bridge message") } + sentMessageID := "" + if statusMessageID != "" { decodedStatusMessageID, err := types.DecodeHex(statusMessageID) if err != nil { @@ -307,18 +314,20 @@ func (b *Bstatus) Send(msg config.Message) (string, error) { Text: msg.Text, ContentType: protobuf.ChatMessage_BRIDGE_MESSAGE, } - _, err = b.messenger.EditMessage(context.Background(), editedMessage) + response, err := b.messenger.EditMessage(context.Background(), editedMessage) if err != nil { return "", errors.Wrap(err, "failed to edit message") } + sentMessageID = response.Messages()[0].ID } else { - _, err := b.messenger.SendChatMessage(context.Background(), statusMessageToSend) + response, err := b.messenger.SendChatMessage(context.Background(), statusMessageToSend) if err != nil { return "", errors.Wrap(err, "failed to send message") } + sentMessageID = response.Messages()[0].ID } - return "", nil + return sentMessageID, nil } func (b *Bstatus) Connect() error { diff --git a/status.toml b/status.toml index fadbaa3cfd..26b4b1df14 100644 --- a/status.toml +++ b/status.toml @@ -12,6 +12,7 @@ RemoteNickFormat="{NICK}" DataDir="path to status data dir" NodeConfigFile="path to json with node config and fleets" + PreserveThreading=true [discord] [discord.mydiscord] @@ -19,6 +20,7 @@ Server="" AutoWebhooks=true RemoteNickFormat="{NICK}" + PreserveThreading=true [[gateway]] name="gateway3"