Skip to content

Commit 5bab9cf

Browse files
committed
Hide journal entries not visible to players from the list
1 parent e4976dd commit 5bab9cf

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/compendium/journal/JournalScreenModel.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import dev.gitlive.firebase.firestore.FirebaseFirestore
1414
import kotlinx.coroutines.flow.Flow
1515
import kotlinx.coroutines.flow.combine
1616
import kotlinx.coroutines.flow.distinctUntilChanged
17+
import kotlinx.coroutines.flow.filter
1718
import kotlinx.coroutines.flow.map
1819

1920
class JournalScreenModel(
@@ -31,15 +32,17 @@ class JournalScreenModel(
3132
.right()
3233
.map { userProvider.userId == it.gameMasterId }
3334
.distinctUntilChanged()
34-
val entries =
35-
items
36-
.combine(isGameMaster) { items, isGameMaster ->
37-
if (isGameMaster) {
38-
items
39-
} else {
40-
items.filter { it.isVisibleToPlayers }
41-
}
35+
private val visibleItems =
36+
items.combine(isGameMaster) { items, isGameMaster ->
37+
if (isGameMaster) {
38+
items
39+
} else {
40+
items.filter { it.isVisibleToPlayers }
4241
}
42+
}
43+
44+
val entries =
45+
visibleItems
4346
.map { entries ->
4447
entries.map(JournalEntryItem::fromEntry)
4548
}
@@ -88,7 +91,7 @@ class JournalScreenModel(
8891
}
8992

9093
val entriesTree: Flow<List<TreeItem>> =
91-
items.map { items ->
94+
visibleItems.map { items ->
9295
val pinned =
9396
items.filter { it.isPinned }
9497
.map {

0 commit comments

Comments
 (0)