mobile: remove cancelled files (#2154)

This commit is contained in:
spaced4ndy
2023-04-07 17:41:07 +04:00
committed by GitHub
parent ccb52e0acd
commit 717c90c58b
4 changed files with 59 additions and 34 deletions

View File

@@ -1002,6 +1002,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
val chatItem = apiCancelFile(fileId)
if (chatItem != null) {
chatItemSimpleUpdate(user, chatItem)
cleanupFile(chatItem)
}
}
@@ -1417,40 +1418,27 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
chatItemSimpleUpdate(r.user, r.chatItem)
is CR.RcvFileComplete ->
chatItemSimpleUpdate(r.user, r.chatItem)
is CR.RcvFileSndCancelled ->
is CR.RcvFileSndCancelled -> {
chatItemSimpleUpdate(r.user, r.chatItem)
cleanupFile(r.chatItem)
}
is CR.RcvFileProgressXFTP ->
chatItemSimpleUpdate(r.user, r.chatItem)
is CR.SndFileStart ->
chatItemSimpleUpdate(r.user, r.chatItem)
is CR.SndFileComplete -> {
chatItemSimpleUpdate(r.user, r.chatItem)
val cItem = r.chatItem.chatItem
val mc = cItem.content.msgContent
val fileName = cItem.file?.fileName
if (
r.chatItem.chatInfo.chatType == ChatType.Direct
&& mc is MsgContent.MCFile
&& fileName != null
) {
removeFile(appContext, fileName)
}
cleanupDirectFile(r.chatItem)
}
is CR.SndFileRcvCancelled ->
is CR.SndFileRcvCancelled -> {
chatItemSimpleUpdate(r.user, r.chatItem)
cleanupDirectFile(r.chatItem)
}
is CR.SndFileProgressXFTP ->
chatItemSimpleUpdate(r.user, r.chatItem)
is CR.SndFileCompleteXFTP -> {
chatItemSimpleUpdate(r.user, r.chatItem)
val cItem = r.chatItem.chatItem
val mc = cItem.content.msgContent
val fileName = cItem.file?.fileName
if (
mc is MsgContent.MCFile
&& fileName != null
) {
removeFile(appContext, fileName)
}
cleanupFile(r.chatItem)
}
is CR.CallInvitation -> {
chatModel.callManager.reportNewIncomingCall(r.callInvitation)
@@ -1502,6 +1490,24 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
}
}
private fun cleanupDirectFile(aChatItem: AChatItem) {
if (aChatItem.chatInfo.chatType == ChatType.Direct) {
cleanupFile(aChatItem)
}
}
private fun cleanupFile(aChatItem: AChatItem) {
val cItem = aChatItem.chatItem
val mc = cItem.content.msgContent
val fileName = cItem.file?.fileName
if (
mc is MsgContent.MCFile
&& fileName != null
) {
removeFile(appContext, fileName)
}
}
private fun active(user: User): Boolean = user.userId == chatModel.currentUser.value?.userId
private fun withCall(r: CR, contact: Contact, perform: (Call) -> Unit) {