Prevent external file sharing to attach file in already opened conversation if any

This commit is contained in:
Sylvain Berfini 2024-09-17 12:53:18 +02:00
parent 3190a1869d
commit 51dd246971
3 changed files with 22 additions and 0 deletions

View file

@ -615,6 +615,16 @@ class MainActivity : GenericActivity() {
Log.i("$TAG Drawer menu is opened, closing it")
closeDrawerMenu()
}
if (findNavController().currentDestination?.id == R.id.conversationsListFragment) {
if (sharedViewModel.displayedChatRoom != null) {
Log.w(
"$TAG Closing already opened conversation to prevent attaching file in it directly"
)
sharedViewModel.hideConversationEvent.postValue(Event(true))
} else {
Log.i("$TAG No chat room currently displayed, nothing to close")
}
}
val paths = deferred.awaitAll()
for (path in paths) {

View file

@ -364,6 +364,7 @@ open class ConversationFragment : SlidingPaneChildFragment() {
override fun goBack(): Boolean {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
sharedViewModel.displayedChatRoom = null
if (findNavController().currentDestination?.id == R.id.conversationFragment) {
// If not done this fragment won't be paused, which will cause us issues
@ -784,6 +785,13 @@ open class ConversationFragment : SlidingPaneChildFragment() {
}
}
sharedViewModel.hideConversationEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w("$TAG We were asked to close conversation, going back")
goBack()
}
}
sharedViewModel.textToShareFromIntent.observe(viewLifecycleOwner) { text ->
if (text.isNotEmpty()) {
Log.i("$TAG Found text to share from intent")

View file

@ -120,6 +120,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Pair<String, String>>>()
}
val hideConversationEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
// When using keyboard to share gif or other, see RichContentReceiver & RichEditText classes
val richContentUri = MutableLiveData<Event<Uri>>()