Make sure the image URL is returned when a replied message is deleted

When we reply to our own message with an image, we didn't set the URL of
the image of the message, which resulted in the image not being
displayed correctly.
This commit is contained in:
Andrea Maria Piana 2023-06-08 13:49:08 +01:00
parent d8eb038d7d
commit 37653638bc
3 changed files with 60 additions and 43 deletions

View File

@ -1 +1 @@
0.157.2
0.157.3

View File

@ -2,19 +2,13 @@ package protocol
import (
"context"
"crypto/ecdsa"
"testing"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/waku"
"github.com/status-im/status-go/server"
)
func TestMessengerDeleteMessageSuite(t *testing.T) {
@ -22,41 +16,7 @@ func TestMessengerDeleteMessageSuite(t *testing.T) {
}
type MessengerDeleteMessageSuite struct {
suite.Suite
m *Messenger // main instance of Messenger
privateKey *ecdsa.PrivateKey // private key for the main instance of Messenger
// If one wants to send messages between different instances of Messenger,
// a single waku service should be shared.
shh types.Waku
logger *zap.Logger
}
func (s *MessengerDeleteMessageSuite) SetupTest() {
s.logger = tt.MustCreateTestLogger()
config := waku.DefaultConfig
config.MinimumAcceptedPoW = 0
shh := waku.New(&config, s.logger)
s.shh = gethbridge.NewGethWakuWrapper(shh)
s.Require().NoError(shh.Start())
s.m = s.newMessenger()
s.privateKey = s.m.identity
_, err := s.m.Start()
s.Require().NoError(err)
}
func (s *MessengerDeleteMessageSuite) TearDownTest() {
s.Require().NoError(s.m.Shutdown())
}
func (s *MessengerDeleteMessageSuite) newMessenger() *Messenger {
privateKey, err := crypto.GenerateKey()
s.Require().NoError(err)
messenger, err := newMessengerWithKey(s.shh, privateKey, s.logger, nil)
s.Require().NoError(err)
return messenger
MessengerBaseTestSuite
}
func (s *MessengerDeleteMessageSuite) TestDeleteMessage() {
@ -518,3 +478,58 @@ func (s *MessengerDeleteMessageSuite) TestDeleteMessageAndChatIsAlreadyRead() {
// Receiver (us) no longer has unread messages and it's not negative
s.Require().Equal(0, int(state.Response.Chats()[0].UnviewedMessagesCount))
}
func (s *MessengerDeleteMessageSuite) TestDeleteMessageReplyToImage() {
theirMessenger := s.newMessenger()
_, err := theirMessenger.Start()
s.Require().NoError(err)
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport)
err = theirMessenger.SaveChat(theirChat)
s.Require().NoError(err)
ourChat := CreateOneToOneChat("Our 1TO1", &theirMessenger.identity.PublicKey, s.m.transport)
err = s.m.SaveChat(ourChat)
s.Require().NoError(err)
inputMessage := buildTestMessage(*theirChat)
sendResponse, err := theirMessenger.SendChatMessage(context.Background(), inputMessage)
s.NoError(err)
s.Require().Len(sendResponse.Messages(), 1)
response, err := WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool { return len(r.messages) == 1 },
"no messages",
)
s.Require().NoError(err)
s.Require().Len(response.Chats(), 1)
s.Require().Len(response.Messages(), 1)
ogMessage := sendResponse.Messages()[0]
// create an http server
mediaServer, err := server.NewMediaServer(nil, nil, nil)
s.Require().NoError(err)
s.Require().NotNil(mediaServer)
s.Require().NoError(mediaServer.Start())
theirMessenger.httpServer = mediaServer
// We reply to our own message with an image
imageMessage, err := buildImageWithoutAlbumIDMessage(*theirChat)
s.NoError(err)
imageMessage.ResponseTo = ogMessage.ID
_, err = theirMessenger.SendChatMessages(context.Background(), []*common.Message{imageMessage})
s.NoError(err)
// We check that the URL is correctly returned
sendResponse, err = theirMessenger.DeleteMessageAndSend(context.Background(), ogMessage.ID)
s.Require().NoError(err)
s.Require().Len(sendResponse.Messages(), 1)
s.Require().NotEmpty(sendResponse.Messages()[0].ImageLocalURL)
s.Require().NoError(theirMessenger.Shutdown())
}

View File

@ -229,7 +229,9 @@ func (m *Messenger) DeleteMessageAndSend(ctx context.Context, messageID string)
if err != nil {
return nil, err
}
response.AddMessages(updatedMessages)
m.prepareMessages(response.messages)
}
response.AddChat(chat)