Avoid code duplication

This commit is contained in:
Benoit Marty 2021-10-12 11:38:16 +02:00
parent 0d85299c57
commit 73c08e2eeb
2 changed files with 3 additions and 19 deletions

View file

@ -379,7 +379,8 @@ internal interface IMXCryptoStore {
fun getOrAddOutgoingSecretShareRequest(secretName: String, recipients: Map<String, List<String>>): OutgoingSecretRequest?
fun saveGossipingEvent(event: Event)
fun saveGossipingEvent(event: Event) = saveGossipingEvents(listOf(event))
fun saveGossipingEvents(events: List<Event>)
fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState) {

View file

@ -1163,8 +1163,8 @@ internal class RealmCryptoStore @Inject constructor(
}
override fun saveGossipingEvents(events: List<Event>) {
val now = System.currentTimeMillis()
monarchy.writeAsync { realm ->
val now = System.currentTimeMillis()
events.forEach { event ->
val ageLocalTs = event.unsignedData?.age?.let { now - it } ?: now
val entity = GossipingEventEntity(
@ -1182,23 +1182,6 @@ internal class RealmCryptoStore @Inject constructor(
}
}
override fun saveGossipingEvent(event: Event) {
monarchy.writeAsync { realm ->
val now = System.currentTimeMillis()
val ageLocalTs = event.unsignedData?.age?.let { now - it } ?: now
val entity = GossipingEventEntity(
type = event.type,
sender = event.senderId,
ageLocalTs = ageLocalTs,
content = ContentMapper.map(event.content)
).apply {
sendState = SendState.SYNCED
decryptionResultJson = MoshiProvider.providesMoshi().adapter(OlmDecryptionResult::class.java).toJson(event.mxDecryptionResult)
decryptionErrorCode = event.mCryptoError?.name
}
realm.insertOrUpdate(entity)
}
}
// override fun getOutgoingRoomKeyRequestByState(states: Set<ShareRequestState>): OutgoingRoomKeyRequest? {
// val statesIndex = states.map { it.ordinal }.toTypedArray()
// return doRealmQueryAndCopy(realmConfiguration) { realm ->