mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Do not rely on chatMessageSending callback for scenario where message(s) are queued because of delayed subscribe
This commit is contained in:
parent
dd9190df07
commit
e306c8c7fc
4 changed files with 30 additions and 12 deletions
|
|
@ -63,6 +63,7 @@ import org.linphone.utils.ImageUtils
|
|||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.PhoneNumberUtils
|
||||
import org.linphone.utils.ShortcutUtils
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
class ContactsManager
|
||||
@UiThread
|
||||
|
|
@ -741,6 +742,8 @@ fun Friend.getNativeContactPictureUri(): Uri? {
|
|||
fd.close()
|
||||
return pictureUri
|
||||
}
|
||||
} catch (fnfe: FileNotFoundException) {
|
||||
Log.w("[Contacts Manager] Can't open [$pictureUri] for contact [$name]: $fnfe")
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Contacts Manager] Can't open [$pictureUri] for contact [$name]: $e")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -740,6 +740,12 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
false
|
||||
}
|
||||
|
||||
sendMessageViewModel.messageSentEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { message ->
|
||||
viewModel.addSentMessageToEventsList(message)
|
||||
}
|
||||
}
|
||||
|
||||
sendMessageViewModel.emojiToAddEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { emoji ->
|
||||
binding.sendArea.messageToSend.addCharacterAtPosition(emoji)
|
||||
|
|
|
|||
|
|
@ -196,17 +196,6 @@ class ConversationViewModel
|
|||
Log.i("$TAG Conversation was marked as read")
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onChatMessageSending(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
val message = eventLog.chatMessage
|
||||
Log.i("$TAG Message [$message] is being sent, marking conversation as read")
|
||||
|
||||
// Prevents auto scroll to go to latest received message
|
||||
chatRoom.markAsRead()
|
||||
|
||||
addEvents(arrayOf(eventLog))
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onChatMessagesReceived(chatRoom: ChatRoom, eventLogs: Array<EventLog>) {
|
||||
Log.i("$TAG Received [${eventLogs.size}] new message(s)")
|
||||
|
|
@ -622,6 +611,19 @@ class ConversationViewModel
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun addSentMessageToEventsList(message: ChatMessage) {
|
||||
coreContext.postOnCoreThread {
|
||||
val eventLog = message.eventLog
|
||||
if (eventLog != null) {
|
||||
Log.i("$TAG Adding sent message with ID [${message.messageId}] to events list")
|
||||
addEvents(arrayOf(eventLog))
|
||||
} else {
|
||||
Log.e("$TAG Failed to get event log for sent message with ID [${message.messageId}]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun configureChatRoom() {
|
||||
if (!isChatRoomInitialized()) return
|
||||
|
|
@ -718,7 +720,7 @@ class ConversationViewModel
|
|||
|
||||
@WorkerThread
|
||||
private fun addEvents(eventLogs: Array<EventLog>) {
|
||||
Log.i("$TAG Adding [${eventLogs.size}] events")
|
||||
Log.i("$TAG Adding [${eventLogs.size}] event(s)")
|
||||
// Need to use a new list, otherwise ConversationFragment's dataObserver isn't triggered...
|
||||
val list = arrayListOf<EventLogModel>()
|
||||
list.addAll(eventsList)
|
||||
|
|
|
|||
|
|
@ -135,6 +135,10 @@ class SendMessageInConversationViewModel
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val messageSentEvent: MutableLiveData<Event<ChatMessage>> by lazy {
|
||||
MutableLiveData<Event<ChatMessage>>()
|
||||
}
|
||||
|
||||
lateinit var chatRoom: ChatRoom
|
||||
|
||||
private var chatMessageToReplyTo: ChatMessage? = null
|
||||
|
|
@ -325,6 +329,7 @@ class SendMessageInConversationViewModel
|
|||
val voiceMessage = chatRoom.createEmptyMessage()
|
||||
voiceMessage.addContent(content)
|
||||
voiceMessage.send()
|
||||
messageSentEvent.postValue(Event(voiceMessage))
|
||||
} else {
|
||||
message.addContent(content)
|
||||
}
|
||||
|
|
@ -356,6 +361,7 @@ class SendMessageInConversationViewModel
|
|||
val fileMessage = chatRoom.createEmptyMessage()
|
||||
fileMessage.addFileContent(content)
|
||||
fileMessage.send()
|
||||
messageSentEvent.postValue(Event(fileMessage))
|
||||
} else {
|
||||
message.addFileContent(content)
|
||||
contentAdded = true
|
||||
|
|
@ -366,6 +372,7 @@ class SendMessageInConversationViewModel
|
|||
if (message.contents.isNotEmpty()) {
|
||||
Log.i("$TAG Sending message")
|
||||
message.send()
|
||||
messageSentEvent.postValue(Event(message))
|
||||
}
|
||||
|
||||
Log.i("$TAG Message sent, re-setting defaults")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue