feat: Implement real-time UI updates for new messages in MessageRepository; refactor ChatViewModel to avoid message duplication
This commit is contained in:
@@ -62,6 +62,10 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
private val _dialogs = MutableStateFlow<List<Dialog>>(emptyList())
|
||||
val dialogs: StateFlow<List<Dialog>> = _dialogs.asStateFlow()
|
||||
|
||||
// 🔔 События новых сообщений для обновления UI в реальном времени
|
||||
private val _newMessageEvents = MutableSharedFlow<String>(replay = 0, extraBufferCapacity = 10)
|
||||
val newMessageEvents: SharedFlow<String> = _newMessageEvents.asSharedFlow()
|
||||
|
||||
// Текущий аккаунт
|
||||
private var currentAccount: String? = null
|
||||
private var currentPrivateKey: String? = null
|
||||
@@ -321,6 +325,9 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
if (!stillExists) {
|
||||
val message = entity.toMessage()
|
||||
updateMessageCache(dialogKey, message)
|
||||
|
||||
// 🔔 Уведомляем UI о новом сообщении (emit dialogKey для обновления)
|
||||
_newMessageEvents.tryEmit(dialogKey)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user