Skip to content

Commit

Permalink
Add preview and counters for CR system messages #16898 (#3872)
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Aug 11, 2023
1 parent 52fb1cd commit 1ca165c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.163.6
0.163.7
8 changes: 8 additions & 0 deletions protocol/messenger_contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ func (m *Messenger) addContact(ctx context.Context, pubKey, ensName, nickname, d
return nil, err
}
response.AddMessage(updateMessage)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return nil, err
}
response.AddChat(chat)
}

Expand Down Expand Up @@ -628,6 +632,10 @@ func (m *Messenger) removeContact(ctx context.Context, response *MessengerRespon
return err
}
response.AddMessage(updateMessage)
err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
response.AddChat(chat)

// Next we retract a contact request
Expand Down
22 changes: 17 additions & 5 deletions protocol/messenger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,11 @@ func (m *Messenger) handleAcceptContactRequestMessage(state *ReceivedMessageStat
}
state.Response.AddMessage(updateMessage)

err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
chat.UnviewedMessagesCount++
state.Response.AddChat(chat)
state.AllChats.Store(chat.ID, chat)
}
Expand Down Expand Up @@ -974,7 +979,7 @@ func (m *Messenger) HandleAcceptContactRequest(state *ReceivedMessageState, mess
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() {
m.logger.Debug("retraction coming from us, ignoring")
return nil
Expand All @@ -992,6 +997,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
if err != nil {
return err
}

timestamp := m.getTimesource().GetCurrentTime()
updateMessage, err := m.prepareMutualStateUpdateMessage(contact.ID, MutualStateUpdateTypeRemoved, clock, timestamp, false)
if err != nil {
Expand All @@ -1003,8 +1009,14 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
if err != nil {
return err
}
response.AddMessage(updateMessage)
response.AddChat(chat)
state.Response.AddMessage(updateMessage)

err = chat.UpdateFromMessage(updateMessage, m.getTimesource())
if err != nil {
return err
}
chat.UnviewedMessagesCount++
state.Response.AddChat(chat)

notification := &ActivityCenterNotification{
ID: types.FromHex(uuid.New().String()),
Expand All @@ -1017,7 +1029,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con
UpdatedAt: m.getCurrentTimeInMillis(),
}

err = m.addActivityCenterNotification(response, notification)
err = m.addActivityCenterNotification(state.Response, notification)
if err != nil {
m.logger.Warn("failed to create activity center notification", zap.Error(err))
return err
Expand All @@ -1030,7 +1042,7 @@ func (m *Messenger) handleRetractContactRequest(response *MessengerResponse, con

func (m *Messenger) HandleRetractContactRequest(state *ReceivedMessageState, message protobuf.RetractContactRequest) error {
contact := state.CurrentMessageState.Contact
err := m.handleRetractContactRequest(state.Response, contact, message)
err := m.handleRetractContactRequest(state, contact, message)
if err != nil {
return err
}
Expand Down

0 comments on commit 1ca165c

Please sign in to comment.