desktop: better status check of loaded remote files (#3453)
This commit is contained in:
parent
97934c8289
commit
50bada24af
@ -3,6 +3,7 @@ package chat.simplex.common.model
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.font.*
|
||||
@ -2303,7 +2304,7 @@ data class CIFile(
|
||||
sent = fileStatus.sent,
|
||||
fileSource = fileSource
|
||||
)
|
||||
cachedRemoteFileRequests.add(fileSource)
|
||||
cachedRemoteFileRequests[fileSource] = false
|
||||
val showAlert = fileSize > 5_000_000 && allowToShowAlert
|
||||
if (showAlert) {
|
||||
AlertManager.shared.showAlertMsgWithProgress(
|
||||
@ -2312,7 +2313,7 @@ data class CIFile(
|
||||
)
|
||||
}
|
||||
val res = chatModel.controller.getRemoteFile(rh.remoteHostId, rf)
|
||||
cachedRemoteFileRequests.remove(fileSource)
|
||||
cachedRemoteFileRequests[fileSource] = res
|
||||
if (showAlert) {
|
||||
AlertManager.shared.hideAlert()
|
||||
}
|
||||
@ -2329,7 +2330,7 @@ data class CIFile(
|
||||
): CIFile =
|
||||
CIFile(fileId = fileId, fileName = fileName, fileSize = fileSize, fileSource = if (filePath == null) null else CryptoFile.plain(filePath), fileStatus = fileStatus, fileProtocol = FileProtocol.XFTP)
|
||||
|
||||
val cachedRemoteFileRequests = SnapshotStateList<CryptoFile>()
|
||||
val cachedRemoteFileRequests = SnapshotStateMap<CryptoFile, Boolean>()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1430,7 +1430,7 @@ object ChatController {
|
||||
return null
|
||||
}
|
||||
|
||||
suspend fun getRemoteFile(rhId: Long, file: RemoteFile): Boolean = sendCommandOkResp(null, CC.GetRemoteFile(rhId, file))
|
||||
suspend fun getRemoteFile(rhId: Long, file: RemoteFile): Boolean = sendCmd(null, CC.GetRemoteFile(rhId, file)) is CR.CmdOk
|
||||
|
||||
suspend fun connectRemoteCtrl(desktopAddress: String): Pair<SomeRemoteCtrl?, CR.ChatCmdError?> {
|
||||
val r = sendCmd(null, CC.ConnectRemoteCtrl(desktopAddress))
|
||||
|
@ -98,7 +98,7 @@ fun getLoadedFileSource(file: CIFile?): CryptoFile? {
|
||||
|
||||
private fun fileReady(file: CIFile, filePath: String) =
|
||||
File(filePath).exists() &&
|
||||
!CIFile.cachedRemoteFileRequests.contains(file.fileSource)
|
||||
CIFile.cachedRemoteFileRequests[file.fileSource] != false
|
||||
&& File(filePath).length() >= file.fileSize
|
||||
|
||||
/**
|
||||
|
@ -850,6 +850,7 @@ fun ComposeView(
|
||||
deleteUnusedFiles()
|
||||
}
|
||||
chatModel.removeLiveDummy()
|
||||
CIFile.cachedRemoteFileRequests.clear()
|
||||
}
|
||||
|
||||
val timedMessageAllowed = remember(chat.chatInfo) { chat.chatInfo.featureEnabled(ChatFeature.TimedMessages) }
|
||||
|
@ -195,7 +195,7 @@ fun ChatItemView(
|
||||
}
|
||||
val clipboard = LocalClipboardManager.current
|
||||
val cachedRemoteReqs = remember { CIFile.cachedRemoteFileRequests }
|
||||
val copyAndShareAllowed = cItem.file == null || !chatModel.connectedToRemote() || getLoadedFilePath(cItem.file) != null || !cachedRemoteReqs.contains(cItem.file.fileSource)
|
||||
val copyAndShareAllowed = cItem.file == null || !chatModel.connectedToRemote() || getLoadedFilePath(cItem.file) != null || cachedRemoteReqs[cItem.file.fileSource] != false
|
||||
if (copyAndShareAllowed) {
|
||||
ItemAction(stringResource(MR.strings.share_verb), painterResource(MR.images.ic_share), onClick = {
|
||||
var fileSource = getLoadedFileSource(cItem.file)
|
||||
@ -221,7 +221,7 @@ fun ChatItemView(
|
||||
showMenu.value = false
|
||||
})
|
||||
}
|
||||
if ((cItem.content.msgContent is MsgContent.MCImage || cItem.content.msgContent is MsgContent.MCVideo || cItem.content.msgContent is MsgContent.MCFile || cItem.content.msgContent is MsgContent.MCVoice) && (getLoadedFilePath(cItem.file) != null || (chatModel.connectedToRemote() && !cachedRemoteReqs.contains(cItem.file?.fileSource)))) {
|
||||
if ((cItem.content.msgContent is MsgContent.MCImage || cItem.content.msgContent is MsgContent.MCVideo || cItem.content.msgContent is MsgContent.MCFile || cItem.content.msgContent is MsgContent.MCVoice) && (getLoadedFilePath(cItem.file) != null || (chatModel.connectedToRemote() && cachedRemoteReqs[cItem.file?.fileSource] != false))) {
|
||||
SaveContentItemAction(cItem, saveFileLauncher, showMenu)
|
||||
}
|
||||
if (cItem.meta.editable && cItem.content.msgContent !is MsgContent.MCVoice && !live) {
|
||||
|
Loading…
Reference in New Issue
Block a user