2023-03-23 16:06:50 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-07-28 20:02:20 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2023-03-23 16:06:50 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2023-04-26 11:10:17 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2023-03-23 16:06:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessengerSendImagesAlbumSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerSendImagesAlbumSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessengerSendImagesAlbumSuite struct {
|
2023-11-27 17:01:13 +00:00
|
|
|
MessengerBaseTestSuite
|
2023-03-23 16:06:50 +00:00
|
|
|
}
|
|
|
|
|
2023-07-28 20:02:20 +00:00
|
|
|
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()}
|
2023-10-20 06:21:41 +00:00
|
|
|
joinCommunity(&s.Suite, community, s.m, user, request, "")
|
2023-07-28 20:02:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 16:06:50 +00:00
|
|
|
func (s *MessengerSendImagesAlbumSuite) TestAlbumImageMessagesSend() {
|
|
|
|
theirMessenger := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, theirMessenger)
|
2023-03-23 16:06:50 +00:00
|
|
|
|
|
|
|
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport)
|
2024-02-26 09:12:37 +00:00
|
|
|
err := theirMessenger.SaveChat(theirChat)
|
2023-03-23 16:06:50 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
ourChat := CreateOneToOneChat("Our 1TO1", &theirMessenger.identity.PublicKey, s.m.transport)
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
const messageCount = 3
|
|
|
|
var album []*common.Message
|
|
|
|
|
|
|
|
for i := 0; i < messageCount; i++ {
|
2023-04-14 17:17:56 +00:00
|
|
|
image, err := buildImageWithoutAlbumIDMessage(*ourChat)
|
|
|
|
s.NoError(err)
|
|
|
|
album = append(album, image)
|
2023-03-23 16:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
s.NoError(err)
|
|
|
|
response, err := s.m.SendChatMessages(context.Background(), album)
|
|
|
|
s.NoError(err)
|
2023-03-30 10:02:20 +00:00
|
|
|
|
|
|
|
// Check that album count was the number of the images sent
|
2023-04-05 13:24:55 +00:00
|
|
|
imagesCount := uint32(0)
|
2023-03-30 10:02:20 +00:00
|
|
|
for _, message := range response.Messages() {
|
|
|
|
if message.ContentType == protobuf.ChatMessage_IMAGE {
|
|
|
|
imagesCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, message := range response.Messages() {
|
2023-04-05 13:24:55 +00:00
|
|
|
s.Require().NotNil(message.GetImage())
|
|
|
|
s.Require().Equal(message.GetImage().AlbumImagesCount, imagesCount)
|
2023-03-30 10:02:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 16:06:50 +00:00
|
|
|
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,
|
2023-07-28 20:02:20 +00:00
|
|
|
func(r *MessengerResponse) bool { return len(r.messages) == messageCount },
|
2023-03-23 16:06:50 +00:00
|
|
|
"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()
|
2023-03-31 09:15:06 +00:00
|
|
|
s.Require().NotNil(image, "Message.ID=%s", message.ID)
|
2023-04-05 13:24:55 +00:00
|
|
|
s.Require().Equal(image.AlbumImagesCount, imagesCount)
|
2023-03-31 09:15:06 +00:00
|
|
|
s.Require().NotEmpty(image.AlbumId, "Message.ID=%s", message.ID)
|
2023-03-23 16:06:50 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-31 09:15:06 +00:00
|
|
|
|
|
|
|
func (s *MessengerSendImagesAlbumSuite) TestAlbumImageMessagesWithMentionSend() {
|
|
|
|
theirMessenger := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, theirMessenger)
|
2023-03-31 09:15:06 +00:00
|
|
|
|
|
|
|
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport)
|
2024-02-26 09:12:37 +00:00
|
|
|
err := theirMessenger.SaveChat(theirChat)
|
2023-03-31 09:15:06 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
ourChat := CreateOneToOneChat("Our 1TO1", &theirMessenger.identity.PublicKey, s.m.transport)
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
const messageCount = 3
|
|
|
|
var album []*common.Message
|
|
|
|
|
|
|
|
for i := 0; i < messageCount; i++ {
|
2023-04-14 17:17:56 +00:00
|
|
|
outgoingMessage, err := buildImageWithoutAlbumIDMessage(*ourChat)
|
|
|
|
s.NoError(err)
|
2023-03-31 09:15:06 +00:00
|
|
|
outgoingMessage.Mentioned = true
|
|
|
|
outgoingMessage.Text = "hey @" + common.PubkeyToHex(&theirMessenger.identity.PublicKey)
|
|
|
|
album = append(album, outgoingMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
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) > 0 },
|
|
|
|
"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().NotEmpty(image.AlbumId, "Message.ID=%s", message.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(uint(1), response.Chats()[0].UnviewedMessagesCount, "Just one unread message")
|
|
|
|
}
|
2023-04-26 11:10:17 +00:00
|
|
|
|
2023-07-28 20:02:20 +00:00
|
|
|
// 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()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, theirMessenger)
|
2023-07-28 20:02:20 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:12:37 +00:00
|
|
|
err := s.m.SaveChat(chat)
|
2023-07-28 20:02:20 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-04-26 11:10:17 +00:00
|
|
|
func (s *MessengerSendImagesAlbumSuite) TestAlbumImageEditText() {
|
|
|
|
theirMessenger := s.newMessenger()
|
|
|
|
|
|
|
|
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport)
|
2024-02-26 09:12:37 +00:00
|
|
|
err := theirMessenger.SaveChat(theirChat)
|
2023-04-26 11:10:17 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
ourChat := CreateOneToOneChat("Our 1TO1", &theirMessenger.identity.PublicKey, s.m.transport)
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
const messageCount = 3
|
|
|
|
var album []*common.Message
|
|
|
|
|
|
|
|
for i := 0; i < messageCount; i++ {
|
|
|
|
outgoingMessage, err := buildImageWithoutAlbumIDMessage(*ourChat)
|
|
|
|
s.NoError(err)
|
|
|
|
outgoingMessage.Text = "You can edit me now"
|
|
|
|
album = append(album, outgoingMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.m.SaveChat(ourChat)
|
|
|
|
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) > 0 },
|
|
|
|
"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().NotEmpty(image.AlbumId, "Message.ID=%s", message.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
firstMessageID, err := types.DecodeHex(album[0].ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
editedText := "edited"
|
|
|
|
editedMessage := &requests.EditMessage{
|
|
|
|
ID: firstMessageID,
|
|
|
|
Text: editedText,
|
|
|
|
}
|
|
|
|
|
|
|
|
sendResponse, err := s.m.EditMessage(context.Background(), editedMessage)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(sendResponse.Messages(), messageCount)
|
|
|
|
|
|
|
|
for _, message := range sendResponse.Messages() {
|
|
|
|
s.Require().NotEmpty(message.EditedAt)
|
|
|
|
s.Require().Equal(message.Text, editedText)
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
theirMessenger,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.messages) > 0 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().Len(response.Messages(), messageCount)
|
|
|
|
|
|
|
|
for _, message := range response.Messages() {
|
|
|
|
s.Require().NotEmpty(message.EditedAt)
|
|
|
|
s.Require().Equal(message.Text, editedText)
|
|
|
|
}
|
|
|
|
}
|
2023-09-19 17:17:11 +00:00
|
|
|
|
|
|
|
// This test makes sure that if you get a mention with an album of images in a community, it sends it correctly and has correct AC notif with album
|
|
|
|
func (s *MessengerSendImagesAlbumSuite) TestAlbumImagesMessageWithMentionInCommunitySend() {
|
|
|
|
theirMessenger := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, theirMessenger)
|
2023-09-19 17:17:11 +00:00
|
|
|
|
|
|
|
community, chat := createCommunity(&s.Suite, s.m)
|
|
|
|
|
|
|
|
s.advertiseCommunityTo(community, theirMessenger)
|
|
|
|
|
|
|
|
s.joinCommunity(community, theirMessenger)
|
|
|
|
|
|
|
|
const messageCount = 3
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:12:37 +00:00
|
|
|
err := s.m.SaveChat(chat)
|
2023-09-19 17:17:11 +00:00
|
|
|
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(), 1)
|
|
|
|
|
|
|
|
for _, notif := range response.ActivityCenterNotifications() {
|
|
|
|
s.Require().Equal(messageCount, len(notif.AlbumMessages), "AC notification should have AlbumMessages")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, message := range response.Messages() {
|
|
|
|
image := message.GetImage()
|
|
|
|
s.Require().NotNil(image, "Message.ID=%s", message.ID)
|
|
|
|
s.Require().NotEmpty(image.AlbumId)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(uint(1), response.Chats()[0].UnviewedMessagesCount, "Just one unread message")
|
|
|
|
}
|