diff --git a/changelog.d/6121.bugfix b/changelog.d/6121.bugfix new file mode 100644 index 0000000000..d8049ce9db --- /dev/null +++ b/changelog.d/6121.bugfix @@ -0,0 +1 @@ +Android app does not show correct poll data diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessor.kt index 2ff43d6812..ca224cd543 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessor.kt @@ -84,7 +84,6 @@ internal class DefaultPollAggregationProcessor @Inject constructor( val roomId = event.roomId ?: return false val senderId = event.senderId ?: return false val targetEventId = event.getRelationContent()?.eventId ?: return false - val targetPollContent = getPollContent(session, roomId, targetEventId) ?: return false val annotationsSummaryEntity = getAnnotationsSummaryEntity(realm, roomId, targetEventId) val aggregatedPollSummaryEntity = getAggregatedPollSummaryEntity(realm, annotationsSummaryEntity) @@ -108,7 +107,8 @@ internal class DefaultPollAggregationProcessor @Inject constructor( } val vote = content.getBestResponse()?.answers?.first() ?: return false - if (!targetPollContent.getBestPollCreationInfo()?.answers?.map { it.id }?.contains(vote).orFalse()) { + val targetPollContent = getPollContent(session, roomId, targetEventId) + if (targetPollContent != null && !targetPollContent.getBestPollCreationInfo()?.answers?.map { it.id }?.contains(vote).orFalse()) { return false } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt index 766e51a8e5..248c4b322d 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/aggregation/poll/DefaultPollAggregationProcessorTest.kt @@ -147,6 +147,19 @@ class DefaultPollAggregationProcessorTest { pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, AN_INVALID_POLL_RESPONSE_EVENT).shouldBeFalse() } + @Test + fun `given a poll response event and no existing poll start event, when processing, then is processed and returns true`() { + // Given + mockRoom(roomId = A_ROOM_ID, eventId = AN_EVENT_ID, hasExistingTimelineEvent = false) + every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity() + + // When + val result = pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, A_POLL_RESPONSE_EVENT) + + // Then + result.shouldBeTrue() + } + @Test fun `given a poll end event, when processing, then is processed and return true`() = runTest { // Given @@ -234,11 +247,12 @@ class DefaultPollAggregationProcessorTest { private fun mockRoom( roomId: String, - eventId: String + eventId: String, + hasExistingTimelineEvent: Boolean = true, ) { val room = mockk() every { session.getRoom(roomId) } returns room - every { room.getTimelineEvent(eventId) } returns A_TIMELINE_EVENT + every { room.getTimelineEvent(eventId) } returns if (hasExistingTimelineEvent) A_TIMELINE_EVENT else null } private fun mockRedactionPowerLevels(userId: String, isAbleToRedact: Boolean): PowerLevelsHelper {