Merge branch 'develop' into feature/read_marker
This commit is contained in:
commit
737959f616
|
@ -20,7 +20,7 @@ data class HomeServerCapabilities(
|
||||||
/**
|
/**
|
||||||
* Max size of file which can be uploaded to the homeserver in bytes. [MAX_UPLOAD_FILE_SIZE_UNKNOWN] if unknown or not retrieved yet
|
* Max size of file which can be uploaded to the homeserver in bytes. [MAX_UPLOAD_FILE_SIZE_UNKNOWN] if unknown or not retrieved yet
|
||||||
*/
|
*/
|
||||||
val maxUploadFileSize: Long
|
val maxUploadFileSize: Long = MAX_UPLOAD_FILE_SIZE_UNKNOWN
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val MAX_UPLOAD_FILE_SIZE_UNKNOWN = -1L
|
const val MAX_UPLOAD_FILE_SIZE_UNKNOWN = -1L
|
||||||
|
|
|
@ -26,13 +26,13 @@ internal object HomeServerCapabilitiesMapper {
|
||||||
|
|
||||||
fun map(entity: HomeServerCapabilitiesEntity): HomeServerCapabilities {
|
fun map(entity: HomeServerCapabilitiesEntity): HomeServerCapabilities {
|
||||||
return HomeServerCapabilities(
|
return HomeServerCapabilities(
|
||||||
entity.maxUploadFileSize
|
maxUploadFileSize = entity.maxUploadFileSize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun map(domain: HomeServerCapabilities): HomeServerCapabilitiesEntity {
|
fun map(domain: HomeServerCapabilities): HomeServerCapabilitiesEntity {
|
||||||
return HomeServerCapabilitiesEntity(
|
return HomeServerCapabilitiesEntity(
|
||||||
domain.maxUploadFileSize
|
maxUploadFileSize = domain.maxUploadFileSize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,17 +21,16 @@ import io.realm.Realm
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
import io.realm.kotlin.where
|
import io.realm.kotlin.where
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current HomeServerCapabilitiesEntity, return null if it does not exist
|
||||||
|
*/
|
||||||
|
internal fun HomeServerCapabilitiesEntity.Companion.get(realm: Realm): HomeServerCapabilitiesEntity? {
|
||||||
|
return realm.where<HomeServerCapabilitiesEntity>().findFirst()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current HomeServerCapabilitiesEntity, create one if it does not exist
|
* Get the current HomeServerCapabilitiesEntity, create one if it does not exist
|
||||||
*/
|
*/
|
||||||
internal fun HomeServerCapabilitiesEntity.Companion.getOrCreate(realm: Realm): HomeServerCapabilitiesEntity {
|
internal fun HomeServerCapabilitiesEntity.Companion.getOrCreate(realm: Realm): HomeServerCapabilitiesEntity {
|
||||||
var homeServerCapabilitiesEntity = realm.where<HomeServerCapabilitiesEntity>().findFirst()
|
return get(realm) ?: realm.createObject()
|
||||||
if (homeServerCapabilitiesEntity == null) {
|
|
||||||
realm.executeTransaction {
|
|
||||||
realm.createObject<HomeServerCapabilitiesEntity>()
|
|
||||||
}
|
|
||||||
homeServerCapabilitiesEntity = realm.where<HomeServerCapabilitiesEntity>().findFirst()!!
|
|
||||||
}
|
|
||||||
|
|
||||||
return homeServerCapabilitiesEntity
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,8 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun insertInDb(getUploadCapabilitiesResult: GetUploadCapabilitiesResult) {
|
private suspend fun insertInDb(getUploadCapabilitiesResult: GetUploadCapabilitiesResult) {
|
||||||
monarchy
|
monarchy.awaitTransaction { realm ->
|
||||||
.writeAsync { realm ->
|
|
||||||
val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm)
|
val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm)
|
||||||
|
|
||||||
homeServerCapabilitiesEntity.maxUploadFileSize = getUploadCapabilitiesResult.maxUploadSize
|
homeServerCapabilitiesEntity.maxUploadFileSize = getUploadCapabilitiesResult.maxUploadSize
|
||||||
|
|
|
@ -21,24 +21,18 @@ import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities
|
||||||
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService
|
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService
|
||||||
import im.vector.matrix.android.internal.database.mapper.HomeServerCapabilitiesMapper
|
import im.vector.matrix.android.internal.database.mapper.HomeServerCapabilitiesMapper
|
||||||
import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntity
|
import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntity
|
||||||
import im.vector.matrix.android.internal.database.query.getOrCreate
|
import im.vector.matrix.android.internal.database.query.get
|
||||||
|
import io.realm.Realm
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class DefaultHomeServerCapabilitiesService @Inject constructor(private val monarchy: Monarchy) : HomeServerCapabilitiesService {
|
internal class DefaultHomeServerCapabilitiesService @Inject constructor(private val monarchy: Monarchy) : HomeServerCapabilitiesService {
|
||||||
|
|
||||||
override fun getHomeServerCapabilities(): HomeServerCapabilities {
|
override fun getHomeServerCapabilities(): HomeServerCapabilities {
|
||||||
var entity: HomeServerCapabilitiesEntity? = null
|
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||||
monarchy.doWithRealm { realm ->
|
HomeServerCapabilitiesEntity.get(realm)?.let {
|
||||||
entity = HomeServerCapabilitiesEntity.getOrCreate(realm)
|
HomeServerCapabilitiesMapper.map(it)
|
||||||
}
|
|
||||||
|
|
||||||
return with(entity) {
|
|
||||||
if (this != null) {
|
|
||||||
HomeServerCapabilitiesMapper.map(this)
|
|
||||||
} else {
|
|
||||||
// Should not happen
|
|
||||||
HomeServerCapabilities(HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
?: HomeServerCapabilities()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,8 +91,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
||||||
holder.timeView.text = attributes.informationData.time
|
holder.timeView.text = attributes.informationData.time
|
||||||
holder.memberNameView.text = attributes.informationData.memberName
|
holder.memberNameView.text = attributes.informationData.memberName
|
||||||
attributes.avatarRenderer.render(attributes.informationData.avatarUrl, attributes.informationData.senderId, attributes.informationData.memberName?.toString(), holder.avatarImageView)
|
attributes.avatarRenderer.render(attributes.informationData.avatarUrl, attributes.informationData.senderId, attributes.informationData.memberName?.toString(), holder.avatarImageView)
|
||||||
holder.view.setOnClickListener(attributes.itemClickListener)
|
|
||||||
holder.view.setOnLongClickListener(attributes.itemLongClickListener)
|
|
||||||
holder.avatarImageView.setOnLongClickListener(attributes.itemLongClickListener)
|
holder.avatarImageView.setOnLongClickListener(attributes.itemLongClickListener)
|
||||||
holder.memberNameView.setOnLongClickListener(attributes.itemLongClickListener)
|
holder.memberNameView.setOnLongClickListener(attributes.itemLongClickListener)
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,11 +99,12 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
||||||
holder.avatarImageView.visibility = View.GONE
|
holder.avatarImageView.visibility = View.GONE
|
||||||
holder.memberNameView.visibility = View.GONE
|
holder.memberNameView.visibility = View.GONE
|
||||||
holder.timeView.visibility = View.GONE
|
holder.timeView.visibility = View.GONE
|
||||||
holder.view.setOnClickListener(null)
|
|
||||||
holder.view.setOnLongClickListener(null)
|
|
||||||
holder.avatarImageView.setOnLongClickListener(null)
|
holder.avatarImageView.setOnLongClickListener(null)
|
||||||
holder.memberNameView.setOnLongClickListener(null)
|
holder.memberNameView.setOnLongClickListener(null)
|
||||||
}
|
}
|
||||||
|
holder.view.setOnClickListener(attributes.itemClickListener)
|
||||||
|
holder.view.setOnLongClickListener(attributes.itemLongClickListener)
|
||||||
|
|
||||||
holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener)
|
holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener)
|
||||||
holder.readMarkerView.bindView(
|
holder.readMarkerView.bindView(
|
||||||
attributes.informationData.eventId,
|
attributes.informationData.eventId,
|
||||||
|
|
Loading…
Reference in New Issue