Add preview and counters for CR system messages #16898 (#3872)

This commit is contained in:
flexsurfer 2023-08-11 19:08:54 +02:00 committed by GitHub
parent 52fb1cd605
commit 1ca165c586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View File

@ -1 +1 @@
0.163.6 0.163.7

View File

@ -494,6 +494,10 @@ func (m *Messenger) addContact(ctx context.Context, pubKey, ensName, nickname, d
return nil, err return nil, err
} }
response.AddMessage(updateMessage) response.AddMessage(updateMessage)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return nil, err
}
response.AddChat(chat) response.AddChat(chat)
} }
@ -628,6 +632,10 @@ func (m *Messenger) removeContact(ctx context.Context, response *MessengerRespon
return err return err
} }
response.AddMessage(updateMessage) response.AddMessage(updateMessage)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
response.AddChat(chat) response.AddChat(chat)
// Next we retract a contact request // Next we retract a contact request

View File

@ -938,6 +938,11 @@ func (m *Messenger) handleAcceptContactRequestMessage(state *ReceivedMessageStat
} }
state.Response.AddMessage(updateMessage) state.Response.AddMessage(updateMessage)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
chat.UnviewedMessagesCount++
state.Response.AddChat(chat) state.Response.AddChat(chat)
state.AllChats.Store(chat.ID, chat) state.AllChats.Store(chat.ID, chat)
} }
@ -974,7 +979,7 @@ func (m *Messenger) HandleAcceptContactRequest(state *ReceivedMessageState, mess
return nil return nil
} }
func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, contact *Contact, message protobuf.RetractContactRequest) error { func (m *Messenger) handleRetractContactRequest(state *ReceivedMessageState, contact *Contact, message protobuf.RetractContactRequest) error {
if contact.ID == m.myHexIdentity() { if contact.ID == m.myHexIdentity() {
m.logger.Debug("retraction coming from us, ignoring") m.logger.Debug("retraction coming from us, ignoring")
return nil return nil
@ -992,6 +997,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
if err != nil { if err != nil {
return err return err
} }
timestamp := m.getTimesource().GetCurrentTime() timestamp := m.getTimesource().GetCurrentTime()
updateMessage, err := m.prepareMutualStateUpdateMessage(contact.ID, MutualStateUpdateTypeRemoved, clock, timestamp, false) updateMessage, err := m.prepareMutualStateUpdateMessage(contact.ID, MutualStateUpdateTypeRemoved, clock, timestamp, false)
if err != nil { if err != nil {
@ -1003,8 +1009,14 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
if err != nil { if err != nil {
return err return err
} }
response.AddMessage(updateMessage) state.Response.AddMessage(updateMessage)
response.AddChat(chat)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
chat.UnviewedMessagesCount++
state.Response.AddChat(chat)
notification := &ActivityCenterNotification{ notification := &ActivityCenterNotification{
ID: types.FromHex(uuid.New().String()), ID: types.FromHex(uuid.New().String()),
@ -1017,7 +1029,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
UpdatedAt: m.getCurrentTimeInMillis(), UpdatedAt: m.getCurrentTimeInMillis(),
} }
err = m.addActivityCenterNotification(response, notification) err = m.addActivityCenterNotification(state.Response, notification)
if err != nil { if err != nil {
m.logger.Warn("failed to create activity center notification", zap.Error(err)) m.logger.Warn("failed to create activity center notification", zap.Error(err))
return err return err
@ -1030,7 +1042,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
func (m *Messenger) HandleRetractContactRequest(state *ReceivedMessageState, message protobuf.RetractContactRequest) error { func (m *Messenger) HandleRetractContactRequest(state *ReceivedMessageState, message protobuf.RetractContactRequest) error {
contact := state.CurrentMessageState.Contact contact := state.CurrentMessageState.Contact
err := m.handleRetractContactRequest(state.Response, contact, message) err := m.handleRetractContactRequest(state, contact, message)
if err != nil { if err != nil {
return err return err
} }