Crypto: decryption is working (but still a lot to do)

This commit is contained in:
ganfra
2019-05-26 19:21:45 +02:00
parent 3519ad7c8d
commit af338b0607
40 changed files with 233 additions and 351 deletions

View File

@ -87,7 +87,7 @@ class EventStreamServiceX : VectorService() {
return
}
if (EventType.CALL_INVITE == event.type) {
if (EventType.CALL_INVITE == event.getClearType()) {
handleCallInviteEvent(event)
return
}

View File

@ -215,7 +215,7 @@ class TimelineEventController(private val dateFormatter: TimelineDateFormatter,
items: List<TimelineEvent>,
addDaySeparator: Boolean,
currentPosition: Int): MergedHeaderItem? {
return if (!event.canBeMerged() || (nextEvent?.root?.type == event.root.type && !addDaySeparator)) {
return if (!event.canBeMerged() || (nextEvent?.root?.getClearType() == event.root.getClearType() && !addDaySeparator)) {
null
} else {
val prevSameTypeEvents = items.prevSameTypeEvents(currentPosition, 2)

View File

@ -120,7 +120,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
private fun canReply(event: TimelineEvent, messageContent: MessageContent): Boolean {
//Only event of type Event.EVENT_TYPE_MESSAGE are supported for the moment
if (event.root.type != EventType.MESSAGE) return false
if (event.root.getClearType() != EventType.MESSAGE) return false
return when (messageContent.type) {
MessageType.MSGTYPE_TEXT,
MessageType.MSGTYPE_NOTICE,
@ -129,13 +129,13 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
MessageType.MSGTYPE_VIDEO,
MessageType.MSGTYPE_AUDIO,
MessageType.MSGTYPE_FILE -> true
else -> false
else -> false
}
}
private fun canQuote(event: TimelineEvent, messageContent: MessageContent): Boolean {
//Only event of type Event.EVENT_TYPE_MESSAGE are supported for the moment
if (event.root.type != EventType.MESSAGE) return false
if (event.root.getClearType() != EventType.MESSAGE) return false
return when (messageContent.type) {
MessageType.MSGTYPE_TEXT,
MessageType.MSGTYPE_NOTICE,
@ -144,7 +144,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
MessageType.MSGTYPE_LOCATION -> {
true
}
else -> false
else -> false
}
}
@ -157,7 +157,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
MessageType.MSGTYPE_LOCATION -> {
true
}
else -> false
else -> false
}
}
@ -169,7 +169,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
MessageType.MSGTYPE_VIDEO -> {
true
}
else -> false
else -> false
}
}

View File

