Skip to content

Commit

Permalink
fix_: fix broken test by even more simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Sep 23, 2024
1 parent e61e8fa commit ba8236f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
17 changes: 0 additions & 17 deletions protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,6 @@ func (db sqlitePersistence) SaveMessages(messages []*common.Message) (err error)
if err != nil {
return
}
// handle replies
err = db.findAndUpdateReplies(tx, msg.GetBridgeMessage().MessageID, msg.ID)
if err != nil {
return
}
parentMessageID := msg.GetBridgeMessage().ParentMessageID
if parentMessageID != "" {
err = db.findAndUpdateRepliedTo(tx, parentMessageID, msg.ID)
Expand Down Expand Up @@ -3044,18 +3039,6 @@ func (db sqlitePersistence) updateBridgeMessageContent(tx *sql.Tx, bridgeMessage
return err
}

// Finds if there are any messages that are replies to that message (in case replies were received earlier)
func (db sqlitePersistence) findAndUpdateReplies(tx *sql.Tx, bridgeMessageID string, statusMessageID string) error {
replyMessageIds, err := db.findStatusMessageIdsReplies(tx, bridgeMessageID)
if err != nil {
return err
}
if len(replyMessageIds) == 0 {
return nil
}
return db.updateStatusMessagesWithResponse(tx, replyMessageIds, statusMessageID)
}

func (db sqlitePersistence) findAndUpdateRepliedTo(tx *sql.Tx, discordParentMessageID string, statusMessageID string) error {
return db.updateStatusMessagesWithResponse(tx, []string{statusMessageID}, discordParentMessageID)
}
Expand Down
10 changes: 5 additions & 5 deletions protocol/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1995,18 +1995,18 @@ func TestBridgeMessageReplies(t *testing.T) {
err = insertMinimalBridgeMessage(p, "444", "4", "3")
require.NoError(t, err)

// status message "222" should have reply_to = "111"
// status message "222" should have reply_to =" 1" because it's a discord message to another discord message
responseTo, err := messageResponseTo(p, "222")
require.NoError(t, err)
require.Equal(t, "111", responseTo)
require.Equal(t, "1", responseTo)

responseTo, err = messageResponseTo(p, "111")
require.NoError(t, err)
require.Equal(t, "", responseTo)

responseTo, err = messageResponseTo(p, "444")
require.NoError(t, err)
require.Equal(t, "", responseTo)
require.Equal(t, "3", responseTo)

// receiving message for which "444" is replied to
err = insertMinimalBridgeMessage(p, "333", "3", "")
Expand All @@ -2016,10 +2016,10 @@ func TestBridgeMessageReplies(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "", responseTo)

// now 444 is replied to 333
// 444 is still replied to 3
responseTo, err = messageResponseTo(p, "444")
require.NoError(t, err)
require.Equal(t, "333", responseTo)
require.Equal(t, "3", responseTo)
}

func createAndSaveMessage(p *sqlitePersistence, id string, from string, deleted bool, communityID string) error {
Expand Down

0 comments on commit ba8236f

Please sign in to comment.