Skip to content

Commit

Permalink
fix(replies): fix replies from Status and to Status messages (#18)
Browse files Browse the repository at this point in the history
Needed for status-im/status-desktop#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
  • Loading branch information
jrainville authored Sep 14, 2024
1 parent 31a42c4 commit e11feb1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bridge/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}

Expand Down
15 changes: 12 additions & 3 deletions bridge/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions status.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
RemoteNickFormat="{NICK}"
DataDir="path to status data dir"
NodeConfigFile="path to json with node config and fleets"
PreserveThreading=true

[discord]
[discord.mydiscord]
Token=""
Server=""
AutoWebhooks=true
RemoteNickFormat="{NICK}"
PreserveThreading=true

[[gateway]]
name="gateway3"
Expand Down

0 comments on commit e11feb1

Please sign in to comment.