@ -39,7 +39,7 @@ class CallItemFactory(private val stringProvider: StringProvider) {
private fun buildNoticeText(event: Event, senderName: String?): CharSequence? {
return when {
EventType.CALL_INVITE == event.type -> {
EventType.CALL_INVITE == event.getClearType() -> {
val content = event.content.toModel<CallInviteContent>() ?: return null
val isVideoCall = content.offer.sdp == CallInviteContent.Offer.SDP_VIDEO
return if (isVideoCall) {
@ -48,8 +48,8 @@ class CallItemFactory(private val stringProvider: StringProvider) {
stringProvider.getString(R.string.notice_placed_voice_call, senderName)
}
}
EventType.CALL_ANSWER == event.type -> stringProvider.getString(R.string.notice_answered_call, senderName)
EventType.CALL_HANGUP == event.type -> stringProvider.getString(R.string.notice_ended_call, senderName)
EventType.CALL_ANSWER == event.getClearType() -> stringProvider.getString(R.string.notice_answered_call, senderName)
EventType.CALL_HANGUP == event.getClearType() -> stringProvider.getString(R.string.notice_ended_call, senderName)
else -> null
}

View File

@ -24,7 +24,7 @@ class DefaultItemFactory {
fun create(event: TimelineEvent, exception: Exception? = null): DefaultItem? {
val text = if (exception == null) {
"${event.root.type} events are not yet handled"
"${event.root.getClearType()} events are not yet handled"
} else {
"an exception occurred when rendering the event ${event.root.eventId}"
}

View File

@ -22,10 +22,12 @@ import android.text.SpannableString
import android.text.style.StyleSpan
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.internal.crypto.MXDecryptionException
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
import im.vector.matrix.android.internal.di.MoshiProvider
import im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.VectorEpoxyModel
import im.vector.riotredesign.core.resources.StringProvider
@ -42,7 +44,7 @@ class EncryptedItemFactory(
callback: TimelineEventController.Callback?): VectorEpoxyModel<*>? {
return when {
EventType.ENCRYPTED == timelineEvent.root.type -> {
EventType.ENCRYPTED == timelineEvent.root.getClearType() -> {
val decrypted: MXEventDecryptionResult?
try {
decrypted = session.decryptEvent(timelineEvent.root, "TODO")
@ -68,12 +70,12 @@ class EncryptedItemFactory(
if (decrypted == null) {
return null
}
if (decrypted.mClearEvent == null) {
return null
}
val decryptedTimelineEvent = timelineEvent.copy(root = decrypted.mClearEvent!!)
val adapter = MoshiProvider.providesMoshi().adapter(Event::class.java)
val clearEvent = adapter.fromJsonValue(decrypted.mClearEvent) ?: return null
val decryptedTimelineEvent = timelineEvent.copy(root = clearEvent)
// Success
return messageItemFactory.create(decryptedTimelineEvent, nextEvent, callback)

View File

@ -38,7 +38,7 @@ class EncryptionItemFactory(private val stringProvider: StringProvider) {
private fun buildNoticeText(event: Event, senderName: String?): CharSequence? {
return when {
EventType.ENCRYPTION == event.type -> {
EventType.ENCRYPTION == event.getClearType() -> {
val content = event.content.toModel<EncryptionEventContent>() ?: return null
stringProvider.getString(R.string.notice_end_to_end, senderName, content.algorithm)
}

View File

@ -63,10 +63,10 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
val showInformation = addDaySeparator
|| event.senderAvatar != nextEvent?.senderAvatar
|| event.senderName != nextEvent?.senderName
|| nextEvent?.root?.type != EventType.MESSAGE
|| nextEvent?.root?.getClearType() != EventType.MESSAGE
|| isNextMessageReceivedMoreThanOneHourAgo
val messageContent: MessageContent = event.root.content.toModel() ?: return null
val messageContent: MessageContent = event.root.getClearContent().toModel() ?: return null
val time = timelineDateFormatter.formatMessageHour(date)
val avatarUrl = event.senderAvatar
val memberName = event.senderName ?: event.root.sender ?: ""

View File

@ -38,7 +38,7 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
callback: TimelineEventController.Callback?): VectorEpoxyModel<*> {
val computedModel = try {
when (event.root.type) {
when (event.root.getClearType()) {
EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, callback)
EventType.STATE_ROOM_NAME -> roomNameItemFactory.create(event)
EventType.STATE_ROOM_TOPIC -> roomTopicItemFactory.create(event)

View File

@ -40,7 +40,7 @@ object TimelineDisplayableEvents {
}
fun TimelineEvent.isDisplayable(): Boolean {
return TimelineDisplayableEvents.DISPLAYABLE_TYPES.contains(root.type) && !root.content.isNullOrEmpty()
return TimelineDisplayableEvents.DISPLAYABLE_TYPES.contains(root.getClearType()) && !root.content.isNullOrEmpty()
}
fun List<TimelineEvent>.filterDisplayableEvents(): List<TimelineEvent> {
@ -50,7 +50,7 @@ fun List<TimelineEvent>.filterDisplayableEvents(): List<TimelineEvent> {
}
fun TimelineEvent.canBeMerged(): Boolean {
return root.type == EventType.STATE_ROOM_MEMBER
return root.getClearType() == EventType.STATE_ROOM_MEMBER
}
fun List<TimelineEvent>.nextSameTypeEvents(index: Int, minSize: Int): List<TimelineEvent> {
@ -69,7 +69,7 @@ fun List<TimelineEvent>.nextSameTypeEvents(index: Int, minSize: Int): List<Timel
} else {
nextSubList.subList(0, indexOfNextDay)
}
val indexOfFirstDifferentEventType = nextSameDayEvents.indexOfFirst { it.root.type != timelineEvent.root.type }
val indexOfFirstDifferentEventType = nextSameDayEvents.indexOfFirst { it.root.getClearType() != timelineEvent.root.getClearType() }
val sameTypeEvents = if (indexOfFirstDifferentEventType == -1) {
nextSameDayEvents
} else {

View File

@ -47,7 +47,7 @@ class NotifiableEventResolver(val context: Context) {
return null
}
when (event.type) {
when (event.getClearType()) {
EventType.MESSAGE -> {
return resolveMessageEvent(event, bingRule, session, store)
}
@ -71,7 +71,7 @@ class NotifiableEventResolver(val context: Context) {
description = body,
soundName = bingRule?.notificationSound,
title = context.getString(R.string.notification_unknown_new_event),
type = event.type)
type = event.getClearType())
}
//Unsupported event
@ -172,7 +172,7 @@ class NotifiableEventResolver(val context: Context) {
title = context.getString(R.string.notification_new_invitation),
description = body,
soundName = bingRule?.notificationSound,
type = event.type,
type = event.getClearType(),
isPushGatewayEvent = false)
} else {
Timber.e("## unsupported notifiable event for eventId [${event.eventId}]")