fix(messenger): fix handling reply with only one image (#3816)

If a message is sent with only 1 image, the album is not generated (no albumID), so then, in the notification handling code, it didn't use the right ID, because it thought it had to use the AlbumID for the message ID
This commit is contained in:
Jonathan Rainville 2023-07-28 16:02:20 -04:00 committed by GitHub
parent 89253ac684
commit cbb845b574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 2 deletions

View File

@ -3296,7 +3296,8 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
// for same message with multiple images
var idToUse string
if message.GetImage() != nil {
image := message.GetImage()
if image != nil && image.GetAlbumId() != "" {
idToUse = message.GetImage().GetAlbumId()
} else {
idToUse = message.ID

View File

@ -12,6 +12,7 @@ import (
"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/communities"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
@ -62,6 +63,15 @@ func (s *MessengerSendImagesAlbumSuite) newMessenger() *Messenger {
return messenger
}
func (s *MessengerSendImagesAlbumSuite) advertiseCommunityTo(community *communities.Community, user *Messenger) {
advertiseCommunityTo(&s.Suite, community, s.m, user)
}
func (s *MessengerSendImagesAlbumSuite) joinCommunity(community *communities.Community, user *Messenger) {
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
joinCommunity(&s.Suite, community, s.m, user, request)
}
func (s *MessengerSendImagesAlbumSuite) TestAlbumImageMessagesSend() {
theirMessenger := s.newMessenger()
_, err := theirMessenger.Start()
@ -108,7 +118,7 @@ func (s *MessengerSendImagesAlbumSuite) TestAlbumImageMessagesSend() {
response, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool { return len(r.messages) == 3 },
func(r *MessengerResponse) bool { return len(r.messages) == messageCount },
"no messages",
)
@ -175,6 +185,58 @@ func (s *MessengerSendImagesAlbumSuite) TestAlbumImageMessagesWithMentionSend()
s.Require().Equal(uint(1), response.Chats()[0].UnviewedMessagesCount, "Just one unread message")
}
// This test makes sure that if you get a mention with an image ina community, it sends it correctly and has a notif
func (s *MessengerSendImagesAlbumSuite) TestSingleImageMessageWithMentionInCommunitySend() {
theirMessenger := s.newMessenger()
_, err := theirMessenger.Start()
s.Require().NoError(err)
defer theirMessenger.Shutdown() // nolint: errcheck
community, chat := createCommunity(&s.Suite, s.m)
s.advertiseCommunityTo(community, theirMessenger)
s.joinCommunity(community, theirMessenger)
const messageCount = 1
var album []*common.Message
for i := 0; i < messageCount; i++ {
outgoingMessage, err := buildImageWithoutAlbumIDMessage(*chat)
s.NoError(err)
outgoingMessage.Mentioned = true
outgoingMessage.Text = "hey @" + common.PubkeyToHex(&theirMessenger.identity.PublicKey)
album = append(album, outgoingMessage)
}
err = s.m.SaveChat(chat)
s.NoError(err)
response, err := s.m.SendChatMessages(context.Background(), album)
s.NoError(err)
s.Require().Equal(messageCount, len(response.Messages()), "it returns the messages")
s.Require().NoError(err)
s.Require().Len(response.Messages(), messageCount)
response, err = WaitOnMessengerResponse(
theirMessenger,
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)
s.Require().Len(response.ActivityCenterNotifications(), messageCount)
for _, message := range response.Messages() {
image := message.GetImage()
s.Require().NotNil(image, "Message.ID=%s", message.ID)
s.Require().Empty(image.AlbumId)
}
s.Require().Equal(uint(1), response.Chats()[0].UnviewedMessagesCount, "Just one unread message")
}
func (s *MessengerSendImagesAlbumSuite) TestAlbumImageEditText() {
theirMessenger := s.newMessenger()
_, err := theirMessenger.Start()