Skip to content
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
13 changes: 13 additions & 0 deletions src/main/kotlin/chatserver/ChatRepositories.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package chatserver

import chatserver.profiles.LocalProfilesRepository

class ChatRepositories(
private val profiles: LocalProfilesRepository,
) {
fun writeProfiles(): WriteChatRepository<String> = profiles

fun readProfiles(): ReadChatRepository<ProfileResult> = profiles

fun subscribeProfiles(): SubscribeChatRepository = profiles
}
2 changes: 2 additions & 0 deletions src/main/kotlin/chatserver/ChatServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package chatserver
import chatserver.MessagesRepository.Read
import chatserver.MessagesRepository.Write
import chatserver.profiles.chatServerProfilesModule
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.binds
import org.koin.dsl.module

val chatServerModule =
module {
includes(chatServerProfilesModule)
factory { MockMessages } binds arrayOf(Read::class, Write::class)
factoryOf(::ChatRepositories)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/chatserver/ReadChatRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ReadChatRepository<T : ReadChatRepository.ReadResult<*>> {

fun observe(): Flow<T>

interface ReadResult<T> {
sealed interface ReadResult<T> {
val isOk: Boolean
val item: T
val error: Exception?
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/chatserver/WriteChatRepository.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package chatserver

interface WriteChatRepository<T> {
fun interface WriteChatRepository<T> {
fun write(item: T)
}
13 changes: 0 additions & 13 deletions src/main/kotlin/chatserver/profiles/ChatServerProfiles.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package chatserver.profiles

import arch.RokyDispatchers
import chatserver.ProfileResult
import chatserver.ReadChatRepository
import chatserver.SubscribeChatRepository
import chatserver.WriteChatRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.koin.dsl.module
Expand All @@ -19,13 +15,4 @@ val chatServerProfilesModule =
),
)
}
factory<ReadChatRepository<ProfileResult>> {
get<LocalProfilesRepository>()
}
factory<WriteChatRepository<String>> {
get<LocalProfilesRepository>()
}
factory<SubscribeChatRepository> {
get<LocalProfilesRepository>()
}
}
3 changes: 1 addition & 2 deletions src/main/kotlin/profile/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ val profileModules =
scoped {
ProfilePresenter(
windowScope = get<ProfileWindow>().windowScope,
requestUsername = get(),
usernames = get(),
repositories = get(),
dispatchers = get(),
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/profile/ProfilePresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package profile

import arch.Presenter
import arch.RokyDispatchers
import chatserver.ChatRepositories
import chatserver.ProfileResult
import chatserver.ReadChatRepository
import chatserver.WriteChatRepository
Expand All @@ -20,6 +21,9 @@ class ProfilePresenter(
private val usernames: ReadChatRepository<ProfileResult>,
dispatchers: RokyDispatchers,
) : Presenter<ProfileView>(dispatchers) {
constructor(windowScope: CoroutineScope, repositories: ChatRepositories, dispatchers: RokyDispatchers) :
this(windowScope, repositories.writeProfiles(), repositories.readProfiles(), dispatchers)

private val state: MutableStateFlow<ProfileViewState> = MutableStateFlow(Idle)

override fun onAttach(view: ProfileView) {
Expand Down
Loading