Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinct database flow in datasource #570

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
Expand Down Expand Up @@ -237,6 +238,7 @@ class BlueskyDataSource(
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.Bluesky)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand All @@ -256,6 +258,7 @@ class BlueskyDataSource(
database
.userDao()
.findByKey(MicroBlogKey(id, accountKey.host))
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -1824,7 +1827,8 @@ class BlueskyDataSource(
.getRoomInfo(
roomKey = roomKey,
accountKey = accountKey,
).mapNotNull {
).distinctUntilChanged()
.mapNotNull {
it?.render(accountKey = accountKey)
}
},
Expand Down Expand Up @@ -2031,9 +2035,13 @@ class BlueskyDataSource(
)
},
cacheSource = {
database.messageDao().getRoomTimeline(accountKey = accountKey).map {
it.sumOf { it.timeline.unreadCount.toInt() }
}
database
.messageDao()
.getRoomTimeline(accountKey = accountKey)
.distinctUntilChanged()
.map {
it.sumOf { it.timeline.unreadCount.toInt() }
}
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import dev.dimension.flare.ui.model.mapper.render
import dev.dimension.flare.ui.model.mapper.renderGuest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand Down Expand Up @@ -57,6 +58,7 @@ object GuestDataSource : MicroblogDataSource, KoinComponent {
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.Mastodon)
.distinctUntilChanged()
.mapNotNull {
val content = it?.content
if (content is UserContent.Mastodon) {
Expand All @@ -80,6 +82,7 @@ object GuestDataSource : MicroblogDataSource, KoinComponent {
database
.userDao()
.findByKey(userKey)
.distinctUntilChanged()
.mapNotNull {
val content = it?.content
if (content is UserContent.Mastodon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -272,6 +273,7 @@ class MastodonDataSource(
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.Mastodon)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand All @@ -288,6 +290,7 @@ class MastodonDataSource(
database
.userDao()
.findByKey(userKey)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -368,6 +371,7 @@ class MastodonDataSource(
database
.statusDao()
.get(statusKey, accountKey)
.distinctUntilChanged()
.mapNotNull { it?.content?.render(accountKey, this) }
},
)
Expand All @@ -383,6 +387,7 @@ class MastodonDataSource(
database
.emojiDao()
.get(accountKey.host)
.distinctUntilChanged()
.mapNotNull { it?.toUi()?.toImmutableList() }
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dev.dimension.flare.ui.presenter.compose.ComposeStatus
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -191,6 +192,7 @@ class MisskeyDataSource(
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.Misskey)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand All @@ -212,6 +214,7 @@ class MisskeyDataSource(
database
.userDao()
.findByKey(userKey)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -304,6 +307,7 @@ class MisskeyDataSource(
database
.statusDao()
.get(statusKey, accountKey)
.distinctUntilChanged()
.mapNotNull { it?.content?.render(accountKey, this) }
},
)
Expand All @@ -327,6 +331,7 @@ class MisskeyDataSource(
database
.emojiDao()
.get(accountKey.host)
.distinctUntilChanged()
.mapNotNull { it?.toUi()?.toImmutableList() }
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import dev.dimension.flare.ui.presenter.compose.ComposeStatus
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
Expand Down Expand Up @@ -169,6 +170,7 @@ class VVODataSource(
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.VVo)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand All @@ -190,6 +192,7 @@ class VVODataSource(
database
.userDao()
.findByKey(userKey)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -283,6 +286,7 @@ class VVODataSource(
database
.statusDao()
.get(statusKey, accountKey)
.distinctUntilChanged()
.mapNotNull { it?.content?.render(accountKey, this) }
},
)
Expand Down Expand Up @@ -312,6 +316,7 @@ class VVODataSource(
database
.statusDao()
.get(statusKey, accountKey)
.distinctUntilChanged()
.mapNotNull { it?.content?.render(accountKey, event = this) }
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -219,6 +220,7 @@ class XQTDataSource(
database
.userDao()
.findByHandleAndHost(name, host, PlatformType.xQt)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -247,6 +249,7 @@ class XQTDataSource(
database
.userDao()
.findByKey(userKey)
.distinctUntilChanged()
.mapNotNull { it?.render(accountKey) }
},
)
Expand Down Expand Up @@ -370,6 +373,7 @@ class XQTDataSource(
database
.statusDao()
.get(statusKey, accountKey)
.distinctUntilChanged()
.mapNotNull { it?.content?.render(accountKey, this) }
},
)
Expand Down