mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Cleanup and split long lines
This commit is contained in:
parent
f190356934
commit
f48d4c021a
3 changed files with 70 additions and 76 deletions
|
@ -1124,7 +1124,7 @@ internal class RealmCryptoStore @Inject constructor(
|
||||||
content = ContentMapper.map(event.content)
|
content = ContentMapper.map(event.content)
|
||||||
).apply {
|
).apply {
|
||||||
sendState = SendState.SYNCED
|
sendState = SendState.SYNCED
|
||||||
decryptionResultJson = MoshiProvider.providesMoshi().adapter<OlmDecryptionResult>(OlmDecryptionResult::class.java).toJson(event.mxDecryptionResult)
|
decryptionResultJson = MoshiProvider.providesMoshi().adapter(OlmDecryptionResult::class.java).toJson(event.mxDecryptionResult)
|
||||||
decryptionErrorCode = event.mCryptoError?.name
|
decryptionErrorCode = event.mCryptoError?.name
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(entity)
|
realm.insertOrUpdate(entity)
|
||||||
|
@ -1143,7 +1143,7 @@ internal class RealmCryptoStore @Inject constructor(
|
||||||
content = ContentMapper.map(event.content)
|
content = ContentMapper.map(event.content)
|
||||||
).apply {
|
).apply {
|
||||||
sendState = SendState.SYNCED
|
sendState = SendState.SYNCED
|
||||||
decryptionResultJson = MoshiProvider.providesMoshi().adapter<OlmDecryptionResult>(OlmDecryptionResult::class.java).toJson(event.mxDecryptionResult)
|
decryptionResultJson = MoshiProvider.providesMoshi().adapter(OlmDecryptionResult::class.java).toJson(event.mxDecryptionResult)
|
||||||
decryptionErrorCode = event.mCryptoError?.name
|
decryptionErrorCode = event.mCryptoError?.name
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(entity)
|
realm.insertOrUpdate(entity)
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.airbnb.mvrx.Uninitialized
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import com.squareup.inject.assisted.Assisted
|
import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
|
import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.platform.VectorViewEvents
|
import im.vector.app.core.platform.VectorViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.core.platform.VectorViewModelAction
|
import im.vector.app.core.platform.VectorViewModelAction
|
||||||
|
@ -54,7 +55,7 @@ sealed class KeyRequestEvents : VectorViewEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
data class KeyRequestViewState(
|
data class KeyRequestViewState(
|
||||||
val exporting: Async<String> = Uninitialized
|
val exporting: Async<Unit> = Uninitialized
|
||||||
) : MvRxState
|
) : MvRxState
|
||||||
|
|
||||||
class KeyRequestViewModel @AssistedInject constructor(
|
class KeyRequestViewModel @AssistedInject constructor(
|
||||||
|
@ -78,7 +79,11 @@ class KeyRequestViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
override fun handle(action: KeyRequestAction) {
|
override fun handle(action: KeyRequestAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is KeyRequestAction.ExportAudit -> {
|
is KeyRequestAction.ExportAudit -> exportAudit(action)
|
||||||
|
}.exhaustive
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun exportAudit(action: KeyRequestAction.ExportAudit) {
|
||||||
setState {
|
setState {
|
||||||
copy(exporting = Loading())
|
copy(exporting = Loading())
|
||||||
}
|
}
|
||||||
|
@ -87,60 +92,56 @@ class KeyRequestViewModel @AssistedInject constructor(
|
||||||
// this can take long
|
// this can take long
|
||||||
val eventList = session.cryptoService().getGossipingEvents()
|
val eventList = session.cryptoService().getGossipingEvents()
|
||||||
// clean it a bit to
|
// clean it a bit to
|
||||||
val stringBuilder = StringBuilder()
|
val raw = buildString {
|
||||||
eventList.forEach {
|
eventList.forEach {
|
||||||
val clearType = it.getClearType()
|
val clearType = it.getClearType()
|
||||||
stringBuilder.append("[${it.ageLocalTs}] : $clearType from:${it.senderId} - ")
|
append("[${it.ageLocalTs}] : $clearType from:${it.senderId} - ")
|
||||||
when (clearType) {
|
when (clearType) {
|
||||||
EventType.ROOM_KEY_REQUEST -> {
|
EventType.ROOM_KEY_REQUEST -> {
|
||||||
val content = it.getClearContent().toModel<RoomKeyShareRequest>()
|
val content = it.getClearContent().toModel<RoomKeyShareRequest>()
|
||||||
stringBuilder.append("reqId:${content?.requestId} action:${content?.action} ")
|
append("reqId:${content?.requestId} action:${content?.action} ")
|
||||||
if (content?.action == GossipingToDeviceObject.ACTION_SHARE_REQUEST) {
|
if (content?.action == GossipingToDeviceObject.ACTION_SHARE_REQUEST) {
|
||||||
stringBuilder.append("sessionId: ${content.body?.sessionId} ")
|
append("sessionId: ${content.body?.sessionId} ")
|
||||||
}
|
}
|
||||||
stringBuilder.append("requestedBy: ${content?.requestingDeviceId} ")
|
append("requestedBy: ${content?.requestingDeviceId}")
|
||||||
stringBuilder.append("\n")
|
|
||||||
}
|
}
|
||||||
EventType.FORWARDED_ROOM_KEY -> {
|
EventType.FORWARDED_ROOM_KEY -> {
|
||||||
val encryptedContent = it.content.toModel<OlmEventContent>()
|
val encryptedContent = it.content.toModel<OlmEventContent>()
|
||||||
val content = it.getClearContent().toModel<ForwardedRoomKeyContent>()
|
val content = it.getClearContent().toModel<ForwardedRoomKeyContent>()
|
||||||
|
|
||||||
stringBuilder.append("sessionId:${content?.sessionId} From Device (sender key):${encryptedContent?.senderKey} ")
|
append("sessionId:${content?.sessionId} From Device (sender key):${encryptedContent?.senderKey}")
|
||||||
span("\nFrom Device (sender key):") {
|
span("\nFrom Device (sender key):") {
|
||||||
textStyle = "bold"
|
textStyle = "bold"
|
||||||
}
|
}
|
||||||
stringBuilder.append("\n")
|
|
||||||
}
|
}
|
||||||
EventType.ROOM_KEY -> {
|
EventType.ROOM_KEY -> {
|
||||||
val content = it.getClearContent()
|
val content = it.getClearContent()
|
||||||
stringBuilder.append("sessionId:${content?.get("session_id")} roomId:${content?.get("room_id")} dest:${content?.get("_dest") ?: "me"}")
|
append("sessionId:${content?.get("session_id")} roomId:${content?.get("room_id")} dest:${content?.get("_dest") ?: "me"}")
|
||||||
stringBuilder.append("\n")
|
|
||||||
}
|
}
|
||||||
EventType.SEND_SECRET -> {
|
EventType.SEND_SECRET -> {
|
||||||
val content = it.getClearContent().toModel<SecretSendEventContent>()
|
val content = it.getClearContent().toModel<SecretSendEventContent>()
|
||||||
stringBuilder.append("requestId:${content?.requestId} From Device:${it.mxDecryptionResult?.payload?.get("sender_device")}")
|
append("requestId:${content?.requestId} From Device:${it.mxDecryptionResult?.payload?.get("sender_device")}")
|
||||||
stringBuilder.append("\n")
|
|
||||||
}
|
}
|
||||||
EventType.REQUEST_SECRET -> {
|
EventType.REQUEST_SECRET -> {
|
||||||
val content = it.getClearContent().toModel<SecretShareRequest>()
|
val content = it.getClearContent().toModel<SecretShareRequest>()
|
||||||
stringBuilder.append("reqId:${content?.requestId} action:${content?.action} ")
|
append("reqId:${content?.requestId} action:${content?.action} ")
|
||||||
if (content?.action == GossipingToDeviceObject.ACTION_SHARE_REQUEST) {
|
if (content?.action == GossipingToDeviceObject.ACTION_SHARE_REQUEST) {
|
||||||
stringBuilder.append("secretName:${content.secretName} ")
|
append("secretName:${content.secretName} ")
|
||||||
}
|
}
|
||||||
stringBuilder.append("requestedBy:${content?.requestingDeviceId}")
|
append("requestedBy:${content?.requestingDeviceId}")
|
||||||
stringBuilder.append("\n")
|
|
||||||
}
|
}
|
||||||
EventType.ENCRYPTED -> {
|
EventType.ENCRYPTED -> {
|
||||||
stringBuilder.append("Failed to Derypt \n")
|
append("Failed to Decrypt")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
stringBuilder.append("?? \n")
|
append("??")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val raw = stringBuilder.toString()
|
|
||||||
setState {
|
setState {
|
||||||
copy(exporting = Success(""))
|
copy(exporting = Success(Unit))
|
||||||
}
|
}
|
||||||
_viewEvents.post(KeyRequestEvents.SaveAudit(action.uri, raw))
|
_viewEvents.post(KeyRequestEvents.SaveAudit(action.uri, raw))
|
||||||
} catch (error: Throwable) {
|
} catch (error: Throwable) {
|
||||||
|
@ -150,6 +151,4 @@ class KeyRequestViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.extensions.registerStartForActivityResult
|
import im.vector.app.core.extensions.registerStartForActivityResult
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
|
@ -103,17 +104,11 @@ class KeyRequestsFragment @Inject constructor(
|
||||||
when (it) {
|
when (it) {
|
||||||
is KeyRequestEvents.SaveAudit -> {
|
is KeyRequestEvents.SaveAudit -> {
|
||||||
tryOrNull {
|
tryOrNull {
|
||||||
val os = requireContext().contentResolver?.openOutputStream(it.uri)
|
requireContext().contentResolver?.openOutputStream(it.uri)
|
||||||
if (os == null) {
|
?.use { os -> os.write(it.raw.toByteArray()) }
|
||||||
false
|
|
||||||
} else {
|
|
||||||
os.write(it.raw.toByteArray())
|
|
||||||
os.flush()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.exhaustive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue