Update after Dominaezzz's review

This commit is contained in:
Benoit Marty 2019-09-26 10:08:44 +02:00
parent 60f6b3ef02
commit 62b7a83a31
5 changed files with 18 additions and 10 deletions

View File

@ -22,6 +22,7 @@ import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEn
import im.vector.matrix.android.internal.database.query.getOrCreate
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import java.util.*
import javax.inject.Inject
@ -35,7 +36,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
override suspend fun execute(params: Unit) {
var doRequest = false
monarchy.doWithRealm { realm ->
monarchy.awaitTransaction { realm ->
val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm)
doRequest = homeServerCapabilitiesEntity.lastUpdatedTimestamp + MIN_DELAY_BETWEEN_TWO_REQUEST_MILLIS < Date().time

View File

@ -32,6 +32,13 @@ internal class DefaultHomeServerCapabilitiesService @Inject constructor(private
entity = HomeServerCapabilitiesEntity.getOrCreate(realm)
}
return entity?.let { HomeServerCapabilitiesMapper.map(it) } ?: HomeServerCapabilities(HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN)
return with(entity) {
if (this != null) {
HomeServerCapabilitiesMapper.map(this)
} else {
// Should not happen
HomeServerCapabilities(HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN)
}
}
}
}
}

View File

@ -264,8 +264,8 @@ class RoomDetailFragment :
.setTitle(R.string.dialog_title_error)
.setMessage(getString(R.string.error_file_too_big,
error.filename,
Formatter.formatFileSize(requireContext(), error.homeServerLimitInBytes),
Formatter.formatFileSize(requireContext(), error.fileSizeInBytes)
Formatter.formatFileSize(requireContext(), error.fileSizeInBytes),
Formatter.formatFileSize(requireContext(), error.homeServerLimitInBytes)
))
.setPositiveButton(R.string.ok, null)
.show()

View File

@ -480,10 +480,10 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
// Unknown limitation
room.sendMedias(attachments)
} else {
attachments.find { it.size > maxUploadFileSize }
?.let {
_fileTooBigEvent.postValue(LiveEvent(FileTooBigError(it.name ?: it.path, it.size, maxUploadFileSize)))
} ?: run { room.sendMedias(attachments) }
when (val tooBigFile = attachments.find { it.size > maxUploadFileSize }) {
null -> room.sendMedias(attachments)
else -> _fileTooBigEvent.postValue(LiveEvent(FileTooBigError(tooBigFile.name ?: tooBigFile.path, tooBigFile.size, maxUploadFileSize)))
}
}
}

View File

@ -22,6 +22,6 @@
<string name="a11y_create_room">Create a new room</string>
<string name="a11y_close_keys_backup_banner">Close keys backup banner</string>
<string name="error_file_too_big">The file %1$s is too large to upload. The file size limit is %2$s but this file is %3$s.</string>
<string name="error_file_too_big">"The file '%1$s' (%2$s) is too large to upload. The limit is %3$s."</string>
</resources>