diff --git a/src/main/kotlin/chatserver/ChatRepositories.kt b/src/main/kotlin/chatserver/ChatRepositories.kt new file mode 100644 index 0000000..9ae4cf0 --- /dev/null +++ b/src/main/kotlin/chatserver/ChatRepositories.kt @@ -0,0 +1,13 @@ +package chatserver + +import chatserver.profiles.LocalProfilesRepository + +class ChatRepositories( + private val profiles: LocalProfilesRepository, +) { + fun writeProfiles(): WriteChatRepository = profiles + + fun readProfiles(): ReadChatRepository = profiles + + fun subscribeProfiles(): SubscribeChatRepository = profiles +} diff --git a/src/main/kotlin/chatserver/ChatServer.kt b/src/main/kotlin/chatserver/ChatServer.kt index 78afe87..19e9b15 100644 --- a/src/main/kotlin/chatserver/ChatServer.kt +++ b/src/main/kotlin/chatserver/ChatServer.kt @@ -3,6 +3,7 @@ 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 @@ -10,4 +11,5 @@ val chatServerModule = module { includes(chatServerProfilesModule) factory { MockMessages } binds arrayOf(Read::class, Write::class) + factoryOf(::ChatRepositories) } diff --git a/src/main/kotlin/chatserver/ReadChatRepository.kt b/src/main/kotlin/chatserver/ReadChatRepository.kt index 935ba4b..d34eec7 100644 --- a/src/main/kotlin/chatserver/ReadChatRepository.kt +++ b/src/main/kotlin/chatserver/ReadChatRepository.kt @@ -7,7 +7,7 @@ interface ReadChatRepository> { fun observe(): Flow - interface ReadResult { + sealed interface ReadResult { val isOk: Boolean val item: T val error: Exception? diff --git a/src/main/kotlin/chatserver/WriteChatRepository.kt b/src/main/kotlin/chatserver/WriteChatRepository.kt index eb4c523..25a7423 100644 --- a/src/main/kotlin/chatserver/WriteChatRepository.kt +++ b/src/main/kotlin/chatserver/WriteChatRepository.kt @@ -1,5 +1,5 @@ package chatserver -interface WriteChatRepository { +fun interface WriteChatRepository { fun write(item: T) } diff --git a/src/main/kotlin/chatserver/profiles/ChatServerProfiles.kt b/src/main/kotlin/chatserver/profiles/ChatServerProfiles.kt index 311caee..1b3816d 100644 --- a/src/main/kotlin/chatserver/profiles/ChatServerProfiles.kt +++ b/src/main/kotlin/chatserver/profiles/ChatServerProfiles.kt @@ -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 @@ -19,13 +15,4 @@ val chatServerProfilesModule = ), ) } - factory> { - get() - } - factory> { - get() - } - factory { - get() - } } diff --git a/src/main/kotlin/profile/Profile.kt b/src/main/kotlin/profile/Profile.kt index 577e637..a587a0c 100644 --- a/src/main/kotlin/profile/Profile.kt +++ b/src/main/kotlin/profile/Profile.kt @@ -8,8 +8,7 @@ val profileModules = scoped { ProfilePresenter( windowScope = get().windowScope, - requestUsername = get(), - usernames = get(), + repositories = get(), dispatchers = get(), ) } diff --git a/src/main/kotlin/profile/ProfilePresenter.kt b/src/main/kotlin/profile/ProfilePresenter.kt index a4503f5..695c9f6 100644 --- a/src/main/kotlin/profile/ProfilePresenter.kt +++ b/src/main/kotlin/profile/ProfilePresenter.kt @@ -2,6 +2,7 @@ package profile import arch.Presenter import arch.RokyDispatchers +import chatserver.ChatRepositories import chatserver.ProfileResult import chatserver.ReadChatRepository import chatserver.WriteChatRepository @@ -20,6 +21,9 @@ class ProfilePresenter( private val usernames: ReadChatRepository, dispatchers: RokyDispatchers, ) : Presenter(dispatchers) { + constructor(windowScope: CoroutineScope, repositories: ChatRepositories, dispatchers: RokyDispatchers) : + this(windowScope, repositories.writeProfiles(), repositories.readProfiles(), dispatchers) + private val state: MutableStateFlow = MutableStateFlow(Idle) override fun onAttach(view: ProfileView) {