Fixed issue with forward message

This commit is contained in:
Sylvain Berfini 2024-09-18 10:39:14 +02:00
parent b2b55305d2
commit fa7486ff36
3 changed files with 43 additions and 6 deletions

View file

@ -55,6 +55,8 @@ class ConversationForwardMessageFragment : SlidingPaneChildFragment() {
private var numberOrAddressPickerDialog: Dialog? = null private var numberOrAddressPickerDialog: Dialog? = null
private var disableConsumingEventOnPause = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -135,6 +137,7 @@ class ConversationForwardMessageFragment : SlidingPaneChildFragment() {
localSipUri, localSipUri,
remoteSipUri remoteSipUri
) )
disableConsumingEventOnPause = true
findNavController().navigate(action) findNavController().navigate(action)
} }
} }
@ -171,10 +174,12 @@ class ConversationForwardMessageFragment : SlidingPaneChildFragment() {
numberOrAddressPickerDialog?.dismiss() numberOrAddressPickerDialog?.dismiss()
numberOrAddressPickerDialog = null numberOrAddressPickerDialog = null
sharedViewModel.messageToForwardEvent.value?.consume { if (!disableConsumingEventOnPause) {
Log.w( sharedViewModel.messageToForwardEvent.value?.consume {
"$TAG Fragment is pausing, consuming forward event to prevent it from being used later" Log.w(
) "$TAG Fragment is pausing, consuming forward event to prevent it from being used later"
)
}
} }
} }

View file

@ -469,8 +469,9 @@ open class ConversationFragment : SlidingPaneChildFragment() {
Log.i("$TAG Found message to forward") Log.i("$TAG Found message to forward")
if (viewModel.isReadOnly.value == true || viewModel.isDisabledBecauseNotSecured.value == true) { if (viewModel.isReadOnly.value == true || viewModel.isDisabledBecauseNotSecured.value == true) {
Log.w( Log.w(
"$TAG Can't forward message in this conversation as it is read only" "$TAG Can't forward message in this conversation as it is read only, keeping it in memory until conversation is joined just in case"
) )
viewModel.pendingForwardMessage = toForward
} else { } else {
sendMessageViewModel.forwardMessage(toForward) sendMessageViewModel.forwardMessage(toForward)
} }
@ -480,6 +481,19 @@ open class ConversationFragment : SlidingPaneChildFragment() {
} }
} }
viewModel.forwardMessageEvent.observe(viewLifecycleOwner) {
it.consume { toForward ->
Log.i("$TAG Found pending message to forward")
if (viewModel.isReadOnly.value == true || viewModel.isDisabledBecauseNotSecured.value == true) {
Log.w(
"$TAG Can't forward message in this conversation as it is still read only"
)
} else {
sendMessageViewModel.forwardMessage(toForward)
}
}
}
viewModel.updateEvents.observe(viewLifecycleOwner) { viewModel.updateEvents.observe(viewLifecycleOwner) {
it.consume { it.consume {
val items = viewModel.eventsList val items = viewModel.eventsList

View file

@ -129,8 +129,14 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
MutableLiveData<Event<Boolean>>() MutableLiveData<Event<Boolean>>()
} }
val forwardMessageEvent: MutableLiveData<Event<MessageModel>> by lazy {
MutableLiveData<Event<MessageModel>>()
}
var eventsList = arrayListOf<EventLogModel>() var eventsList = arrayListOf<EventLogModel>()
var pendingForwardMessage: MessageModel? = null
private var latestMatch: EventLog? = null private var latestMatch: EventLog? = null
private val chatRoomListener = object : ChatRoomListenerStub() { private val chatRoomListener = object : ChatRoomListenerStub() {
@ -138,6 +144,13 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
override fun onConferenceJoined(chatRoom: ChatRoom, eventLog: EventLog) { override fun onConferenceJoined(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG Conversation was joined") Log.i("$TAG Conversation was joined")
computeConversationInfo() computeConversationInfo()
val messageToForward = pendingForwardMessage
if (messageToForward != null) {
Log.i("$TAG Found pending forward message, doing it now")
forwardMessageEvent.postValue(Event(messageToForward))
pendingForwardMessage = null
}
} }
@WorkerThread @WorkerThread
@ -552,7 +565,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
if (!chatRoom.hasCapability(ChatRoom.Capabilities.Encrypted.toInt())) { if (!chatRoom.hasCapability(ChatRoom.Capabilities.Encrypted.toInt())) {
if (LinphoneUtils.getAccountForAddress(chatRoom.localAddress)?.params?.instantMessagingEncryptionMandatory == true) { if (LinphoneUtils.getAccountForAddress(chatRoom.localAddress)?.params?.instantMessagingEncryptionMandatory == true) {
Log.w( Log.w(
"$TAG Conversation with subject [${chatRoom.subject}] has been disabled because it isn't encrypted and default account is in secure mode" "$TAG Conversation with subject [${chatRoom.subject}] is considered as read-only because it isn't encrypted and default account is in secure mode"
) )
isDisabledBecauseNotSecured.postValue(true) isDisabledBecauseNotSecured.postValue(true)
} else { } else {
@ -604,6 +617,11 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
val empty = val empty =
chatRoom.hasCapability(ChatRoom.Capabilities.Conference.toInt()) && chatRoom.participants.isEmpty() chatRoom.hasCapability(ChatRoom.Capabilities.Conference.toInt()) && chatRoom.participants.isEmpty()
if (empty) {
Log.w(
"$TAG Conversation has conference capability but has no participants, will be considered as read only!"
)
}
val readOnly = chatRoom.isReadOnly || empty val readOnly = chatRoom.isReadOnly || empty
isReadOnly.postValue(readOnly) isReadOnly.postValue(readOnly)
if (readOnly) { if (readOnly) {