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
This commit is contained in:
Jonathan Rainville 2024-09-14 11:20:17 -04:00 committed by GitHub
parent 31a42c4459
commit e11feb13a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -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(),
}

View File

@ -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 {

View File

@ -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"