This commit is contained in:
Халимов Рустам
2026-04-15 02:40:52 +03:00
parent 9560a9235f
commit 8409c51842
16 changed files with 207 additions and 34 deletions
@@ -24,6 +24,7 @@ data class ChatListState(
@HiltViewModel
class ChatListViewModel @Inject constructor(
private val repository: ChatRepository,
private val authRepository: auth.domain.repository.AuthRepository,
private val signalrClient: ChatHubClient,
private val serverConfig: ServerConfig,
private val tokenManager: TokenManager
@@ -33,6 +34,8 @@ class ChatListViewModel @Inject constructor(
val state: StateFlow<ChatListState> = _state.asStateFlow()
init {
updatePushToken()
val isStoriesEnabled = try {
serverConfig.getServerConfig().features.stories
} catch (e: Exception) {
@@ -50,6 +53,21 @@ class ChatListViewModel @Inject constructor(
observeSignalREvents()
}
private fun updatePushToken() {
com.google.firebase.messaging.FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful) {
val token = task.result
viewModelScope.launch {
try {
authRepository.updatePushToken(token)
} catch (e: Exception) {
android.util.Log.e("ChatListVM", "Failed to update push token: ${e.message}")
}
}
}
}
}
private fun getCurrentUserId(): String = tokenManager.getUserId() ?: ""