[status-im/status-react#12450] Add push notification for deleted message
This commit is contained in:
parent
c51f9b800c
commit
45212b0823
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue