dm-32
This commit is contained in:
parent
816983a45c
commit
32eec439e2
2 changed files with 7 additions and 5 deletions
|
|
@ -14,7 +14,6 @@ import javax.inject.Inject
|
|||
class TokenManager @Inject constructor(
|
||||
private val dataStore: DataStore<Preferences>
|
||||
) {
|
||||
private val USER_ID_LIST = stringSetPreferencesKey("user_id_list")
|
||||
// 獲取所有已登入的使用者 ID 清單
|
||||
val allUserIds: Flow<Set<String>> = dataStore.data.map { preferences ->
|
||||
preferences[USER_ID_LIST] ?: emptySet()
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ import kotlinx.coroutines.launch
|
|||
import javax.inject.Inject
|
||||
import com.example.login_v3.data.api.api_class.Message
|
||||
import com.example.login_v3.data.api.api_class.fullContactAvatarUrl
|
||||
import com.example.login_v3.data.repository.basic.TokenManager
|
||||
import com.example.login_v3.home.Message.ViewModel.UserStatus
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
|
||||
//message sending state
|
||||
|
|
@ -41,7 +43,8 @@ sealed interface MessagesUiState {
|
|||
|
||||
@HiltViewModel
|
||||
class ChatViewModel @Inject constructor(
|
||||
private val repository: ChatRoomsRepository
|
||||
private val repository: ChatRoomsRepository,
|
||||
private val tokenManager: TokenManager
|
||||
) : ViewModel() {
|
||||
|
||||
//UI state var
|
||||
|
|
@ -56,6 +59,9 @@ class ChatViewModel @Inject constructor(
|
|||
viewModelScope.launch {
|
||||
_uiState.value = MessagesUiState.Loading
|
||||
|
||||
|
||||
//isMe
|
||||
val currentLoggedInUserId = tokenManager.currentUserId.first() ?: ""
|
||||
// 1. 同時獲取房間資訊與訊息列表
|
||||
val roomResult = repository.getChatRoom(roomId) // ⚠️ 需確保 Repository 有提供此方法
|
||||
val messagesResult = repository.getChatMessages(roomId)
|
||||
|
|
@ -77,9 +83,6 @@ class ChatViewModel @Inject constructor(
|
|||
Triple("聊天室", UserStatus.UNKNOWN, R.drawable.avatar_v1)
|
||||
}
|
||||
|
||||
|
||||
val currentLoggedInUserId = "user_123"
|
||||
|
||||
_uiState.value = MessagesUiState.Success(
|
||||
roomTitle = title,
|
||||
partnerStatus = status,
|
||||
|
|
|
|||
Loading…
Reference in a new issue