Skip to content
Snippets Groups Projects
Commit 0657bf9d authored by Pierre Nicolas's avatar Pierre Nicolas :joy: Committed by Adrien Béraud
Browse files

file transfer: fix path to send picture

The bug is that the image is not placed in the correct path.
Also fix bug where images were not preview in notifications.

GitLab: #1298
Change-Id: Ifb4041dcd7d82eccb72d5e40e6f3cdc04d027e17
parent 911f4f7d
No related branches found
No related tags found
No related merge requests found
......@@ -76,10 +76,7 @@ class DeviceRuntimeServiceImpl(
override fun getFilePath(filename: String) = AndroidFileUtils.getFilePath(mContext, filename)
override fun getConversationPath(conversationId: String, name: String): File =
AndroidFileUtils.getConversationPath(mContext, conversationId, name)
override fun getConversationPath(accountId: String, conversationId: String,name: String): File =
override fun getConversationPath(accountId: String, conversationId: String, name: String): File =
AndroidFileUtils.getConversationPath(mContext, accountId, conversationId, name)
override fun getTemporaryPath(conversationId: String, name: String): File =
......
......@@ -689,7 +689,7 @@ class NotificationServiceImpl(
.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(), intentViewConversation, ContentUriHandler.immutable()))
.setAutoCancel(true)
if (info.showPicture()) {
val filePath = mDeviceRuntimeService.getConversationPath(conversation.uri.rawRingId, info.storagePath)
val filePath = mDeviceRuntimeService.getConversationPath(conversation.accountId, conversation.uri.rawRingId, info.storagePath)
val img: Bitmap
try {
val d = Glide.with(mContext)
......
......@@ -340,16 +340,6 @@ object AndroidFileUtils {
} }
}.subscribeOn(Schedulers.io())
@Throws(IOException::class)
fun getConversationFile(context: Context, uri: Uri, conversationId: String, name: String): File {
val file = getConversationPath(context, conversationId, name)
context.contentResolver.openInputStream(uri)?.use { inputStream ->
FileOutputStream(file).use { output ->
FileUtils.copyFile(inputStream, output)
} }
return file
}
fun getCachePath(context: Context, filename: String) = File(context.cacheDir, filename)
fun getFilePath(context: Context, filename: String): File = context.getFileStreamPath(filename)
......@@ -372,9 +362,6 @@ object AndroidFileUtils {
return conversationDir
}
fun getConversationPath(context: Context, conversationId: String, name: String) =
File(getConversationDir(context, conversationId), name)
fun getConversationPath(context: Context, accountId: String, conversationId: String, name: String) =
File(getConversationDir(context, accountId, conversationId), name)
......
......@@ -130,16 +130,7 @@ class DataTransfer : Interaction {
val b = body
return if (b == null) {
if (fileId.isNullOrEmpty()) { "Error" } else fileId!!
} else {
var ext = StringUtils.getFileExtension(b)
if (ext.length > 8) ext = ext.substring(0, 8)
val dId = daemonId
if (dId == null || dId == 0L) {
id.toLong().toString() + '_' + HashUtils.sha1(b).toHex() + '.' + ext
} else {
dId.toString() + '_' + HashUtils.sha1(b).toHex() + '.' + ext
}
}
} else return b
}
fun setSize(size: Long) {
......
......@@ -168,7 +168,7 @@ class ConversationFacade(
if (transfer.status === InteractionStatus.TRANSFER_ONGOING) {
mAccountService.cancelDataTransfer(conversation.accountId, conversation.uri.rawRingId, transfer.messageId, transfer.fileId!!)
} else {
val file = mDeviceRuntimeService.getConversationPath(conversation.uri.rawRingId, transfer.storagePath)
val file = mDeviceRuntimeService.getConversationPath(conversation.accountId, conversation.uri.rawRingId, transfer.storagePath)
if (conversation.isSwarm) {
mDisposableBag.add(Completable.fromAction { file.delete() }
.subscribeOn(Schedulers.io())
......
......@@ -28,11 +28,10 @@ abstract class DeviceRuntimeService : SystemInfoCallbacks {
abstract fun provideFilesDir(): File
abstract val cacheDir: File
abstract fun getFilePath(name: String): File
abstract fun getConversationPath(conversationId: String, name: String): File
abstract fun getConversationPath(accountId: String, conversationId: String, name: String): File
fun getConversationPath(interaction: DataTransfer): File =
if (interaction.conversationId == null)
getConversationPath(interaction.conversation!!.participant!!, interaction.storagePath)
getConversationPath(interaction.account!!, interaction.conversation!!.participant!!, interaction.storagePath)
else interaction.publicPath!!
fun getNewConversationPath(accountId: String, conversationId: String, name: String): File {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment