-
Notifications
You must be signed in to change notification settings - Fork 1
/
TopicProvider.kt
54 lines (48 loc) · 1.43 KB
/
TopicProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.dluvian.voyage.data.provider
import com.dluvian.voyage.core.Topic
import com.dluvian.voyage.data.room.dao.TopicDao
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
class TopicProvider(
private val topicDao: TopicDao,
val forcedFollowStates: Flow<Map<Topic, Boolean>>,
) {
suspend fun getMyTopics() = topicDao.getMyTopics()
suspend fun getAllTopics() = topicDao.getAllTopics()
suspend fun getPopularUnfollowedTopics(limit: Int): List<Topic> {
return topicDao.getUnfollowedTopics(limit = limit)
.ifEmpty { (defaultTopics - topicDao.getMyTopics().toSet()).shuffled() }
}
fun getIsFollowedFlow(topic: Topic): Flow<Boolean> {
return combine(
topicDao.getIsFollowedFlow(topic = topic),
forcedFollowStates
) { db, forced ->
forced[topic] ?: db
}
}
// Not named "getMaxCreatedAt" bc there should only be one createdAt available
suspend fun getCreatedAt() = topicDao.getMaxCreatedAt()
private val defaultTopics = listOf(
"voyage",
"nostr",
"asknostr",
"introductions",
"foodstr",
"food",
"grownostr",
"artstr",
"art",
"nature",
"photography",
"news",
"newstr",
"bitcoin",
"fitness",
"japan",
"spain",
"travel",
"farmstr",
"running",
)
}