From 45212b08231e55d256c0cf2d5a0641791c7259c0 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 19 Aug 2021 16:16:45 +0300 Subject: [PATCH] [status-im/status-react#12450] Add push notification for deleted message --- VERSION | 2 +- protocol/local_notifications.go | 11 +++++++++++ protocol/messenger.go | 2 +- protocol/messenger_delete_message_test.go | 8 +++++--- protocol/messenger_handler.go | 10 ++++++---- services/local-notifications/core.go | 3 +++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 4670a4b39..846f23d16 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.83.14 +0.83.15 diff --git a/protocol/local_notifications.go b/protocol/local_notifications.go index 8fe7cc695..0c1dbb317 100644 --- a/protocol/local_notifications.go +++ b/protocol/local_notifications.go @@ -54,6 +54,17 @@ func NewMessageNotification(id string, message *common.Message, chat *Chat, cont return body.toMessageNotification(id, contacts) } +func DeletedMessageNotification(id string, chat *Chat) *localnotifications.Notification { + return &localnotifications.Notification{ + BodyType: localnotifications.TypeMessage, + ID: gethcommon.HexToHash(id), + IsConversation: true, + ConversationID: chat.ID, + Deeplink: chat.DeepLink(), + Deleted: true, + } +} + func NewCommunityRequestToJoinNotification(id string, community *communities.Community, contact *Contact) *localnotifications.Notification { body := &NotificationBody{ Community: community, diff --git a/protocol/messenger.go b/protocol/messenger.go index aecb34498..4a5675667 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2600,7 +2600,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte SigPubKey: publicKey, } - err = m.HandleDeleteMessage(messageState.Response, deleteMessage) + err = m.HandleDeleteMessage(messageState, deleteMessage) if err != nil { logger.Warn("failed to handle DeleteMessage", zap.Error(err)) allMessagesProcessed = false diff --git a/protocol/messenger_delete_message_test.go b/protocol/messenger_delete_message_test.go index d398691ee..65aedddca 100644 --- a/protocol/messenger_delete_message_test.go +++ b/protocol/messenger_delete_message_test.go @@ -212,14 +212,16 @@ func (s *MessengerDeleteMessageSuite) TestDeleteMessageFirstThenMessage() { From: common.PubkeyToHex(&theirMessenger.identity.PublicKey), } - response := &MessengerResponse{} + state := &ReceivedMessageState{ + Response: &MessengerResponse{}, + } // Handle Delete first - err = s.m.HandleDeleteMessage(response, deleteMessage) + err = s.m.HandleDeleteMessage(state, deleteMessage) s.Require().NoError(err) // // Handle chat message - state := &ReceivedMessageState{ + state = &ReceivedMessageState{ Response: &MessengerResponse{}, CurrentMessageState: &CurrentMessageState{ Message: inputMessage.ChatMessage, diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 64b961f9e..717f6dbe7 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -553,14 +553,14 @@ func (m *Messenger) HandleEditMessage(response *MessengerResponse, editMessage E return nil } -func (m *Messenger) HandleDeleteMessage(response *MessengerResponse, deleteMessage DeleteMessage) error { +func (m *Messenger) HandleDeleteMessage(state *ReceivedMessageState, deleteMessage DeleteMessage) error { if err := ValidateDeleteMessage(deleteMessage.DeleteMessage); err != nil { return err } messageID := deleteMessage.MessageId // Check if it's already in the response - originalMessage := response.GetMessage(messageID) + originalMessage := state.Response.GetMessage(messageID) // otherwise pull from database if originalMessage == nil { var err error @@ -603,8 +603,10 @@ func (m *Messenger) HandleDeleteMessage(response *MessengerResponse, deleteMessa return err } } - response.AddRemovedMessage(messageID) - response.AddChat(chat) + + state.Response.AddRemovedMessage(messageID) + state.Response.AddChat(chat) + state.Response.AddNotification(DeletedMessageNotification(messageID, chat)) return nil } diff --git a/services/local-notifications/core.go b/services/local-notifications/core.go index 97187d26f..99f41a8dd 100644 --- a/services/local-notifications/core.go +++ b/services/local-notifications/core.go @@ -40,6 +40,7 @@ type Notification struct { ConversationID string Timestamp uint64 Author NotificationAuthor + Deleted bool } type NotificationAuthor struct { @@ -66,6 +67,7 @@ type notificationAlias struct { ConversationID string `json:"conversationId,omitempty"` Timestamp uint64 `json:"timestamp,omitempty"` Author NotificationAuthor `json:"notificationAuthor,omitempty"` + Deleted bool `json:"deleted,omitempty"` } // MessageEvent - structure used to pass messages from chat to bus @@ -136,6 +138,7 @@ func (n *Notification) MarshalJSON() ([]byte, error) { ConversationID: n.ConversationID, Timestamp: n.Timestamp, Author: n.Author, + Deleted: n.Deleted, } return json.Marshal(alias)