Add `New` flag to a received message

This change allows to count unviewed messages properly on the client
side when replied message is attached to reply before being passed.
This commit is contained in:
Roman Volosovskyi 2020-11-10 17:08:32 +02:00
parent f10e70ce96
commit 4026841dc1
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 17 additions and 2 deletions

View File

@ -1 +1 @@
0.63.6
0.63.7

View File

@ -117,7 +117,9 @@ type Message struct {
// Replace indicates that this is a replacement of a message
// that has been updated
Replace string `json:"replace,omitempty"`
Replace string `json:"replace,omitempty"`
New bool `json:"new,omitempty"`
SigPubKey *ecdsa.PublicKey `json:"-"`
// Mentions is an array of mentions for a given message
@ -150,6 +152,7 @@ func (m *Message) MarshalJSON() ([]byte, error) {
Clock uint64 `json:"clock"`
Replace string `json:"replace"`
ResponseTo string `json:"responseTo"`
New bool `json:"new,omitempty"`
EnsName string `json:"ensName"`
Image string `json:"image,omitempty"`
Audio string `json:"audio,omitempty"`
@ -179,6 +182,7 @@ func (m *Message) MarshalJSON() ([]byte, error) {
LocalChatID: m.LocalChatID,
Clock: m.Clock,
ResponseTo: m.ResponseTo,
New: m.New,
EnsName: m.EnsName,
Image: m.Base64Image,
Audio: m.Base64Audio,

View File

@ -2534,12 +2534,23 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
}
}
newMessagesIds := map[string]struct{}{}
for _, message := range messageState.Response.Messages {
newMessagesIds[message.ID] = struct{}{}
}
messagesWithResponses, err := m.pullMessagesAndResponsesFromDB(messageState.Response.Messages)
if err != nil {
return nil, err
}
messageState.Response.Messages = messagesWithResponses
for _, message := range messageState.Response.Messages {
if _, ok := newMessagesIds[message.ID]; ok {
message.New = true
}
}
// Reset installations
m.modifiedInstallations = make(map[string]bool)