Make sure message has correctly set contact notification state

In case we received a message with propagated state, the message state
wasn't correctly set in the database.
This commit is contained in:
Andrea Maria Piana 2023-02-16 16:01:11 +00:00
parent 08403df4c0
commit dab0e5d6d3
4 changed files with 19 additions and 4 deletions

View File

@ -1 +1 @@
0.131.5
0.131.6

View File

@ -114,6 +114,16 @@ func (s *MessengerContactRequestSuite) TestReceiveAndAcceptContactRequest() { //
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactRequestStatePending, resp.Messages()[0].ContactRequestState)
notifications, err := theirMessenger.ActivityCenterNotifications("", 10)
s.Require().NoError(err)
s.Require().Len(notifications.Notifications, 1)
s.Require().NotNil(common.ContactRequestStatePending, notifications.Notifications[0].Message)
s.Require().Equal(common.ContactRequestStatePending, notifications.Notifications[0].Message.ContactRequestState)
// Check the contact state is correctly set
s.Require().Len(resp.Contacts, 1)
s.Require().Equal(ContactRequestStateReceived, resp.Contacts[0].ContactRequestRemoteState)

View File

@ -1750,6 +1750,11 @@ func (m *Messenger) HandleChatMessage(state *ReceivedMessageState) error {
}
}
if result.newContactRequestReceived {
if contact.hasAddedUs() && !contact.mutual() {
receivedMessage.ContactRequestState = common.ContactRequestStatePending
}
err = m.createContactRequestNotification(contact, state, receivedMessage, true)
if err != nil {
return err

View File

@ -7,9 +7,9 @@ import (
// timeoutManager represents a discrete encapsulation of timeout functionality.
// this struct expose 3 functions:
// - SetTimeout
// - StartTimeout
// - StopTimeout
// - SetTimeout
// - StartTimeout
// - StopTimeout
type timeoutManager struct {
// timeout number of milliseconds the timeout operation will run before executing the `terminate` func()
// 0 represents an inactive timeout