[Chat] Visibility of Unread Indicator improvements (#659)

This commit is contained in:
Adam Hammer 2022-12-06 10:11:08 -08:00 коммит произвёл GitHub
Родитель 087d6bb398
Коммит b520bd4843
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 19 добавлений и 23 удалений

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

@ -122,7 +122,9 @@ internal fun ChatScreen(
) {
UnreadMessagesIndicatorView(
scrollState = listState,
visible = viewModel.unreadMessagesIndicatorVisibility,
visible = viewModel.unreadMessagesIndicatorVisibility &&
listState.firstVisibleItemIndex > 1 &&
!(viewModel.messages.lastOrNull()?.isLocalUser ?: true),
unreadCount = viewModel.unreadMessagesCount,
)
}

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

@ -16,7 +16,6 @@ import com.azure.android.communication.ui.chat.redux.state.ChatStatus
import com.azure.android.communication.ui.chat.redux.state.NavigationStatus
import com.azure.android.communication.ui.chat.redux.state.ReduxState
import com.azure.android.communication.ui.chat.utilities.findMessageIdxById
import kotlin.math.max
// View Model for the Chat Screen
internal data class ChatScreenViewModel(
@ -79,15 +78,15 @@ private fun getUnReadMessagesCount(
messages: List<MessageInfoModel>,
): Int {
val lastReadId = store.getCurrentState().chatState.lastReadMessageId
val lastSendId = store.getCurrentState().chatState.lastSendMessageId
if (lastReadId.isEmpty() || lastSendId.isEmpty()) {
if (lastReadId.isEmpty()) {
return 0
}
val internalLastReadIndex = messages.findMessageIdxById(lastReadId.toLong())
val internalLastSendIndex = messages.findMessageIdxById(lastSendId.toLong())
val internalLastIndex = max(internalLastReadIndex, internalLastSendIndex)
return if (internalLastIndex == -1) 0 else messages.size - internalLastIndex - 1
var internalLastReadIndex = messages.findMessageIdxById(lastReadId.toLong())
var selfCount = 0
while (internalLastReadIndex >= 0 && messages[internalLastReadIndex].isCurrentUser) {
internalLastReadIndex--
selfCount++
}
return if (internalLastReadIndex == -1) 0 else messages.size - internalLastReadIndex - 1 - selfCount
}

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

@ -34,9 +34,6 @@ internal class ChatReducerImpl : ChatReducer {
is ChatAction.ThreadDeleted -> {
state.copy(chatInfoModel = state.chatInfoModel.copy(isThreadDeleted = true))
}
is ChatAction.MessageSent -> {
state.copy(lastSendMessageId = action.messageInfoModel.normalizedID.toString())
}
is ChatAction.MessageLastReceived -> {
state.copy(
lastReadMessageId = if (state.lastReadMessageId > action.messageId) state.lastReadMessageId

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

@ -23,7 +23,6 @@ internal class AppReduxState(
isThreadDeleted = false
),
lastReadMessageId = "",
lastSendMessageId = "",
messageContextMenu = MessageContextMenuModel(EMPTY_MESSAGE_INFO_MODEL, emptyList())
)

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

@ -18,6 +18,5 @@ internal data class ChatState(
val chatStatus: ChatStatus,
val chatInfoModel: ChatInfoModel,
val lastReadMessageId: String,
val lastSendMessageId: String,
val messageContextMenu: MessageContextMenuModel,
)

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

@ -24,7 +24,7 @@ internal class ChatReducerUnitTest {
val chatInfoModel = mock<ChatInfoModel>()
val previousState =
ChatState(
ChatStatus.NONE, chatInfoModel, "", "",
ChatStatus.NONE, chatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -45,7 +45,7 @@ internal class ChatReducerUnitTest {
val chatInfoModel = mock<ChatInfoModel>()
val previousState =
ChatState(
ChatStatus.NONE, chatInfoModel, "", "",
ChatStatus.NONE, chatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -66,7 +66,7 @@ internal class ChatReducerUnitTest {
val chatInfoModel = ChatInfoModel(threadId = "", topic = "Previous Chat topic")
val previousState =
ChatState(
ChatStatus.NONE, chatInfoModel, "", "",
ChatStatus.NONE, chatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -75,7 +75,7 @@ internal class ChatReducerUnitTest {
val afterChatInfoModel = ChatInfoModel(threadId = "", topic = "New Chat topic")
val afterState =
ChatState(
ChatStatus.NONE, afterChatInfoModel, "", "",
ChatStatus.NONE, afterChatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -95,7 +95,7 @@ internal class ChatReducerUnitTest {
val chatInfoModel = ChatInfoModel(threadId = "", topic = "", allMessagesFetched = false)
val previousState =
ChatState(
ChatStatus.NONE, chatInfoModel, "", "",
ChatStatus.NONE, chatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -104,7 +104,7 @@ internal class ChatReducerUnitTest {
val afterChatInfoModel = ChatInfoModel(threadId = "", topic = "", allMessagesFetched = true)
val afterState =
ChatState(
ChatStatus.NONE, afterChatInfoModel, "", "",
ChatStatus.NONE, afterChatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -130,7 +130,7 @@ internal class ChatReducerUnitTest {
)
val previousState =
ChatState(
ChatStatus.NONE, chatInfoModel, "", "",
ChatStatus.NONE, chatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)
@ -146,7 +146,7 @@ internal class ChatReducerUnitTest {
)
val afterState =
ChatState(
ChatStatus.NONE, afterChatInfoModel, "", "",
ChatStatus.NONE, afterChatInfoModel, "",
messageContextMenu = MessageContextMenuModel(
EMPTY_MESSAGE_INFO_MODEL, emptyList()
)