Skip to content

Commit

Permalink
fix(bridge)_: fix bridge replies not working when they come from Discord
Browse files Browse the repository at this point in the history
Fixes status-im/status-desktop#16323

The problem was that the code expected to receive the Discord message ID, but the bridge is smart enough to return the Status message ID already, so there is no need to try and convert it.

There were also a couple issues in the bridge code itself.
  • Loading branch information
jrainville committed Sep 13, 2024
1 parent 13ab5b6 commit 2552a78
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -3010,24 +3010,6 @@ func (db sqlitePersistence) FindStatusMessageIDForBridgeMessageID(messageID stri
return "", nil
}

func (db sqlitePersistence) findStatusMessageIDForBridgeMessageID(tx *sql.Tx, messageID string) (string, error) {
rows, err := tx.Query(`SELECT user_messages_id FROM bridge_messages WHERE message_id = ?`, messageID)
if err != nil {
return "", err
}
defer rows.Close()

if rows.Next() {
var statusMessageID string
err = rows.Scan(&statusMessageID)
if err != nil {
return "", err
}
return statusMessageID, nil
}
return "", nil
}

func (db sqlitePersistence) updateStatusMessagesWithResponse(tx *sql.Tx, statusMessagesToUpdate []string, responseValue string) error {
sql := "UPDATE user_messages SET response_to = ? WHERE id IN (?" + strings.Repeat(",?", len(statusMessagesToUpdate)-1) + ")" //nolint: gosec
stmt, err := tx.Prepare(sql)
Expand Down Expand Up @@ -3075,15 +3057,7 @@ func (db sqlitePersistence) findAndUpdateReplies(tx *sql.Tx, bridgeMessageID str
}

func (db sqlitePersistence) findAndUpdateRepliedTo(tx *sql.Tx, discordParentMessageID string, statusMessageID string) error {
// Finds status messages id which are replies for bridgeMessageID
repliedMessageID, err := db.findStatusMessageIDForBridgeMessageID(tx, discordParentMessageID)
if err != nil {
return err
}
if repliedMessageID == "" {
return nil
}
return db.updateStatusMessagesWithResponse(tx, []string{statusMessageID}, repliedMessageID)
return db.updateStatusMessagesWithResponse(tx, []string{statusMessageID}, discordParentMessageID)
}

func (db sqlitePersistence) GetCommunityMemberAllMessages(member string, communityID string) ([]*common.Message, error) {
Expand Down

0 comments on commit 2552a78

Please sign in to comment.