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:
parent
f10e70ce96
commit
4026841dc1
|
@ -118,6 +118,8 @@ type Message struct {
|
|||
// Replace indicates that this is a replacement of a message
|
||||
// that has been updated
|
||||
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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue