[status-im/status-react#12450] Add push notification for deleted message

This commit is contained in:
Roman Volosovskyi 2021-08-19 16:16:45 +03:00
parent c51f9b800c
commit 45212b0823
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
6 changed files with 27 additions and 9 deletions

View File

@ -1 +1 @@
0.83.14 0.83.15

View File

@ -54,6 +54,17 @@ func NewMessageNotification(id string, message *common.Message, chat *Chat, cont
return body.toMessageNotification(id, contacts) 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 { func NewCommunityRequestToJoinNotification(id string, community *communities.Community, contact *Contact) *localnotifications.Notification {
body := &NotificationBody{ body := &NotificationBody{
Community: community, Community: community,

View File

@ -2600,7 +2600,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
SigPubKey: publicKey, SigPubKey: publicKey,
} }
err = m.HandleDeleteMessage(messageState.Response, deleteMessage) err = m.HandleDeleteMessage(messageState, deleteMessage)
if err != nil { if err != nil {
logger.Warn("failed to handle DeleteMessage", zap.Error(err)) logger.Warn("failed to handle DeleteMessage", zap.Error(err))
allMessagesProcessed = false allMessagesProcessed = false

View File

@ -212,14 +212,16 @@ func (s *MessengerDeleteMessageSuite) TestDeleteMessageFirstThenMessage() {
From: common.PubkeyToHex(&theirMessenger.identity.PublicKey), From: common.PubkeyToHex(&theirMessenger.identity.PublicKey),
} }
response := &MessengerResponse{} state := &ReceivedMessageState{
Response: &MessengerResponse{},
}
// Handle Delete first // Handle Delete first
err = s.m.HandleDeleteMessage(response, deleteMessage) err = s.m.HandleDeleteMessage(state, deleteMessage)
s.Require().NoError(err) s.Require().NoError(err)
// // Handle chat message // // Handle chat message
state := &ReceivedMessageState{ state = &ReceivedMessageState{
Response: &MessengerResponse{}, Response: &MessengerResponse{},
CurrentMessageState: &CurrentMessageState{ CurrentMessageState: &CurrentMessageState{
Message: inputMessage.ChatMessage, Message: inputMessage.ChatMessage,

View File

@ -553,14 +553,14 @@ func (m *Messenger) HandleEditMessage(response *MessengerResponse, editMessage E
return nil 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 { if err := ValidateDeleteMessage(deleteMessage.DeleteMessage); err != nil {
return err return err
} }
messageID := deleteMessage.MessageId messageID := deleteMessage.MessageId
// Check if it's already in the response // Check if it's already in the response
originalMessage := response.GetMessage(messageID) originalMessage := state.Response.GetMessage(messageID)
// otherwise pull from database // otherwise pull from database
if originalMessage == nil { if originalMessage == nil {
var err error var err error
@ -603,8 +603,10 @@ func (m *Messenger) HandleDeleteMessage(response *MessengerResponse, deleteMessa
return err return err
} }
} }
response.AddRemovedMessage(messageID)
response.AddChat(chat) state.Response.AddRemovedMessage(messageID)
state.Response.AddChat(chat)
state.Response.AddNotification(DeletedMessageNotification(messageID, chat))
return nil return nil
} }

View File

@ -40,6 +40,7 @@ type Notification struct {
ConversationID string ConversationID string
Timestamp uint64 Timestamp uint64
Author NotificationAuthor Author NotificationAuthor
Deleted bool
} }
type NotificationAuthor struct { type NotificationAuthor struct {
@ -66,6 +67,7 @@ type notificationAlias struct {
ConversationID string `json:"conversationId,omitempty"` ConversationID string `json:"conversationId,omitempty"`
Timestamp uint64 `json:"timestamp,omitempty"` Timestamp uint64 `json:"timestamp,omitempty"`
Author NotificationAuthor `json:"notificationAuthor,omitempty"` Author NotificationAuthor `json:"notificationAuthor,omitempty"`
Deleted bool `json:"deleted,omitempty"`
} }
// MessageEvent - structure used to pass messages from chat to bus // MessageEvent - structure used to pass messages from chat to bus
@ -136,6 +138,7 @@ func (n *Notification) MarshalJSON() ([]byte, error) {
ConversationID: n.ConversationID, ConversationID: n.ConversationID,
Timestamp: n.Timestamp, Timestamp: n.Timestamp,
Author: n.Author, Author: n.Author,
Deleted: n.Deleted,
} }
return json.Marshal(alias) return json.Marshal(alias)