Merge pull request #8126 from vector-im/fix/mna/poll-votes-aggregation
[Poll] Fix votes aggregation process (PSG-1153)
This commit is contained in:
commit
2ae6cd40c7
|
@ -0,0 +1 @@
|
||||||
|
Android app does not show correct poll data
|
|
@ -84,7 +84,6 @@ internal class DefaultPollAggregationProcessor @Inject constructor(
|
||||||
val roomId = event.roomId ?: return false
|
val roomId = event.roomId ?: return false
|
||||||
val senderId = event.senderId ?: return false
|
val senderId = event.senderId ?: return false
|
||||||
val targetEventId = event.getRelationContent()?.eventId ?: return false
|
val targetEventId = event.getRelationContent()?.eventId ?: return false
|
||||||
val targetPollContent = getPollContent(session, roomId, targetEventId) ?: return false
|
|
||||||
|
|
||||||
val annotationsSummaryEntity = getAnnotationsSummaryEntity(realm, roomId, targetEventId)
|
val annotationsSummaryEntity = getAnnotationsSummaryEntity(realm, roomId, targetEventId)
|
||||||
val aggregatedPollSummaryEntity = getAggregatedPollSummaryEntity(realm, annotationsSummaryEntity)
|
val aggregatedPollSummaryEntity = getAggregatedPollSummaryEntity(realm, annotationsSummaryEntity)
|
||||||
|
@ -108,7 +107,8 @@ internal class DefaultPollAggregationProcessor @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
val vote = content.getBestResponse()?.answers?.first() ?: return false
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,19 @@ class DefaultPollAggregationProcessorTest {
|
||||||
pollAggregationProcessor.handlePollResponseEvent(session, realm.instance, AN_INVALID_POLL_RESPONSE_EVENT).shouldBeFalse()
|
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
|
@Test
|
||||||
fun `given a poll end event, when processing, then is processed and return true`() = runTest {
|
fun `given a poll end event, when processing, then is processed and return true`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
|
@ -234,11 +247,12 @@ class DefaultPollAggregationProcessorTest {
|
||||||
|
|
||||||
private fun mockRoom(
|
private fun mockRoom(
|
||||||
roomId: String,
|
roomId: String,
|
||||||
eventId: String
|
eventId: String,
|
||||||
|
hasExistingTimelineEvent: Boolean = true,
|
||||||
) {
|
) {
|
||||||
val room = mockk<Room>()
|
val room = mockk<Room>()
|
||||||
every { session.getRoom(roomId) } returns 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 {
|
private fun mockRedactionPowerLevels(userId: String, isAbleToRedact: Boolean): PowerLevelsHelper {
|
||||||
|
|
Loading…
Reference in New Issue