2021-06-29 08:27:11 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-02-21 16:20:10 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-10-25 14:26:18 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2023-02-21 16:20:10 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2021-06-29 08:27:11 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2023-08-10 15:12:23 +00:00
|
|
|
"github.com/status-im/status-go/server"
|
2021-06-29 08:27:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessengerActivityCenterMessageSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerActivityCenterMessageSuite))
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
func (s *MessengerActivityCenterMessageSuite) createCommunity(owner *Messenger) (*communities.Community, *Chat) {
|
|
|
|
return createCommunity(&s.Suite, owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) advertiseCommunityTo(community *communities.Community, owner *Messenger, user *Messenger) {
|
|
|
|
advertiseCommunityTo(&s.Suite, community, owner, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) joinCommunity(community *communities.Community, owner *Messenger, user *Messenger) {
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
2023-10-20 06:21:41 +00:00
|
|
|
joinCommunity(&s.Suite, community, owner, user, request, "")
|
2023-10-25 14:26:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 08:27:11 +00:00
|
|
|
type MessengerActivityCenterMessageSuite struct {
|
2023-11-27 17:01:13 +00:00
|
|
|
MessengerBaseTestSuite
|
2021-06-29 08:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestDeleteOneToOneChat() {
|
|
|
|
theirMessenger := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, theirMessenger)
|
2021-06-29 08:27:11 +00:00
|
|
|
|
|
|
|
theirChat := CreateOneToOneChat("Their 1TO1", &s.privateKey.PublicKey, s.m.transport)
|
2024-02-26 09:12:37 +00:00
|
|
|
err := theirMessenger.SaveChat(theirChat)
|
2021-06-29 08:27:11 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-02-08 14:58:10 +00:00
|
|
|
r := &requests.SendContactRequest{
|
2022-10-14 08:50:36 +00:00
|
|
|
ID: s.m.myHexIdentity(),
|
2023-02-08 14:58:10 +00:00
|
|
|
Message: "hello",
|
|
|
|
}
|
|
|
|
sendResponse, err := theirMessenger.SendContactRequest(context.Background(), r)
|
2021-06-29 08:27:11 +00:00
|
|
|
s.NoError(err)
|
2023-06-08 12:00:19 +00:00
|
|
|
s.Require().Len(sendResponse.Messages(), 2)
|
2021-06-29 08:27:11 +00:00
|
|
|
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
s.m,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.messages) > 0 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
2023-06-08 12:00:19 +00:00
|
|
|
s.Require().Len(response.Messages(), 2)
|
2021-06-29 08:27:11 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
request := &requests.DeactivateChat{ID: response.Chats()[0].ID}
|
|
|
|
response, err = s.m.DeactivateChat(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
deletedChat := response.Chats()[0]
|
|
|
|
s.Require().NotEmpty(deletedChat.DeletedAtClockValue)
|
|
|
|
|
|
|
|
// Make sure deleted at clock value is greater
|
|
|
|
theirChat.LastClockValue = deletedChat.DeletedAtClockValue + 1
|
|
|
|
err = theirMessenger.SaveChat(theirChat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Send another message
|
2023-02-08 14:58:10 +00:00
|
|
|
inputMessage := buildTestMessage(*theirChat)
|
2021-06-29 08:27:11 +00:00
|
|
|
sendResponse, err = theirMessenger.SendChatMessage(context.Background(), inputMessage)
|
|
|
|
s.NoError(err)
|
|
|
|
s.Require().Len(sendResponse.Messages(), 1)
|
|
|
|
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
s.m,
|
2023-02-08 14:58:10 +00:00
|
|
|
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
|
2021-06-29 08:27:11 +00:00
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
}
|
2023-02-21 16:20:10 +00:00
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestEveryoneMentionTag() {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-02-21 16:20:10 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
2023-02-21 16:20:10 +00:00
|
|
|
s.Require().NotNil(community)
|
2023-10-25 14:26:18 +00:00
|
|
|
s.Require().NotNil(chat)
|
2023-02-21 16:20:10 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Alice joins the community
|
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
2023-02-21 16:20:10 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// alice sends a community message
|
2023-08-18 11:39:59 +00:00
|
|
|
inputMessage := common.NewMessage()
|
2023-02-21 16:20:10 +00:00
|
|
|
inputMessage.ChatId = chat.ID
|
2023-10-25 14:26:18 +00:00
|
|
|
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
2023-02-21 16:20:10 +00:00
|
|
|
inputMessage.Text = "Good news, @" + common.EveryoneMentionTag + " !"
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
response, err := alice.SendChatMessage(context.Background(), inputMessage)
|
2023-02-21 16:20:10 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
bob,
|
2023-10-25 14:26:18 +00:00
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) >= 1 },
|
2023-02-21 16:20:10 +00:00
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
s.Require().Equal(ActivityCenterNotificationTypeMention, response.ActivityCenterNotifications()[0].Type)
|
|
|
|
}
|
2023-08-10 15:12:23 +00:00
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestReplyWithImage() {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-08-10 15:12:23 +00:00
|
|
|
|
|
|
|
// create an http server
|
2023-12-15 20:29:39 +00:00
|
|
|
mediaServer, err := server.NewMediaServer(nil, nil, nil, nil)
|
2023-08-10 15:12:23 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(mediaServer)
|
|
|
|
s.Require().NoError(mediaServer.Start())
|
2024-07-01 18:52:57 +00:00
|
|
|
alice.SetMediaServer(mediaServer)
|
2023-08-10 15:12:23 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
2023-08-10 15:12:23 +00:00
|
|
|
s.Require().NotNil(community)
|
2023-10-25 14:26:18 +00:00
|
|
|
s.Require().NotNil(chat)
|
2023-08-10 15:12:23 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Alice joins the community
|
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
2023-08-10 15:12:23 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Alice sends a community message
|
2023-08-18 11:39:59 +00:00
|
|
|
inputMessage := common.NewMessage()
|
2023-08-10 15:12:23 +00:00
|
|
|
inputMessage.ChatId = chat.ID
|
2023-10-25 14:26:18 +00:00
|
|
|
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
2023-08-10 15:12:23 +00:00
|
|
|
inputMessage.Text = "test message"
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
response, err := alice.SendChatMessage(context.Background(), inputMessage)
|
2023-08-10 15:12:23 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
bob,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) == 1 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// bob sends a reply with an image
|
|
|
|
inputMessage, err = buildImageWithAlbumIDMessage(*chat, "0x34")
|
2023-08-10 15:12:23 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
inputMessage.Text = "test message reply"
|
|
|
|
inputMessage.ResponseTo = response.Messages()[0].ID
|
|
|
|
|
|
|
|
response, err = bob.SendChatMessage(context.Background(), inputMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 2)
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
alice,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) == 2 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// verify the new message
|
2023-08-10 15:12:23 +00:00
|
|
|
var newMessage *common.Message
|
|
|
|
for _, m := range response.Messages() {
|
|
|
|
if m.Text == "test message reply" {
|
|
|
|
newMessage = m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().NotNil(newMessage)
|
|
|
|
s.Require().Equal(protobuf.ChatMessage_IMAGE, newMessage.ContentType)
|
|
|
|
s.Require().NotEmpty(newMessage.ImageLocalURL)
|
|
|
|
|
|
|
|
s.Require().NotNil(response.ActivityCenterNotifications()[0].Message)
|
|
|
|
s.Require().NotEmpty(response.ActivityCenterNotifications()[0].Message.ImageLocalURL)
|
|
|
|
s.Require().Equal(ActivityCenterNotificationTypeReply, response.ActivityCenterNotifications()[0].Type)
|
|
|
|
|
|
|
|
notifResponse, err := alice.ActivityCenterNotifications(ActivityCenterNotificationsRequest{
|
|
|
|
Limit: 8,
|
|
|
|
ReadType: ActivityCenterQueryParamsReadAll,
|
|
|
|
ActivityTypes: []ActivityCenterType{ActivityCenterNotificationTypeReply},
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifResponse.Notifications, 1)
|
|
|
|
s.Require().NotNil(notifResponse.Notifications[0].Message)
|
|
|
|
s.Require().NotEmpty(notifResponse.Notifications[0].Message.ImageLocalURL)
|
|
|
|
}
|
2023-10-06 11:48:30 +00:00
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestMuteCommunityActivityCenterNotifications() {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2024-02-26 09:12:37 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-10-06 11:48:30 +00:00
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NotNil(community)
|
2023-10-25 14:26:18 +00:00
|
|
|
s.Require().NotNil(chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
|
|
|
|
// Alice joins the community
|
2023-10-25 14:26:18 +00:00
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
2023-10-06 11:48:30 +00:00
|
|
|
|
|
|
|
// Bob mutes the community
|
|
|
|
time, err := bob.MuteAllCommunityChats(&requests.MuteCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
MutedType: MuteTillUnmuted,
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(time)
|
|
|
|
|
|
|
|
bobCommunity, err := bob.GetCommunityByID(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(bobCommunity.Muted())
|
|
|
|
|
|
|
|
// alice sends a community message
|
2023-10-25 14:26:18 +00:00
|
|
|
inputMessage := common.NewMessage()
|
|
|
|
inputMessage.ChatId = chat.ID
|
|
|
|
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
2023-10-06 11:48:30 +00:00
|
|
|
inputMessage.Text = "Good news, @" + common.EveryoneMentionTag + " !"
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
response, err := alice.SendChatMessage(context.Background(), inputMessage)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
bob,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) == 1 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
|
2023-10-25 14:26:18 +00:00
|
|
|
// Bob still receives it, but no AC notif
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 0)
|
|
|
|
}
|
2023-11-27 11:22:24 +00:00
|
|
|
|
2023-12-04 11:48:28 +00:00
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestReadCommunityOverviewNotifications() {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2024-02-26 09:12:37 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-12-04 11:48:28 +00:00
|
|
|
|
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
|
|
|
s.Require().NotNil(community)
|
|
|
|
s.Require().NotNil(chat)
|
|
|
|
|
|
|
|
// Alice joins the community
|
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
|
|
|
|
|
|
|
// Mark community overview notification read
|
2024-02-26 09:12:37 +00:00
|
|
|
err := alice.DismissActivityCenterNotificationsByCommunity(context.Background(), &requests.DismissCommunityNotifications{CommunityID: community.ID()})
|
2023-12-04 11:48:28 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response, err := alice.GetActivityCenterState()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(response.HasSeen, true)
|
|
|
|
}
|
|
|
|
|
2023-11-27 11:22:24 +00:00
|
|
|
func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMentionAndReply() (*Messenger, *Messenger, *common.Message, *common.Message, *communities.Community) {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2023-11-27 17:01:13 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-11-27 11:22:24 +00:00
|
|
|
|
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
|
|
|
s.Require().NotNil(community)
|
|
|
|
s.Require().NotNil(chat)
|
|
|
|
|
|
|
|
// Alice joins the community
|
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
|
|
|
|
|
|
|
// Bob sends a mention message
|
|
|
|
mentionMessage := common.NewMessage()
|
|
|
|
mentionMessage.ChatId = chat.ID
|
|
|
|
mentionMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
mentionMessage.Text = "Good news, @" + common.EveryoneMentionTag + " !"
|
|
|
|
|
|
|
|
response, err := bob.SendChatMessage(context.Background(), mentionMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
|
|
|
|
// check alice got the mention message
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
alice,
|
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
return len(r.Messages()) == 1 && len(r.ActivityCenterNotifications()) == 1 &&
|
|
|
|
r.Messages()[0].ID == r.ActivityCenterNotifications()[0].Message.ID &&
|
|
|
|
r.ActivityCenterNotifications()[0].Type == ActivityCenterNotificationTypeMention
|
|
|
|
},
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().False(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().Equal(response.ActivityCenterNotifications()[0].ID.String(), response.ActivityCenterNotifications()[0].Message.ID)
|
|
|
|
mentionMessage = response.Messages()[0]
|
|
|
|
|
|
|
|
// Alice sends a community message
|
|
|
|
inputMessage := common.NewMessage()
|
|
|
|
inputMessage.ChatId = chat.ID
|
|
|
|
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
inputMessage.Text = "test message"
|
|
|
|
|
|
|
|
response, err = alice.SendChatMessage(context.Background(), inputMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
|
|
|
|
// Check the community message is received by Bob
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
bob,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) == 1 },
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Bob sends a reply message
|
|
|
|
replyMessage := common.NewMessage()
|
|
|
|
replyMessage.ChatId = chat.ID
|
|
|
|
replyMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
replyMessage.Text = "test message reply"
|
|
|
|
replyMessage.ResponseTo = response.Messages()[0].ID
|
|
|
|
|
|
|
|
response, err = bob.SendChatMessage(context.Background(), replyMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 2)
|
|
|
|
|
|
|
|
// Check Alice got the reply message
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
alice,
|
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
return len(r.Messages()) == 2 && len(r.ActivityCenterNotifications()) == 1 &&
|
|
|
|
(r.Messages()[0].ID == r.ActivityCenterNotifications()[0].Message.ID ||
|
|
|
|
r.Messages()[1].ID == r.ActivityCenterNotifications()[0].Message.ID) &&
|
|
|
|
r.ActivityCenterNotifications()[0].Type == ActivityCenterNotificationTypeReply
|
|
|
|
},
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
2024-02-22 01:44:14 +00:00
|
|
|
replyNotification := response.ActivityCenterNotifications()[0]
|
2023-11-27 11:22:24 +00:00
|
|
|
s.Require().False(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
|
2024-02-22 01:44:14 +00:00
|
|
|
// One message is the community message, the other is the reply to the community message
|
|
|
|
s.Require().Len(response.Messages(), 2)
|
|
|
|
|
|
|
|
replyMessage, ok := response.messages[replyNotification.Message.ID]
|
|
|
|
s.Require().True(ok)
|
|
|
|
s.Require().NotNil(replyMessage)
|
|
|
|
s.Require().Equal(replyMessage.ID, replyNotification.ID.String())
|
2023-11-27 11:22:24 +00:00
|
|
|
|
|
|
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, false)
|
|
|
|
|
|
|
|
return alice, bob, mentionMessage, replyMessage, community
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) confirmMentionAndReplyNotificationsRead(user *Messenger, mentionMessage *common.Message, replyMessage *common.Message, read bool) {
|
|
|
|
// Confirm reply notification
|
|
|
|
notifResponse, err := user.ActivityCenterNotifications(ActivityCenterNotificationsRequest{
|
|
|
|
Limit: 8,
|
|
|
|
ReadType: ActivityCenterQueryParamsReadAll,
|
|
|
|
ActivityTypes: []ActivityCenterType{ActivityCenterNotificationTypeReply},
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifResponse.Notifications, 1)
|
|
|
|
s.Require().Equal(read, notifResponse.Notifications[0].Read)
|
|
|
|
|
|
|
|
// Confirm mention notification
|
|
|
|
notifResponse, err = user.ActivityCenterNotifications(ActivityCenterNotificationsRequest{
|
|
|
|
Limit: 8,
|
|
|
|
ReadType: ActivityCenterQueryParamsReadAll,
|
|
|
|
ActivityTypes: []ActivityCenterType{ActivityCenterNotificationTypeMention},
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifResponse.Notifications, 1)
|
|
|
|
s.Require().Equal(read, notifResponse.Notifications[0].Read)
|
2024-02-22 01:44:14 +00:00
|
|
|
s.Require().Equal(mentionMessage.ID, notifResponse.Notifications[0].ID.String())
|
2023-11-27 11:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificationsRead() {
|
|
|
|
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
|
|
|
|
2023-12-25 06:25:22 +00:00
|
|
|
response, err := alice.MarkMessagesRead(replyMessage.ChatId, []string{mentionMessage.ID, replyMessage.ID})
|
2023-11-27 11:22:24 +00:00
|
|
|
|
|
|
|
s.Require().NoError(err)
|
2023-12-25 06:25:22 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 2)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[1].Read)
|
2023-11-27 11:22:24 +00:00
|
|
|
|
|
|
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestMarkAllReadMarksNotificationsRead() {
|
|
|
|
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
|
|
|
|
|
|
|
response, err := alice.MarkAllRead(context.Background(), mentionMessage.ChatId)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 2)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[1].Read)
|
|
|
|
|
|
|
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestMarkAllReadInCommunityMarksNotificationsRead() {
|
|
|
|
alice, _, mentionMessage, replyMessage, community := s.prepareCommunityChannelWithMentionAndReply()
|
|
|
|
|
|
|
|
response, err := alice.MarkAllReadInCommunity(context.Background(), community.IDString())
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 2)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[1].Read)
|
|
|
|
|
|
|
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestMarkAllActivityCenterNotificationsReadMarksMessagesAsSeen() {
|
|
|
|
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
|
|
|
|
|
|
|
|
response, err := alice.MarkAllActivityCenterNotificationsRead(context.Background())
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 3)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[1].Read)
|
|
|
|
s.Require().True(response.ActivityCenterNotifications()[2].Read)
|
|
|
|
|
|
|
|
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
|
|
|
}
|
2023-11-29 15:28:04 +00:00
|
|
|
|
|
|
|
func (s *MessengerActivityCenterMessageSuite) TestAliceDoesNotReceiveCommunityNotificationsBeforeJoined() {
|
|
|
|
alice := s.m
|
|
|
|
bob := s.newMessenger()
|
2024-02-26 09:12:37 +00:00
|
|
|
defer TearDownMessenger(&s.Suite, bob)
|
2023-11-29 15:28:04 +00:00
|
|
|
|
|
|
|
// Create a community
|
|
|
|
community, chat := s.createCommunity(bob)
|
|
|
|
s.Require().NotNil(community)
|
|
|
|
s.Require().NotNil(chat)
|
|
|
|
|
|
|
|
// Bob sends a mention message
|
|
|
|
mentionMessage := common.NewMessage()
|
|
|
|
mentionMessage.ChatId = chat.ID
|
|
|
|
mentionMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
mentionMessage.Text = "Good news, @" + common.EveryoneMentionTag + " !"
|
|
|
|
|
|
|
|
response, err := bob.SendChatMessage(context.Background(), mentionMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
|
|
|
|
// Alice joins the community
|
|
|
|
s.advertiseCommunityTo(community, bob, alice)
|
|
|
|
s.joinCommunity(community, bob, alice)
|
|
|
|
|
|
|
|
// Bob sends an another mention message
|
|
|
|
mentionMessage = common.NewMessage()
|
|
|
|
mentionMessage.ChatId = chat.ID
|
|
|
|
mentionMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
mentionMessage.Text = "Welcome new joiners, @" + common.EveryoneMentionTag + " !"
|
|
|
|
|
|
|
|
response, err = bob.SendChatMessage(context.Background(), mentionMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().True(response.Messages()[0].Mentioned)
|
|
|
|
|
|
|
|
// check alice got only second mention message
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
alice,
|
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
return len(r.Messages()) == 1 && len(r.ActivityCenterNotifications()) == 1 &&
|
|
|
|
r.Messages()[0].ID == r.ActivityCenterNotifications()[0].Message.ID &&
|
|
|
|
r.ActivityCenterNotifications()[0].Type == ActivityCenterNotificationTypeMention
|
|
|
|
},
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().False(response.ActivityCenterNotifications()[0].Read)
|
|
|
|
s.Require().Equal(response.ActivityCenterNotifications()[0].ID.String(), response.ActivityCenterNotifications()[0].Message.ID)
|
|
|
|
}
|