[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)
|
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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue