This commit is contained in:
Халимов Рустам
2026-04-14 10:48:07 +03:00
parent dc051fa9ae
commit d8b0d86534
19 changed files with 504 additions and 184 deletions
@@ -51,7 +51,7 @@ interface ChatApi {
suspend fun markGifShared(@Path("id") id: String, @Body query: String)
@POST("messages/{messageId}/reactions")
suspend fun addReaction(@Path("messageId") messageId: String, @Body emoji: String)
suspend fun addReaction(@Path("messageId") messageId: String, @Query("emoji") emoji: String)
@POST("chats/{chatId}/typing")
suspend fun sendTypingStatus(@Path("chatId") chatId: String)
@@ -18,7 +18,14 @@ data class MessageDto(
@SerializedName("sequenceId") val sequenceId: Int,
@SerializedName("createdAt") val createdAt: String,
@SerializedName("sender") val sender: UserBasicDto,
@SerializedName("media") val media: List<MediaItemDto> = emptyList()
@SerializedName("media") val media: List<MediaItemDto> = emptyList(),
@SerializedName("reactions") val reactions: List<ReactionDto>? = emptyList()
)
data class ReactionDto(
@SerializedName("emoji") val emoji: String,
@SerializedName("count") val count: Int,
@SerializedName("isSetByMe") val isSetByMe: Boolean
)
data class MediaItemDto(
@@ -10,6 +10,9 @@ import chats.data.remote.dto.MessageDto
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
@@ -18,6 +21,7 @@ class ChatHubClient @Inject constructor() {
private var hubConnection: HubConnection? = null
private val _events = MutableSharedFlow<ChatEvent>(extraBufferCapacity = 64)
val events: SharedFlow<ChatEvent> = _events.asSharedFlow()
private val scope = CoroutineScope(Dispatchers.IO)
fun connect(baseUrl: String, accessToken: String) {
if (hubConnection?.connectionState == HubConnectionState.CONNECTED) return
@@ -30,9 +34,17 @@ class ChatHubClient @Inject constructor() {
hubConnection?.onClosed { exception ->
Log.e("ChatHubClient", "Connection closed", exception)
// Optional: Reconnect logic
}
hubConnection?.start()?.blockingAwait()
scope.launch {
try {
hubConnection?.start()?.blockingAwait()
Log.d("ChatHubClient", "SignalR Connected")
} catch (e: Exception) {
Log.e("ChatHubClient", "SignalR Connection Error", e)
}
}
}
private fun setupHandlers() {