[Chat][UI] Participants count shows actual count (#498)

* Call requestParticipants when chat is initialized, unit tests included

* Removed the unnecessary remoteParticipants variable in preview

Co-authored-by: ShaunaSong <93549644+ShaunaSong@users.noreply.github.com>
This commit is contained in:
Dhiraj Gupta 2022-10-13 13:43:08 -04:00 коммит произвёл GitHub
Родитель 5f1f91ae02
Коммит f7a4614cd9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -24,7 +24,7 @@ import com.azure.android.communication.ui.chat.models.RemoteParticipantInfoModel
import com.azure.android.communication.ui.chat.service.sdk.wrapper.CommunicationIdentifier
@Composable
internal fun TypingIndicatorView(participants: List<RemoteParticipantInfoModel>) {
internal fun TypingIndicatorView(participants: Collection<RemoteParticipantInfoModel>) {
val typers = participants.filter { it.isTyping }
AnimatedVisibility(

Просмотреть файл

@ -35,7 +35,7 @@ internal fun ChatScreen(viewModel: ChatScreenViewModel) {
topBar = {
val dispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
ActionBarView(
participantCount = 4,
participantCount = viewModel.participants.count(),
topic = stringResource(R.string.azure_communication_ui_chat_chat_action_bar_title)
) {
dispatcher?.onBackPressed()
@ -57,8 +57,8 @@ internal fun ChatScreen(viewModel: ChatScreenViewModel) {
)
}
viewModel.remoteParticipants?.also { remoteParticipants ->
TypingIndicatorView(participants = remoteParticipants)
viewModel.participants.also { remoteParticipants ->
TypingIndicatorView(participants = remoteParticipants.values)
}
},
bottomBar = { BottomBarView(viewModel.postMessage) }
@ -100,16 +100,17 @@ internal fun ChatScreenPreview() {
state = ChatStatus.INITIALIZED.name,
buildCount = 2,
postMessage = {},
participants = listOf(
RemoteParticipantInfoModel(CommunicationIdentifier.UnknownIdentifier("7A13DD2C-B49F-4521-9364-975F12F6E333"), "John Smith"),
RemoteParticipantInfoModel(CommunicationIdentifier.UnknownIdentifier("931804B1-D72E-4E70-BFEA-7813C7761BD2"), "William Brown"),
RemoteParticipantInfoModel(CommunicationIdentifier.UnknownIdentifier("152D5D76-3DDC-44BE-873F-A4575F8C91DF"), "James Miller"),
RemoteParticipantInfoModel(CommunicationIdentifier.UnknownIdentifier("85FF2697-2ABB-480E-ACCA-09EBE3D6F5EC"), "George Johnson"),
RemoteParticipantInfoModel(CommunicationIdentifier.UnknownIdentifier("DB75F1F0-65E4-46B0-A213-DA4F574659A5"), "Henry Jones"),
).associateBy({ it.userIdentifier.id })
// error = ChatStateError(
// errorCode = ErrorCode.CHAT_JOIN_FAILED
// )
remoteParticipants = listOf(
RemoteParticipantInfoModel(
CommunicationIdentifier.CommunicationUserIdentifier(""),
displayName = "John Doe", isTyping = true
)
)
)
)
}

Просмотреть файл

@ -21,7 +21,7 @@ internal data class ChatScreenViewModel(
var buildCount: Int,
val postMessage: (String) -> Unit,
private val error: ChatStateError? = null,
val remoteParticipants: List<RemoteParticipantInfoModel>? = null
val participants: Map<String, RemoteParticipantInfoModel>
) {
val showError get() = error != null
val errorMessage get() = error?.errorCode?.toString() ?: ""
@ -52,5 +52,6 @@ internal fun buildChatScreenViewModel(
)
)
)
}
},
participants = store.getCurrentState().participantState.participants
)