Merge pull request #8126 from vector-im/fix/mna/poll-votes-aggregation

[Poll] Fix votes aggregation process (PSG-1153)
This commit is contained in:
Maxime NATUREL 2023-02-16 17:29:45 +01:00 committed by GitHub
commit 2ae6cd40c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

1
changelog.d/6121.bugfix Normal file
View File

@ -0,0 +1 @@
Android app does not show correct poll data

View File

@ -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
}

View File

@ -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<Room>()
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 {