From fa136ebaa7edd1ff9bdd180cfc441162c285ad72 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 4 Nov 2020 15:35:23 +0200 Subject: [PATCH] Allow receiving old messages after rejoining a pubchat --- VERSION | 2 +- protocol/message_handler.go | 2 +- protocol/messenger_test.go | 31 ++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 2d9cdfc21..068337d83 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.63.2 +0.63.3 diff --git a/protocol/message_handler.go b/protocol/message_handler.go index 103c45251..e09bb802f 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -355,7 +355,7 @@ func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error { } // If deleted-at is greater, ignore message - if chat.DeletedAtClockValue >= receivedMessage.Clock { + if chat.DeletedAtClockValue >= receivedMessage.Clock && !chat.Public() { return nil } diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index fc0949642..fbc8567c2 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -566,6 +566,35 @@ func (s *MessengerSuite) TestRetrieveTheirPublic() { } func (s *MessengerSuite) TestDeletedAtClockValue() { + theirMessenger := s.newMessenger(s.shh) + s.Require().NoError(theirMessenger.Start()) + theirChat := CreateOneToOneChat("XXX", &s.privateKey.PublicKey, s.m.transport) + err := theirMessenger.SaveChat(&theirChat) + s.Require().NoError(err) + + ourChat := CreateOneToOneChat("our-chat", &theirMessenger.identity.PublicKey, s.m.transport) + ourChat.UnviewedMessagesCount = 1 + s.Require().NoError(err) + + inputMessage := buildTestMessage(theirChat) + + sendResponse, err := theirMessenger.SendChatMessage(context.Background(), inputMessage) + s.NoError(err) + s.Require().Len(sendResponse.Messages, 1) + + ourChat.DeletedAtClockValue = sendResponse.Messages[0].Clock + err = s.m.SaveChat(&ourChat) + s.NoError(err) + + // Wait for the message to reach its destination + time.Sleep(100 * time.Millisecond) + response, err := s.m.RetrieveAll() + s.Require().NoError(err) + s.Require().Len(response.Messages, 0) + s.Require().NoError(theirMessenger.Shutdown()) +} + +func (s *MessengerSuite) TestDeletedAtClockValuePubChat() { theirMessenger := s.newMessenger(s.shh) s.Require().NoError(theirMessenger.Start()) theirChat := CreatePublicChat("status", s.m.transport) @@ -592,7 +621,7 @@ func (s *MessengerSuite) TestDeletedAtClockValue() { time.Sleep(100 * time.Millisecond) response, err := s.m.RetrieveAll() s.Require().NoError(err) - s.Require().Len(response.Messages, 0) + s.Require().Len(response.Messages, 1) s.Require().NoError(theirMessenger.Shutdown()) }