ios: voice message repeat receive ui workaround (#1437)

This commit is contained in:
JRoberts
2022-11-26 12:43:26 +04:00
committed by GitHub
parent 1d819a4af3
commit 9c06acd4bc
7 changed files with 19 additions and 15 deletions

View File

@@ -41,13 +41,13 @@ class AudioRecorder {
AVNumberOfChannelsKey: 1
]
audioRecorder = try AVAudioRecorder(url: getAppFilePath(fileName), settings: settings)
audioRecorder?.record(forDuration: maxVoiceMessageLength)
audioRecorder?.record(forDuration: MAX_VOICE_MESSAGE_LENGTH)
await MainActor.run {
recordingTimer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true) { timer in
guard let time = self.audioRecorder?.currentTime else { return }
self.onTimer?(time)
if time >= maxVoiceMessageLength {
if time >= MAX_VOICE_MESSAGE_LENGTH {
self.stop()
self.onFinishRecording?()
}

View File

@@ -969,14 +969,15 @@ func processReceivedMsg(_ res: ChatResponse) async {
m.addChatItem(cInfo, cItem)
if case .image = cItem.content.msgContent,
let file = cItem.file,
file.fileSize <= maxImageSize,
file.fileSize <= MAX_IMAGE_SIZE,
UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_ACCEPT_IMAGES) {
Task {
await receiveFile(fileId: file.fileId)
}
} else if case .voice = cItem.content.msgContent, // TODO check inlineFileMode != IFMSent
let file = cItem.file,
file.fileSize <= maxImageSize,
file.fileSize <= MAX_IMAGE_SIZE,
file.fileSize > MAX_VOICE_MESSAGE_SIZE_INLINE_SEND,
UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_ACCEPT_IMAGES) {
Task {
await receiveFile(fileId: file.fileId)

View File

@@ -50,7 +50,7 @@ struct CIFileView: View {
func fileSizeValid() -> Bool {
if let file = file {
return file.fileSize <= maxFileSize
return file.fileSize <= MAX_FILE_SIZE
}
return false
}
@@ -66,7 +66,7 @@ struct CIFileView: View {
await receiveFile(fileId: file.fileId)
}
} else {
let prettyMaxFileSize = ByteCountFormatter().string(fromByteCount: maxFileSize)
let prettyMaxFileSize = ByteCountFormatter().string(fromByteCount: MAX_FILE_SIZE)
AlertManager.shared.showAlertMsg(
title: "Large file!",
message: "Your contact sent a file that is larger than currently supported maximum size (\(prettyMaxFileSize))."

View File

@@ -284,11 +284,11 @@ struct ComposeView: View {
}
fileURL.stopAccessingSecurityScopedResource()
if let fileSize = fileSize,
fileSize <= maxFileSize {
fileSize <= MAX_FILE_SIZE {
chosenFile = fileURL
composeState = composeState.copy(preview: .filePreview(fileName: fileURL.lastPathComponent))
} else {
let prettyMaxFileSize = ByteCountFormatter().string(fromByteCount: maxFileSize)
let prettyMaxFileSize = ByteCountFormatter().string(fromByteCount: MAX_FILE_SIZE)
AlertManager.shared.showAlertMsg(
title: "Large file!",
message: "Currently maximum supported file size is \(prettyMaxFileSize)."

View File

@@ -80,7 +80,7 @@ struct ComposeVoiceView: View {
}
.padding(.trailing, 12)
ProgressBar(length: maxVoiceMessageLength, progress: $recordingTime)
ProgressBar(length: MAX_VOICE_MESSAGE_LENGTH, progress: $recordingTime)
}
}

View File

@@ -218,14 +218,15 @@ func receivedMsgNtf(_ res: ChatResponse) async -> (String, UNMutableNotification
var cItem = aChatItem.chatItem
if case .image = cItem.content.msgContent {
if let file = cItem.file,
file.fileSize <= maxImageSize,
file.fileSize <= MAX_IMAGE_SIZE,
privacyAcceptImagesGroupDefault.get() {
let inline = privacyTransferImagesInlineGroupDefault.get()
cItem = apiReceiveFile(fileId: file.fileId, inline: inline)?.chatItem ?? cItem
}
} else if case .voice = cItem.content.msgContent { // TODO check inlineFileMode != IFMSent
if let file = cItem.file,
file.fileSize <= maxImageSize,
file.fileSize <= MAX_IMAGE_SIZE,
file.fileSize > MAX_VOICE_MESSAGE_SIZE_INLINE_SEND,
privacyAcceptImagesGroupDefault.get() {
let inline = privacyTransferImagesInlineGroupDefault.get()
cItem = apiReceiveFile(fileId: file.fileId, inline: inline)?.chatItem ?? cItem

View File

@@ -13,11 +13,13 @@ import OSLog
let logger = Logger()
// maximum image file size to be auto-accepted
public let maxImageSize: Int64 = 236700
public let MAX_IMAGE_SIZE: Int64 = 236700
public let maxFileSize: Int64 = 8000000
public let MAX_FILE_SIZE: Int64 = 8000000
public let maxVoiceMessageLength = TimeInterval(30)
public let MAX_VOICE_MESSAGE_LENGTH = TimeInterval(30)
public let MAX_VOICE_MESSAGE_SIZE_INLINE_SEND: Int64 = 94680
private let CHAT_DB: String = "_chat.db"
@@ -206,7 +208,7 @@ public func saveFileFromURL(_ url: URL) -> String? {
}
public func saveImage(_ uiImage: UIImage) -> String? {
if let imageDataResized = resizeImageToDataSize(uiImage, maxDataSize: maxImageSize) {
if let imageDataResized = resizeImageToDataSize(uiImage, maxDataSize: MAX_IMAGE_SIZE) {
let fileName = generateNewFileName("IMG", "jpg")
return saveFile(imageDataResized, fileName)
}