|
@@ -31,6 +31,7 @@ class MediaRecorderManager : LifecycleAwareManager {
|
|
|
private const val VOICE_MESSAGE_CHANNELS = 1
|
|
|
private const val FILE_DATE_PATTERN = "yyyy-MM-dd HH-mm-ss"
|
|
|
private const val VOICE_MESSAGE_FILE_SUFFIX = ".mp3"
|
|
|
+ private const val VOICE_MESSAGE_PREFIX_MAX_LENGTH = 146
|
|
|
}
|
|
|
|
|
|
var currentVoiceRecordFile: String = ""
|
|
@@ -140,14 +141,19 @@ class MediaRecorderManager : LifecycleAwareManager {
|
|
|
private fun setVoiceRecordFileName(context: Context, currentConversation: ConversationModel) {
|
|
|
val simpleDateFormat = SimpleDateFormat(FILE_DATE_PATTERN)
|
|
|
val date: String = simpleDateFormat.format(Date())
|
|
|
+ val regex = "[/\\\\:%]".toRegex()
|
|
|
+ val displayName = currentConversation.displayName.replace(regex, " ")
|
|
|
+ val validDisplayName = displayName.replace("\\s+".toRegex(), " ")
|
|
|
|
|
|
- val fileNameWithoutSuffix = String.format(
|
|
|
+ var fileNameWithoutSuffix = String.format(
|
|
|
context.resources.getString(R.string.nc_voice_message_filename),
|
|
|
date,
|
|
|
- currentConversation.displayName
|
|
|
+ validDisplayName
|
|
|
)
|
|
|
+ if (fileNameWithoutSuffix.length > VOICE_MESSAGE_PREFIX_MAX_LENGTH) {
|
|
|
+ fileNameWithoutSuffix = fileNameWithoutSuffix.substring(0, VOICE_MESSAGE_PREFIX_MAX_LENGTH)
|
|
|
+ }
|
|
|
val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX
|
|
|
-
|
|
|
currentVoiceRecordFile = "${context.cacheDir.absolutePath}/$fileName"
|
|
|
}
|
|
|
|