Protect calls to FileService.downloadFile()
This commit is contained in:
parent
2495fa49f3
commit
511a0c22e2
|
@ -1675,10 +1675,12 @@ class RoomDetailFragment @Inject constructor(
|
||||||
shareText(requireContext(), action.messageContent.body)
|
shareText(requireContext(), action.messageContent.body)
|
||||||
} else if (action.messageContent is MessageWithAttachmentContent) {
|
} else if (action.messageContent is MessageWithAttachmentContent) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val data = session.fileService().downloadFile(messageContent = action.messageContent)
|
val result = runCatching { session.fileService().downloadFile(messageContent = action.messageContent) }
|
||||||
if (isAdded) {
|
if (!isAdded) return@launch
|
||||||
shareMedia(requireContext(), data, getMimeTypeFromUri(requireContext(), data.toUri()))
|
result.fold(
|
||||||
}
|
{ shareMedia(requireContext(), it, getMimeTypeFromUri(requireContext(), it.toUri())) },
|
||||||
|
{ showErrorInSnackbar(it) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1701,16 +1703,22 @@ class RoomDetailFragment @Inject constructor(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val data = session.fileService().downloadFile(messageContent = action.messageContent)
|
val result = runCatching { session.fileService().downloadFile(messageContent = action.messageContent) }
|
||||||
if (isAdded) {
|
if (!isAdded) return@launch
|
||||||
saveMedia(
|
result.fold(
|
||||||
context = requireContext(),
|
{
|
||||||
file = data,
|
saveMedia(
|
||||||
title = action.messageContent.body,
|
context = requireContext(),
|
||||||
mediaMimeType = action.messageContent.mimeType ?: getMimeTypeFromUri(requireContext(), data.toUri()),
|
file = it,
|
||||||
notificationUtils = notificationUtils
|
title = action.messageContent.body,
|
||||||
)
|
mediaMimeType = action.messageContent.mimeType ?: getMimeTypeFromUri(requireContext(), it.toUri()),
|
||||||
}
|
notificationUtils = notificationUtils
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
showErrorInSnackbar(it)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue