mirror of
https://github.com/status-im/status-go.git
synced 2025-01-12 23:55:03 +00:00
feat: Ignore AC notifications created before the request to join the community (#4385)
* fix: Ignore AC notifications created before the request to join the community * review fixes
This commit is contained in:
parent
c0f2f76e9a
commit
317ad2f906
@ -2975,6 +2975,20 @@ func (m *Manager) GetRequestToJoinIDByPkAndCommunityID(pk *ecdsa.PublicKey, comm
|
||||
return m.persistence.GetRequestToJoinIDByPkAndCommunityID(common.PubkeyToHex(pk), communityID)
|
||||
}
|
||||
|
||||
func (m *Manager) GetCommunityRequestToJoinClock(pk *ecdsa.PublicKey, communityID string) (uint64, error) {
|
||||
request, err := m.persistence.GetRequestToJoinByPkAndCommunityID(common.PubkeyToHex(pk), []byte(communityID))
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, nil
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if request == nil || request.State != RequestToJoinStateAccepted {
|
||||
return 0, nil
|
||||
}
|
||||
return request.Clock, nil
|
||||
}
|
||||
|
||||
func (m *Manager) UpdateCommunityDescriptionMagnetlinkMessageClock(communityID types.HexBytes, clock uint64) error {
|
||||
community, err := m.GetByIDString(communityID.String())
|
||||
if err != nil {
|
||||
|
@ -3457,6 +3457,23 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
||||
return fmt.Errorf("chat ID '%s' not present", message.LocalChatID)
|
||||
}
|
||||
|
||||
isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo)
|
||||
if !isNotification {
|
||||
return nil
|
||||
}
|
||||
|
||||
if chat.CommunityChat() {
|
||||
joinedClock, err := m.communitiesManager.GetCommunityRequestToJoinClock(&publicKey, message.CommunityID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Ignore mentions & replies in community before joining
|
||||
if message.Clock < joinedClock {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Use albumId as notificationId to prevent multiple notifications
|
||||
// for same message with multiple images
|
||||
var notificationID string
|
||||
@ -3480,8 +3497,6 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
||||
notificationID = message.ID
|
||||
}
|
||||
|
||||
isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo)
|
||||
if isNotification {
|
||||
notification := &ActivityCenterNotification{
|
||||
ID: types.FromHex(notificationID),
|
||||
Name: chat.Name,
|
||||
@ -3496,10 +3511,8 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
||||
AlbumMessages: albumMessages,
|
||||
Read: message.Seen,
|
||||
}
|
||||
return m.addActivityCenterNotification(r.Response, notification, nil)
|
||||
}
|
||||
|
||||
return nil
|
||||
return m.addActivityCenterNotification(r.Response, notification, nil)
|
||||
}
|
||||
|
||||
func (m *Messenger) buildMessageState() *ReceivedMessageState {
|
||||
|
@ -441,3 +441,57 @@ func (s *MessengerActivityCenterMessageSuite) TestMarkAllActivityCenterNotificat
|
||||
|
||||
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
|
||||
}
|
||||
|
||||
func (s *MessengerActivityCenterMessageSuite) TestAliceDoesNotReceiveCommunityNotificationsBeforeJoined() {
|
||||
alice := s.m
|
||||
bob := s.newMessenger()
|
||||
_, err := bob.Start()
|
||||
s.Require().NoError(err)
|
||||
defer bob.Shutdown() // nolint: errcheck
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user