mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Fix / view source, decrypted source was not correct
This commit is contained in:
parent
d52613d723
commit
8777d13d8b
2 changed files with 19 additions and 4 deletions
|
@ -23,6 +23,7 @@ import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
||||||
import im.vector.matrix.android.api.util.JsonDict
|
import im.vector.matrix.android.api.util.JsonDict
|
||||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||||
|
import org.json.JSONObject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
typealias Content = JsonDict
|
typealias Content = JsonDict
|
||||||
|
@ -234,6 +235,20 @@ data class Event(
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
fun toContentStringWithIndent(): String {
|
||||||
|
val contentMap = this.toContent()?.toMutableMap() ?: HashMap()
|
||||||
|
contentMap.remove("mxDecryptionResult")
|
||||||
|
contentMap.remove("mCryptoError")
|
||||||
|
return JSONObject(contentMap).toString(4)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toClearContentStringWithIndent(): String? {
|
||||||
|
val contentMap = this.mxDecryptionResult?.payload?.toMutableMap()
|
||||||
|
val adapter = MoshiProvider.providesMoshi().adapter(Map::class.java)
|
||||||
|
return contentMap?.let { JSONObject(adapter.toJson(it)).toString(4) }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the event is redacted
|
* Tells if the event is redacted
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,8 @@ import im.vector.matrix.android.api.session.room.model.message.MessageImageConte
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
||||||
import im.vector.matrix.android.api.session.room.send.SendState
|
import im.vector.matrix.android.api.session.room.send.SendState
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
|
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||||
|
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||||
import im.vector.matrix.rx.RxRoom
|
import im.vector.matrix.rx.RxRoom
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
|
@ -174,11 +176,9 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M
|
||||||
//TODO sent by me or sufficient power level
|
//TODO sent by me or sufficient power level
|
||||||
}
|
}
|
||||||
|
|
||||||
this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source, JSONObject(event.root.toContent()).toString(4)))
|
this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source,event.root.toContentStringWithIndent()))
|
||||||
if (event.isEncrypted()) {
|
if (event.isEncrypted()) {
|
||||||
val decryptedContent = event.root.getClearContent()?.let {
|
val decryptedContent = event.root.toClearContentStringWithIndent() ?: stringProvider.getString(R.string.encryption_information_decryption_error)
|
||||||
JSONObject(it).toString(4)
|
|
||||||
} ?: stringProvider.getString(R.string.encryption_information_decryption_error)
|
|
||||||
this.add(SimpleAction(VIEW_DECRYPTED_SOURCE, R.string.view_decrypted_source, R.drawable.ic_view_source, decryptedContent))
|
this.add(SimpleAction(VIEW_DECRYPTED_SOURCE, R.string.view_decrypted_source, R.drawable.ic_view_source, decryptedContent))
|
||||||
}
|
}
|
||||||
this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId))
|
this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId))
|
||||||
|
|
Loading…
Reference in a new issue