forked from GitHub-Mirror/riotX-android
Merge pull request #317 from vector-im/feature/realm_entity_rework
Feature/realm entity rework
This commit is contained in:
@ -73,7 +73,7 @@ class HomeActivityViewModel @AssistedInject constructor(@Assisted initialState:
|
||||
private fun observeRoomAndGroup() {
|
||||
Observable
|
||||
.combineLatest<List<RoomSummary>, Option<GroupSummary>, List<RoomSummary>>(
|
||||
session.rx().liveRoomSummaries(fetchLastEvents = true).throttleLast(300, TimeUnit.MILLISECONDS),
|
||||
session.rx().liveRoomSummaries().throttleLast(300, TimeUnit.MILLISECONDS),
|
||||
selectedGroupStore.observe(),
|
||||
BiFunction { rooms, selectedGroupOption ->
|
||||
val selectedGroup = selectedGroupOption.orNull()
|
||||
|
@ -212,6 +212,7 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate {
|
||||
is SyncState.RUNNING -> if (it.syncState.catchingUp) View.VISIBLE else View.GONE
|
||||
else -> View.GONE
|
||||
}
|
||||
syncProgressBarWrap.visibility = syncProgressBar.visibility
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -500,17 +500,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
||||
}
|
||||
|
||||
private fun observeRoomSummary() {
|
||||
room.rx().liveRoomSummary(false)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap {
|
||||
if (it.membership != Membership.INVITE || it.latestEvent != null) {
|
||||
// Not an invitation, or already fetching last event
|
||||
Observable.just(it)
|
||||
} else {
|
||||
// We need the last event
|
||||
room.rx().liveRoomSummary(true)
|
||||
}
|
||||
}
|
||||
room.rx().liveRoomSummary()
|
||||
.execute { async ->
|
||||
copy(
|
||||
asyncRoomSummary = async,
|
||||
|
@ -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.send.SendState
|
||||
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.riotx.R
|
||||
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
|
||||
}
|
||||
|
||||
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()) {
|
||||
val decryptedContent = event.root.mClearEvent.toContent()?.let {
|
||||
JSONObject(it).toString(4)
|
||||
} ?: stringProvider.getString(R.string.encryption_information_decryption_error)
|
||||
val decryptedContent = event.root.toClearContentStringWithIndent() ?: 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(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId))
|
||||
|
@ -48,19 +48,15 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
|
||||
EventType.ENCRYPTED == event.root.getClearType() -> {
|
||||
val cryptoError = event.root.mCryptoError
|
||||
val errorDescription =
|
||||
if (cryptoError is MXCryptoError.Base) {
|
||||
if (cryptoError.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
|
||||
stringProvider.getString(R.string.notice_crypto_error_unkwown_inbound_session_id)
|
||||
} else {
|
||||
// TODO i18n
|
||||
cryptoError.technicalMessage
|
||||
}
|
||||
if (cryptoError == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
|
||||
stringProvider.getString(R.string.notice_crypto_error_unkwown_inbound_session_id)
|
||||
} else {
|
||||
// Cannot happen (for now)
|
||||
"Other error"
|
||||
// TODO i18n
|
||||
cryptoError?.name
|
||||
}
|
||||
|
||||
val message = stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
|
||||
val message = stringProvider.getString(R.string.encrypted_message).takeIf { cryptoError == null }
|
||||
?: stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
|
||||
val spannableStr = span(message) {
|
||||
textStyle = "italic"
|
||||
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
|
||||
|
@ -93,7 +93,10 @@ class RoomSummaryItemFactory @Inject constructor(private val noticeEventFormatte
|
||||
val date = latestEvent.root.localDateTime()
|
||||
val currentDate = DateProvider.currentLocalDateTime()
|
||||
val isSameDay = date.toLocalDate() == currentDate.toLocalDate()
|
||||
latestFormattedEvent = if (latestEvent.root.getClearType() == EventType.MESSAGE) {
|
||||
latestFormattedEvent = if (latestEvent.root.isEncrypted()
|
||||
&& latestEvent.root.mxDecryptionResult == null) {
|
||||
stringProvider.getString(R.string.encrypted_message)
|
||||
} else if (latestEvent.root.getClearType() == EventType.MESSAGE) {
|
||||
val senderName = latestEvent.senderName() ?: latestEvent.root.senderId
|
||||
val content = latestEvent.root.getClearContent()?.toModel<MessageContent>()
|
||||
val message = content?.body ?: ""
|
||||
|
@ -18,6 +18,8 @@ package im.vector.riotx.features.notifications
|
||||
import androidx.core.app.NotificationCompat
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||
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.events.model.toModel
|
||||
@ -25,11 +27,13 @@ import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||
import im.vector.riotx.BuildConfig
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.room.detail.timeline.format.NoticeEventFormatter
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@ -47,7 +51,6 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
|
||||
val roomID = event.roomId ?: return null
|
||||
val eventId = event.eventId ?: return null
|
||||
val timelineEvent = session.getRoom(roomID)?.getTimeLineEvent(eventId) ?: return null
|
||||
|
||||
when (event.getClearType()) {
|
||||
EventType.MESSAGE -> {
|
||||
return resolveMessageEvent(timelineEvent, session)
|
||||
@ -110,6 +113,22 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
|
||||
notifiableEvent.matrixID = session.sessionParams.credentials.userId
|
||||
return notifiableEvent
|
||||
} else {
|
||||
if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) {
|
||||
//TODO use a global event decryptor? attache to session and that listen to new sessionId?
|
||||
//for now decrypt sync
|
||||
try {
|
||||
val result = session.decryptEvent(event.root, event.root.roomId + UUID.randomUUID().toString())
|
||||
event.root.mxDecryptionResult = OlmDecryptionResult(
|
||||
payload = result.clearEvent,
|
||||
senderKey = result.senderCurve25519Key,
|
||||
keysClaimed = result.claimedEd25519Key?.let { mapOf("ed25519" to it) },
|
||||
forwardingCurve25519KeyChain = result.forwardingCurve25519KeyChain
|
||||
)
|
||||
} catch (e: MXCryptoError) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
val body = event.annotations?.editSummary?.aggregatedContent?.toModel<MessageContent>()?.body
|
||||
?: event.root.getClearContent().toModel<MessageContent>()?.body
|
||||
?: stringProvider.getString(R.string.notification_unknown_new_event)
|
||||
|
@ -86,7 +86,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
||||
private fun observeJoinedRooms() {
|
||||
session
|
||||
.rx()
|
||||
.liveRoomSummaries(fetchLastEvents = false)
|
||||
.liveRoomSummaries()
|
||||
.subscribe { list ->
|
||||
val joinedRoomIds = list
|
||||
// Keep only joined room
|
||||
|
@ -54,7 +54,7 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted initialState: R
|
||||
private fun observeJoinedRooms() {
|
||||
session
|
||||
.rx()
|
||||
.liveRoomSummaries(fetchLastEvents = false)
|
||||
.liveRoomSummaries()
|
||||
.subscribe { list ->
|
||||
withState { state ->
|
||||
val isRoomJoined = list
|
||||
|
@ -44,18 +44,29 @@
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/syncProgressBar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?riotx_header_panel_background"
|
||||
android:indeterminate="true"
|
||||
<!-- Trick to remove surrounding padding (clip frome wrapping frame) -->
|
||||
<FrameLayout
|
||||
android:id="@+id/syncProgressBarWrap"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/groupToolbar"
|
||||
tools:visibility="visible" />
|
||||
tools:visibility="visible">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/syncProgressBar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="14dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="?riotx_header_panel_background"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
<im.vector.riotx.core.ui.views.KeysBackupBanner
|
||||
android:id="@+id/homeKeysBackupBanner"
|
||||
@ -65,7 +76,7 @@
|
||||
android:minHeight="67dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/syncProgressBar" />
|
||||
app:layout_constraintTop_toBottomOf="@id/syncProgressBarWrap" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/roomListContainer"
|
||||
|
Reference in New Issue
Block a user