mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Use chatMessage.markAsRead() newly added API
This commit is contained in:
parent
e0dc53564e
commit
ded00052b5
8 changed files with 62 additions and 16 deletions
|
|
@ -973,8 +973,14 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
viewModel.markAsRead()
|
||||
} else {
|
||||
val firstUnread = adapter.currentList[firstUnreadMessagePosition]
|
||||
(firstUnread.model as MessageModel).isRead = true
|
||||
viewModel.markFirstUnreadMessageAsRead()
|
||||
if (firstUnread.model is MessageModel) {
|
||||
Log.i("$TAG Marking only first message (to which user scrolled to) as read")
|
||||
firstUnread.model.markAsRead()
|
||||
viewModel.updateUnreadMessageCount()
|
||||
sharedViewModel.updateUnreadMessageCountForCurrentConversationEvent.postValue(
|
||||
Event(true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -281,6 +281,21 @@ class ConversationsListFragment : AbstractMainFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
sharedViewModel.updateUnreadMessageCountForCurrentConversationEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
it.consume {
|
||||
val displayChatRoom = sharedViewModel.displayedChatRoom
|
||||
if (displayChatRoom != null) {
|
||||
val found = listViewModel.conversations.value.orEmpty().find { model ->
|
||||
model.chatRoom == displayChatRoom
|
||||
}
|
||||
found?.updateUnreadCount()
|
||||
}
|
||||
listViewModel.updateUnreadMessagesCount()
|
||||
}
|
||||
}
|
||||
|
||||
// AbstractMainFragment related
|
||||
|
||||
listViewModel.title.value = getString(R.string.bottom_navigation_conversations_label)
|
||||
|
|
|
|||
|
|
@ -196,6 +196,13 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun updateUnreadCount() {
|
||||
coreContext.postOnCoreThread {
|
||||
unreadMessageCount.postValue(chatRoom.unreadMessagesCount)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun toggleMute() {
|
||||
coreContext.postOnCoreThread {
|
||||
|
|
|
|||
|
|
@ -346,6 +346,14 @@ class MessageModel @WorkerThread constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun markAsRead() {
|
||||
coreContext.postOnCoreThread {
|
||||
Log.i("$TAG Marking chat message with ID [$id] as read")
|
||||
chatMessage.markAsRead()
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun updateAvatarModel() {
|
||||
val avatar = coreContext.contactsManager.getContactAvatarModelForAddress(
|
||||
|
|
|
|||
|
|
@ -410,12 +410,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
|
|||
}
|
||||
|
||||
@UiThread
|
||||
fun markFirstUnreadMessageAsRead() {
|
||||
// As we can't mark a single message as read in our SDK, small workaround
|
||||
// TODO FIXME: when SDK will support chatMessage.markAsRead(), use it
|
||||
val unreadCount = unreadMessagesCount.value ?: 0
|
||||
if (unreadCount > 1) {
|
||||
unreadMessagesCount.value = unreadCount - 1
|
||||
fun updateUnreadMessageCount() {
|
||||
coreContext.postOnCoreThread {
|
||||
unreadMessagesCount.postValue(chatRoom.unreadMessagesCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -476,6 +473,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
|
|||
@UiThread
|
||||
fun markAsRead() {
|
||||
coreContext.postOnCoreThread {
|
||||
if (chatRoom.unreadMessagesCount == 0) return@postOnCoreThread
|
||||
Log.i("$TAG Marking chat room as read")
|
||||
chatRoom.markAsRead()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@ open class AbstractMainViewModel @UiThread constructor() : GenericViewModel() {
|
|||
chatRoom: ChatRoom,
|
||||
messages: Array<out ChatMessage>
|
||||
) {
|
||||
updateUnreadMessagesCount()
|
||||
computeUnreadMessagesCount()
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onChatRoomRead(core: Core, chatRoom: ChatRoom) {
|
||||
updateUnreadMessagesCount()
|
||||
computeUnreadMessagesCount()
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -157,7 +157,7 @@ open class AbstractMainViewModel @UiThread constructor() : GenericViewModel() {
|
|||
account.postValue(AccountModel(defaultAccount))
|
||||
}
|
||||
|
||||
updateUnreadMessagesCount()
|
||||
computeUnreadMessagesCount()
|
||||
updateMissedCallsCount()
|
||||
updateAvailableMenus()
|
||||
|
||||
|
|
@ -251,6 +251,13 @@ open class AbstractMainViewModel @UiThread constructor() : GenericViewModel() {
|
|||
navigateToMeetingsEvent.value = Event(true)
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun updateUnreadMessagesCount() {
|
||||
coreContext.postOnCoreThread {
|
||||
computeUnreadMessagesCount()
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun updateMissedCallsCount() {
|
||||
val account = LinphoneUtils.getDefaultAccount()
|
||||
|
|
@ -263,7 +270,7 @@ open class AbstractMainViewModel @UiThread constructor() : GenericViewModel() {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
fun updateUnreadMessagesCount() {
|
||||
fun computeUnreadMessagesCount() {
|
||||
val account = LinphoneUtils.getDefaultAccount()
|
||||
val count = account?.unreadChatMessageCount ?: coreContext.core.unreadChatMessageCount
|
||||
val moreThanOne = count > 1
|
||||
|
|
@ -305,7 +312,7 @@ open class AbstractMainViewModel @UiThread constructor() : GenericViewModel() {
|
|||
account.value?.destroy()
|
||||
account.postValue(AccountModel(defaultAccount ?: core.accountList.first()))
|
||||
|
||||
updateUnreadMessagesCount()
|
||||
computeUnreadMessagesCount()
|
||||
updateMissedCallsCount()
|
||||
} else {
|
||||
Log.e("$TAG Accounts list no supposed to be empty!")
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val filesToShareFromIntent = MutableLiveData<ArrayList<String>>()
|
||||
|
||||
val messageToForwardEvent = MutableLiveData<Event<MessageModel>>()
|
||||
val messageToForwardEvent: MutableLiveData<Event<MessageModel>> by lazy {
|
||||
MutableLiveData<Event<MessageModel>>()
|
||||
}
|
||||
|
||||
var displayedChatRoom: ChatRoom? = null // Prevents the need to go look for the chat room
|
||||
val showConversationEvent: MutableLiveData<Event<Pair<String, String>>> by lazy {
|
||||
|
|
@ -141,6 +143,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<Long>>()
|
||||
}
|
||||
|
||||
val updateUnreadMessageCountForCurrentConversationEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
/* Meetings related */
|
||||
|
||||
var displayedMeeting: ConferenceInfo? = null // Prevents the need to go look for the conference info
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue