mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 20:29:10 +03:00
Fix ending poll power level condition.
This commit is contained in:
parent
4c079cc0ac
commit
edd35872f3
3 changed files with 16 additions and 4 deletions
1
changelog.d/6074.bugfix
Normal file
1
changelog.d/6074.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Poll refactoring with unit tests
|
|
@ -140,8 +140,10 @@ class DefaultPollAggregationProcessor @Inject constructor() : PollAggregationPro
|
|||
aggregatedPollSummaryEntity.sourceEvents.add(event.eventId)
|
||||
}
|
||||
|
||||
val myVote = existingVotes.find { it.userId == session.myUserId }?.option
|
||||
|
||||
val newSumModel = PollSummaryContent(
|
||||
myVote = vote,
|
||||
myVote = myVote,
|
||||
votes = existingVotes,
|
||||
votesSummary = newVotesSummary,
|
||||
totalVotes = totalVotes,
|
||||
|
@ -159,7 +161,7 @@ class DefaultPollAggregationProcessor @Inject constructor() : PollAggregationPro
|
|||
val pollOwnerId = getPollEvent(session, roomId, pollEventId)?.root?.senderId
|
||||
val isPollOwner = pollOwnerId == event.senderId
|
||||
|
||||
if (!isPollOwner || !powerLevelsHelper.isUserAbleToRedact(event.senderId ?: "")) {
|
||||
if (!isPollOwner && !powerLevelsHelper.isUserAbleToRedact(event.senderId ?: "")) {
|
||||
Timber.v("## Received poll.end event $pollEventId but user ${event.senderId} doesn't have enough power level in room $roomId")
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -196,6 +196,7 @@ class PollAggregationProcessorTest {
|
|||
fun setup() {
|
||||
mockEventAnnotationsSummaryEntity()
|
||||
mockRoom(A_ROOM_ID, AN_EVENT_ID)
|
||||
every { session.myUserId } returns A_USER_ID_1
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -259,10 +260,18 @@ class PollAggregationProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `given a poll end event without redaction power level is not processed by poll aggregator`() {
|
||||
fun `given a poll end event without redaction power level of event owner is processed by poll aggregator`() {
|
||||
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
||||
val powerLevelsHelper = mockRedactionPowerLevels(A_USER_ID_1, false)
|
||||
pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT).shouldBeFalse()
|
||||
pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, A_POLL_END_EVENT).shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a poll end event without redaction power level of non event owner is not processed by poll aggregator`() {
|
||||
every { realm.instance.createObject(PollResponseAggregatedSummaryEntity::class.java) } returns PollResponseAggregatedSummaryEntity()
|
||||
val powerLevelsHelper = mockRedactionPowerLevels("another-sender-id", false)
|
||||
val event = A_POLL_END_EVENT.copy(senderId = "another-sender-id")
|
||||
pollAggregationProcessor.handlePollEndEvent(session, powerLevelsHelper, realm.instance, event).shouldBeFalse()
|
||||
}
|
||||
|
||||
private inline fun <reified T : RealmModel> RealmQuery<T>.givenEqualTo(fieldName: String, value: String, result: RealmQuery<T>) {
|
||||
|
|
Loading…
Add table
Reference in a new issue