[status-mobile-16467] Fix delete for me on receiver side using wrong chatID (#3732)

This commit is contained in:
Ibrahem Khalil 2023-07-10 22:26:32 +03:00 committed by GitHub
parent 2c275058ad
commit 0c57890a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 4 deletions

View File

@ -1 +1 @@
0.161.2
0.161.3

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/waku"
)
@ -210,3 +211,79 @@ func (s *MessengerDeleteMessageForMeSuite) TestDeleteMessageForMe() {
s.Require().NoError(err)
s.Require().False(otherMessage.DeletedForMe)
}
func (s *MessengerDeleteMessageForMeSuite) TestDeleteImageMessageFromReceiverSide() {
alice := s.otherNewMessenger()
_, err := alice.Start()
s.Require().NoError(err)
defer alice.Shutdown() // nolint: errcheck
bob := s.otherNewMessenger()
_, err = bob.Start()
s.Require().NoError(err)
defer bob.Shutdown() // nolint: errcheck
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, alice.transport)
err = alice.SaveChat(theirChat)
s.Require().NoError(err)
ourChat := CreateOneToOneChat("Our 1TO1", &alice.identity.PublicKey, alice.transport)
err = bob.SaveChat(ourChat)
s.Require().NoError(err)
messageCount := 3
var album []*common.Message
for i := 0; i < messageCount; i++ {
image, err := buildImageWithoutAlbumIDMessage(*ourChat)
s.NoError(err)
album = append(album, image)
}
response, err := bob.SendChatMessages(context.Background(), album)
s.NoError(err)
// Check that album count was the number of the images sent
imagesCount := uint32(0)
for _, message := range response.Messages() {
if message.ContentType == protobuf.ChatMessage_IMAGE {
imagesCount++
}
}
for _, message := range response.Messages() {
s.Require().NotNil(message.GetImage())
s.Require().Equal(message.GetImage().AlbumImagesCount, imagesCount)
}
s.Require().Equal(messageCount, len(response.Messages()), "it returns the messages")
s.Require().NoError(err)
s.Require().Len(response.Messages(), messageCount)
response, err = WaitOnMessengerResponse(
alice,
func(r *MessengerResponse) bool { return len(r.messages) == messageCount },
"no messages",
)
s.Require().NoError(err)
s.Require().Len(response.Chats(), 1)
s.Require().Len(response.Messages(), messageCount)
for _, message := range response.Messages() {
image := message.GetImage()
s.Require().NotNil(image, "Message.ID=%s", message.ID)
s.Require().Equal(image.AlbumImagesCount, imagesCount)
s.Require().NotEmpty(image.AlbumId, "Message.ID=%s", message.ID)
}
messages := response.Messages()
firstMessageID := messages[0].ID
localChatID := messages[0].LocalChatID
sendResponse, err := alice.DeleteMessageForMeAndSync(context.Background(), localChatID, firstMessageID)
s.Require().NoError(err)
s.Require().Len(sendResponse.Messages(), 3)
s.Require().Len(sendResponse.Chats(), 1)
// LastMessage marked as deleted
s.Require().Equal(sendResponse.Chats()[0].LastMessage.ID, album[2].ID)
s.Require().Equal(sendResponse.Chats()[0].LastMessage.DeletedForMe, true)
}

View File

@ -239,14 +239,14 @@ func (m *Messenger) DeleteMessageAndSend(ctx context.Context, messageID string)
return response, nil
}
func (m *Messenger) DeleteMessageForMeAndSync(ctx context.Context, chatID string, messageID string) (*MessengerResponse, error) {
func (m *Messenger) DeleteMessageForMeAndSync(ctx context.Context, localChatID string, messageID string) (*MessengerResponse, error) {
message, err := m.persistence.MessageByID(messageID)
if err != nil {
return nil, err
}
// A valid added chat is required.
chat, ok := m.allChats.Load(chatID)
chat, ok := m.allChats.Load(localChatID)
if !ok {
return nil, ErrChatNotFound
}
@ -260,7 +260,7 @@ func (m *Messenger) DeleteMessageForMeAndSync(ctx context.Context, chatID string
return nil, ErrInvalidDeleteTypeAuthor
}
messagesToDelete, err := m.getConnectedMessages(message, message.ChatId)
messagesToDelete, err := m.getConnectedMessages(message, localChatID)
if err != nil {
return nil, err
}