srctree

Robin Linden parent e07ec26a de1d6880
Make sure ft races can't crash the client

inlinesplit
atox/src/main/kotlin/ui/chat/ChatAdapter.kt added: 17, removed: 7, total 10
@@ -27,8 +27,14 @@ import ltd.evilcorp.core.vo.isComplete
import ltd.evilcorp.core.vo.isRejected
import ltd.evilcorp.core.vo.isStarted
 
private fun FileTransfer.isImage() =
private const val TAG = "ChatAdapter"
 
private fun FileTransfer.isImage() = try {
URLConnection.guessContentTypeFromName(fileName).startsWith("image/")
} catch (e: Exception) {
Log.e(TAG, e.toString())
false
}
 
private fun inflateView(type: ChatItemType, inflater: LayoutInflater): View =
inflater.inflate(
@@ -74,8 +80,6 @@ private class FileTransferViewHolder(row: View) {
val imagePreview = row.findViewById(R.id.imagePreview) as ImageView
}
 
private const val TAG = "ChatAdapter"
 
class ChatAdapter(
private val inflater: LayoutInflater,
private val resources: Resources
 
domain/src/main/kotlin/tox/ToxWrapper.kt added: 17, removed: 7, total 10
@@ -109,8 +109,11 @@ class ToxWrapper(
Log.e(TAG, "Exception while accepting friend request $publicKey: $e")
}
 
fun startFileTransfer(publicKey: PublicKey, fileNumber: Int) =
fun startFileTransfer(publicKey: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(publicKey), fileNumber, ToxFileControl.RESUME)
} catch (e: ToxFileControlException) {
Log.e(TAG, "Error starting ft ${publicKey.string().take(8)} $fileNumber\n$e")
}
 
fun stopFileTransfer(publicKey: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(publicKey), fileNumber, ToxFileControl.CANCEL)
@@ -118,8 +121,11 @@ class ToxWrapper(
Log.e(TAG, "Error stopping ft ${publicKey.string().take(8)} $fileNumber\n$e")
}
 
fun sendFile(pk: PublicKey, fileKind: FileKind, fileSize: Long, fileName: String) =
fun sendFile(pk: PublicKey, fileKind: FileKind, fileSize: Long, fileName: String) = try {
tox.fileSend(contactByKey(pk), fileKind.toToxtype(), fileSize, Random.nextBytes(32), fileName.toByteArray())
} catch (e: ToxFileControlException) {
Log.e(TAG, "Error sending ft $fileName ${pk.string().take(8)}\n$e")
}
 
fun sendFileChunk(pk: PublicKey, fileNo: Int, pos: Long, data: ByteArray) = try {
tox.fileSendChunk(contactByKey(pk), fileNo, pos, data)