|
16 | 16 |
|
17 | 17 | package im.vector.app.features.roomprofile.polls
|
18 | 18 |
|
| 19 | +import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState |
19 | 20 | import kotlinx.coroutines.flow.Flow
|
20 |
| -import kotlinx.coroutines.flow.emptyFlow |
21 | 21 | import kotlinx.coroutines.flow.flowOf
|
22 | 22 | import kotlinx.coroutines.flow.map
|
23 | 23 | import javax.inject.Inject
|
24 | 24 |
|
25 | 25 | class GetPollsUseCase @Inject constructor() {
|
26 | 26 |
|
27 |
| - fun execute(filter: RoomPollsFilterType): Flow<List<PollSummary>> { |
| 27 | + fun execute(): Flow<List<PollSummary>> { |
28 | 28 | // TODO unmock and add unit tests
|
29 |
| - return when (filter) { |
30 |
| - RoomPollsFilterType.ACTIVE -> getActivePolls() |
31 |
| - RoomPollsFilterType.ENDED -> emptyFlow() |
32 |
| - }.map { it.sortedByDescending { poll -> poll.creationTimestamp } } |
| 29 | + return flowOf(getActivePolls() + getEndedPolls()) |
| 30 | + .map { it.sortedByDescending { poll -> poll.creationTimestamp } } |
33 | 31 | }
|
34 | 32 |
|
35 |
| - private fun getActivePolls(): Flow<List<PollSummary.ActivePoll>> { |
36 |
| - return flowOf( |
37 |
| - listOf( |
38 |
| - PollSummary.ActivePoll( |
39 |
| - id = "id1", |
40 |
| - // 2022/06/28 UTC+1 |
41 |
| - creationTimestamp = 1656367200000, |
42 |
| - title = "Which charity would you like to support?" |
43 |
| - ), |
44 |
| - PollSummary.ActivePoll( |
45 |
| - id = "id2", |
46 |
| - // 2022/06/26 UTC+1 |
47 |
| - creationTimestamp = 1656194400000, |
48 |
| - title = "Which sport should the pupils do this year?" |
| 33 | + private fun getActivePolls(): List<PollSummary.ActivePoll> { |
| 34 | + return listOf( |
| 35 | + PollSummary.ActivePoll( |
| 36 | + id = "id1", |
| 37 | + // 2022/06/28 UTC+1 |
| 38 | + creationTimestamp = 1656367200000, |
| 39 | + title = "Which charity would you like to support?" |
| 40 | + ), |
| 41 | + PollSummary.ActivePoll( |
| 42 | + id = "id2", |
| 43 | + // 2022/06/26 UTC+1 |
| 44 | + creationTimestamp = 1656194400000, |
| 45 | + title = "Which sport should the pupils do this year?" |
| 46 | + ), |
| 47 | + PollSummary.ActivePoll( |
| 48 | + id = "id3", |
| 49 | + // 2022/06/24 UTC+1 |
| 50 | + creationTimestamp = 1656021600000, |
| 51 | + title = "What type of food should we have at the party?" |
| 52 | + ), |
| 53 | + PollSummary.ActivePoll( |
| 54 | + id = "id4", |
| 55 | + // 2022/06/22 UTC+1 |
| 56 | + creationTimestamp = 1655848800000, |
| 57 | + title = "What film should we show at the end of the year party?" |
| 58 | + ), |
| 59 | + ) |
| 60 | + } |
| 61 | + |
| 62 | + private fun getEndedPolls(): List<PollSummary.EndedPoll> { |
| 63 | + return listOf( |
| 64 | + PollSummary.EndedPoll( |
| 65 | + id = "id1-ended", |
| 66 | + // 2022/06/28 UTC+1 |
| 67 | + creationTimestamp = 1656367200000, |
| 68 | + title = "Which charity would you like to support?", |
| 69 | + totalVotes = 22, |
| 70 | + winnerOptions = listOf( |
| 71 | + PollOptionViewState.PollEnded( |
| 72 | + optionId = "id1", |
| 73 | + optionAnswer = "Cancer research", |
| 74 | + voteCount = 13, |
| 75 | + votePercentage = 13 / 22.0, |
| 76 | + isWinner = true, |
| 77 | + ) |
49 | 78 | ),
|
50 |
| - PollSummary.ActivePoll( |
51 |
| - id = "id3", |
52 |
| - // 2022/06/24 UTC+1 |
53 |
| - creationTimestamp = 1656021600000, |
54 |
| - title = "What type of food should we have at the party?" |
| 79 | + ), |
| 80 | + PollSummary.EndedPoll( |
| 81 | + id = "id2-ended", |
| 82 | + // 2022/06/26 UTC+1 |
| 83 | + creationTimestamp = 1656194400000, |
| 84 | + title = "Where should we do the offsite?", |
| 85 | + totalVotes = 92, |
| 86 | + winnerOptions = listOf( |
| 87 | + PollOptionViewState.PollEnded( |
| 88 | + optionId = "id1", |
| 89 | + optionAnswer = "Hawaii", |
| 90 | + voteCount = 43, |
| 91 | + votePercentage = 43 / 92.0, |
| 92 | + isWinner = true, |
| 93 | + ) |
55 | 94 | ),
|
56 |
| - PollSummary.ActivePoll( |
57 |
| - id = "id4", |
58 |
| - // 2022/06/22 UTC+1 |
59 |
| - creationTimestamp = 1655848800000, |
60 |
| - title = "What film should we show at the end of the year party?" |
| 95 | + ), |
| 96 | + PollSummary.EndedPoll( |
| 97 | + id = "id3-ended", |
| 98 | + // 2022/06/24 UTC+1 |
| 99 | + creationTimestamp = 1656021600000, |
| 100 | + title = "What type of food should we have at the party?", |
| 101 | + totalVotes = 22, |
| 102 | + winnerOptions = listOf( |
| 103 | + PollOptionViewState.PollEnded( |
| 104 | + optionId = "id1", |
| 105 | + optionAnswer = "Brazilian", |
| 106 | + voteCount = 13, |
| 107 | + votePercentage = 13 / 22.0, |
| 108 | + isWinner = true, |
| 109 | + ) |
61 | 110 | ),
|
62 |
| - ) |
| 111 | + ), |
63 | 112 | )
|
64 | 113 | }
|
65 | 114 | }
|
0 commit comments