Add chatID to removed messages
This commit is contained in:
parent
5c408f8ce4
commit
83394e0ed1
|
@ -1196,6 +1196,12 @@ func (db sqlitePersistence) HideMessage(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHideOnMessage set the hide flag, but not the seen flag, as it's needed by the client to understand whether the count should be updated
|
||||||
|
func (db sqlitePersistence) SetHideOnMessage(id string) error {
|
||||||
|
_, err := db.db.Exec(`UPDATE user_messages SET hide = 1 WHERE id = ?`, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) DeleteMessagesByChatID(id string) error {
|
func (db sqlitePersistence) DeleteMessagesByChatID(id string) error {
|
||||||
return db.deleteMessagesByChatID(id, nil)
|
return db.deleteMessagesByChatID(id, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (s *MessengerDeleteMessageSuite) TestDeleteMessage() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(sendResponse.Messages(), 0)
|
s.Require().Len(sendResponse.Messages(), 0)
|
||||||
s.Require().Len(sendResponse.RemovedMessages(), 1)
|
s.Require().Len(sendResponse.RemovedMessages(), 1)
|
||||||
s.Require().Equal(messageID, sendResponse.RemovedMessages()[0])
|
s.Require().Equal(messageID, sendResponse.RemovedMessages()[0].MessageID)
|
||||||
s.Require().Len(sendResponse.Chats(), 1)
|
s.Require().Len(sendResponse.Chats(), 1)
|
||||||
// LastMessage is removed
|
// LastMessage is removed
|
||||||
s.Require().Nil(sendResponse.Chats()[0].LastMessage)
|
s.Require().Nil(sendResponse.Chats()[0].LastMessage)
|
||||||
|
@ -147,7 +147,7 @@ func (s *MessengerDeleteMessageSuite) TestDeleteMessagePreviousLastMessage() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(sendResponse.Messages(), 0)
|
s.Require().Len(sendResponse.Messages(), 0)
|
||||||
s.Require().Len(sendResponse.RemovedMessages(), 1)
|
s.Require().Len(sendResponse.RemovedMessages(), 1)
|
||||||
s.Require().Equal(messageID, sendResponse.RemovedMessages()[0])
|
s.Require().Equal(messageID, sendResponse.RemovedMessages()[0].MessageID)
|
||||||
s.Require().Len(sendResponse.Chats(), 1)
|
s.Require().Len(sendResponse.Chats(), 1)
|
||||||
// LastMessage is updated to previous message
|
// LastMessage is updated to previous message
|
||||||
s.Require().NotNil(sendResponse.Chats()[0].LastMessage)
|
s.Require().NotNil(sendResponse.Chats()[0].LastMessage)
|
||||||
|
|
|
@ -593,7 +593,7 @@ func (m *Messenger) HandleDeleteMessage(state *ReceivedMessageState, deleteMessa
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.persistence.HideMessage(deleteMessage.MessageId)
|
err = m.persistence.SetHideOnMessage(deleteMessage.MessageId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ func (m *Messenger) HandleDeleteMessage(state *ReceivedMessageState, deleteMessa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.Response.AddRemovedMessage(messageID)
|
state.Response.AddRemovedMessage(&RemovedMessage{MessageID: messageID, ChatID: chat.ID})
|
||||||
state.Response.AddChat(chat)
|
state.Response.AddChat(chat)
|
||||||
state.Response.AddNotification(DeletedMessageNotification(messageID, chat))
|
state.Response.AddNotification(DeletedMessageNotification(messageID, chat))
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ func (m *Messenger) DeleteMessageAndSend(ctx context.Context, messageID string)
|
||||||
|
|
||||||
response := &MessengerResponse{}
|
response := &MessengerResponse{}
|
||||||
response.AddMessage(message)
|
response.AddMessage(message)
|
||||||
response.AddRemovedMessage(messageID)
|
response.AddRemovedMessage(&RemovedMessage{MessageID: messageID, ChatID: chat.ID})
|
||||||
response.AddChat(chat)
|
response.AddChat(chat)
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|
|
@ -10,6 +10,11 @@ import (
|
||||||
"github.com/status-im/status-go/services/mailservers"
|
"github.com/status-im/status-go/services/mailservers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RemovedMessage struct {
|
||||||
|
ChatID string `json:"chatId"`
|
||||||
|
MessageID string `json:"messageId"`
|
||||||
|
}
|
||||||
|
|
||||||
type MessengerResponse struct {
|
type MessengerResponse struct {
|
||||||
Contacts []*Contact
|
Contacts []*Contact
|
||||||
Installations []*multidevice.Installation
|
Installations []*multidevice.Installation
|
||||||
|
@ -24,7 +29,7 @@ type MessengerResponse struct {
|
||||||
notifications map[string]*localnotifications.Notification
|
notifications map[string]*localnotifications.Notification
|
||||||
chats map[string]*Chat
|
chats map[string]*Chat
|
||||||
removedChats map[string]bool
|
removedChats map[string]bool
|
||||||
removedMessages map[string]bool
|
removedMessages map[string]*RemovedMessage
|
||||||
communities map[string]*communities.Community
|
communities map[string]*communities.Community
|
||||||
activityCenterNotifications map[string]*ActivityCenterNotification
|
activityCenterNotifications map[string]*ActivityCenterNotification
|
||||||
messages map[string]*common.Message
|
messages map[string]*common.Message
|
||||||
|
@ -37,7 +42,7 @@ func (r *MessengerResponse) MarshalJSON() ([]byte, error) {
|
||||||
responseItem := struct {
|
responseItem := struct {
|
||||||
Chats []*Chat `json:"chats,omitempty"`
|
Chats []*Chat `json:"chats,omitempty"`
|
||||||
RemovedChats []string `json:"removedChats,omitempty"`
|
RemovedChats []string `json:"removedChats,omitempty"`
|
||||||
RemovedMessages []string `json:"removedMessages,omitempty"`
|
RemovedMessages []*RemovedMessage `json:"removedMessages,omitempty"`
|
||||||
Messages []*common.Message `json:"messages,omitempty"`
|
Messages []*common.Message `json:"messages,omitempty"`
|
||||||
Contacts []*Contact `json:"contacts,omitempty"`
|
Contacts []*Contact `json:"contacts,omitempty"`
|
||||||
Installations []*multidevice.Installation `json:"installations,omitempty"`
|
Installations []*multidevice.Installation `json:"installations,omitempty"`
|
||||||
|
@ -94,10 +99,10 @@ func (r *MessengerResponse) RemovedChats() []string {
|
||||||
return chats
|
return chats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) RemovedMessages() []string {
|
func (r *MessengerResponse) RemovedMessages() []*RemovedMessage {
|
||||||
var messages []string
|
var messages []*RemovedMessage
|
||||||
for messageID := range r.removedMessages {
|
for messageID := range r.removedMessages {
|
||||||
messages = append(messages, messageID)
|
messages = append(messages, r.removedMessages[messageID])
|
||||||
}
|
}
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
@ -240,18 +245,18 @@ func (r *MessengerResponse) AddRemovedChat(chatID string) {
|
||||||
r.removedChats[chatID] = true
|
r.removedChats[chatID] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) AddRemovedMessages(messages []string) {
|
func (r *MessengerResponse) AddRemovedMessages(messages []*RemovedMessage) {
|
||||||
for _, m := range messages {
|
for _, m := range messages {
|
||||||
r.AddRemovedMessage(m)
|
r.AddRemovedMessage(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) AddRemovedMessage(messageID string) {
|
func (r *MessengerResponse) AddRemovedMessage(rm *RemovedMessage) {
|
||||||
if r.removedMessages == nil {
|
if r.removedMessages == nil {
|
||||||
r.removedMessages = make(map[string]bool)
|
r.removedMessages = make(map[string]*RemovedMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.removedMessages[messageID] = true
|
r.removedMessages[rm.MessageID] = rm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) AddActivityCenterNotifications(ns []*ActivityCenterNotification) {
|
func (r *MessengerResponse) AddActivityCenterNotifications(ns []*ActivityCenterNotification) {
|
||||||
|
|
Loading…
Reference in New Issue