From e131d738bd1c0b98a950143229ef43c9601b853e Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:06:24 +0800 Subject: [PATCH] [Fix] Remove AC request notification on community request cancellation (#3381) --- VERSION | 2 +- protocol/communities_messenger_test.go | 14 ++++++++++++++ protocol/messenger_handler.go | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7caf62650..a9087abf4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.142.9 +0.143.0 diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index 9c8fb050c..d5ea8a090 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -1156,6 +1156,9 @@ func (s *MessengerCommunitiesSuite) TestCancelRequestAccess() { if len(response.RequestsToJoinCommunity) == 0 { return errors.New("request to join community not received") } + if len(response.ActivityCenterNotifications()) == 0 { + return errors.New("request to join community notification not added in activity center") + } return nil }) s.Require().NoError(err) @@ -1210,6 +1213,17 @@ func (s *MessengerCommunitiesSuite) TestCancelRequestAccess() { s.Require().NoError(err) s.Require().Len(response.RequestsToJoinCommunity, 1) + // Retrieve activity center notifications for admin to make sure the request notification is deleted + notifications, err := s.bob.ActivityCenterNotifications(ActivityCenterNotificationsRequest{ + Cursor: "", + Limit: 10, + ActivityTypes: []ActivityCenterType{}, + ReadType: ActivityCenterQueryParamsReadUnread, + }) + + s.Require().NoError(err) + s.Require().Len(notifications.Notifications, 0) + cancelRequestToJoin2 := response.RequestsToJoinCommunity[0] s.Require().NotNil(cancelRequestToJoin2) diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 301f49836..a4070220b 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -9,6 +9,8 @@ import ( "runtime" "sync" + "github.com/status-im/status-go/signal" + "github.com/pborman/uuid" "github.com/pkg/errors" "go.uber.org/zap" @@ -1229,6 +1231,28 @@ func (m *Messenger) HandleCommunityCancelRequestToJoin(state *ReceivedMessageSta } state.Response.RequestsToJoinCommunity = append(state.Response.RequestsToJoinCommunity, requestToJoin) + + // delete activity center notification + notification, err := m.persistence.GetActivityCenterNotificationByID(requestToJoin.ID) + if err != nil { + return err + } + + if notification != nil { + err = m.persistence.DeleteActivityCenterNotification(types.FromHex(requestToJoin.ID.String())) + if err != nil { + m.logger.Error("failed to delete notification from Activity Center", zap.Error(err)) + return err + } + + // sending signal to client to remove the activity center notification from UI + response := &MessengerResponse{} + notification.Deleted = true + response.AddActivityCenterNotification(notification) + + signal.SendNewMessages(response) + } + return nil }