add local GigaChatRepository

This commit is contained in:
2026-09-13 08:17:29 +03:00
parent d6dbf59766
commit 08a7c008a1
10 changed files with 58 additions and 7 deletions
@@ -14,4 +14,5 @@ fun Routing.setupChat(useCase: ProcessUserMessageUseCase) {
val message = call.receive<Message>().copy(timestamp = System.currentTimeMillis()) val message = call.receive<Message>().copy(timestamp = System.currentTimeMillis())
call.respond(useCase.execute(message, MOCK_USER_ID)) call.respond(useCase.execute(message, MOCK_USER_ID))
} }
} }
+2
View File
@@ -29,6 +29,8 @@ dependencies {
implementation(project(":libs:ui")) implementation(project(":libs:ui"))
implementation(project(":libs:http-client")) implementation(project(":libs:http-client"))
implementation(project(":libs:base")) implementation(project(":libs:base"))
implementation(project(":feature:chat:chat-common"))
implementation(libs.activity.compose) implementation(libs.activity.compose)
implementation(libs.androidx.compose.foundation) implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material3)
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
</manifest>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates
src="user"
tools:ignore="AcceptsUserCertificates" />
</trust-anchors>
</base-config>
</network-security-config>
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:name="android.hardware.type.watch" /> <uses-feature android:name="android.hardware.type.watch" />
@@ -11,7 +12,9 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault"> android:networkSecurityConfig="@xml/network_security_config"
android:theme="@android:style/Theme.DeviceDefault"
tools:ignore="WatchFaceFormatDeclaresHasNoCode">
<uses-library <uses-library
android:name="com.google.android.wearable" android:name="com.google.android.wearable"
@@ -0,0 +1,21 @@
package ru.shadowsparky.gigawear.data
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import org.koin.core.annotation.Factory
import ru.shadowsparky.chat.domain.ChatRepository
import ru.shadowsparky.chat.domain.Message
@Factory
class GigaChatRepository(
private val httpClient: HttpClient
) : ChatRepository {
override suspend fun query(afterId: Long?): List<Message> = emptyList()
override suspend fun send(message: Message): Message {
return httpClient.post("http://192.168.0.76:8181/chat") {
setBody(message)
}.body<Message>()
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
@@ -22,7 +22,7 @@ class BackendChatRepository(
return history.sortedBy { it.timestamp } return history.sortedBy { it.timestamp }
} }
override suspend fun send(message: Message) { override suspend fun send(message: Message): Message {
storage.insert(userId, message) error("Must be not called")
} }
} }
@@ -33,8 +33,8 @@ class RemoteChatRepository(
).content.asReversed() ).content.asReversed()
} }
override suspend fun send(message: Message) { override suspend fun send(message: Message): Message {
httpClient.post { return httpClient.post {
setBody(message) setBody(message)
serverConfigurationRepository.getServerConfiguration().apply( serverConfigurationRepository.getServerConfiguration().apply(
this, this,
@@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable
interface ChatRepository { interface ChatRepository {
suspend fun query(afterId: Long?): List<Message> suspend fun query(afterId: Long?): List<Message>
suspend fun send(message: Message) suspend fun send(message: Message): Message
companion object { companion object {
const val ARG_AFTER_ID = "after_id" const val ARG_AFTER_ID = "after_id"