Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Read receipts not generated when responding from notification (WPB-8756) #2994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ internal interface MessageRepository {
)
suspend fun persistMessage(
message: Message.Standalone,
updateConversationReadDate: Boolean = false,
updateConversationModifiedDate: Boolean = false,
): Either<CoreFailure, InsertMessageResult>

Expand Down Expand Up @@ -321,12 +320,10 @@ internal class MessageDataSource internal constructor(
)
override suspend fun persistMessage(
message: Message.Standalone,
updateConversationReadDate: Boolean,
updateConversationModifiedDate: Boolean,
): Either<CoreFailure, InsertMessageResult> = wrapStorageRequest {
messageDAO.insertOrIgnoreMessage(
messageMapper.fromMessageToEntity(message),
updateConversationReadDate,
updateConversationModifiedDate
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ internal class PersistMessageUseCaseImpl(
override suspend operator fun invoke(message: Message.Standalone): Either<CoreFailure, Unit> {
val modifiedMessage = getExpectsReadConfirmationFromMessage(message)
val isSelfSender = message.isSelfTheSender(selfUserId)
val shouldUpdateConversationReadDate = modifiedMessage.content !is MessageContent.MissedCall && isSelfSender

return messageRepository.persistMessage(
message = modifiedMessage,
updateConversationReadDate = shouldUpdateConversationReadDate,
updateConversationModifiedDate = message.content.shouldUpdateConversationOrder()
).onSuccess {
val isConversationMuted = it == InsertMessageResult.INSERTED_INTO_MUTED_CONVERSATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class MessageRepositoryTest {
}.wasInvoked(exactly = once)

coVerify {
messageDAO.insertOrIgnoreMessage(eq(mappedEntity), any(), any())
messageDAO.insertOrIgnoreMessage(eq(mappedEntity), any())
}.wasInvoked(exactly = once)
}
}
Expand Down Expand Up @@ -764,7 +764,7 @@ class MessageRepositoryTest {

suspend fun withInsertOrIgnoreMessage(result: InsertMessageResult) = apply {
coEvery {
messageDAO.insertOrIgnoreMessage(any(), any(), any())
messageDAO.insertOrIgnoreMessage(any(), any())
}.returns(result)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PersistMessageUseCaseTest {
result.shouldFail()

coVerify {
arrangement.messageRepository.persistMessage(any(), any(), any())
arrangement.messageRepository.persistMessage(any(), any())
}.wasInvoked(once)

coVerify {
Expand All @@ -76,7 +76,7 @@ class PersistMessageUseCaseTest {
result.shouldSucceed()

coVerify {
arrangement.messageRepository.persistMessage(any(), any(), any())
arrangement.messageRepository.persistMessage(any(), any())
}.wasInvoked(once)

coVerify {
Expand All @@ -102,7 +102,7 @@ class PersistMessageUseCaseTest {
result.shouldSucceed()

coVerify {
arrangement.messageRepository.persistMessage(any(), any(), any())
arrangement.messageRepository.persistMessage(any(), any())
}.wasInvoked(once)

coVerify {
Expand All @@ -114,22 +114,6 @@ class PersistMessageUseCaseTest {
}.wasNotInvoked()
}

@Test
fun givenMissedCallMessage_whenRunningUseCase_thenCallPersistMessageWithUpdateConversationReadDateIsFalse() =
runTest {
val (arrangement, persistMessage) = Arrangement()
.withPersistMessageSuccess()
.arrange()
val missedCallMessage = TestMessage.MISSED_CALL_MESSAGE

val result = persistMessage.invoke(missedCallMessage)

result.shouldSucceed()
coVerify {
arrangement.messageRepository.persistMessage(any(), eq(false), any())
}.wasInvoked(once)
}

private class Arrangement {
@Mock
val messageRepository = mock(MessageRepository::class)
Expand All @@ -145,13 +129,13 @@ class PersistMessageUseCaseTest {

suspend fun withPersistMessageSuccess() = apply {
coEvery {
messageRepository.persistMessage(any(), any(), any())
messageRepository.persistMessage(any(), any())
}.returns(Either.Right(InsertMessageResult.INSERTED_NEED_TO_NOTIFY_USER))
}

suspend fun withPersistMessageFailure() = apply {
coEvery {
messageRepository.persistMessage(any(), any(), any())
messageRepository.persistMessage(any(), any())
}.returns(Either.Left(CoreFailure.InvalidEventSenderID))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ interface MessageDAO {
*/
suspend fun insertOrIgnoreMessage(
message: MessageEntity,
updateConversationReadDate: Boolean = false,
updateConversationModifiedDate: Boolean = false
): InsertMessageResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,11 @@ internal class MessageDAOImpl internal constructor(

override suspend fun insertOrIgnoreMessage(
message: MessageEntity,
updateConversationReadDate: Boolean,
updateConversationModifiedDate: Boolean
) = withContext(coroutineContext) {
queries.transactionWithResult {
val messageCreationInstant = message.date

if (updateConversationReadDate) {
conversationsQueries.updateConversationReadDate(messageCreationInstant, message.conversationId)
unreadEventsQueries.deleteUnreadEvents(message.date, message.conversationId)
}

insertInDB(message)

val needsToBeNotified = nonSuspendNeedsToBeNotified(message.id, message.conversationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

@OptIn(ExperimentalCoroutinesApi::class)
class MessageTextEditTest : BaseMessageTest() {

@Test
Expand Down Expand Up @@ -247,16 +246,15 @@ class MessageTextEditTest : BaseMessageTest() {
}

@Test
fun givenTextWasInsertedAndIsRead_whenUpdatingContentWithSelfMention_thenUnreadEventShouldNotChange() = runTest {
fun givenTextWasInsertedAndIsNotRead_whenUpdatingContentWithSelfMention_thenUnreadEventShouldNotChange() = runTest {
// Given
val initMentions = listOf(
MessageEntity.Mention(0, 1, SELF_USER_ID),
MessageEntity.Mention(2, 3, OTHER_USER.id)
)

insertInitialDataWithMentions(
mentions = initMentions,
updateConversationReadDate = true
mentions = initMentions
)

// When
Expand All @@ -276,20 +274,19 @@ class MessageTextEditTest : BaseMessageTest() {
val unreadEvents = messageDAO.observeUnreadEvents()
.first()[CONVERSATION_ID]

assertTrue(unreadEvents.isNullOrEmpty())
assertNotNull(unreadEvents)
assertEquals(1, unreadEvents.size)
}

private suspend fun insertInitialDataWithMentions(
mentions: List<MessageEntity.Mention>,
updateConversationReadDate: Boolean = false
) {
super.insertInitialData()

messageDAO.insertOrIgnoreMessage(
ORIGINAL_MESSAGE.copy(
content = ORIGINAL_CONTENT.copy(mentions = mentions)
),
updateConversationReadDate = updateConversationReadDate
)
)
}

Expand Down
Loading