Skip to content

Kotlin decryption. Fix showing inline attachments #1354

Description

@DenBond7

it seems that Ivan's realization of recognizing inline attachments works well. Just need to fix the Android side.

image

MsgBlock.Type.DECRYPTED_ATT -> {
                if (tempDir != null) {
                  try {
                    val decryptedAtt: DecryptedAttMsgBlock = block as DecryptedAttMsgBlock
                    val fileName =
                      FileAndDirectoryUtils.normalizeFileName(decryptedAtt.attMeta.name)
                    val file = if (fileName.isNullOrEmpty()) {
                      File.createTempFile("tmp", null, tempDir)
                    } else {
                      val file = File(tempDir, fileName)
                      if (file.exists()) {
                        FileAndDirectoryUtils.createFileWithIncreasedIndex(tempDir, fileName)
                      } else {
                        file
                      }
                    }
                    FileUtils.writeByteArrayToFile(
                      file,
                      Base64.decode(decryptedAtt.attMeta.data, Base64.DEFAULT)
                    )
                    decryptedAtt.attMeta.data = null //clear raw info to prevent Binder exception
                    decryptedAtt.fileUri = Uri.fromFile(file)
                    msgBlocks?.add(decryptedAtt)
                  } catch (e: Exception) {
                    e.printStackTrace()
                    ExceptionUtil.handleError(e)
                  }
                } else {
                  ExceptionUtil.handleError(IOException("The temp cache dir == null"))
                }
              }

ref

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions