diff --git a/CHANGES.md b/CHANGES.md index 8a7b82c77b..135b881501 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,37 @@ +Changes in Element 1.0.14 (2020-XX-XX) +=================================================== + +Features ✨: + - Enable url previews for notices (#2562) + - Edit room permissions (#2471) + +Improvements 🙌: + - Add System theme option and set as default (#904, #2387) + - Store megolm outbound session to improve send time of first message after app launch. + - Warn user when they are leaving a not public room (#1460) + - Option to disable emoji keyboard (#2563) + +Bugfix 🐛: + - Unspecced msgType field in m.sticker (#2580) + - Wait for all room members to be known before sending a message to a e2e room (#2518) + - Url previews sometimes attached to wrong message (#2561) + - Room Topic not displayed correctly after visiting a link (#2551) + - Hiding membership events works the exact opposite (#2603) + - Tapping drawer having more than 1 room in notifications gives "malformed link" error (#2605) + - Sent image not displayed when opened immediately after sending (#409) + - Initial sync is not retried correctly when there is some network error. (#2632) + - Fix switch theme issue, and white field issue (#2599, #2528) + - Fix request too large Uri error when joining a room + +Translations 🗣: + - New language supported: Hebrew + +Build 🧱: + - Remove dependency to org.greenrobot.eventbus library + +Other changes: + - Migrate to ViewBindings (#1072) + Changes in Element 1.0.13 (2020-12-18) =================================================== diff --git a/attachment-viewer/build.gradle b/attachment-viewer/build.gradle index 59ba6c4500..d8cd7d0c98 100644 --- a/attachment-viewer/build.gradle +++ b/attachment-viewer/build.gradle @@ -16,7 +16,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' buildscript { repositories { @@ -55,6 +54,10 @@ android { kotlinOptions { jvmTarget = '1.8' } + + buildFeatures { + viewBinding true + } } dependencies { diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AnimatedImageViewHolder.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AnimatedImageViewHolder.kt index 96e6c92467..0d9eaf59b7 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AnimatedImageViewHolder.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AnimatedImageViewHolder.kt @@ -17,19 +17,17 @@ package im.vector.lib.attachmentviewer import android.view.View -import android.widget.ImageView -import android.widget.ProgressBar +import im.vector.lib.attachmentviewer.databinding.ItemAnimatedImageAttachmentBinding class AnimatedImageViewHolder constructor(itemView: View) : BaseViewHolder(itemView) { - val touchImageView: ImageView = itemView.findViewById(R.id.imageView) - val imageLoaderProgress: ProgressBar = itemView.findViewById(R.id.imageLoaderProgress) + val views = ItemAnimatedImageAttachmentBinding.bind(itemView) - internal val target = DefaultImageLoaderTarget(this, this.touchImageView) + internal val target = DefaultImageLoaderTarget(this, views.imageView) override fun onRecycled() { super.onRecycled() - touchImageView.setImageDrawable(null) + views.imageView.setImageDrawable(null) } } diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt index 71ce436cf2..9b1345cd39 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt @@ -33,43 +33,51 @@ import androidx.core.view.isVisible import androidx.core.view.updatePadding import androidx.transition.TransitionManager import androidx.viewpager2.widget.ViewPager2 -import kotlinx.android.synthetic.main.activity_attachment_viewer.* +import im.vector.lib.attachmentviewer.databinding.ActivityAttachmentViewerBinding + import java.lang.ref.WeakReference import kotlin.math.abs abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventListener { - lateinit var pager2: ViewPager2 - lateinit var imageTransitionView: ImageView - lateinit var transitionImageContainer: ViewGroup + protected val pager2: ViewPager2 + get() = views.attachmentPager + protected val imageTransitionView: ImageView + get() = views.transitionImageView + protected val transitionImageContainer: ViewGroup + get() = views.transitionImageContainer - var topInset = 0 - var bottomInset = 0 - var systemUiVisibility = true + private var topInset = 0 + private var bottomInset = 0 + private var systemUiVisibility = true private var overlayView: View? = null set(value) { if (value == overlayView) return - overlayView?.let { rootContainer.removeView(it) } - rootContainer.addView(value) + overlayView?.let { views.rootContainer.removeView(it) } + views.rootContainer.addView(value) value?.updatePadding(top = topInset, bottom = bottomInset) field = value } + private lateinit var views: ActivityAttachmentViewerBinding + private lateinit var swipeDismissHandler: SwipeToDismissHandler private lateinit var directionDetector: SwipeDirectionDetector private lateinit var scaleDetector: ScaleGestureDetector private lateinit var gestureDetector: GestureDetectorCompat var currentPosition = 0 + private set private var swipeDirection: SwipeDirection? = null private fun isScaled() = attachmentsAdapter.isScaled(currentPosition) + private val attachmentsAdapter = AttachmentsAdapter() + private var wasScaled: Boolean = false private var isSwipeToDismissAllowed: Boolean = true - private lateinit var attachmentsAdapter: AttachmentsAdapter private var isOverlayWasClicked = false // private val shouldDismissToBottom: Boolean @@ -95,17 +103,14 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) - setContentView(R.layout.activity_attachment_viewer) - attachmentPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL - attachmentsAdapter = AttachmentsAdapter() - attachmentPager.adapter = attachmentsAdapter - imageTransitionView = transitionImageView - transitionImageContainer = findViewById(R.id.transitionImageContainer) - pager2 = attachmentPager + views = ActivityAttachmentViewerBinding.inflate(layoutInflater) + setContentView(views.root) + views.attachmentPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL + views.attachmentPager.adapter = attachmentsAdapter directionDetector = createSwipeDirectionDetector() gestureDetector = createGestureDetector() - attachmentPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { + views.attachmentPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { override fun onPageScrollStateChanged(state: Int) { isImagePagerIdle = state == ViewPager2.SCROLL_STATE_IDLE } @@ -116,12 +121,12 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi }) swipeDismissHandler = createSwipeToDismissHandler() - rootContainer.setOnTouchListener(swipeDismissHandler) - rootContainer.viewTreeObserver.addOnGlobalLayoutListener { swipeDismissHandler.translationLimit = dismissContainer.height / 4 } + views.rootContainer.setOnTouchListener(swipeDismissHandler) + views.rootContainer.viewTreeObserver.addOnGlobalLayoutListener { swipeDismissHandler.translationLimit = views.dismissContainer.height / 4 } scaleDetector = createScaleGestureDetector() - ViewCompat.setOnApplyWindowInsetsListener(rootContainer) { _, insets -> + ViewCompat.setOnApplyWindowInsetsListener(views.rootContainer) { _, insets -> overlayView?.updatePadding(top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom) topInset = insets.systemWindowInsetTop bottomInset = insets.systemWindowInsetBottom @@ -170,7 +175,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi if (swipeDirection == null && (scaleDetector.isInProgress || ev.pointerCount > 1 || wasScaled)) { wasScaled = true // Log.v("ATTACHEMENTS", "dispatch to pager") - return attachmentPager.dispatchTouchEvent(ev) + return views.attachmentPager.dispatchTouchEvent(ev) } // Log.v("ATTACHEMENTS", "is current item scaled ${isScaled()}") @@ -196,16 +201,16 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi private fun handleEventActionDown(event: MotionEvent) { swipeDirection = null wasScaled = false - attachmentPager.dispatchTouchEvent(event) + views.attachmentPager.dispatchTouchEvent(event) - swipeDismissHandler.onTouch(rootContainer, event) + swipeDismissHandler.onTouch(views.rootContainer, event) isOverlayWasClicked = dispatchOverlayTouch(event) } private fun handleEventActionUp(event: MotionEvent) { // wasDoubleTapped = false - swipeDismissHandler.onTouch(rootContainer, event) - attachmentPager.dispatchTouchEvent(event) + swipeDismissHandler.onTouch(views.rootContainer, event) + views.attachmentPager.dispatchTouchEvent(event) isOverlayWasClicked = dispatchOverlayTouch(event) } @@ -220,12 +225,12 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi private fun toggleOverlayViewVisibility() { if (systemUiVisibility) { // we hide - TransitionManager.beginDelayedTransition(rootContainer) + TransitionManager.beginDelayedTransition(views.rootContainer) hideSystemUI() overlayView?.isVisible = false } else { // we show - TransitionManager.beginDelayedTransition(rootContainer) + TransitionManager.beginDelayedTransition(views.rootContainer) showSystemUI() overlayView?.isVisible = true } @@ -238,11 +243,11 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi return when (swipeDirection) { SwipeDirection.Up, SwipeDirection.Down -> { if (isSwipeToDismissAllowed && !wasScaled && isImagePagerIdle) { - swipeDismissHandler.onTouch(rootContainer, event) + swipeDismissHandler.onTouch(views.rootContainer, event) } else true } SwipeDirection.Left, SwipeDirection.Right -> { - attachmentPager.dispatchTouchEvent(event) + views.attachmentPager.dispatchTouchEvent(event) } else -> true } @@ -250,8 +255,8 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi private fun handleSwipeViewMove(translationY: Float, translationLimit: Int) { val alpha = calculateTranslationAlpha(translationY, translationLimit) - backgroundView.alpha = alpha - dismissContainer.alpha = alpha + views.backgroundView.alpha = alpha + views.dismissContainer.alpha = alpha overlayView?.alpha = alpha } @@ -265,7 +270,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi private fun createSwipeToDismissHandler() : SwipeToDismissHandler = SwipeToDismissHandler( - swipeView = dismissContainer, + swipeView = views.dismissContainer, shouldAnimateDismiss = { shouldAnimateDismiss() }, onDismiss = { animateClose() }, onSwipeViewMove = ::handleSwipeViewMove) diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentsAdapter.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentsAdapter.kt index 99c7777220..4805a1186b 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentsAdapter.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentsAdapter.kt @@ -98,7 +98,7 @@ class AttachmentsAdapter : RecyclerView.Adapter() { fun isScaled(position: Int): Boolean { val holder = recyclerView?.findViewHolderForAdapterPosition(position) if (holder is ZoomableImageViewHolder) { - return holder.touchImageView.attacher.scale > 1f + return holder.views.touchImageView.attacher.scale > 1f } return false } diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ImageLoaderTarget.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ImageLoaderTarget.kt index 9166c2ce4f..531e8171e1 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ImageLoaderTarget.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ImageLoaderTarget.kt @@ -44,29 +44,29 @@ internal class DefaultImageLoaderTarget(val holder: AnimatedImageViewHolder, pri override fun onResourceLoading(uid: String, placeholder: Drawable?) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = true + holder.views.imageLoaderProgress.isVisible = true } override fun onLoadFailed(uid: String, errorDrawable: Drawable?) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = false - holder.touchImageView.setImageDrawable(errorDrawable) + holder.views.imageLoaderProgress.isVisible = false + holder.views.imageView.setImageDrawable(errorDrawable) } override fun onResourceCleared(uid: String, placeholder: Drawable?) { if (holder.boundResourceUid != uid) return - holder.touchImageView.setImageDrawable(placeholder) + holder.views.imageView.setImageDrawable(placeholder) } override fun onResourceReady(uid: String, resource: Drawable) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = false + holder.views.imageLoaderProgress.isVisible = false // Glide mess up the view size :/ - holder.touchImageView.updateLayoutParams { + holder.views.imageView.updateLayoutParams { width = LinearLayout.LayoutParams.MATCH_PARENT height = LinearLayout.LayoutParams.MATCH_PARENT } - holder.touchImageView.setImageDrawable(resource) + holder.views.imageView.setImageDrawable(resource) if (resource is Animatable) { resource.start() } @@ -77,30 +77,30 @@ internal class DefaultImageLoaderTarget(val holder: AnimatedImageViewHolder, pri override fun onResourceLoading(uid: String, placeholder: Drawable?) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = true - holder.touchImageView.setImageDrawable(placeholder) + holder.views.imageLoaderProgress.isVisible = true + holder.views.touchImageView.setImageDrawable(placeholder) } override fun onLoadFailed(uid: String, errorDrawable: Drawable?) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = false - holder.touchImageView.setImageDrawable(errorDrawable) + holder.views.imageLoaderProgress.isVisible = false + holder.views.touchImageView.setImageDrawable(errorDrawable) } override fun onResourceCleared(uid: String, placeholder: Drawable?) { if (holder.boundResourceUid != uid) return - holder.touchImageView.setImageDrawable(placeholder) + holder.views.touchImageView.setImageDrawable(placeholder) } override fun onResourceReady(uid: String, resource: Drawable) { if (holder.boundResourceUid != uid) return - holder.imageLoaderProgress.isVisible = false + holder.views.imageLoaderProgress.isVisible = false // Glide mess up the view size :/ - holder.touchImageView.updateLayoutParams { + holder.views.touchImageView.updateLayoutParams { width = LinearLayout.LayoutParams.MATCH_PARENT height = LinearLayout.LayoutParams.MATCH_PARENT } - holder.touchImageView.setImageDrawable(resource) + holder.views.touchImageView.setImageDrawable(resource) } } } diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoLoaderTarget.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoLoaderTarget.kt index d88faba110..078edfc548 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoLoaderTarget.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoLoaderTarget.kt @@ -49,19 +49,19 @@ internal class DefaultVideoLoaderTarget(val holder: VideoViewHolder, private val override fun onThumbnailResourceCleared(uid: String, placeholder: Drawable?) { if (holder.boundResourceUid != uid) return - holder.thumbnailImage.setImageDrawable(placeholder) + holder.views.videoThumbnailImage.setImageDrawable(placeholder) } override fun onThumbnailResourceReady(uid: String, resource: Drawable) { if (holder.boundResourceUid != uid) return - holder.thumbnailImage.setImageDrawable(resource) + holder.views.videoThumbnailImage.setImageDrawable(resource) } override fun onVideoFileLoading(uid: String) { if (holder.boundResourceUid != uid) return - holder.thumbnailImage.isVisible = true - holder.loaderProgressBar.isVisible = true - holder.videoView.isVisible = false + holder.views.videoThumbnailImage.isVisible = true + holder.views.videoLoaderProgress.isVisible = true + holder.views.videoView.isVisible = false } override fun onVideoFileLoadFailed(uid: String) { @@ -82,8 +82,8 @@ internal class DefaultVideoLoaderTarget(val holder: VideoViewHolder, private val } private fun arrangeForVideoReady() { - holder.thumbnailImage.isVisible = false - holder.loaderProgressBar.isVisible = false - holder.videoView.isVisible = true + holder.views.videoThumbnailImage.isVisible = false + holder.views.videoLoaderProgress.isVisible = false + holder.views.videoView.isVisible = true } } diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoViewHolder.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoViewHolder.kt index 4d8be6468b..0b72ef36f0 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoViewHolder.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/VideoViewHolder.kt @@ -18,11 +18,8 @@ package im.vector.lib.attachmentviewer import android.util.Log import android.view.View -import android.widget.ImageView -import android.widget.ProgressBar -import android.widget.TextView -import android.widget.VideoView import androidx.core.view.isVisible +import im.vector.lib.attachmentviewer.databinding.ItemVideoAttachmentBinding import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -44,13 +41,9 @@ class VideoViewHolder constructor(itemView: View) : var eventListener: WeakReference? = null - val thumbnailImage: ImageView = itemView.findViewById(R.id.videoThumbnailImage) - val videoView: VideoView = itemView.findViewById(R.id.videoView) - val loaderProgressBar: ProgressBar = itemView.findViewById(R.id.videoLoaderProgress) - val videoControlIcon: ImageView = itemView.findViewById(R.id.videoControlIcon) - val errorTextView: TextView = itemView.findViewById(R.id.videoMediaViewerErrorView) + val views = ItemVideoAttachmentBinding.bind(itemView) - internal val target = DefaultVideoLoaderTarget(this, thumbnailImage) + internal val target = DefaultVideoLoaderTarget(this, views.videoThumbnailImage) override fun onRecycled() { super.onRecycled() @@ -77,12 +70,12 @@ class VideoViewHolder constructor(itemView: View) : } override fun entersBackground() { - if (videoView.isPlaying) { - progress = videoView.currentPosition + if (views.videoView.isPlaying) { + progress = views.videoView.currentPosition progressDisposable?.dispose() progressDisposable = null - videoView.stopPlayback() - videoView.pause() + views.videoView.stopPlayback() + views.videoView.pause() } } @@ -92,9 +85,9 @@ class VideoViewHolder constructor(itemView: View) : override fun onSelected(selected: Boolean) { if (!selected) { - if (videoView.isPlaying) { - progress = videoView.currentPosition - videoView.stopPlayback() + if (views.videoView.isPlaying) { + progress = views.videoView.currentPosition + views.videoView.stopPlayback() } else { progress = 0 } @@ -109,34 +102,34 @@ class VideoViewHolder constructor(itemView: View) : } private fun startPlaying() { - thumbnailImage.isVisible = false - loaderProgressBar.isVisible = false - videoView.isVisible = true + views.videoThumbnailImage.isVisible = false + views.videoLoaderProgress.isVisible = false + views.videoView.isVisible = true - videoView.setOnPreparedListener { + views.videoView.setOnPreparedListener { progressDisposable?.dispose() progressDisposable = Observable.interval(100, TimeUnit.MILLISECONDS) .timeInterval() .observeOn(AndroidSchedulers.mainThread()) .subscribe { - val duration = videoView.duration - val progress = videoView.currentPosition - val isPlaying = videoView.isPlaying + val duration = views.videoView.duration + val progress = views.videoView.currentPosition + val isPlaying = views.videoView.isPlaying // Log.v("FOO", "isPlaying $isPlaying $progress/$duration") eventListener?.get()?.onEvent(AttachmentEvents.VideoEvent(isPlaying, progress, duration)) } } try { - videoView.setVideoPath(mVideoPath) + views.videoView.setVideoPath(mVideoPath) } catch (failure: Throwable) { // Couldn't open Log.v(VideoViewHolder::class.java.name, "Failed to start video") } if (!wasPaused) { - videoView.start() + views.videoView.start() if (progress > 0) { - videoView.seekTo(progress) + views.videoView.seekTo(progress) } } } @@ -146,17 +139,17 @@ class VideoViewHolder constructor(itemView: View) : when (commands) { AttachmentCommands.StartVideo -> { wasPaused = false - videoView.start() + views.videoView.start() } AttachmentCommands.PauseVideo -> { wasPaused = true - videoView.pause() + views.videoView.pause() } is AttachmentCommands.SeekTo -> { - val duration = videoView.duration + val duration = views.videoView.duration if (duration > 0) { val seekDuration = duration * (commands.percentProgress / 100f) - videoView.seekTo(seekDuration.toInt()) + views.videoView.seekTo(seekDuration.toInt()) } } } diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ZoomableImageViewHolder.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ZoomableImageViewHolder.kt index 49378631e8..2a212c16a6 100644 --- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ZoomableImageViewHolder.kt +++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/ZoomableImageViewHolder.kt @@ -17,31 +17,29 @@ package im.vector.lib.attachmentviewer import android.view.View -import android.widget.ProgressBar -import com.github.chrisbanes.photoview.PhotoView +import im.vector.lib.attachmentviewer.databinding.ItemImageAttachmentBinding class ZoomableImageViewHolder constructor(itemView: View) : BaseViewHolder(itemView) { - val touchImageView: PhotoView = itemView.findViewById(R.id.touchImageView) - val imageLoaderProgress: ProgressBar = itemView.findViewById(R.id.imageLoaderProgress) + val views = ItemImageAttachmentBinding.bind(itemView) init { - touchImageView.setAllowParentInterceptOnEdge(false) - touchImageView.setOnScaleChangeListener { scaleFactor, _, _ -> + views.touchImageView.setAllowParentInterceptOnEdge(false) + views.touchImageView.setOnScaleChangeListener { scaleFactor, _, _ -> // Log.v("ATTACHEMENTS", "scaleFactor $scaleFactor") // It's a bit annoying but when you pitch down the scaling // is not exactly one :/ - touchImageView.setAllowParentInterceptOnEdge(scaleFactor <= 1.0008f) + views.touchImageView.setAllowParentInterceptOnEdge(scaleFactor <= 1.0008f) } - touchImageView.setScale(1.0f, true) - touchImageView.setAllowParentInterceptOnEdge(true) + views.touchImageView.setScale(1.0f, true) + views.touchImageView.setAllowParentInterceptOnEdge(true) } - internal val target = DefaultImageLoaderTarget.ZoomableImageTarget(this, touchImageView) + internal val target = DefaultImageLoaderTarget.ZoomableImageTarget(this, views.touchImageView) override fun onRecycled() { super.onRecycled() - touchImageView.setImageDrawable(null) + views.touchImageView.setImageDrawable(null) } } diff --git a/docs/ui-tests.md b/docs/ui-tests.md index ff01da0b31..6ebb52abe8 100644 --- a/docs/ui-tests.md +++ b/docs/ui-tests.md @@ -27,7 +27,6 @@ $ source env/bin/activate Every time you want to launch these test homeservers, type: ```shell script -$ virtualenv -p python3 env $ source env/bin/activate (env) $ demo/start.sh --no-rate-limit ``` diff --git a/fastlane/metadata/android/de/changelogs/40100100.txt b/fastlane/metadata/android/de/changelogs/40100100.txt index 70b786d12e..2faf4b5d39 100644 --- a/fastlane/metadata/android/de/changelogs/40100100.txt +++ b/fastlane/metadata/android/de/changelogs/40100100.txt @@ -1 +1,2 @@ -// TODO +Diese neue Version enthält hauptsächlich Fehlerkorrekturen und Verbesserungen. Nachrichten verschicken geht jetzt viel schneller. +Vollständige Versionshinweise: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/de/changelogs/40100110.txt b/fastlane/metadata/android/de/changelogs/40100110.txt new file mode 100644 index 0000000000..e70007b5d7 --- /dev/null +++ b/fastlane/metadata/android/de/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Diese neue Version enthält hauptsächlich Verbesserungen der Benutzer*innenoberfläche und der Handhabung. Du kannst jetzt ganz schnell Freund*innen einladen und DMs erstellen, indem du schlicht einen QR-Code scannst. +Vollständige Versionshinweise: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/en-US/changelogs/40100130.txt b/fastlane/metadata/android/en-US/changelogs/40100130.txt index 39715c2910..dc517fac48 100644 --- a/fastlane/metadata/android/en-US/changelogs/40100130.txt +++ b/fastlane/metadata/android/en-US/changelogs/40100130.txt @@ -1,2 +1,2 @@ Main changes in this version: URL Preview, new Emoji keyboard, new room settings capabilities, and snow for Christmas! -Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.12 \ No newline at end of file +Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.13 \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/40100140.txt b/fastlane/metadata/android/en-US/changelogs/40100140.txt new file mode 100644 index 0000000000..74f609fa15 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40100140.txt @@ -0,0 +1,2 @@ +Main changes in this version: Edit room permissions, automatic light/dark theme, and a bunch of bug fixes. +Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.14 \ No newline at end of file diff --git a/fastlane/metadata/android/et/changelogs/40100100.txt b/fastlane/metadata/android/et/changelogs/40100100.txt new file mode 100644 index 0000000000..11a040ceb0 --- /dev/null +++ b/fastlane/metadata/android/et/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Selles uues versioonis leidub põhiliselt veaparandusi ja pisikohendusi. Sõnumite saatmine on nüüd märkatavalt kiirem. +Kogu ingliskeelne muudatuste logi: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/et/changelogs/40100110.txt b/fastlane/metadata/android/et/changelogs/40100110.txt new file mode 100644 index 0000000000..019a84a2be --- /dev/null +++ b/fastlane/metadata/android/et/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Uues versioonis leidub põhiliselt kasutajaliidese ning kasutajakogemuse parandusi. Nüüd saad sõpradele kutseid saata ning otsevestlusi alustada QR-koodi lugemise abil. +Kõik muudatused: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/fa/changelogs/40100100.txt b/fastlane/metadata/android/fa/changelogs/40100100.txt index 6123bfc7fc..080d80a3ad 100644 --- a/fastlane/metadata/android/fa/changelogs/40100100.txt +++ b/fastlane/metadata/android/fa/changelogs/40100100.txt @@ -1 +1,2 @@ -// برای انجام +این نگارش جدید به طور عمده شامل رفع اشکال‌ها و بهبودها است. ارسال پیام اکنون بسیار سریعتر است. +گزارش دگرگونی کامل: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/fa/changelogs/40100110.txt b/fastlane/metadata/android/fa/changelogs/40100110.txt new file mode 100644 index 0000000000..c95922e2d7 --- /dev/null +++ b/fastlane/metadata/android/fa/changelogs/40100110.txt @@ -0,0 +1,2 @@ +این نگارش جدید به طور عمده شامل رابط کاربری و بهبود تجربه کاربر است. اکنون می‌توانید با پویش کدهای QR دوستانتان را دعوت کرده و بسیار سریع پیام مستقیم ایجاد کنید. +گزارش دگرگونی کامل: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/fa/short_description.txt b/fastlane/metadata/android/fa/short_description.txt index 4cfa767649..aba229f959 100644 --- a/fastlane/metadata/android/fa/short_description.txt +++ b/fastlane/metadata/android/fa/short_description.txt @@ -1 +1 @@ -گپ و تماس نامتمرکز امن. داده‌هایتان را از شرکت‌ها امن نگه دارید. +گپ و تماس نامتمرکز امن. داده‌هایتان را از اشخاص سوم امن نگه دارید. diff --git a/fastlane/metadata/android/fa/title.txt b/fastlane/metadata/android/fa/title.txt index fb4ea4125e..899b3d6adb 100644 --- a/fastlane/metadata/android/fa/title.txt +++ b/fastlane/metadata/android/fa/title.txt @@ -1 +1 @@ -المنت (ریوت سابق) +Element (پیشتر Riot.im) diff --git a/fastlane/metadata/android/fi/changelogs/40100110.txt b/fastlane/metadata/android/fi/changelogs/40100110.txt new file mode 100644 index 0000000000..356eabd29b --- /dev/null +++ b/fastlane/metadata/android/fi/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Tämä versio sisältää pääosin käyttöliittymä- ja käyttökokemusparannuksia. Voit nyt kutsua kavereita ja luoda yksityisviestejä nopeasti QR-koodeja lukemalla. +Täysi muutosloki: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/fi/full_description.txt b/fastlane/metadata/android/fi/full_description.txt index 70def518da..947d19ce3d 100644 --- a/fastlane/metadata/android/fi/full_description.txt +++ b/fastlane/metadata/android/fi/full_description.txt @@ -1,30 +1,30 @@ Element on uudenlainen viestinsovellus, joka: -1. Antaa sinun päättää yksityisyydestäsi. +1. Antaa sinun päättää yksityisyydestäsi 2. Antaa sinun kommunikoida kenen tahansa kanssa Matrix-verkossa ja jopa sen ulkopuolella siltaamalla sovelluksiin, kuten Slack 3. Suojaa sinua mainonnalta, tietojen keräämiseltä ja suljetuilta alustoilta 4. Suojaa sinut päästä päähän -salauksella sekä ristiin varmentamisella muiden todentamiseksi Element eroaa täysin muista viestintäsovelluksista, koska se on hajautettu ja avointa lähdekoodia. -Element antaa sinun isännöidä itse - valita isännän - jotta sinulla on yksityisyys ja voit hallita tietojasi sekä keskustelujasi. Se antaa sinulle pääsyn avoimeen verkkoon; joten et ole jumissa Elementin käyttäjissä. +Element antaa sinun isännöidä itse - tai valita palveluntarjoajan - jotta sinulla on yksityisyys ja voit hallita tietojasi sekä keskustelujasi. Se antaa sinulle pääsyn avoimeen verkkoon, joten et jää juttelemaan vain toisten Elementin käyttäjien kanssa. Se on myös hyvin turvallinen. Element pystyy tekemään kaiken tämän, koska se toimii Matrixilla - avoimella, hajautetun viestinnän standardilla. -Element antaa sinulle hallinnan antamalla sinun valita, kuka isännöi keskustelujasi. Element-sovelluksessa voit valita isännän eri tavoin: +Element antaa sinulle päätösvallan antamalla sinun valita, kuka isännöi keskustelujasi. Element-sovelluksessa voit valita isännän eri tavoin: 1. Hanki ilmainen tili Matrix-kehittäjien ylläpitämällä matrix.org-palvelimella tai valitse tuhansista vapaaehtoisten ylläpitämistä julkisista palvelimista. -2. Isännöi tiliäsi itse suorittamalla palvelinta omalla laitteellasi -3. Luo tili mukautetulla palvelimella yksinkertaisesti tilaamalla Element Matrix Services -palvelu +2. Isännöi tiliäsi itse ylläpitämällä palvelinta omalla laitteellasi +3. Luo tili sinua varten tehdyllä palvelimella tilaamalla Element Matrix Services -palvelu Miksi valita Element? -OMAT TIEDOT: Sinä päätät, missä tietosi ja viestisi säilytetään. Hallitset sitä itse, eikä jokin MEGAYHTIÖ, joka tutkii tietojasi tai antaa niitä kolmansille osapuolille. +OMAT TIEDOT: Sinä päätät, missä tietosi ja viestisi säilytetään. Sinä määräät, ei jokin jättiyhtiö, joka tutkii tietojasi tai antaa niitä kolmansille osapuolille. -AVOIN KOMMUNIKOINYI JA YHTEISTYÖ: Voit keskustella kaikkien muiden Matrix-verkon käyttäjien kanssa, riippumatta siitä käyttävätkö he Elementiä tai muuta Matrix-sovellusta, ja vaikka he käyttäisivät eri viestijärjestelmiä, kuten Slack, IRC tai XMPP. +AVOINTA VIESTINTÄÄ JA YHTEISTYÖTÄ: Voit keskustella kaikkien muiden Matrix-verkon käyttäjien kanssa, riippumatta siitä käyttävätkö he Elementiä tai muuta Matrix-sovellusta, ja vaikka he käyttäisivät eri viestijärjestelmiä, kuten Slack, IRC tai XMPP. ERITTÄIN TURVALLINEN: Vahva päästä päähän -salaus (vain keskustelussa olevat voivat purkaa viestien salauksen), ja ristiin varmentaminen keskustelun osallistujien laitteiden tarkistamiseksi. -TÄYDELLISTÄ VIESTINTÄÄ: Viestit, ääni- ja videopuhelut, tiedostojen jakaminen, näytön jakaminen ja koko joukko integraatioita, botteja ja widgettejä. Rakenna huoneita, yhteisöjä, pidä yhteyttä ja tee asioita. +KATTAVAA VIESTINTÄÄ: Viestit, ääni- ja videopuhelut, tiedostojen jakaminen, näytön jakaminen ja koko joukko integraatioita, botteja ja sovelmia. Rakenna huoneita ja yhteisöjä, pidä yhteyttä ja hoida asiasi. MISSÄ TAHANSA OLETKIN: Pidä yhteyttä missä tahansa, täysin synkronoidun viestihistorian kautta kaikilla laitteillasi ja verkossa osoitteessa https://app.element.io. diff --git a/fastlane/metadata/android/fi/short_description.txt b/fastlane/metadata/android/fi/short_description.txt index 5573ac1cb9..64f35a7dff 100644 --- a/fastlane/metadata/android/fi/short_description.txt +++ b/fastlane/metadata/android/fi/short_description.txt @@ -1 +1 @@ -Turvallista, hajautettua, keskusteluja ja VoIP-puheluita. Pidä tietosi turvassa. +Turvallista, hajautettua keskustelua ja VoIP-puheluita. Pidä tietosi turvassa. diff --git a/fastlane/metadata/android/fr/changelogs/40100100.txt b/fastlane/metadata/android/fr/changelogs/40100100.txt new file mode 100644 index 0000000000..36ca3016b6 --- /dev/null +++ b/fastlane/metadata/android/fr/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Cette nouvelle version contient principalement des corrections de bogues et des améliorations. Envoyer un message est maintenant plus rapide. +Liste complète des changements : https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/hu/changelogs/40100100.txt b/fastlane/metadata/android/hu/changelogs/40100100.txt new file mode 100644 index 0000000000..87a00efded --- /dev/null +++ b/fastlane/metadata/android/hu/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Ez az új verzió főképp hibajavításokat, és teljesítménybeli fejlesztéseket tartalmaz. Most már sokkal gyorsabb az üzenetek elküldése. +A változtatások teljes listája itt található: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/hu/changelogs/40100110.txt b/fastlane/metadata/android/hu/changelogs/40100110.txt new file mode 100644 index 0000000000..c14ed73aeb --- /dev/null +++ b/fastlane/metadata/android/hu/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Ez az új verzió főleg a felhasználói felülettel és a felhasználói élménnyel kapcsolatos javításokat tartalmaz. Mostantól már sokkal gyorsabban hívhatsz meg új ismerősöket a QR kód beolvasás által. +A változtatások teljes listája itt található: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/hu/full_description.txt b/fastlane/metadata/android/hu/full_description.txt index dfc842594d..b75f259d02 100644 --- a/fastlane/metadata/android/hu/full_description.txt +++ b/fastlane/metadata/android/hu/full_description.txt @@ -17,7 +17,7 @@ Az Element a te kezedbe adja az irányítást azáltal, hogy eldöntheted, ki t 2. A saját számítógépeden is futtathatsz szervert 3. Előfizethetsz egy saját szerverre az Element Matrix Szolgáltatások platformon -Miért válaszd az Element-et? +Miért jó az Element-et választani? ADATAID MEGVÉDÉSE: Eldöntheted, hol tárold az adataid és üzeneteid. A te tulajdonodban van, nem valami megacégnél, ami bányássza az adataid, vagy továbbadja másoknak. diff --git a/fastlane/metadata/android/it/changelogs/40100110.txt b/fastlane/metadata/android/it/changelogs/40100110.txt new file mode 100644 index 0000000000..897dda36d2 --- /dev/null +++ b/fastlane/metadata/android/it/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Questa nuova versione contiene principalmente miglioramenti di interfaccia ed esperienza utente. Ora puoi invitare amici e iniziare messaggi diretti rapidamente tramite codici QR. +Cronologia completa: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/nb_NO/changelogs/40100100.txt b/fastlane/metadata/android/nb_NO/changelogs/40100100.txt new file mode 100644 index 0000000000..7ef80a2532 --- /dev/null +++ b/fastlane/metadata/android/nb_NO/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Denne nye versjonen inneholder hovedsakelig feilrettinger og forbedringer. Å sende en melding er nå mye raskere. +Full endringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/nb_NO/changelogs/40100110.txt b/fastlane/metadata/android/nb_NO/changelogs/40100110.txt new file mode 100644 index 0000000000..c2f5e03845 --- /dev/null +++ b/fastlane/metadata/android/nb_NO/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Denne nye versjonen inneholder hovedsakelig forbedringer av brukergrensesnittet og brukeropplevelsen. Nå kan du invitere venner og opprette DM veldig raskt ved å skanne QR-koder. +Full endringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/nb_NO/short_description.txt b/fastlane/metadata/android/nb_NO/short_description.txt new file mode 100644 index 0000000000..b7cad4c849 --- /dev/null +++ b/fastlane/metadata/android/nb_NO/short_description.txt @@ -0,0 +1 @@ +Sikker desentralisert chat & VoIP. Beskytt dataene dine fra tredjeparter. diff --git a/fastlane/metadata/android/nb_NO/title.txt b/fastlane/metadata/android/nb_NO/title.txt new file mode 100644 index 0000000000..aacee5be54 --- /dev/null +++ b/fastlane/metadata/android/nb_NO/title.txt @@ -0,0 +1 @@ +Element (tidligere Riot.im) diff --git a/fastlane/metadata/android/pt_BR/changelogs/40100110.txt b/fastlane/metadata/android/pt_BR/changelogs/40100110.txt new file mode 100644 index 0000000000..2e9aef1c4a --- /dev/null +++ b/fastlane/metadata/android/pt_BR/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Esta nova versão contém principalmente melhorias na interface do usuário e na experiência do usuário. Agora você pode convidar amigos e criar conversas rapidamente, digitalizando códigos QR. +Registro completo de alterações: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/ru/changelogs/40100100.txt b/fastlane/metadata/android/ru/changelogs/40100100.txt new file mode 100644 index 0000000000..326562fb32 --- /dev/null +++ b/fastlane/metadata/android/ru/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Эта новая версия в основном содержит исправления ошибок и улучшения. Отправка сообщения стала намного быстрее. +Полный список изменений: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/ru/changelogs/40100110.txt b/fastlane/metadata/android/ru/changelogs/40100110.txt new file mode 100644 index 0000000000..166e5b701c --- /dev/null +++ b/fastlane/metadata/android/ru/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Эта новая версия в основном содержит улучшения пользовательского интерфейса и взаимодействия с пользователем. Теперь вы можете приглашать друзей и очень быстро создавать чаты, сканируя QR-коды. +Полный список изменений: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/sk/changelogs/40100100.txt b/fastlane/metadata/android/sk/changelogs/40100100.txt new file mode 100644 index 0000000000..b5fe2085ca --- /dev/null +++ b/fastlane/metadata/android/sk/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Táto verzia obsahuje predovšetkým opravy chýb. Odosielanie správ je odteraz omnoho rýchlejšie. +Kompletný zoznam zmien: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/sk/changelogs/40100110.txt b/fastlane/metadata/android/sk/changelogs/40100110.txt new file mode 100644 index 0000000000..ae68eee15e --- /dev/null +++ b/fastlane/metadata/android/sk/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Táto verzia obsahuje najmä vylepšenia používateľského rozhrania. Pozývať priateľov alebo vytvárať priame konverzácie môžete veľmi rýchlo naskenovaním QR kódov. +Kompletný zoznam zmien: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/sv/changelogs/40100110.txt b/fastlane/metadata/android/sv/changelogs/40100110.txt new file mode 100644 index 0000000000..e3ed460f17 --- /dev/null +++ b/fastlane/metadata/android/sv/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Den här nya versionen innehåller mest förbättringar för användargränssnittet och användarupplevelsen. Du kan nu bjuda in vänner och skapa direktmeddelanden väldigt snabbt genom att skanna QR-koder. +Full ändringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/uk/changelogs/40100110.txt b/fastlane/metadata/android/uk/changelogs/40100110.txt new file mode 100644 index 0000000000..32f220e75d --- /dev/null +++ b/fastlane/metadata/android/uk/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Ця нова версія містить переважно поліпшення інтерфейсу та зручності користування. Тепер ви можете запросити друзів і створити прямі повідомлення дуже швидко, скануючи QR-коди. +Повний перелік змін: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/vi/changelogs/40100100.txt b/fastlane/metadata/android/vi/changelogs/40100100.txt new file mode 100644 index 0000000000..7125bbde9a --- /dev/null +++ b/fastlane/metadata/android/vi/changelogs/40100100.txt @@ -0,0 +1,2 @@ +Phiên bản mới này chủ yếu bao gồm sửa lỗi và một số cải thiện. Gửi tin nhắn trở nên nhanh chóng hơn trước. +Danh sách đầy đủ các thay đổi: https://github.com/vector-im/element-android/releases/tag/v1.0.10 diff --git a/fastlane/metadata/android/vi/changelogs/40100110.txt b/fastlane/metadata/android/vi/changelogs/40100110.txt new file mode 100644 index 0000000000..fce5eff648 --- /dev/null +++ b/fastlane/metadata/android/vi/changelogs/40100110.txt @@ -0,0 +1,2 @@ +Phiên bản mới này chủ yếu bao gồm các cải thiện về giao diện và trải nghiệm người dùng. Bây giờ bạn có thể mời bạn bè và bắt đầu nói chuyện nhanh chóng bằng cách quét mã QR. +Danh sách đầy đủ các thay đổi: https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/vi/short_description.txt b/fastlane/metadata/android/vi/short_description.txt new file mode 100644 index 0000000000..b41ac0ce82 --- /dev/null +++ b/fastlane/metadata/android/vi/short_description.txt @@ -0,0 +1 @@ +Ứng dụng chat và gọi phân tán bảo mật. Bảo vệ dữ liệu của bạn khỏi bên thứ ba. diff --git a/fastlane/metadata/android/vi/title.txt b/fastlane/metadata/android/vi/title.txt new file mode 100644 index 0000000000..2a3bef31df --- /dev/null +++ b/fastlane/metadata/android/vi/title.txt @@ -0,0 +1 @@ +Element (trước là Riot.im) diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt new file mode 100644 index 0000000000..22dfe07097 --- /dev/null +++ b/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt @@ -0,0 +1,2 @@ +這個新版本主要包含使用者介面與使用者體驗改善。現在您可以邀請朋友,並透過掃描 QR code 來快速建立直接訊息了。 +完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.11 diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt new file mode 100644 index 0000000000..846126af63 --- /dev/null +++ b/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt @@ -0,0 +1,2 @@ +此版本中的主要變更:URL 預覽、新的表情符號鍵盤、新的聊天室設定功能以及聖誕節降雪! +完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.12 diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt new file mode 100644 index 0000000000..846126af63 --- /dev/null +++ b/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt @@ -0,0 +1,2 @@ +此版本中的主要變更:URL 預覽、新的表情符號鍵盤、新的聊天室設定功能以及聖誕節降雪! +完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.12 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cdc95ef6eb..f1577bddaa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=22449f5231796abd892c98b2a07c9ceebe4688d192cd2d6763f8e3bf8acbedeb -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionSha256Sum=a7ca23b3ccf265680f2bfd35f1f00b1424f4466292c7337c85d46c9641b3f053 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 519b8439c9..6a2f7575e5 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'realm-android' buildscript { @@ -13,10 +13,6 @@ buildscript { } } -androidExtensions { - experimental = true -} - android { compileSdkVersion 29 testOptions.unitTests.includeAndroidResources = true @@ -171,9 +167,6 @@ dependencies { implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' - // Bus - implementation 'org.greenrobot:eventbus:3.1.1' - // Phone number https://github.com/google/libphonenumber implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.23' diff --git a/matrix-sdk-android/proguard-rules.pro b/matrix-sdk-android/proguard-rules.pro index fa860d8049..182f9473e8 100644 --- a/matrix-sdk-android/proguard-rules.pro +++ b/matrix-sdk-android/proguard-rules.pro @@ -20,14 +20,8 @@ # hide the original source file name. #-renamesourcefileattribute SourceFile - -### EVENT BUS ### - +# BMA: Not sure I can delete this one without side effect -keepattributes *Annotation* --keepclassmembers class * { - @org.greenrobot.eventbus.Subscribe ; -} --keep enum org.greenrobot.eventbus.ThreadMode { *; } ### MOSHI ### diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt index 0e7088a6a5..cb49ee8818 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt @@ -86,7 +86,7 @@ class CommonTestHelper(context: Context) { * * @param session the session to sync */ - fun syncSession(session: Session) { + fun syncSession(session: Session, timeout: Long = TestConstants.timeOutMillis) { val lock = CountDownLatch(1) val job = GlobalScope.launch(Dispatchers.Main) { @@ -109,7 +109,7 @@ class CommonTestHelper(context: Context) { } GlobalScope.launch(Dispatchers.Main) { syncLiveData.observeForever(syncObserver) } - await(lock) + await(lock, timeout) } /** @@ -119,7 +119,7 @@ class CommonTestHelper(context: Context) { * @param message the message to send * @param nbOfMessages the number of time the message will be sent */ - fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List { + fun sendTextMessage(room: Room, message: String, nbOfMessages: Int, timeout: Long = TestConstants.timeOutMillis): List { val timeline = room.createTimeline(null, TimelineSettings(10)) val sentEvents = ArrayList(nbOfMessages) val latch = CountDownLatch(1) @@ -151,7 +151,7 @@ class CommonTestHelper(context: Context) { room.sendTextMessage(message + " #" + (i + 1)) } // Wait 3 second more per message - await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages) + await(latch, timeout = timeout + 3_000L * nbOfMessages) timeline.dispose() // Check that all events has been created @@ -215,14 +215,14 @@ class CommonTestHelper(context: Context) { .getLoginFlow(hs, it) } - doSync { + doSync(timeout = 60_000) { matrix.authenticationService .getRegistrationWizard() .createAccount(userName, password, null, it) } // Perform dummy step - val registrationResult = doSync { + val registrationResult = doSync(timeout = 60_000) { matrix.authenticationService .getRegistrationWizard() .dummy(it) @@ -231,7 +231,7 @@ class CommonTestHelper(context: Context) { assertTrue(registrationResult is RegistrationResult.Success) val session = (registrationResult as RegistrationResult.Success).session if (sessionTestParams.withInitialSync) { - syncSession(session) + syncSession(session, 60_000) } return session diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt index 76e59d9a90..b6bedbd719 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt @@ -18,14 +18,21 @@ package org.matrix.android.sdk.common import org.matrix.android.sdk.api.session.Session -data class CryptoTestData(val firstSession: Session, - val roomId: String, - val secondSession: Session? = null, - val thirdSession: Session? = null) { +data class CryptoTestData(val roomId: String, + val sessions: List) { + + val firstSession: Session + get() = sessions.first() + + val secondSession: Session? + get() = sessions.getOrNull(1) + + val thirdSession: Session? + get() = sessions.getOrNull(2) fun cleanUp(testHelper: CommonTestHelper) { - testHelper.signOutAndClose(firstSession) - secondSession?.let { testHelper.signOutAndClose(it) } - thirdSession?.let { testHelper.signOutAndClose(it) } + sessions.forEach { + testHelper.signOutAndClose(it) + } } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt index cbb22daf0f..3d5856fc64 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt @@ -73,7 +73,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { } } - return CryptoTestData(aliceSession, roomId) + return CryptoTestData(roomId, listOf(aliceSession)) } /** @@ -139,7 +139,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { // assertNotNull(roomFromBobPOV.powerLevels) // assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId)) - return CryptoTestData(aliceSession, aliceRoomId, bobSession) + return CryptoTestData(aliceRoomId, listOf(aliceSession, bobSession)) } /** @@ -157,7 +157,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { // wait the initial sync SystemClock.sleep(1000) - return CryptoTestData(aliceSession, aliceRoomId, cryptoTestData.secondSession, samSession) + return CryptoTestData(aliceRoomId, listOf(aliceSession, cryptoTestData.secondSession!!, samSession)) } /** @@ -381,4 +381,30 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) { } } } + + fun doE2ETestWithManyMembers(numberOfMembers: Int): CryptoTestData { + val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams) + aliceSession.cryptoService().setWarnOnUnknownDevices(false) + + val roomId = mTestHelper.doSync { + aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, it) + } + val room = aliceSession.getRoom(roomId)!! + + mTestHelper.runBlockingTest { + room.enableEncryption() + } + + val sessions = mutableListOf(aliceSession) + for (index in 1 until numberOfMembers) { + val session = mTestHelper.createAccount("User_$index", defaultSessionParams) + mTestHelper.doSync(timeout = 600_000) { room.invite(session.myUserId, null, it) } + println("TEST -> " + session.myUserId + " invited") + mTestHelper.doSync { session.joinRoom(room.roomId, null, emptyList(), it) } + println("TEST -> " + session.myUserId + " joined") + sessions.add(session) + } + + return CryptoTestData(roomId, sessions) + } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt index 197e36df06..2c4d89b070 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt @@ -50,6 +50,8 @@ import org.junit.FixMethodOrder import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.MethodSorters +import org.matrix.android.sdk.api.extensions.tryOrNull +import org.matrix.android.sdk.api.session.room.model.message.MessageContent import java.util.concurrent.CountDownLatch @RunWith(AndroidJUnit4::class) @@ -296,4 +298,77 @@ class KeyShareTests : InstrumentedTest { mTestHelper.signOutAndClose(aliceSession1) mTestHelper.signOutAndClose(aliceSession2) } + + @Test + fun test_ImproperKeyShareBug() { + val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true)) + + mTestHelper.doSync { + aliceSession.cryptoService().crossSigningService() + .initializeCrossSigning(UserPasswordAuth( + user = aliceSession.myUserId, + password = TestConstants.PASSWORD + ), it) + } + + // Create an encrypted room and send a couple of messages + val roomId = mTestHelper.doSync { + aliceSession.createRoom( + CreateRoomParams().apply { + visibility = RoomDirectoryVisibility.PRIVATE + enableEncryption() + }, + it + ) + } + val roomAlicePov = aliceSession.getRoom(roomId) + assertNotNull(roomAlicePov) + Thread.sleep(1_000) + assertTrue(roomAlicePov?.isEncrypted() == true) + val secondEventId = mTestHelper.sendTextMessage(roomAlicePov!!, "Message", 3)[1].eventId + + // Create bob session + + val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, SessionTestParams(true)) + mTestHelper.doSync { + bobSession.cryptoService().crossSigningService() + .initializeCrossSigning(UserPasswordAuth( + user = bobSession.myUserId, + password = TestConstants.PASSWORD + ), it) + } + + // Let alice invite bob + mTestHelper.doSync { + roomAlicePov.invite(bobSession.myUserId, null, it) + } + + mTestHelper.doSync { + bobSession.joinRoom(roomAlicePov.roomId, null, emptyList(), it) + } + + // we want to discard alice outbound session + aliceSession.cryptoService().discardOutboundSession(roomAlicePov.roomId) + + // and now resend a new message to reset index to 0 + mTestHelper.sendTextMessage(roomAlicePov, "After", 1) + + val roomRoomBobPov = aliceSession.getRoom(roomId) + val beforeJoin = roomRoomBobPov!!.getTimeLineEvent(secondEventId) + + var dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin!!.root, "") } + + assert(dRes == null) + + // Try to re-ask the keys + + bobSession.cryptoService().reRequestRoomKeyForEvent(beforeJoin!!.root) + + Thread.sleep(3_000) + + // With the bug the first session would have improperly reshare that key :/ + dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin.root, "") } + Log.d("#TEST", "KS: sgould not decrypt that ${beforeJoin.root.getClearContent().toModel()?.body}") + assert(dRes?.clearEvent == null) + } } diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt new file mode 100644 index 0000000000..ff07cf1d1d --- /dev/null +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.session.room.timeline + +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.runners.MethodSorters +import org.matrix.android.sdk.InstrumentedTest +import org.matrix.android.sdk.api.extensions.orFalse +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.message.MessageContent +import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings +import org.matrix.android.sdk.common.CommonTestHelper +import org.matrix.android.sdk.common.CryptoTestHelper +import java.util.concurrent.CountDownLatch +import kotlin.test.fail + +@RunWith(JUnit4::class) +@FixMethodOrder(MethodSorters.JVM) +class TimelineWithManyMembersTest : InstrumentedTest { + + companion object { + private const val NUMBER_OF_MEMBERS = 6 + } + + private val commonTestHelper = CommonTestHelper(context()) + private val cryptoTestHelper = CryptoTestHelper(commonTestHelper) + + /** + * Ensures when someone sends a message to a crowded room, everyone can decrypt the message. + */ + @Test + fun everyone_should_decrypt_message_in_a_crowded_room() { + val cryptoTestData = cryptoTestHelper.doE2ETestWithManyMembers(NUMBER_OF_MEMBERS) + + val sessionForFirstMember = cryptoTestData.firstSession + val roomForFirstMember = sessionForFirstMember.getRoom(cryptoTestData.roomId)!! + + val firstMessage = "First messages from Alice" + commonTestHelper.sendTextMessage( + roomForFirstMember, + firstMessage, + 1, + 600_000 + ) + + for (index in 1 until cryptoTestData.sessions.size) { + val session = cryptoTestData.sessions[index] + val roomForCurrentMember = session.getRoom(cryptoTestData.roomId)!! + val timelineForCurrentMember = roomForCurrentMember.createTimeline(null, TimelineSettings(30)) + timelineForCurrentMember.start() + + session.startSync(true) + + run { + val lock = CountDownLatch(1) + val eventsListener = commonTestHelper.createEventListener(lock) { snapshot -> + snapshot + .find { it.isEncrypted() } + ?.let { + val body = it.root.getClearContent()?.toModel()?.body + if (body?.startsWith(firstMessage).orFalse()) { + println("User " + session.myUserId + " decrypted as " + body) + return@createEventListener true + } else { + fail("User " + session.myUserId + " decrypted as " + body + " CryptoError: " + it.root.mCryptoError) + } + } ?: return@createEventListener false + } + timelineForCurrentMember.addListener(eventsListener) + commonTestHelper.await(lock, 600_000) + } + session.stopSync() + } + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt index 360b955869..bf21941e0c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt @@ -41,6 +41,16 @@ interface AuthenticationService { */ fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback): Cancelable + /** + * Get a SSO url + */ + fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String? + + /** + * Get the sign in or sign up fallback URL + */ + fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String? + /** * Return a LoginWizard, to login to the homeserver. The login flow has to be retrieved first. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt index d89607843f..6759c59237 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.api.auth.data import android.os.Parcelable import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @JsonClass(generateAdapter = true) @Parcelize diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt index 4f9c84a47c..6675fb0ff5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt @@ -37,6 +37,6 @@ class SenderNotificationPermissionCondition( fun isSatisfied(event: Event, powerLevels: PowerLevelsContent): Boolean { val powerLevelsHelper = PowerLevelsHelper(powerLevels) - return event.senderId != null && powerLevelsHelper.getUserPowerLevelValue(event.senderId) >= powerLevelsHelper.notificationLevel(key) + return event.senderId != null && powerLevelsHelper.getUserPowerLevelValue(event.senderId) >= powerLevels.notificationLevel(key) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt index 4164b84ecd..98a84b8b66 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt @@ -20,7 +20,7 @@ import android.net.Uri import android.os.Parcelable import androidx.exifinterface.media.ExifInterface import com.squareup.moshi.JsonClass -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.util.MimeTypes.normalizeMimeType @Parcelize diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt index aefc086b43..ac1d726d03 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt @@ -25,7 +25,6 @@ interface PermalinkService { companion object { const val MATRIX_TO_URL_BASE = "https://matrix.to/#/" - const val MATRIX_TO_CUSTOM_SCHEME_URL_BASE = "element://" } /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt index 696b612389..e778f5740d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt @@ -25,28 +25,85 @@ import org.matrix.android.sdk.api.session.room.powerlevels.Role */ @JsonClass(generateAdapter = true) data class PowerLevelsContent( + /** + * The level required to ban a user. Defaults to 50 if unspecified. + */ @Json(name = "ban") val ban: Int = Role.Moderator.value, + /** + * The level required to kick a user. Defaults to 50 if unspecified. + */ @Json(name = "kick") val kick: Int = Role.Moderator.value, + /** + * The level required to invite a user. Defaults to 50 if unspecified. + */ @Json(name = "invite") val invite: Int = Role.Moderator.value, + /** + * The level required to redact an event. Defaults to 50 if unspecified. + */ @Json(name = "redact") val redact: Int = Role.Moderator.value, + /** + * The default level required to send message events. Can be overridden by the events key. Defaults to 0 if unspecified. + */ @Json(name = "events_default") val eventsDefault: Int = Role.Default.value, - @Json(name = "events") val events: MutableMap = HashMap(), + /** + * The level required to send specific event types. This is a mapping from event type to power level required. + */ + @Json(name = "events") val events: Map = emptyMap(), + /** + * The default power level for every user in the room, unless their user_id is mentioned in the users key. Defaults to 0 if unspecified. + */ @Json(name = "users_default") val usersDefault: Int = Role.Default.value, - @Json(name = "users") val users: MutableMap = HashMap(), + /** + * The power levels for specific users. This is a mapping from user_id to power level for that user. + */ + @Json(name = "users") val users: Map = emptyMap(), + /** + * The default level required to send state events. Can be overridden by the events key. Defaults to 50 if unspecified. + */ @Json(name = "state_default") val stateDefault: Int = Role.Moderator.value, - @Json(name = "notifications") val notifications: Map = HashMap() + /** + * The power level requirements for specific notification types. This is a mapping from key to power level for that notifications key. + */ + @Json(name = "notifications") val notifications: Map = emptyMap() ) { /** - * Alter this content with a new power level for the specified user + * Return a copy of this content with a new power level for the specified user * * @param userId the userId to alter the power level of * @param powerLevel the new power level, or null to set the default value. */ - fun setUserPowerLevel(userId: String, powerLevel: Int?) { - if (powerLevel == null || powerLevel == usersDefault) { - users.remove(userId) - } else { - users[userId] = powerLevel + fun setUserPowerLevel(userId: String, powerLevel: Int?): PowerLevelsContent { + return copy( + users = users.toMutableMap().apply { + if (powerLevel == null || powerLevel == usersDefault) { + remove(userId) + } else { + put(userId, powerLevel) + } + } + ) + } + + /** + * Get the notification level for a dedicated key. + * + * @param key the notification key + * @return the level, default to Moderator if the key is not found + */ + fun notificationLevel(key: String): Int { + return when (val value = notifications[key]) { + // the first implementation was a string value + is String -> value.toInt() + is Double -> value.toInt() + is Int -> value + else -> Role.Moderator.value } } + + companion object { + /** + * Key to use for content.notifications and get the level required to trigger an @room notification. Defaults to 50 if unspecified. + */ + const val NOTIFICATIONS_ROOM_KEY = "room" + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt index 00fa68c0ac..280316d4b5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt @@ -27,6 +27,7 @@ data class MessageStickerContent( /** * Set in local, not from server */ + @Transient override val msgType: String = MessageType.MSGTYPE_STICKER_LOCAL, /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt index 47922f6968..4f1253c6df 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt @@ -108,19 +108,4 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) { val powerLevel = getUserPowerLevelValue(userId) return powerLevel >= powerLevelsContent.redact } - - /** - * Get the notification level for a dedicated key. - * - * @param key the notification key - * @return the level - */ - fun notificationLevel(key: String): Int { - return when (val value = powerLevelsContent.notifications[key]) { - // the first implementation was a string value - is String -> value.toInt() - is Int -> value - else -> Role.Moderator.value - } - } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt new file mode 100644 index 0000000000..c625a7f088 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.session.room.state + +import org.matrix.android.sdk.api.query.QueryStringValue +import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.RoomJoinRules +import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent + +/** + * Return true if a room can be joined by anyone (RoomJoinRules.PUBLIC) + */ +fun StateService.isPublic(): Boolean { + return getStateEvent(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition) + ?.content + ?.toModel() + ?.joinRules == RoomJoinRules.PUBLIC +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt new file mode 100644 index 0000000000..17f27b2514 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.api.util + +import java.net.URLEncoder + +/** + * Append param and value to a Url, using "?" or "&". Value parameter will be encoded + * Return this for chaining purpose + */ +fun StringBuilder.appendParamToUrl(param: String, value: String): StringBuilder { + if (contains("?")) { + append("&") + } else { + append("?") + } + + append(param) + append("=") + append(URLEncoder.encode(value, "utf-8")) + + return this +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt similarity index 69% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt index 7d18aba627..642279cc27 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt @@ -14,25 +14,25 @@ * limitations under the License. */ -package org.matrix.android.sdk.api.auth +package org.matrix.android.sdk.internal.auth /** * Path to use when the client does not supported any or all login flows * Ref: https://matrix.org/docs/spec/client_server/latest#login-fallback */ -const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/" +internal const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/" /** * Path to use when the client does not supported any or all registration flows * Not documented */ -const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/" +internal const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/" /** * Path to use when the client want to connect using SSO * Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login */ -const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect" -const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect" +internal const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect" +internal const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect" -const val SSO_REDIRECT_URL_PARAM = "redirectUrl" +internal const val SSO_REDIRECT_URL_PARAM = "redirectUrl" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt index 55f053de8d..c99e9bd81c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt @@ -34,6 +34,7 @@ import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.api.util.NoOpCancellable +import org.matrix.android.sdk.api.util.appendParamToUrl import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse import org.matrix.android.sdk.internal.auth.data.RiotConfig @@ -99,6 +100,52 @@ internal class DefaultAuthenticationService @Inject constructor( } } + override fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String? { + val homeServerUrlBase = getHomeServerUrlBase() ?: return null + + return buildString { + append(homeServerUrlBase) + if (providerId != null) { + append(MSC2858_SSO_REDIRECT_PATH) + append("/$providerId") + } else { + append(SSO_REDIRECT_PATH) + } + // Set the redirect url + appendParamToUrl(SSO_REDIRECT_URL_PARAM, redirectUrl) + deviceId?.takeIf { it.isNotBlank() }?.let { + // But https://github.com/matrix-org/synapse/issues/5755 + appendParamToUrl("device_id", it) + } + } + } + + override fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String? { + val homeServerUrlBase = getHomeServerUrlBase() ?: return null + + return buildString { + append(homeServerUrlBase) + if (forSignIn) { + append(LOGIN_FALLBACK_PATH) + deviceId?.takeIf { it.isNotBlank() }?.let { + // But https://github.com/matrix-org/synapse/issues/5755 + appendParamToUrl("device_id", it) + } + } else { + // For sign up + append(REGISTER_FALLBACK_PATH) + } + } + } + + private fun getHomeServerUrlBase(): String? { + return pendingSessionData + ?.homeServerConnectionConfig + ?.homeServerUri + ?.toString() + ?.trim { it == '/' } + } + override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback): Cancelable { pendingSessionData = null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/LocalizedFlowDataLoginTerms.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/LocalizedFlowDataLoginTerms.kt index 1e18887008..5d119bb617 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/LocalizedFlowDataLoginTerms.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/LocalizedFlowDataLoginTerms.kt @@ -17,7 +17,7 @@ package org.matrix.android.sdk.internal.auth.registration import android.os.Parcelable -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize /** * This class represent a localized privacy policy for registration Flow. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt index c2c81894fb..7e92ff3e88 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.session.events.model.Event @@ -60,7 +59,6 @@ internal class CancelGossipRequestWorker(context: Context, @Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var cryptoStore: IMXCryptoStore - @Inject lateinit var eventBus: EventBus @Inject lateinit var credentials: Credentials override fun injectWith(injector: SessionComponent) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt index 4f94a27bbd..c075c90eb9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt @@ -32,6 +32,7 @@ import org.matrix.android.sdk.internal.crypto.crosssigning.toBase64NoPadding import org.matrix.android.sdk.internal.crypto.keysbackup.util.extractCurveKeyFromRecoveryKey import org.matrix.android.sdk.internal.crypto.model.rest.GossipingDefaultContent import org.matrix.android.sdk.internal.crypto.model.rest.GossipingToDeviceObject +import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyRequestBody import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.session.SessionScope @@ -206,34 +207,7 @@ internal class IncomingGossipingRequestManager @Inject constructor( Timber.v("## CRYPTO | GOSSIP processIncomingRoomKeyRequest from $userId:$deviceId for $roomId / ${body.sessionId} id ${request.requestId}") if (credentials.userId != userId) { - Timber.w("## CRYPTO | GOSSIP processReceivedGossipingRequests() : room key request from other user") - val senderKey = body.senderKey ?: return Unit - .also { Timber.w("missing senderKey") } - .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } - val sessionId = body.sessionId ?: return Unit - .also { Timber.w("missing sessionId") } - .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } - - if (alg != MXCRYPTO_ALGORITHM_MEGOLM) { - return Unit - .also { Timber.w("Only megolm is accepted here") } - .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } - } - - val roomEncryptor = roomEncryptorsStore.get(roomId) ?: return Unit - .also { Timber.w("no room Encryptor") } - .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } - - cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { - val isSuccess = roomEncryptor.reshareKey(sessionId, userId, deviceId, senderKey) - - if (isSuccess) { - cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTED) - } else { - cryptoStore.updateGossipingRequestState(request, GossipingRequestState.UNABLE_TO_PROCESS) - } - } - cryptoStore.updateGossipingRequestState(request, GossipingRequestState.RE_REQUESTED) + handleKeyRequestFromOtherUser(body, request, alg, roomId, userId, deviceId) return } // TODO: should we queue up requests we don't yet have keys for, in case they turn up later? @@ -291,6 +265,42 @@ internal class IncomingGossipingRequestManager @Inject constructor( onRoomKeyRequest(request) } + private fun handleKeyRequestFromOtherUser(body: RoomKeyRequestBody, + request: IncomingRoomKeyRequest, + alg: String, + roomId: String, + userId: String, + deviceId: String) { + Timber.w("## CRYPTO | GOSSIP processReceivedGossipingRequests() : room key request from other user") + val senderKey = body.senderKey ?: return Unit + .also { Timber.w("missing senderKey") } + .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } + val sessionId = body.sessionId ?: return Unit + .also { Timber.w("missing sessionId") } + .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } + + if (alg != MXCRYPTO_ALGORITHM_MEGOLM) { + return Unit + .also { Timber.w("Only megolm is accepted here") } + .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } + } + + val roomEncryptor = roomEncryptorsStore.get(roomId) ?: return Unit + .also { Timber.w("no room Encryptor") } + .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) } + + cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { + val isSuccess = roomEncryptor.reshareKey(sessionId, userId, deviceId, senderKey) + + if (isSuccess) { + cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTED) + } else { + cryptoStore.updateGossipingRequestState(request, GossipingRequestState.UNABLE_TO_PROCESS) + } + } + cryptoStore.updateGossipingRequestState(request, GossipingRequestState.RE_REQUESTED) + } + private fun processIncomingSecretShareRequest(request: IncomingSecretShareRequest) { val secretName = request.secretName ?: return Unit.also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt index c952602d93..b1e91e8d50 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt @@ -19,6 +19,8 @@ package org.matrix.android.sdk.internal.crypto import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.util.JSON_DICT_PARAMETERIZED_TYPE import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.internal.crypto.algorithms.megolm.MXOutboundSessionInfo +import org.matrix.android.sdk.internal.crypto.algorithms.megolm.SharedWithHelper import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult import org.matrix.android.sdk.internal.crypto.model.OlmInboundGroupSessionWrapper2 import org.matrix.android.sdk.internal.crypto.model.OlmSessionWrapper @@ -46,7 +48,7 @@ internal class MXOlmDevice @Inject constructor( */ private val store: IMXCryptoStore, private val inboundGroupSessionStore: InboundGroupSessionStore - ) { +) { /** * @return the Curve25519 key for the account. @@ -63,11 +65,15 @@ internal class MXOlmDevice @Inject constructor( // The OLM lib utility instance. private var olmUtility: OlmUtility? = null + private data class GroupSessionCacheItem( + val groupId: String, + val groupSession: OlmOutboundGroupSession + ) + // The outbound group session. - // They are not stored in 'store' to avoid to remember to which devices we sent the session key. - // Plus, in cryptography, it is good to refresh sessions from time to time. - // The key is the session id, the value the outbound group session. - private val outboundGroupSessionStore: MutableMap = HashMap() + // Caches active outbound session to avoid to sync with DB before read + // The key is the session id, the value the . + private val outboundGroupSessionCache: MutableMap = HashMap() // Store a set of decrypted message indexes for each group session. // This partially mitigates a replay attack where a MITM resends a group @@ -135,6 +141,10 @@ internal class MXOlmDevice @Inject constructor( */ fun release() { olmUtility?.releaseUtility() + outboundGroupSessionCache.values.forEach { + it.groupSession.releaseSession() + } + outboundGroupSessionCache.clear() } /** @@ -406,11 +416,12 @@ internal class MXOlmDevice @Inject constructor( * * @return the session id for the outbound session. */ - fun createOutboundGroupSession(): String? { + fun createOutboundGroupSessionForRoom(roomId: String): String? { var session: OlmOutboundGroupSession? = null try { session = OlmOutboundGroupSession() - outboundGroupSessionStore[session.sessionIdentifier()] = session + outboundGroupSessionCache[session.sessionIdentifier()] = GroupSessionCacheItem(roomId, session) + store.storeCurrentOutboundGroupSessionForRoom(roomId, session) return session.sessionIdentifier() } catch (e: Exception) { Timber.e(e, "createOutboundGroupSession") @@ -421,6 +432,39 @@ internal class MXOlmDevice @Inject constructor( return null } + fun storeOutboundGroupSessionForRoom(roomId: String, sessionId: String) { + outboundGroupSessionCache[sessionId]?.let { + store.storeCurrentOutboundGroupSessionForRoom(roomId, it.groupSession) + } + } + + fun restoreOutboundGroupSessionForRoom(roomId: String): MXOutboundSessionInfo? { + val restoredOutboundGroupSession = store.getCurrentOutboundGroupSessionForRoom(roomId) + if (restoredOutboundGroupSession != null) { + val sessionId = restoredOutboundGroupSession.outboundGroupSession.sessionIdentifier() + // cache it + outboundGroupSessionCache[sessionId] = GroupSessionCacheItem(roomId, restoredOutboundGroupSession.outboundGroupSession) + + return MXOutboundSessionInfo( + sessionId = sessionId, + sharedWithHelper = SharedWithHelper(roomId, sessionId, store), + restoredOutboundGroupSession.creationTime + ) + } + return null + } + + fun discardOutboundGroupSessionForRoom(roomId: String) { + val toDiscard = outboundGroupSessionCache.filter { + it.value.groupId == roomId + } + toDiscard.forEach { (sessionId, cacheItem) -> + cacheItem.groupSession.releaseSession() + outboundGroupSessionCache.remove(sessionId) + } + store.storeCurrentOutboundGroupSessionForRoom(roomId, null) + } + /** * Get the current session key of an outbound group session. * @@ -430,7 +474,7 @@ internal class MXOlmDevice @Inject constructor( fun getSessionKey(sessionId: String): String? { if (sessionId.isNotEmpty()) { try { - return outboundGroupSessionStore[sessionId]!!.sessionKey() + return outboundGroupSessionCache[sessionId]!!.groupSession.sessionKey() } catch (e: Exception) { Timber.e(e, "## getSessionKey() : failed") } @@ -446,7 +490,7 @@ internal class MXOlmDevice @Inject constructor( */ fun getMessageIndex(sessionId: String): Int { return if (sessionId.isNotEmpty()) { - outboundGroupSessionStore[sessionId]!!.messageIndex() + outboundGroupSessionCache[sessionId]!!.groupSession.messageIndex() } else 0 } @@ -460,7 +504,7 @@ internal class MXOlmDevice @Inject constructor( fun encryptGroupMessage(sessionId: String, payloadString: String): String? { if (sessionId.isNotEmpty() && payloadString.isNotEmpty()) { try { - return outboundGroupSessionStore[sessionId]!!.encryptMessage(payloadString) + return outboundGroupSessionCache[sessionId]!!.groupSession.encryptMessage(payloadString) } catch (e: Exception) { Timber.e(e, "## encryptGroupMessage() : failed") } @@ -747,7 +791,7 @@ internal class MXOlmDevice @Inject constructor( throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY, MXCryptoError.ERROR_MISSING_PROPERTY_REASON) } - val session = inboundGroupSessionStore.getInboundGroupSession(sessionId, senderKey) + val session = inboundGroupSessionStore.getInboundGroupSession(sessionId, senderKey) if (session != null) { // Check that the room id matches the original one for the session. This stops diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt index 085469e9d9..e8d567b944 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.session.events.model.Event @@ -52,7 +51,6 @@ internal class SendGossipRequestWorker(context: Context, @Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var cryptoStore: IMXCryptoStore - @Inject lateinit var eventBus: EventBus @Inject lateinit var credentials: Credentials override fun injectWith(injector: SessionComponent) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt index bcaa16f356..8c68057056 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.session.events.model.Event @@ -54,7 +53,6 @@ internal class SendGossipWorker(context: Context, @Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var cryptoStore: IMXCryptoStore - @Inject lateinit var eventBus: EventBus @Inject lateinit var credentials: Credentials @Inject lateinit var messageEncrypter: MessageEncrypter @Inject lateinit var ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt index fd431ce735..fa8acafb83 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt @@ -68,6 +68,10 @@ internal class MXMegolmEncryption( // case outboundSession.shareOperation will be non-null.) private var outboundSession: MXOutboundSessionInfo? = null + init { + // restore existing outbound session if any + outboundSession = olmDevice.restoreOutboundGroupSessionForRoom(roomId) + } // Default rotation periods // TODO: Make it configurable via parameters // Session rotation periods @@ -86,6 +90,9 @@ internal class MXMegolmEncryption( return encryptContent(outboundSession, eventType, eventContent) .also { notifyWithheldForSession(devices.withHeldDevices, outboundSession) + // annoyingly we have to serialize again the saved outbound session to store message index :/ + // if not we would see duplicate message index errors + olmDevice.storeOutboundGroupSessionForRoom(roomId, outboundSession.sessionId) } } @@ -107,6 +114,7 @@ internal class MXMegolmEncryption( override fun discardSessionKey() { outboundSession = null + olmDevice.discardOutboundGroupSessionForRoom(roomId) } /** @@ -116,7 +124,7 @@ internal class MXMegolmEncryption( */ private fun prepareNewSessionInRoom(): MXOutboundSessionInfo { Timber.v("## CRYPTO | prepareNewSessionInRoom() ") - val sessionId = olmDevice.createOutboundGroupSession() + val sessionId = olmDevice.createOutboundGroupSessionForRoom(roomId) val keysClaimedMap = HashMap() keysClaimedMap["ed25519"] = olmDevice.deviceEd25519Key!! @@ -152,7 +160,7 @@ internal class MXMegolmEncryption( val deviceIds = devicesInRoom.getUserDeviceIds(userId) for (deviceId in deviceIds!!) { val deviceInfo = devicesInRoom.getObject(userId, deviceId) - if (deviceInfo != null && !cryptoStore.wasSessionSharedWithUser(roomId, safeSession.sessionId, userId, deviceId).found) { + if (deviceInfo != null && !cryptoStore.getSharedSessionInfo(roomId, safeSession.sessionId, userId, deviceId).found) { val devices = shareMap.getOrPut(userId) { ArrayList() } devices.add(deviceInfo) } @@ -401,11 +409,18 @@ internal class MXMegolmEncryption( .also { Timber.w("## Crypto reshareKey: Device not found") } // Get the chain index of the key we previously sent this device - val chainIndex = outboundSession?.sharedWithHelper?.wasSharedWith(userId, deviceId) ?: return false + val wasSessionSharedWithUser = cryptoStore.getSharedSessionInfo(roomId, sessionId, userId, deviceId) + if (!wasSessionSharedWithUser.found) { + // This session was never shared with this user + // Send a room key with held + notifyKeyWithHeld(listOf(UserDevice(userId, deviceId)), sessionId, senderKey, WithHeldCode.UNAUTHORISED) + Timber.w("## Crypto reshareKey: ERROR : Never shared megolm with this device") + return false + } + // if found chain index should not be null + val chainIndex = wasSessionSharedWithUser.chainIndex ?: return false .also { - // Send a room key with held - notifyKeyWithHeld(listOf(UserDevice(userId, deviceId)), sessionId, senderKey, WithHeldCode.UNAUTHORISED) - Timber.w("## Crypto reshareKey: ERROR : Never share megolm with this device") + Timber.w("## Crypto reshareKey: Null chain index") } val devicesByUser = mapOf(userId to listOf(deviceInfo)) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt index 9244b4d5e7..5a68937868 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt @@ -23,9 +23,9 @@ import timber.log.Timber internal class MXOutboundSessionInfo( // The id of the session val sessionId: String, - val sharedWithHelper: SharedWithHelper) { - // When the session was created - private val creationTime = System.currentTimeMillis() + val sharedWithHelper: SharedWithHelper, + // When the session was created + private val creationTime: Long = System.currentTimeMillis()) { // Number of times this session has been used var useCount: Int = 0 diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt index 921f9b2cdc..f17168a6d2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt @@ -28,10 +28,6 @@ internal class SharedWithHelper( return cryptoStore.getSharedWithInfo(roomId, sessionId) } - fun wasSharedWith(userId: String, deviceId: String): Int? { - return cryptoStore.wasSessionSharedWithUser(roomId, sessionId, userId, deviceId).chainIndex - } - fun markedSessionAsShared(userId: String, deviceId: String, chainIndex: Int) { cryptoStore.markedSessionAsShared(roomId, sessionId, userId, deviceId, chainIndex) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/attachments/ElementToDecrypt.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/attachments/ElementToDecrypt.kt index b77006aa3a..c071384df4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/attachments/ElementToDecrypt.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/attachments/ElementToDecrypt.kt @@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.crypto.attachments import android.os.Parcelable import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileInfo -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize fun EncryptedFileInfo.toElementToDecrypt(): ElementToDecrypt? { // Check the validity of some fields diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt index 36b667911d..5c59cfd80e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt @@ -19,20 +19,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersion +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface CreateKeysBackupVersionTask : Task internal class DefaultCreateKeysBackupVersionTask @Inject constructor( private val roomKeysApi: RoomKeysApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : CreateKeysBackupVersionTask { override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomKeysApi.createKeysBackupVersion(params) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt index d174be20a2..ec09da7240 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface DeleteBackupTask : Task { @@ -30,11 +30,11 @@ internal interface DeleteBackupTask : Task { internal class DefaultDeleteBackupTask @Inject constructor( private val roomKeysApi: RoomKeysApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : DeleteBackupTask { override suspend fun execute(params: DeleteBackupTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomKeysApi.deleteBackup(params.version) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt index 6826596ba4..9c477efb78 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface DeleteRoomSessionDataTask : Task { @@ -32,11 +32,11 @@ internal interface DeleteRoomSessionDataTask : Task { @@ -31,11 +31,11 @@ internal interface DeleteRoomSessionsDataTask : Task { @@ -30,11 +30,11 @@ internal interface DeleteSessionsDataTask : Task internal class DefaultGetKeysBackupLastVersionTask @Inject constructor( private val roomKeysApi: RoomKeysApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetKeysBackupLastVersionTask { override suspend fun execute(params: Unit): KeysVersionResult { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomKeysApi.getKeysBackupLastVersion() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt index dd2dd70e4d..13c99fb0f4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt @@ -18,20 +18,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetKeysBackupVersionTask : Task internal class DefaultGetKeysBackupVersionTask @Inject constructor( private val roomKeysApi: RoomKeysApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetKeysBackupVersionTask { override suspend fun execute(params: String): KeysVersionResult { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomKeysApi.getKeysBackupVersion(params) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt index 8ca03491a1..168020d9cd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetRoomSessionDataTask : Task { @@ -33,11 +33,11 @@ internal interface GetRoomSessionDataTask : Task { @@ -32,11 +32,11 @@ internal interface GetRoomSessionsDataTask : Task { @@ -31,11 +31,11 @@ internal interface GetSessionsDataTask : Task { @@ -35,11 +35,11 @@ internal interface StoreRoomSessionDataTask : Task { @@ -34,11 +34,11 @@ internal interface StoreRoomSessionsDataTask : Task { @@ -33,11 +33,11 @@ internal interface StoreSessionsDataTask : Task { @@ -32,11 +32,11 @@ internal interface UpdateKeysBackupVersionTask : Task diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index 6b83c4f7d1..369a4976c9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -47,6 +47,7 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.OlmInboundGroupSessionWrapper2 import org.matrix.android.sdk.internal.crypto.model.OlmSessionWrapper +import org.matrix.android.sdk.internal.crypto.model.OutboundGroupSessionWrapper import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyRequestBody @@ -73,6 +74,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSess import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntityFields import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntity import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntityFields +import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntity import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingGossipingRequestEntity import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingGossipingRequestEntityFields import org.matrix.android.sdk.internal.crypto.store.db.model.SharedSessionEntity @@ -95,6 +97,7 @@ import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.olm.OlmAccount import org.matrix.olm.OlmException +import org.matrix.olm.OlmOutboundGroupSession import timber.log.Timber import javax.inject.Inject import kotlin.collections.set @@ -756,6 +759,42 @@ internal class RealmCryptoStore @Inject constructor( return inboundGroupSessionToRelease[key] } + override fun getCurrentOutboundGroupSessionForRoom(roomId: String): OutboundGroupSessionWrapper? { + return doWithRealm(realmConfiguration) { realm -> + realm.where() + .equalTo(CryptoRoomEntityFields.ROOM_ID, roomId) + .findFirst()?.outboundSessionInfo?.let { entity -> + entity.getOutboundGroupSession()?.let { + OutboundGroupSessionWrapper( + it, + entity.creationTime ?: 0 + ) + } + } + } + } + + override fun storeCurrentOutboundGroupSessionForRoom(roomId: String, outboundGroupSession: OlmOutboundGroupSession?) { + // we can do this async, as it's just for restoring on next launch + // the olmdevice is caching the active instance + // this is called for each sent message (so not high frequency), thus we can use basic realm async without + // risk of reaching max async operation limit? + doRealmTransactionAsync(realmConfiguration) { realm -> + CryptoRoomEntity.getById(realm, roomId)?.let { entity -> + // we should delete existing outbound session info if any + entity.outboundSessionInfo?.deleteFromRealm() + + if (outboundGroupSession != null) { + val info = realm.createObject(OutboundGroupSessionInfoEntity::class.java).apply { + creationTime = System.currentTimeMillis() + putOutboundGroupSession(outboundGroupSession) + } + entity.outboundSessionInfo = info + } + } + } + } + /** * Note: the result will be only use to export all the keys and not to use the OlmInboundGroupSessionWrapper2, * so there is no need to use or update `inboundGroupSessionToRelease` for native memory management @@ -1645,7 +1684,7 @@ internal class RealmCryptoStore @Inject constructor( } } - override fun wasSessionSharedWithUser(roomId: String?, sessionId: String, userId: String, deviceId: String): IMXCryptoStore.SharedSessionResult { + override fun getSharedSessionInfo(roomId: String?, sessionId: String, userId: String, deviceId: String): IMXCryptoStore.SharedSessionResult { return doWithRealm(realmConfiguration) { realm -> SharedSessionEntity.get(realm, roomId, sessionId, userId, deviceId)?.let { IMXCryptoStore.SharedSessionResult(true, it.chainIndex) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt index 08806b0627..bca7914388 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt @@ -44,6 +44,7 @@ import org.matrix.android.sdk.internal.di.SerializeNulls import io.realm.DynamicRealm import io.realm.RealmMigration import io.realm.RealmObjectSchema +import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntityFields import org.matrix.androidsdk.crypto.data.MXOlmInboundGroupSession2 import timber.log.Timber import javax.inject.Inject @@ -55,7 +56,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi // 0, 1, 2: legacy Riot-Android // 3: migrate to RiotX schema // 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6) - const val CRYPTO_STORE_SCHEMA_VERSION = 11L + const val CRYPTO_STORE_SCHEMA_VERSION = 12L } private fun RealmObjectSchema.addFieldIfNotExists(fieldName: String, fieldType: Class<*>): RealmObjectSchema { @@ -93,6 +94,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi if (oldVersion <= 8) migrateTo9(realm) if (oldVersion <= 9) migrateTo10(realm) if (oldVersion <= 10) migrateTo11(realm) + if (oldVersion <= 11) migrateTo12(realm) } private fun migrateTo1Legacy(realm: DynamicRealm) { @@ -483,4 +485,16 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi realm.schema.get("CryptoMetadataEntity") ?.addField(CryptoMetadataEntityFields.DEVICE_KEYS_SENT_TO_SERVER, Boolean::class.java) } + + // Version 12L added outbound group session persistence + private fun migrateTo12(realm: DynamicRealm) { + Timber.d("Step 11 -> 12") + val outboundEntitySchema = realm.schema.create("OutboundGroupSessionInfoEntity") + .addField(OutboundGroupSessionInfoEntityFields.SERIALIZED_OUTBOUND_SESSION_DATA, String::class.java) + .addField(OutboundGroupSessionInfoEntityFields.CREATION_TIME, Long::class.java) + .setNullable(OutboundGroupSessionInfoEntityFields.CREATION_TIME, true) + + realm.schema.get("CryptoRoomEntity") + ?.addRealmObjectField(CryptoRoomEntityFields.OUTBOUND_SESSION_INFO.`$`, outboundEntitySchema) + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt index a453fc3ed0..6aae68c83e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.TrustLevelEntity import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity import org.matrix.android.sdk.internal.crypto.store.db.model.WithHeldSessionEntity import io.realm.annotations.RealmModule +import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntity /** * Realm module for Crypto store classes @@ -54,6 +55,7 @@ import io.realm.annotations.RealmModule OutgoingGossipingRequestEntity::class, MyDeviceLastSeenInfoEntity::class, WithHeldSessionEntity::class, - SharedSessionEntity::class + SharedSessionEntity::class, + OutboundGroupSessionInfoEntity::class ]) internal class RealmCryptoStoreModule diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt index 4c19b5eb0e..e226f3eaa8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt @@ -23,7 +23,12 @@ internal open class CryptoRoomEntity( @PrimaryKey var roomId: String? = null, var algorithm: String? = null, var shouldEncryptForInvitedMembers: Boolean? = null, - var blacklistUnverifiedDevices: Boolean = false) + var blacklistUnverifiedDevices: Boolean = false, + // Store the current outbound session for this room, + // to avoid re-create and re-share at each startup (if rotation not needed..) + // This is specific to megolm but not sure how to model it better + var outboundSessionInfo: OutboundGroupSessionInfoEntity? = null + ) : RealmObject() { companion object diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt new file mode 100644 index 0000000000..d50db78415 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.crypto.store.db.model + +import io.realm.RealmObject +import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm +import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm +import org.matrix.olm.OlmOutboundGroupSession +import timber.log.Timber + +internal open class OutboundGroupSessionInfoEntity( + var serializedOutboundSessionData: String? = null, + var creationTime: Long? = null +) : RealmObject() { + + fun getOutboundGroupSession(): OlmOutboundGroupSession? { + return try { + deserializeFromRealm(serializedOutboundSessionData) + } catch (failure: Throwable) { + Timber.e(failure, "## getOutboundGroupSession() Deserialization failure") + return null + } + } + + fun putOutboundGroupSession(olmOutboundGroupSession: OlmOutboundGroupSession?) { + serializedOutboundSessionData = serializeForRealm(olmOutboundGroupSession) + } + + companion object +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt index ae72c7198a..3df6312adb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt @@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.model.MXKey import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimBody import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import timber.log.Timber import javax.inject.Inject @@ -36,13 +36,13 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task { val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map) - val keysClaimResponse = executeRequest(eventBus) { + val keysClaimResponse = executeRequest(globalErrorReceiver) { apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body) } val map = MXUsersDevicesMap() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt index e5078d5b4e..8f1569a037 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt @@ -20,9 +20,9 @@ import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface DeleteDeviceTask : Task { @@ -33,12 +33,12 @@ internal interface DeleteDeviceTask : Task { internal class DefaultDeleteDeviceTask @Inject constructor( private val cryptoApi: CryptoApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : DeleteDeviceTask { override suspend fun execute(params: DeleteDeviceTask.Params) { try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()) } } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt index 38eee7f932..b4c1e6d27c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt @@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface DeleteDeviceWithUserPasswordTask : Task { @@ -37,11 +37,11 @@ internal interface DeleteDeviceWithUserPasswordTask : Task { @@ -35,7 +35,7 @@ internal interface DownloadKeysForUsersTask : Task { @@ -29,11 +29,11 @@ internal interface GetDeviceInfoTask : Task internal class DefaultGetDevicesTask @Inject constructor( private val cryptoApi: CryptoApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetDevicesTask { override suspend fun execute(params: Unit): DevicesListResponse { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = cryptoApi.getDevices() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt index 289a5226f5..4cc9ab2fcb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.KeyChangesResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetKeyChangesTask : Task { @@ -34,11 +34,11 @@ internal interface GetKeyChangesTask : Task { internal class DefaultRedactEventTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus) : RedactEventTask { + private val globalErrorReceiver: GlobalErrorReceiver) : RedactEventTask { override suspend fun execute(params: RedactEventTask.Params): String { - val executeRequest = executeRequest(eventBus) { + val executeRequest = executeRequest(globalErrorReceiver) { apiCall = roomAPI.redactEvent( txId = params.txID, roomId = params.roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt index 8b739c4b64..b772bfbce2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt @@ -15,11 +15,12 @@ */ package org.matrix.android.sdk.internal.crypto.tasks -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.room.send.SendState +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI +import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.task.Task @@ -35,16 +36,24 @@ internal interface SendEventTask : Task { internal class DefaultSendEventTask @Inject constructor( private val localEchoRepository: LocalEchoRepository, private val encryptEventTask: DefaultEncryptEventTask, + private val loadRoomMembersTask: LoadRoomMembersTask, private val roomAPI: RoomAPI, - private val eventBus: EventBus) : SendEventTask { + private val globalErrorReceiver: GlobalErrorReceiver) : SendEventTask { override suspend fun execute(params: SendEventTask.Params): String { try { + // Make sure to load all members in the room before sending the event. + params.event.roomId + ?.takeIf { params.encrypt } + ?.let { roomId -> + loadRoomMembersTask.execute(LoadRoomMembersTask.Params(roomId)) + } + val event = handleEncryption(params) val localId = event.eventId!! localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENDING) - val executeRequest = executeRequest(eventBus) { + val executeRequest = executeRequest(globalErrorReceiver) { apiCall = roomAPI.send( localId, roomId = event.roomId ?: "", diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt index 37e0bbc887..d2af91601b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt @@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.rest.SendToDeviceBody +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject import kotlin.random.Random @@ -38,7 +38,7 @@ internal interface SendToDeviceTask : Task { internal class DefaultSendToDeviceTask @Inject constructor( private val cryptoApi: CryptoApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SendToDeviceTask { override suspend fun execute(params: SendToDeviceTask.Params) { @@ -46,7 +46,7 @@ internal class DefaultSendToDeviceTask @Inject constructor( messages = params.contentMap.map ) - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = cryptoApi.sendToDevice( params.eventType, params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(), diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt index cedb7a6618..c39dfb1016 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt @@ -15,10 +15,10 @@ */ package org.matrix.android.sdk.internal.crypto.tasks -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.internal.crypto.CryptoSessionInfoProvider +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository @@ -37,7 +37,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor( private val encryptEventTask: DefaultEncryptEventTask, private val roomAPI: RoomAPI, private val cryptoSessionInfoProvider: CryptoSessionInfoProvider, - private val eventBus: EventBus) : SendVerificationMessageTask { + private val globalErrorReceiver: GlobalErrorReceiver) : SendVerificationMessageTask { override suspend fun execute(params: SendVerificationMessageTask.Params): String { val event = handleEncryption(params) @@ -45,7 +45,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor( try { localEchoRepository.updateSendState(localId, event.roomId, SendState.SENDING) - val executeRequest = executeRequest(eventBus) { + val executeRequest = executeRequest(globalErrorReceiver) { apiCall = roomAPI.send( localId, roomId = event.roomId ?: "", diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt index 51b9624554..b835d46236 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.UpdateDeviceInfoBody +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface SetDeviceNameTask : Task { @@ -34,14 +34,14 @@ internal interface SetDeviceNameTask : Task { internal class DefaultSetDeviceNameTask @Inject constructor( private val cryptoApi: CryptoApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SetDeviceNameTask { override suspend fun execute(params: SetDeviceNameTask.Params) { val body = UpdateDeviceInfoBody( displayName = params.deviceName ) - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt index 6216a3a305..eb53bbbf8d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt @@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeys import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadBody import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import timber.log.Timber import javax.inject.Inject @@ -38,7 +38,7 @@ internal interface UploadKeysTask : Task $body") - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = cryptoApi.uploadKeys(body) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt index a4e10ddbfc..c50faf37b1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UploadSignaturesTask : Task { @@ -31,12 +31,12 @@ internal interface UploadSignaturesTask : Task(eventBus) { + val response = executeRequest(globalErrorReceiver) { this.isRetryable = true this.maxRetryCount = 10 this.apiCall = cryptoApi.uploadSignatures(params.signatures) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt index 038ef9dbd3..cceff355bb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt @@ -25,9 +25,9 @@ import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth import org.matrix.android.sdk.internal.crypto.model.toRest +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UploadSigningKeysTask : Task { @@ -55,7 +55,7 @@ data class UploadSigningKeys(val failures: Map?) : Failure.FeatureF internal class DefaultUploadSigningKeysTask @Inject constructor( private val cryptoApi: CryptoApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : UploadSigningKeysTask { override suspend fun execute(params: UploadSigningKeysTask.Params) { @@ -87,7 +87,7 @@ internal class DefaultUploadSigningKeysTask @Inject constructor( } private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) { - val keysQueryResponse = executeRequest(eventBus) { + val keysQueryResponse = executeRequest(globalErrorReceiver) { apiCall = cryptoApi.uploadSigningKeys(uploadQuery) } if (keysQueryResponse.failures?.isNotEmpty() == true) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index b970ec60e2..57002b5a60 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -21,6 +21,8 @@ import io.realm.RealmMigration import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields +import org.matrix.android.sdk.internal.database.model.RoomEntityFields +import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import timber.log.Timber import javax.inject.Inject @@ -28,7 +30,7 @@ import javax.inject.Inject class RealmSessionStoreMigration @Inject constructor() : RealmMigration { companion object { - const val SESSION_STORE_SCHEMA_VERSION = 6L + const val SESSION_STORE_SCHEMA_VERSION = 7L } override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { @@ -40,6 +42,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration { if (oldVersion <= 3) migrateTo4(realm) if (oldVersion <= 4) migrateTo5(realm) if (oldVersion <= 5) migrateTo6(realm) + if (oldVersion <= 6) migrateTo7(realm) } private fun migrateTo1(realm: DynamicRealm) { @@ -105,4 +108,18 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration { .addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java) .addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java) } + + private fun migrateTo7(realm: DynamicRealm) { + Timber.d("Step 6 -> 7") + realm.schema.get("RoomEntity") + ?.addField(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, String::class.java) + ?.transform { obj -> + if (obj.getBoolean("areAllMembersLoaded")) { + obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.LOADED.name) + } else { + obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.NONE.name) + } + } + ?.removeField("areAllMembersLoaded") + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt index 9af1646a4c..3ff2532604 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt @@ -23,8 +23,7 @@ import io.realm.annotations.PrimaryKey internal open class RoomEntity(@PrimaryKey var roomId: String = "", var chunks: RealmList = RealmList(), - var sendingTimelineEvents: RealmList = RealmList(), - var areAllMembersLoaded: Boolean = false + var sendingTimelineEvents: RealmList = RealmList() ) : RealmObject() { private var membershipStr: String = Membership.NONE.name @@ -36,5 +35,14 @@ internal open class RoomEntity(@PrimaryKey var roomId: String = "", membershipStr = value.name } + private var membersLoadStatusStr: String = RoomMembersLoadStatusType.NONE.name + var membersLoadStatus: RoomMembersLoadStatusType + get() { + return RoomMembersLoadStatusType.valueOf(membersLoadStatusStr) + } + set(value) { + membersLoadStatusStr = value.name + } + companion object } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt similarity index 63% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt index 2cbd7ba7f0..79fe17253b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt @@ -14,18 +14,10 @@ * limitations under the License. */ -package org.matrix.android.sdk.internal.eventbus +package org.matrix.android.sdk.internal.database.model -import org.greenrobot.eventbus.Logger -import timber.log.Timber -import java.util.logging.Level - -class EventBusTimberLogger : Logger { - override fun log(level: Level, msg: String) { - Timber.d(msg) - } - - override fun log(level: Level, msg: String, th: Throwable) { - Timber.e(th, msg) - } +internal enum class RoomMembersLoadStatusType { + NONE, + LOADING, + LOADED } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt new file mode 100644 index 0000000000..9afdb40ed1 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2021 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.network + +import org.matrix.android.sdk.api.failure.GlobalError +import org.matrix.android.sdk.internal.auth.SessionParamsStore +import org.matrix.android.sdk.internal.di.SessionId +import org.matrix.android.sdk.internal.session.SessionScope +import org.matrix.android.sdk.internal.task.TaskExecutor +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import timber.log.Timber +import javax.inject.Inject + +@SessionScope +internal class GlobalErrorHandler @Inject constructor( + private val taskExecutor: TaskExecutor, + private val sessionParamsStore: SessionParamsStore, + @SessionId private val sessionId: String +) : GlobalErrorReceiver { + + var listener: Listener? = null + + override fun handleGlobalError(globalError: GlobalError) { + Timber.e("Global error received: $globalError") + + if (globalError is GlobalError.InvalidToken && globalError.softLogout) { + // Mark the token has invalid + taskExecutor.executorScope.launch(Dispatchers.IO) { + sessionParamsStore.setTokenInvalid(sessionId) + } + } + + listener?.onGlobalError(globalError) + } + + internal interface Listener { + fun onGlobalError(globalError: GlobalError) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt new file mode 100644 index 0000000000..47607ba893 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2021 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.network + +import org.matrix.android.sdk.api.failure.GlobalError + +internal interface GlobalErrorReceiver { + fun handleGlobalError(globalError: GlobalError) +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt index 2535a5347a..442029127d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.network import kotlinx.coroutines.CancellationException import kotlinx.coroutines.delay -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.internal.network.ssl.CertUtil @@ -27,10 +26,10 @@ import retrofit2.awaitResponse import timber.log.Timber import java.io.IOException -internal suspend inline fun executeRequest(eventBus: EventBus?, - block: Request.() -> Unit) = Request(eventBus).apply(block).execute() +internal suspend inline fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?, + block: Request.() -> Unit) = Request(globalErrorReceiver).apply(block).execute() -internal class Request(private val eventBus: EventBus?) { +internal class Request(private val globalErrorReceiver: GlobalErrorReceiver?) { var isRetryable = false var initialDelay: Long = 100L @@ -47,7 +46,7 @@ internal class Request(private val eventBus: EventBus?) { response.body() ?: throw IllegalStateException("The request returned a null body") } else { - throw response.toFailure(eventBus) + throw response.toFailure(globalErrorReceiver) } } catch (exception: Throwable) { // Log some details about the request which has failed diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt index c54af571d8..dd5a69dd3c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt @@ -25,7 +25,6 @@ import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.internal.di.MoshiProvider import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.ResponseBody -import org.greenrobot.eventbus.EventBus import retrofit2.Response import timber.log.Timber import java.io.IOException @@ -54,18 +53,18 @@ internal suspend fun okhttp3.Call.awaitResponse(): okhttp3.Response { /** * Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError */ -internal fun Response.toFailure(eventBus: EventBus?): Failure { - return toFailure(errorBody(), code(), eventBus) +internal fun Response.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure { + return toFailure(errorBody(), code(), globalErrorReceiver) } /** * Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError */ -internal fun okhttp3.Response.toFailure(eventBus: EventBus?): Failure { - return toFailure(body, code, eventBus) +internal fun okhttp3.Response.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure { + return toFailure(body, code, globalErrorReceiver) } -private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBus?): Failure { +private fun toFailure(errorBody: ResponseBody?, httpCode: Int, globalErrorReceiver: GlobalErrorReceiver?): Failure { if (errorBody == null) { return Failure.Unknown(RuntimeException("errorBody should not be null")) } @@ -79,12 +78,12 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBu if (matrixError != null) { if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) { - // Also send this error to the bus, for a global management - eventBus?.post(GlobalError.ConsentNotGivenError(matrixError.consentUri)) + // Also send this error to the globalErrorReceiver, for a global management + globalErrorReceiver?.handleGlobalError(GlobalError.ConsentNotGivenError(matrixError.consentUri)) } else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */ && matrixError.code == MatrixError.M_UNKNOWN_TOKEN) { - // Also send this error to the bus, for a global management - eventBus?.post(GlobalError.InvalidToken(matrixError.isSoftLogout)) + // Also send this error to the globalErrorReceiver, for a global management + globalErrorReceiver?.handleGlobalError(GlobalError.InvalidToken(matrixError.isSoftLogout)) } return Failure.ServerError(matrixError, httpCode) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt index c5f3f65a34..fa07b16c32 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt @@ -19,12 +19,7 @@ package org.matrix.android.sdk.internal.session import androidx.annotation.MainThread import dagger.Lazy import io.realm.RealmConfiguration -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import okhttp3.OkHttpClient -import org.greenrobot.eventbus.EventBus -import org.greenrobot.eventbus.Subscribe -import org.greenrobot.eventbus.ThreadMode import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.api.failure.GlobalError @@ -65,13 +60,12 @@ import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate import org.matrix.android.sdk.internal.di.WorkManagerProvider +import org.matrix.android.sdk.internal.network.GlobalErrorHandler import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.session.sync.SyncTokenStore import org.matrix.android.sdk.internal.session.sync.job.SyncThread import org.matrix.android.sdk.internal.session.sync.job.SyncWorker -import org.matrix.android.sdk.internal.task.TaskExecutor -import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.android.sdk.internal.util.createUIHandler import timber.log.Timber import javax.inject.Inject @@ -81,7 +75,7 @@ import javax.inject.Provider internal class DefaultSession @Inject constructor( override val sessionParams: SessionParams, private val workManagerProvider: WorkManagerProvider, - private val eventBus: EventBus, + private val globalErrorHandler: GlobalErrorHandler, @SessionId override val sessionId: String, @SessionDatabase private val realmConfiguration: RealmConfiguration, @@ -117,10 +111,8 @@ internal class DefaultSession @Inject constructor( private val accountDataService: Lazy, private val _sharedSecretStorageService: Lazy, private val accountService: Lazy, - private val coroutineDispatchers: MatrixCoroutineDispatchers, private val defaultIdentityService: DefaultIdentityService, private val integrationManagerService: IntegrationManagerService, - private val taskExecutor: TaskExecutor, private val callSignalingService: Lazy, @UnauthenticatedWithCertificate private val unauthenticatedWithCertificateOkHttpClient: Lazy, @@ -140,7 +132,8 @@ internal class DefaultSession @Inject constructor( HomeServerCapabilitiesService by homeServerCapabilitiesService.get(), ProfileService by profileService.get(), AccountDataService by accountDataService.get(), - AccountService by accountService.get() { + AccountService by accountService.get(), + GlobalErrorHandler.Listener { override val sharedSecretStorageService: SharedSecretStorageService get() = _sharedSecretStorageService.get() @@ -162,7 +155,7 @@ internal class DefaultSession @Inject constructor( uiHandler.post { lifecycleObservers.forEach { it.onStart() } } - eventBus.register(this) + globalErrorHandler.listener = this eventSenderProcessor.start() } @@ -206,7 +199,7 @@ internal class DefaultSession @Inject constructor( } cryptoService.get().close() isOpen = false - eventBus.unregister(this) + globalErrorHandler.listener = null eventSenderProcessor.interrupt() } @@ -234,16 +227,7 @@ internal class DefaultSession @Inject constructor( workManagerProvider.cancelAllWorks() } - @Subscribe(threadMode = ThreadMode.MAIN) - fun onGlobalError(globalError: GlobalError) { - if (globalError is GlobalError.InvalidToken - && globalError.softLogout) { - // Mark the token has invalid - taskExecutor.executorScope.launch(Dispatchers.IO) { - sessionParamsStore.setTokenInvalid(sessionId) - } - } - + override fun onGlobalError(globalError: GlobalError) { sessionListeners.dispatchGlobalError(globalError) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt index 96b44917bd..468c193ad3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt @@ -26,7 +26,6 @@ import dagger.Provides import dagger.multibindings.IntoSet import io.realm.RealmConfiguration import okhttp3.OkHttpClient -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig @@ -61,9 +60,10 @@ import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificateWithProgress import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserMd5 -import org.matrix.android.sdk.internal.eventbus.EventBusTimberLogger import org.matrix.android.sdk.internal.network.DefaultNetworkConnectivityChecker import org.matrix.android.sdk.internal.network.FallbackNetworkCallbackStrategy +import org.matrix.android.sdk.internal.network.GlobalErrorHandler +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.NetworkCallbackStrategy import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker import org.matrix.android.sdk.internal.network.PreferredNetworkCallbackStrategy @@ -256,16 +256,6 @@ internal abstract class SessionModule { .create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString()) } - @JvmStatic - @Provides - @SessionScope - fun providesEventBus(): EventBus { - return EventBus - .builder() - .logger(EventBusTimberLogger()) - .build() - } - @JvmStatic @Provides @SessionScope @@ -294,6 +284,9 @@ internal abstract class SessionModule { @Binds abstract fun bindSession(session: DefaultSession): Session + @Binds + abstract fun bindGlobalErrorReceiver(handler: GlobalErrorHandler): GlobalErrorReceiver + @Binds abstract fun bindNetworkConnectivityChecker(checker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt index 869d3f516c..1f043b0a9d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.account import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface ChangePasswordTask : Task { @@ -32,14 +32,14 @@ internal interface ChangePasswordTask : Task { internal class DefaultChangePasswordTask @Inject constructor( private val accountAPI: AccountAPI, - private val eventBus: EventBus, + private val globalErrorReceiver: GlobalErrorReceiver, @UserId private val userId: String ) : ChangePasswordTask { override suspend fun execute(params: ChangePasswordTask.Params) { val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword) try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = accountAPI.changePassword(changePasswordParams) } } catch (throwable: Throwable) { @@ -49,7 +49,7 @@ internal class DefaultChangePasswordTask @Inject constructor( /* Avoid infinite loop */ && changePasswordParams.auth?.session == null) { // Retry with authentication - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = accountAPI.changePassword( changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session)) ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt index ac5febcdae..9fb1cbb7d7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt @@ -17,11 +17,11 @@ package org.matrix.android.sdk.internal.session.account import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.cleanup.CleanupSession import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import timber.log.Timber import javax.inject.Inject @@ -34,7 +34,7 @@ internal interface DeactivateAccountTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = accountAPI.deactivate(deactivateAccountParams) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt index 1cedee3374..b21ec1113a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.call import org.matrix.android.sdk.api.session.call.TurnServerResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal abstract class GetTurnServerTask : Task { @@ -27,10 +27,10 @@ internal abstract class GetTurnServerTask : Task if (!response.isSuccessful) { - throw response.toFailure(eventBus) + throw response.toFailure(globalErrorReceiver) } else { response.body?.source()?.let { responseAdapter.fromJson(it) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt index 69ced92fe5..da747934e2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.filter import org.matrix.android.sdk.api.session.sync.FilterService import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject /** @@ -37,7 +37,7 @@ internal class DefaultSaveFilterTask @Inject constructor( @UserId private val userId: String, private val filterAPI: FilterApi, private val filterRepository: FilterRepository, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SaveFilterTask { override suspend fun execute(params: SaveFilterTask.Params) { @@ -59,7 +59,7 @@ internal class DefaultSaveFilterTask @Inject constructor( } val updated = filterRepository.storeFilter(filterBody, roomFilter) if (updated) { - val filterResponse = executeRequest(eventBus) { + val filterResponse = executeRequest(globalErrorReceiver) { // TODO auto retry apiCall = filterAPI.uploadFilter(userId, filterBody) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt index dd703a5e93..9836164aec 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt @@ -23,13 +23,13 @@ import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.group.model.GroupRooms import org.matrix.android.sdk.internal.session.group.model.GroupSummaryResponse import org.matrix.android.sdk.internal.session.group.model.GroupUsers import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction -import org.greenrobot.eventbus.EventBus import timber.log.Timber import javax.inject.Inject @@ -43,7 +43,7 @@ internal interface GetGroupDataTask : Task { internal class DefaultGetGroupDataTask @Inject constructor( private val groupAPI: GroupAPI, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetGroupDataTask { private data class GroupData( @@ -64,13 +64,13 @@ internal class DefaultGetGroupDataTask @Inject constructor( } Timber.v("Fetch data for group with ids: ${groupIds.joinToString(";")}") val data = groupIds.map { groupId -> - val groupSummary = executeRequest(eventBus) { + val groupSummary = executeRequest(globalErrorReceiver) { apiCall = groupAPI.getSummary(groupId) } - val groupRooms = executeRequest(eventBus) { + val groupRooms = executeRequest(globalErrorReceiver) { apiCall = groupAPI.getRooms(groupId) } - val groupUsers = executeRequest(eventBus) { + val groupUsers = executeRequest(globalErrorReceiver) { apiCall = groupAPI.getUsers(groupId) } GroupData(groupId, groupSummary, groupRooms, groupUsers) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index f3686b02d3..845cfb392e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.homeserver import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.wellknown.WellknownResult import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities @@ -27,6 +26,7 @@ import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEnti import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult @@ -44,7 +44,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( private val capabilitiesAPI: CapabilitiesAPI, private val mediaAPI: MediaAPI, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus, + private val globalErrorReceiver: GlobalErrorReceiver, private val getWellknownTask: GetWellknownTask, private val configExtractor: IntegrationManagerConfigExtractor, private val homeServerConnectionConfig: HomeServerConnectionConfig, @@ -65,13 +65,13 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( } val capabilities = runCatching { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = capabilitiesAPI.getCapabilities() } }.getOrNull() val mediaConfig = runCatching { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = mediaAPI.getMediaConfig() } }.getOrNull() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt index 69cdfa8faa..a218f3f93c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.media import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.cache.CacheStrategy import org.matrix.android.sdk.api.session.media.PreviewUrlData import org.matrix.android.sdk.api.util.JsonDict @@ -25,6 +24,7 @@ import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntity import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction @@ -41,7 +41,7 @@ internal interface GetPreviewUrlTask : Task(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = mediaAPI.getPreviewUrlData(url, timestamp) } .toPreviewUrlData(url) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt index 6c5dad2422..32305cd4e4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt @@ -16,8 +16,8 @@ package org.matrix.android.sdk.internal.session.media -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -31,11 +31,11 @@ internal interface GetRawPreviewUrlTask : Task() - ?.takeIf { it.msgType == MessageType.MSGTYPE_TEXT || it.msgType == MessageType.MSGTYPE_EMOTE } + ?.takeIf { + it.msgType == MessageType.MSGTYPE_TEXT + || it.msgType == MessageType.MSGTYPE_NOTICE + || it.msgType == MessageType.MSGTYPE_EMOTE + } ?.body ?.let { urlRegex.findAll(it) } ?.map { it.value } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt index 5d7cfd1719..f83c6b770a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.openid import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetOpenIdTokenTask : Task @@ -27,10 +27,10 @@ internal interface GetOpenIdTokenTask : Task internal class DefaultGetOpenIdTokenTask @Inject constructor( @UserId private val userId: String, private val openIdAPI: OpenIdAPI, - private val eventBus: EventBus) : GetOpenIdTokenTask { + private val globalErrorReceiver: GlobalErrorReceiver) : GetOpenIdTokenTask { override suspend fun execute(params: Unit): RequestOpenIdTokenResponse { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = openIdAPI.openIdToken(userId) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt index 2e8a0b3884..6d6d70bb0d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.profile import com.google.i18n.phonenumbers.PhoneNumberUtil import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction @@ -37,7 +37,7 @@ internal class DefaultAddThreePidTask @Inject constructor( private val profileAPI: ProfileAPI, @SessionDatabase private val monarchy: Monarchy, private val pendingThreePidMapper: PendingThreePidMapper, - private val eventBus: EventBus) : AddThreePidTask() { + private val globalErrorReceiver: GlobalErrorReceiver) : AddThreePidTask() { override suspend fun execute(params: Params) { when (params.threePid) { @@ -50,7 +50,7 @@ internal class DefaultAddThreePidTask @Inject constructor( val clientSecret = UUID.randomUUID().toString() val sendAttempt = 1 - val result = executeRequest(eventBus) { + val result = executeRequest(globalErrorReceiver) { val body = AddEmailBody( clientSecret = clientSecret, email = threePid.email, @@ -84,7 +84,7 @@ internal class DefaultAddThreePidTask @Inject constructor( val countryCode = parsedNumber.countryCode val country = phoneNumberUtil.getRegionCodeForCountryCode(countryCode) - val result = executeRequest(eventBus) { + val result = executeRequest(globalErrorReceiver) { val body = AddMsisdnBody( clientSecret = clientSecret, country = country, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt index dbe6bff508..a37e5380bc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt @@ -19,12 +19,12 @@ package org.matrix.android.sdk.internal.session.profile import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.internal.di.AuthenticatedIdentity +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.token.AccessTokenProvider import org.matrix.android.sdk.internal.session.identity.data.IdentityStore import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal abstract class BindThreePidsTask : Task { @@ -37,13 +37,13 @@ internal class DefaultBindThreePidsTask @Inject constructor(private val profileA private val identityStore: IdentityStore, @AuthenticatedIdentity private val accessTokenProvider: AccessTokenProvider, - private val eventBus: EventBus) : BindThreePidsTask() { + private val globalErrorReceiver: GlobalErrorReceiver) : BindThreePidsTask() { override suspend fun execute(params: Params) { val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = profileAPI.bindThreePid( BindThreePidBody( clientSecret = identityPendingBinding.clientSecret, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt index 3f43cbe599..3549f3613f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt @@ -16,9 +16,9 @@ package org.matrix.android.sdk.internal.session.profile -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.toMedium +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -31,10 +31,10 @@ internal abstract class DeleteThreePidTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { val body = DeleteThreePidBody( medium = params.threePid.toMedium(), address = params.threePid.value diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt index 0b1bf88280..1e3a2cb501 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.profile import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.api.session.identity.ThreePid @@ -26,6 +25,7 @@ import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction @@ -45,7 +45,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor( @SessionDatabase private val monarchy: Monarchy, private val pendingThreePidMapper: PendingThreePidMapper, @UserId private val userId: String, - private val eventBus: EventBus) : FinalizeAddingThreePidTask() { + private val globalErrorReceiver: GlobalErrorReceiver) : FinalizeAddingThreePidTask() { override suspend fun execute(params: Params) { if (params.userWantsToCancel.not()) { @@ -58,7 +58,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor( ?: throw IllegalArgumentException("unknown threepid") try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { val body = FinalizeAddThreePidBody( clientSecret = pendingThreePids.clientSecret, sid = pendingThreePids.sid, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt index 5f1f621ddb..ed60c4a368 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt @@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.profile import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal abstract class GetProfileInfoTask : Task { @@ -30,10 +30,10 @@ internal abstract class GetProfileInfoTask : Task internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus) : RefreshUserThreePidsTask() { + private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() { override suspend fun execute(params: Unit) { - val accountThreePidsResponse = executeRequest(eventBus) { + val accountThreePidsResponse = executeRequest(globalErrorReceiver) { apiCall = profileAPI.getThreePIDs() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt index 4b863c2098..b29153d665 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt @@ -16,9 +16,9 @@ package org.matrix.android.sdk.internal.session.profile +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal abstract class SetAvatarUrlTask : Task { @@ -30,10 +30,10 @@ internal abstract class SetAvatarUrlTask : Task { internal class DefaultSetAvatarUrlTask @Inject constructor( private val profileAPI: ProfileAPI, - private val eventBus: EventBus) : SetAvatarUrlTask() { + private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() { override suspend fun execute(params: Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { val body = SetAvatarUrlBody( avatarUrl = params.newAvatarUrl ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt index 1fa84f98c1..3f236bc589 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt @@ -16,9 +16,9 @@ package org.matrix.android.sdk.internal.session.profile +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal abstract class SetDisplayNameTask : Task { @@ -30,10 +30,10 @@ internal abstract class SetDisplayNameTask : Task { @@ -34,12 +34,12 @@ internal abstract class UnbindThreePidsTask : Task(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = profileAPI.unbindThreePid( UnbindThreePidBody( identityServerUrlWithoutProtocol, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt index 36804e06fe..efb6c6e836 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt @@ -17,13 +17,13 @@ package org.matrix.android.sdk.internal.session.profile import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -40,7 +40,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor( @SessionDatabase private val monarchy: Monarchy, private val pendingThreePidMapper: PendingThreePidMapper, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : ValidateSmsCodeTask { override suspend fun execute(params: ValidateSmsCodeTask.Params) { @@ -58,7 +58,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor( sid = pendingThreePids.sid, code = params.code ) - val result = executeRequest(eventBus) { + val result = executeRequest(globalErrorReceiver) { apiCall = profileAPI.validateMsisdn(url, body) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt index 31c5cda5ec..d0f7cbfca3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt @@ -19,13 +19,13 @@ import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.pushers.PusherState import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.PusherEntity import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.util.awaitTransaction @@ -45,7 +45,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters) @Inject lateinit var pushersAPI: PushersAPI @Inject @SessionDatabase lateinit var monarchy: Monarchy - @Inject lateinit var eventBus: EventBus + @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver override fun injectWith(injector: SessionComponent) { injector.inject(this) @@ -81,7 +81,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters) } private suspend fun setPusher(pusher: JsonPusher) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = pushersAPI.setPusher(pusher) } monarchy.awaitTransaction { realm -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt index 28ac5db52e..03748b1528 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.rest.PushRule +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface AddPushRuleTask : Task { @@ -31,11 +31,11 @@ internal interface AddPushRuleTask : Task { internal class DefaultAddPushRuleTask @Inject constructor( private val pushRulesApi: PushRulesApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : AddPushRuleTask { override suspend fun execute(params: AddPushRuleTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt index 0c532cedbc..9fb2d51664 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt @@ -16,9 +16,9 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetPushRulesTask : Task { @@ -31,11 +31,11 @@ internal interface GetPushRulesTask : Task { internal class DefaultGetPushRulesTask @Inject constructor( private val pushRulesApi: PushRulesApi, private val savePushRulesTask: SavePushRulesTask, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetPushRulesTask { override suspend fun execute(params: GetPushRulesTask.Params) { - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = pushRulesApi.getAllRules() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt index 39e970f4a8..4c7d370446 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt @@ -20,10 +20,10 @@ import org.matrix.android.sdk.api.session.pushers.PusherState import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.PusherEntity import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetPushersTask : Task @@ -31,11 +31,11 @@ internal interface GetPushersTask : Task internal class DefaultGetPushersTask @Inject constructor( private val pushersAPI: PushersAPI, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetPushersTask { override suspend fun execute(params: Unit) { - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = pushersAPI.getPushers() } monarchy.awaitTransaction { realm -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt index 2fc97cf023..ff3122f566 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.rest.PushRule +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface RemovePushRuleTask : Task { @@ -31,11 +31,11 @@ internal interface RemovePushRuleTask : Task { internal class DefaultRemovePushRuleTask @Inject constructor( private val pushRulesApi: PushRulesApi, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : RemovePushRuleTask { override suspend fun execute(params: RemovePushRuleTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt index 1f10863799..e3f4fdb789 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt @@ -26,7 +26,7 @@ import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import io.realm.Realm -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import javax.inject.Inject internal interface RemovePusherTask : Task { @@ -37,7 +37,7 @@ internal interface RemovePusherTask : Task { internal class DefaultRemovePusherTask @Inject constructor( private val pushersAPI: PushersAPI, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : RemovePusherTask { override suspend fun execute(params: RemovePusherTask.Params) { @@ -62,7 +62,7 @@ internal class DefaultRemovePusherTask @Inject constructor( data = JsonPusherData(existing.data.url, existing.data.format), append = false ) - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = pushersAPI.setPusher(deleteBody) } monarchy.awaitTransaction { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt index c2dca8a9a5..a5c220e662 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.rest.PushRule +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UpdatePushRuleActionsTask : Task { @@ -32,13 +32,13 @@ internal interface UpdatePushRuleActionsTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled) } } @@ -47,7 +47,7 @@ internal class DefaultUpdatePushRuleActionsTask @Inject constructor( // Also ensure the actions are up to date val body = mapOf("actions" to params.newPushRule.actions) - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt index 4100071c90..f36b5c55fb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt @@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.rest.PushRule +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UpdatePushRuleEnableStatusTask : Task { @@ -30,11 +30,11 @@ internal interface UpdatePushRuleEnableStatusTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = directoryAPI.addRoomAlias( roomAlias = params.aliasLocalPart.toFullLocalAlias(userId), body = AddRoomAliasBody( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt index 3400fd994c..6ad3db90a9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt @@ -16,7 +16,7 @@ package org.matrix.android.sdk.internal.session.room.alias -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.task.Task @@ -30,11 +30,11 @@ internal interface DeleteRoomAliasTask : Task internal class DefaultDeleteRoomAliasTask @Inject constructor( private val directoryAPI: DirectoryAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : DeleteRoomAliasTask { override suspend fun execute(params: DeleteRoomAliasTask.Params) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = directoryAPI.deleteRoomAlias( roomAlias = params.roomAlias ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt index 543d605707..a53ffc4fcd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt @@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.alias import com.zhuinden.monarchy.Monarchy import io.realm.Realm -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.query.findByAlias import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.task.Task @@ -39,7 +39,7 @@ internal interface GetRoomIdByAliasTask : Task { @@ -52,7 +52,7 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor( Optional.from(null) } else { val description = tryOrNull("## Failed to get roomId from alias") { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = directoryAPI.getRoomIdByAlias(params.roomAlias) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt index 7cfce4ecdc..202cb1f6de 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt @@ -16,7 +16,7 @@ package org.matrix.android.sdk.internal.session.room.alias -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task @@ -30,12 +30,12 @@ internal interface GetRoomLocalAliasesTask : Task { // We do not check for "org.matrix.msc2432", so the API may be missing - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = roomAPI.getAliases(roomId = params.roomId) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt index 25ba493891..51a849a35e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt @@ -16,10 +16,10 @@ package org.matrix.android.sdk.internal.session.room.alias -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.room.alias.RoomAliasError import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import javax.inject.Inject @@ -27,7 +27,7 @@ import javax.inject.Inject internal class RoomAliasAvailabilityChecker @Inject constructor( @UserId private val userId: String, private val directoryAPI: DirectoryAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) { /** * @param aliasLocalPart the local part of the alias. @@ -41,7 +41,7 @@ internal class RoomAliasAvailabilityChecker @Inject constructor( // Check alias availability val fullAlias = aliasLocalPart.toFullLocalAlias(userId) try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = directoryAPI.getRoomIdByAlias(fullAlias) } } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt index ef792ab98e..9c16bd1b0f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.room.create import com.zhuinden.monarchy.Monarchy import io.realm.RealmConfiguration import kotlinx.coroutines.TimeoutCancellationException -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.api.session.room.alias.RoomAliasError @@ -32,6 +31,7 @@ import org.matrix.android.sdk.internal.database.model.RoomEntityFields import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.alias.RoomAliasAvailabilityChecker @@ -55,7 +55,7 @@ internal class DefaultCreateRoomTask @Inject constructor( @SessionDatabase private val realmConfiguration: RealmConfiguration, private val createRoomBodyBuilder: CreateRoomBodyBuilder, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : CreateRoomTask { override suspend fun execute(params: CreateRoomParams): String { @@ -75,7 +75,7 @@ internal class DefaultCreateRoomTask @Inject constructor( val createRoomBody = createRoomBodyBuilder.build(params) val createRoomResponse = try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.createRoom(createRoomBody) } } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt index f2bd0c5f69..edd8ae9b0d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt @@ -18,10 +18,10 @@ package org.matrix.android.sdk.internal.session.room.directory import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsParams import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsResponse +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetPublicRoomTask : Task { @@ -33,11 +33,11 @@ internal interface GetPublicRoomTask : Task(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = directoryAPI.getRoomDirectoryVisibility(params.roomId) } .visibility diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt index 5e08284706..3477aa671e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt @@ -17,21 +17,21 @@ package org.matrix.android.sdk.internal.session.room.directory import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetThirdPartyProtocolsTask : Task> internal class DefaultGetThirdPartyProtocolsTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetThirdPartyProtocolsTask { override suspend fun execute(params: Unit): Map { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomAPI.thirdPartyProtocols() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt index 33b12aa1ca..cbb0b6d5d1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt @@ -16,8 +16,8 @@ package org.matrix.android.sdk.internal.session.room.directory -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.session.directory.RoomDirectoryVisibilityJson @@ -33,11 +33,11 @@ internal interface SetRoomDirectoryVisibilityTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = directoryAPI.setRoomDirectoryVisibility( params.roomId, RoomDirectoryVisibilityJson(visibility = params.roomDirectoryVisibility) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt index 627f927ad8..2be90bf8e3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt @@ -17,25 +17,30 @@ package org.matrix.android.sdk.internal.session.room.membership import com.zhuinden.monarchy.Monarchy +import io.realm.Realm +import io.realm.kotlin.createObject +import kotlinx.coroutines.TimeoutCancellationException import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.send.SendState +import org.matrix.android.sdk.internal.database.awaitNotEmptyResult import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity import org.matrix.android.sdk.internal.database.model.EventInsertType import org.matrix.android.sdk.internal.database.model.RoomEntity +import org.matrix.android.sdk.internal.database.model.RoomEntityFields +import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater import org.matrix.android.sdk.internal.session.sync.SyncTokenStore import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction -import io.realm.Realm -import io.realm.kotlin.createObject -import org.greenrobot.eventbus.EventBus +import java.util.concurrent.TimeUnit import javax.inject.Inject internal interface LoadRoomMembersTask : Task { @@ -52,17 +57,44 @@ internal class DefaultLoadRoomMembersTask @Inject constructor( private val syncTokenStore: SyncTokenStore, private val roomSummaryUpdater: RoomSummaryUpdater, private val roomMemberEventHandler: RoomMemberEventHandler, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : LoadRoomMembersTask { override suspend fun execute(params: LoadRoomMembersTask.Params) { - if (areAllMembersAlreadyLoaded(params.roomId)) { - return + when (getRoomMembersLoadStatus(params.roomId)) { + RoomMembersLoadStatusType.NONE -> doRequest(params) + RoomMembersLoadStatusType.LOADING -> waitPreviousRequestToFinish(params) + RoomMembersLoadStatusType.LOADED -> Unit } + } + + private suspend fun waitPreviousRequestToFinish(params: LoadRoomMembersTask.Params) { + try { + awaitNotEmptyResult(monarchy.realmConfiguration, TimeUnit.MINUTES.toMillis(1L)) { realm -> + realm.where(RoomEntity::class.java) + .equalTo(RoomEntityFields.ROOM_ID, params.roomId) + .equalTo(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, RoomMembersLoadStatusType.LOADED.name) + } + } catch (exception: TimeoutCancellationException) { + // Timeout, do the request anyway (?) + doRequest(params) + } + } + + private suspend fun doRequest(params: LoadRoomMembersTask.Params) { + setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.LOADING) + val lastToken = syncTokenStore.getLastToken() - val response = executeRequest(eventBus) { - apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value) + val response = try { + executeRequest(globalErrorReceiver) { + apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value) + } + } catch (throwable: Throwable) { + // Revert status to NONE + setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.NONE) + throw throwable } + // This will also set the status to LOADED insertInDb(response, params.roomId) } @@ -84,14 +116,23 @@ internal class DefaultLoadRoomMembersTask @Inject constructor( } roomMemberEventHandler.handle(realm, roomId, roomMemberEvent) } - roomEntity.areAllMembersLoaded = true + roomEntity.membersLoadStatus = RoomMembersLoadStatusType.LOADED roomSummaryUpdater.update(realm, roomId, updateMembers = true) } } - private fun areAllMembersAlreadyLoaded(roomId: String): Boolean { - return Realm.getInstance(monarchy.realmConfiguration).use { - RoomEntity.where(it, roomId).findFirst()?.areAllMembersLoaded ?: false + private fun getRoomMembersLoadStatus(roomId: String): RoomMembersLoadStatusType { + var result: RoomMembersLoadStatusType? + Realm.getInstance(monarchy.realmConfiguration).use { + result = RoomEntity.where(it, roomId).findFirst()?.membersLoadStatus + } + return result ?: RoomMembersLoadStatusType.NONE + } + + private suspend fun setRoomMembersLoadStatus(roomId: String, status: RoomMembersLoadStatusType) { + monarchy.awaitTransaction { realm -> + val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId) + roomEntity.membersLoadStatus = status } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt index 854a332679..05503bd643 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt @@ -16,10 +16,10 @@ package org.matrix.android.sdk.internal.session.room.membership.joining +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface InviteTask : Task { @@ -32,11 +32,11 @@ internal interface InviteTask : Task { internal class DefaultInviteTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : InviteTask { override suspend fun execute(params: InviteTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { val body = InviteBody(params.userId, params.reason) apiCall = roomAPI.invite(params.roomId, body) isRetryable = true diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt index dd1dc5fa8a..3b7639d42f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt @@ -30,7 +30,7 @@ import org.matrix.android.sdk.internal.session.room.read.SetReadMarkersTask import org.matrix.android.sdk.internal.task.Task import io.realm.RealmConfiguration import kotlinx.coroutines.TimeoutCancellationException -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -48,14 +48,18 @@ internal class DefaultJoinRoomTask @Inject constructor( @SessionDatabase private val realmConfiguration: RealmConfiguration, private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : JoinRoomTask { override suspend fun execute(params: JoinRoomTask.Params) { roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.Joining) val joinRoomResponse = try { - executeRequest(eventBus) { - apiCall = roomAPI.join(params.roomIdOrAlias, params.viaServers, mapOf("reason" to params.reason)) + executeRequest(globalErrorReceiver) { + apiCall = roomAPI.join( + roomIdOrAlias = params.roomIdOrAlias, + viaServers = params.viaServers.take(3), + params = mapOf("reason" to params.reason) + ) } } catch (failure: Throwable) { roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.FailedJoining(failure)) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt index 58e34a15ec..37bb7570d1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt @@ -21,13 +21,13 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import timber.log.Timber import javax.inject.Inject @@ -40,7 +40,7 @@ internal interface LeaveRoomTask : Task { internal class DefaultLeaveRoomTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus, + private val globalErrorReceiver: GlobalErrorReceiver, private val stateEventDataSource: StateEventDataSource, private val roomSummaryDataSource: RoomSummaryDataSource, private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource @@ -68,7 +68,7 @@ internal class DefaultLeaveRoomTask @Inject constructor( leaveRoom(predecessorRoomId, reason) } try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.leave(roomId, mapOf("reason" to reason)) } } catch (failure: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt index 80af00fc78..d237ec795e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt @@ -16,11 +16,11 @@ package org.matrix.android.sdk.internal.session.room.membership.threepid -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.toMedium import org.matrix.android.sdk.internal.di.AuthenticatedIdentity +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.token.AccessTokenProvider import org.matrix.android.sdk.internal.session.identity.EnsureIdentityTokenTask @@ -39,7 +39,7 @@ internal interface InviteThreePidTask : Task { internal class DefaultInviteThreePidTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus, + private val globalErrorReceiver: GlobalErrorReceiver, private val identityStore: IdentityStore, private val ensureIdentityTokenTask: EnsureIdentityTokenTask, @AuthenticatedIdentity @@ -52,7 +52,7 @@ internal class DefaultInviteThreePidTask @Inject constructor( val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { val body = ThreePidInviteBody( idServer = identityServerUrlWithoutProtocol, idAccessToken = identityServerAccessToken, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt index 03ea2408f0..dbec6b555c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt @@ -16,8 +16,8 @@ package org.matrix.android.sdk.internal.session.room.peeking -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task @@ -31,11 +31,11 @@ internal interface ResolveRoomStateTask : Task { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomAPI.getRoomState(params.roomId) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt index a98bb02c83..c7f962a699 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt @@ -33,7 +33,7 @@ import org.matrix.android.sdk.internal.session.sync.RoomFullyReadHandler import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import io.realm.Realm -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import timber.log.Timber import javax.inject.Inject import kotlin.collections.set @@ -58,7 +58,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor( private val roomFullyReadHandler: RoomFullyReadHandler, private val readReceiptHandler: ReadReceiptHandler, @UserId private val userId: String, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SetReadMarkersTask { override suspend fun execute(params: SetReadMarkersTask.Params) { @@ -96,7 +96,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor( updateDatabase(params.roomId, markers, shouldUpdateRoomSummary) } if (markers.isNotEmpty()) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { isRetryable = true apiCall = roomAPI.sendReadMarker(params.roomId, markers) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt index 51eecb8c2a..99d02b50da 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt @@ -18,10 +18,10 @@ package org.matrix.android.sdk.internal.session.room.relation import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.RelationType +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface FetchEditHistoryTask : Task> { @@ -35,11 +35,11 @@ internal interface FetchEditHistoryTask : Task { - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = roomAPI.getRelations(params.roomId, params.eventId, RelationType.REPLACE, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt index 25dfe32cbb..c12597bea0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt @@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.relation import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.relation.ReactionContent import org.matrix.android.sdk.api.session.room.model.relation.ReactionInfo +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.room.RoomAPI @@ -47,7 +47,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) ) : SessionWorkerParams @Inject lateinit var roomAPI: RoomAPI - @Inject lateinit var eventBus: EventBus + @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver @Inject lateinit var localEchoRepository: LocalEchoRepository override fun injectWith(injector: SessionComponent) { @@ -84,7 +84,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) } private suspend fun sendRelation(roomId: String, relationType: String, relatedEventId: String, localEvent: Event) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.sendRelation( roomId = roomId, parentId = relatedEventId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt index bd11937676..9c6e9907a4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt @@ -16,10 +16,10 @@ package org.matrix.android.sdk.internal.session.room.reporting +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface ReportContentTask : Task { @@ -33,11 +33,11 @@ internal interface ReportContentTask : Task { internal class DefaultReportContentTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : ReportContentTask { override suspend fun execute(params: ReportContentTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason)) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt index f4871ab35d..f742271fa7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.room.send import com.zhuinden.monarchy.Monarchy import io.realm.Realm -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel @@ -42,7 +41,7 @@ import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater -import org.matrix.android.sdk.internal.session.room.timeline.DefaultTimeline +import org.matrix.android.sdk.internal.session.room.timeline.TimelineInput import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.util.awaitTransaction import timber.log.Timber @@ -52,7 +51,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private private val taskExecutor: TaskExecutor, private val realmSessionProvider: RealmSessionProvider, private val roomSummaryUpdater: RoomSummaryUpdater, - private val eventBus: EventBus, + private val timelineInput: TimelineInput, private val timelineEventMapper: TimelineEventMapper) { fun createLocalEcho(event: Event) { @@ -76,7 +75,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private } } val timelineEvent = timelineEventMapper.map(timelineEventEntity) - eventBus.post(DefaultTimeline.OnLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent)) + timelineInput.onLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent) taskExecutor.executorScope.asyncTransaction(monarchy) { realm -> val eventInsertEntity = EventInsertEntity(event.eventId, event.type).apply { this.insertType = EventInsertType.LOCAL_ECHO @@ -90,7 +89,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private fun updateSendState(eventId: String, roomId: String?, sendState: SendState) { Timber.v("## SendEvent: [${System.currentTimeMillis()}] Update local state of $eventId to ${sendState.name}") - eventBus.post(DefaultTimeline.OnLocalEchoUpdated(roomId ?: "", eventId, sendState)) + timelineInput.onLocalEchoUpdated(roomId = roomId ?: "", eventId = eventId, sendState = sendState) updateEchoAsync(eventId) { realm, sendingEventEntity -> if (sendState == SendState.SENT && sendingEventEntity.sendState == SendState.SYNCED) { // If already synced, do not put as sent diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt index 682865eaee..c901c7e18e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt @@ -18,8 +18,8 @@ package org.matrix.android.sdk.internal.session.room.send import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.Failure +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.room.RoomAPI @@ -46,7 +46,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) ) : SessionWorkerParams @Inject lateinit var roomAPI: RoomAPI - @Inject lateinit var eventBus: EventBus + @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver override fun injectWith(injector: SessionComponent) { injector.inject(this) @@ -55,7 +55,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) override suspend fun doSafeWork(params: Params): Result { val eventId = params.eventId return runCatching { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.redactEvent( params.txID, params.roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt index 37a429d242..c1fc2fd9fe 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt @@ -20,7 +20,6 @@ import android.content.Context import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass import io.realm.RealmConfiguration -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.session.crypto.CryptoService import org.matrix.android.sdk.api.session.room.send.SendState @@ -54,7 +53,6 @@ internal class SendEventWorker(context: Context, @Inject lateinit var localEchoRepository: LocalEchoRepository @Inject lateinit var sendEventTask: SendEventTask @Inject lateinit var cryptoService: CryptoService - @Inject lateinit var eventBus: EventBus @Inject lateinit var cancelSendTracker: CancelSendTracker @SessionDatabase @Inject lateinit var realmConfiguration: RealmConfiguration diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt index b546584450..804968bac0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt @@ -35,13 +35,11 @@ import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.MimeTypes import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.internal.session.content.FileUploader -import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasTask internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String, private val stateEventDataSource: StateEventDataSource, private val sendStateTask: SendStateTask, - private val fileUploader: FileUploader, - private val addRoomAliasTask: AddRoomAliasTask + private val fileUploader: FileUploader ) : StateService { @AssistedInject.Factory @@ -74,11 +72,19 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private roomId = roomId, stateKey = stateKey, eventType = eventType, - body = body + body = body.toSafeJson(eventType) ) sendStateTask.execute(params) } + private fun JsonDict.toSafeJson(eventType: String): JsonDict { + // Safe treatment for PowerLevelContent + return when (eventType) { + EventType.STATE_ROOM_POWER_LEVELS -> toSafePowerLevelsContentDict() + else -> this + } + } + override suspend fun updateTopic(topic: String) { sendStateEvent( eventType = EventType.STATE_ROOM_TOPIC, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt new file mode 100644 index 0000000000..a97709e38b --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.session.room.state + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent +import org.matrix.android.sdk.api.session.room.powerlevels.Role +import org.matrix.android.sdk.api.util.JsonDict + +@JsonClass(generateAdapter = true) +internal data class SerializablePowerLevelsContent( + @Json(name = "ban") val ban: Int = Role.Moderator.value, + @Json(name = "kick") val kick: Int = Role.Moderator.value, + @Json(name = "invite") val invite: Int = Role.Moderator.value, + @Json(name = "redact") val redact: Int = Role.Moderator.value, + @Json(name = "events_default") val eventsDefault: Int = Role.Default.value, + @Json(name = "events") val events: Map = emptyMap(), + @Json(name = "users_default") val usersDefault: Int = Role.Default.value, + @Json(name = "users") val users: Map = emptyMap(), + @Json(name = "state_default") val stateDefault: Int = Role.Moderator.value, + // `Int` is the diff here (instead of `Any`) + @Json(name = "notifications") val notifications: Map = emptyMap() +) + +internal fun JsonDict.toSafePowerLevelsContentDict(): JsonDict { + return toModel() + ?.let { content -> + SerializablePowerLevelsContent( + ban = content.ban, + kick = content.kick, + invite = content.invite, + redact = content.redact, + eventsDefault = content.eventsDefault, + events = content.events, + usersDefault = content.usersDefault, + users = content.users, + stateDefault = content.stateDefault, + notifications = content.notifications.mapValues { content.notificationLevel(it.key) } + ) + } + ?.toContent() + ?: emptyMap() +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt index 642f68c15b..63691d9207 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt @@ -17,10 +17,10 @@ package org.matrix.android.sdk.internal.session.room.state import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface SendStateTask : Task { @@ -34,11 +34,11 @@ internal interface SendStateTask : Task { internal class DefaultSendStateTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SendStateTask { override suspend fun execute(params: SendStateTask.Params) { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = if (params.stateKey == null) { roomAPI.sendStateEvent( roomId = params.roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt index 013fc86d5c..c3b5c3f78f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt @@ -17,10 +17,10 @@ package org.matrix.android.sdk.internal.session.room.tags import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface AddTagToRoomTask : Task { @@ -35,11 +35,11 @@ internal interface AddTagToRoomTask : Task { internal class DefaultAddTagToRoomTask @Inject constructor( private val roomAPI: RoomAPI, @UserId private val userId: String, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : AddTagToRoomTask { override suspend fun execute(params: AddTagToRoomTask.Params) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.putTag( userId = userId, roomId = params.roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt index b22355d431..d578d21fde 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt @@ -17,10 +17,10 @@ package org.matrix.android.sdk.internal.session.room.tags import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface DeleteTagFromRoomTask : Task { @@ -34,11 +34,11 @@ internal interface DeleteTagFromRoomTask : Task(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.deleteTag( userId = userId, roomId = params.roomId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt index 86b0497bd0..ae90282d52 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt @@ -23,10 +23,8 @@ import io.realm.RealmConfiguration import io.realm.RealmQuery import io.realm.RealmResults import io.realm.Sort -import org.greenrobot.eventbus.EventBus -import org.greenrobot.eventbus.Subscribe -import org.greenrobot.eventbus.ThreadMode import org.matrix.android.sdk.api.MatrixCallback +import org.matrix.android.sdk.api.NoOpMatrixCallback import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.events.model.EventType @@ -53,6 +51,7 @@ import org.matrix.android.sdk.internal.database.query.filterEvents import org.matrix.android.sdk.internal.database.query.findAllInRoomWithSendStates import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.database.query.whereRoomId +import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.task.configureWith import org.matrix.android.sdk.internal.util.Debouncer @@ -79,14 +78,13 @@ internal class DefaultTimeline( private val timelineEventMapper: TimelineEventMapper, private val settings: TimelineSettings, private val hiddenReadReceipts: TimelineHiddenReadReceipts, - private val eventBus: EventBus, + private val timelineInput: TimelineInput, private val eventDecryptor: TimelineEventDecryptor, - private val realmSessionProvider: RealmSessionProvider -) : Timeline, TimelineHiddenReadReceipts.Delegate { - - data class OnNewTimelineEvents(val roomId: String, val eventIds: List) - data class OnLocalEchoCreated(val roomId: String, val timelineEvent: TimelineEvent) - data class OnLocalEchoUpdated(val roomId: String, val eventId: String, val sendState: SendState) + private val realmSessionProvider: RealmSessionProvider, + private val loadRoomMembersTask: LoadRoomMembersTask +) : Timeline, + TimelineHiddenReadReceipts.Delegate, + TimelineInput.Listener { companion object { val BACKGROUND_HANDLER = createBackgroundHandler("TIMELINE_DB_THREAD") @@ -158,7 +156,7 @@ internal class DefaultTimeline( override fun start() { if (isStarted.compareAndSet(false, true)) { Timber.v("Start timeline for roomId: $roomId and eventId: $initialEventId") - eventBus.register(this) + timelineInput.listeners.add(this) BACKGROUND_HANDLER.post { eventDecryptor.start() val realm = Realm.getInstance(realmConfiguration) @@ -184,6 +182,13 @@ internal class DefaultTimeline( if (settings.shouldHandleHiddenReadReceipts()) { hiddenReadReceipts.start(realm, filteredEvents, nonFilteredEvents, this) } + + loadRoomMembersTask + .configureWith(LoadRoomMembersTask.Params(roomId)) { + this.callback = NoOpMatrixCallback() + } + .executeBy(taskExecutor) + isReady.set(true) } } @@ -196,7 +201,7 @@ internal class DefaultTimeline( override fun dispose() { if (isStarted.compareAndSet(true, false)) { isReady.set(false) - eventBus.unregister(this) + timelineInput.listeners.remove(this) Timber.v("Dispose timeline for roomId: $roomId and eventId: $initialEventId") cancelableBag.cancel() BACKGROUND_HANDLER.removeCallbacksAndMessages(null) @@ -313,25 +318,22 @@ internal class DefaultTimeline( postSnapshot() } - @Subscribe(threadMode = ThreadMode.MAIN) - fun onNewTimelineEvents(onNewTimelineEvents: OnNewTimelineEvents) { - if (isLive && onNewTimelineEvents.roomId == roomId) { + override fun onNewTimelineEvents(roomId: String, eventIds: List) { + if (isLive && this.roomId == roomId) { listeners.forEach { - it.onNewTimelineEvents(onNewTimelineEvents.eventIds) + it.onNewTimelineEvents(eventIds) } } } - @Subscribe(threadMode = ThreadMode.MAIN) - fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated) { - if (uiEchoManager.onLocalEchoCreated(onLocalEchoCreated)) { + override fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent) { + if (uiEchoManager.onLocalEchoCreated(roomId, timelineEvent)) { postSnapshot() } } - @Subscribe(threadMode = ThreadMode.MAIN) - fun onLocalEchoUpdated(onLocalEchoUpdated: OnLocalEchoUpdated) { - if (uiEchoManager.onLocalEchoUpdated(onLocalEchoUpdated)) { + override fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState) { + if (uiEchoManager.onLocalEchoUpdated(roomId, eventId, sendState)) { postSnapshot() } } @@ -848,11 +850,11 @@ internal class DefaultTimeline( } } - fun onLocalEchoUpdated(onLocalEchoUpdated: OnLocalEchoUpdated): Boolean { - if (isLive && onLocalEchoUpdated.roomId == roomId) { - val existingState = inMemorySendingStates[onLocalEchoUpdated.eventId] - inMemorySendingStates[onLocalEchoUpdated.eventId] = onLocalEchoUpdated.sendState - if (existingState != onLocalEchoUpdated.sendState) { + fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState): Boolean { + if (isLive && roomId == this@DefaultTimeline.roomId) { + val existingState = inMemorySendingStates[eventId] + inMemorySendingStates[eventId] = sendState + if (existingState != sendState) { return true } } @@ -860,22 +862,22 @@ internal class DefaultTimeline( } // return true if should update - fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated): Boolean { + fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent): Boolean { var postSnapshot = false - if (isLive && onLocalEchoCreated.roomId == roomId) { + if (isLive && roomId == this@DefaultTimeline.roomId) { // Manage some ui echos (do it before filter because actual event could be filtered out) - when (onLocalEchoCreated.timelineEvent.root.getClearType()) { + when (timelineEvent.root.getClearType()) { EventType.REDACTION -> { } EventType.REACTION -> { - val content = onLocalEchoCreated.timelineEvent.root.content?.toModel() + val content = timelineEvent.root.content?.toModel() if (RelationType.ANNOTATION == content?.relatesTo?.type) { val reaction = content.relatesTo.key val relatedEventID = content.relatesTo.eventId inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() } .add( ReactionUiEchoData( - localEchoId = onLocalEchoCreated.timelineEvent.eventId, + localEchoId = timelineEvent.eventId, reactedOnEventId = relatedEventID, reaction = reaction ) @@ -888,12 +890,12 @@ internal class DefaultTimeline( } // do not add events that would have been filtered - if (listOf(onLocalEchoCreated.timelineEvent).filterEventsWithSettings().isNotEmpty()) { + if (listOf(timelineEvent).filterEventsWithSettings().isNotEmpty()) { listeners.forEach { - it.onNewTimelineEvents(listOf(onLocalEchoCreated.timelineEvent.eventId)) + it.onNewTimelineEvents(listOf(timelineEvent.eventId)) } - Timber.v("On local echo created: ${onLocalEchoCreated.timelineEvent.eventId}") - inMemorySendingEvents.add(0, onLocalEchoCreated.timelineEvent) + Timber.v("On local echo created: ${timelineEvent.eventId}") + inMemorySendingEvents.add(0, timelineEvent) postSnapshot = true } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt index 783aa53ddf..fce09cc97c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt @@ -23,7 +23,6 @@ import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy import io.realm.Sort import io.realm.kotlin.where -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.events.model.isImageMessage import org.matrix.android.sdk.api.session.events.model.isVideoMessage import org.matrix.android.sdk.api.session.room.timeline.Timeline @@ -39,19 +38,21 @@ import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask import org.matrix.android.sdk.internal.task.TaskExecutor internal class DefaultTimelineService @AssistedInject constructor(@Assisted private val roomId: String, @SessionDatabase private val monarchy: Monarchy, private val realmSessionProvider: RealmSessionProvider, - private val eventBus: EventBus, + private val timelineInput: TimelineInput, private val taskExecutor: TaskExecutor, private val contextOfEventTask: GetContextOfEventTask, private val eventDecryptor: TimelineEventDecryptor, private val paginationTask: PaginationTask, private val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask, private val timelineEventMapper: TimelineEventMapper, - private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper + private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper, + private val loadRoomMembersTask: LoadRoomMembersTask ) : TimelineService { @AssistedInject.Factory @@ -70,10 +71,11 @@ internal class DefaultTimelineService @AssistedInject constructor(@Assisted priv timelineEventMapper = timelineEventMapper, settings = settings, hiddenReadReceipts = TimelineHiddenReadReceipts(readReceiptsSummaryMapper, roomId, settings), - eventBus = eventBus, + timelineInput = timelineInput, eventDecryptor = eventDecryptor, fetchTokenAndPaginateTask = fetchTokenAndPaginateTask, - realmSessionProvider = realmSessionProvider + realmSessionProvider = realmSessionProvider, + loadRoomMembersTask = loadRoomMembersTask ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt index d1bfa1adcb..76c4b3812c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt @@ -20,12 +20,12 @@ import com.zhuinden.monarchy.Monarchy import org.matrix.android.sdk.internal.database.model.ChunkEntity import org.matrix.android.sdk.internal.database.query.findIncludingEvent import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.filter.FilterRepository import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface FetchTokenAndPaginateTask : Task { @@ -43,12 +43,12 @@ internal class DefaultFetchTokenAndPaginateTask @Inject constructor( @SessionDatabase private val monarchy: Monarchy, private val filterRepository: FilterRepository, private val paginationTask: PaginationTask, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : FetchTokenAndPaginateTask { override suspend fun execute(params: FetchTokenAndPaginateTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = roomAPI.getContextOfEvent(params.roomId, params.lastKnownEventId, 0, filter) } val fromToken = if (params.direction == PaginationDirection.FORWARDS) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt index 7a611dd350..d02a7bafe9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt @@ -16,11 +16,11 @@ package org.matrix.android.sdk.internal.session.room.timeline +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.filter.FilterRepository import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetContextOfEventTask : Task { @@ -35,12 +35,12 @@ internal class DefaultGetContextOfEventTask @Inject constructor( private val roomAPI: RoomAPI, private val filterRepository: FilterRepository, private val tokenChunkEventPersistor: TokenChunkEventPersistor, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : GetContextOfEventTask { override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { // We are limiting the response to the event with eventId to be sure we don't have any issue with potential merging process. apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, 0, filter) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt index acac3929ae..b8585b1e74 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt @@ -17,17 +17,17 @@ package org.matrix.android.sdk.internal.session.room.timeline import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject // TODO Add parent task internal class GetEventTask @Inject constructor( private val roomAPI: RoomAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : Task { internal data class Params( @@ -36,7 +36,7 @@ internal class GetEventTask @Inject constructor( ) override suspend fun execute(params: Params): Event { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { apiCall = roomAPI.getEvent(params.roomId, params.eventId) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt index b663d03bd7..1f99893e17 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt @@ -16,11 +16,11 @@ package org.matrix.android.sdk.internal.session.room.timeline +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.filter.FilterRepository import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface PaginationTask : Task { @@ -37,12 +37,12 @@ internal class DefaultPaginationTask @Inject constructor( private val roomAPI: RoomAPI, private val filterRepository: FilterRepository, private val tokenChunkEventPersistor: TokenChunkEventPersistor, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : PaginationTask { override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val chunk = executeRequest(eventBus) { + val chunk = executeRequest(globalErrorReceiver) { isRetryable = true apiCall = roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt new file mode 100644 index 0000000000..002ab1dd8a --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.session.room.timeline + +import org.matrix.android.sdk.api.session.room.send.SendState +import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent +import org.matrix.android.sdk.internal.session.SessionScope +import javax.inject.Inject + +@SessionScope +internal class TimelineInput @Inject constructor() { + fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent) { + listeners.toSet().forEach { it.onLocalEchoCreated(roomId, timelineEvent) } + } + + fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState) { + listeners.toSet().forEach { it.onLocalEchoUpdated(roomId, eventId, sendState) } + } + + fun onNewTimelineEvents(roomId: String, eventIds: List) { + listeners.toSet().forEach { it.onNewTimelineEvents(roomId, eventIds) } + } + + val listeners = mutableSetOf() + + internal interface Listener { + fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent) + fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState) + fun onNewTimelineEvents(roomId: String, eventIds: List) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt index c8cbb08e2c..3b56d04872 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt @@ -21,7 +21,7 @@ import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task import kotlinx.coroutines.delay -import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import javax.inject.Inject internal interface SendTypingTask : Task { @@ -38,13 +38,13 @@ internal interface SendTypingTask : Task { internal class DefaultSendTypingTask @Inject constructor( private val roomAPI: RoomAPI, @UserId private val userId: String, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SendTypingTask { override suspend fun execute(params: SendTypingTask.Params) { delay(params.delay ?: -1) - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.sendTypingState( params.roomId, userId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt index d0439ce7f9..0c0e6a8ed0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt @@ -31,6 +31,7 @@ import org.matrix.android.sdk.internal.database.model.EventEntityFields import org.matrix.android.sdk.internal.database.query.TimelineEventFilter import org.matrix.android.sdk.internal.database.query.whereType import org.matrix.android.sdk.internal.di.SessionDatabase +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.filter.FilterFactory import org.matrix.android.sdk.internal.session.room.RoomAPI @@ -39,7 +40,6 @@ import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection import org.matrix.android.sdk.internal.session.room.timeline.PaginationResponse import org.matrix.android.sdk.internal.session.sync.SyncTokenStore import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface GetUploadsTask : Task { @@ -56,7 +56,7 @@ internal class DefaultGetUploadsTask @Inject constructor( private val roomAPI: RoomAPI, private val tokenStore: SyncTokenStore, @SessionDatabase private val monarchy: Monarchy, - private val eventBus: EventBus) + private val globalErrorReceiver: GlobalErrorReceiver) : GetUploadsTask { override suspend fun execute(params: GetUploadsTask.Params): GetUploadsResult { @@ -86,7 +86,7 @@ internal class DefaultGetUploadsTask @Inject constructor( val since = params.since ?: tokenStore.getLastToken() ?: throw IllegalStateException("No token available") val filter = FilterFactory.createUploadsFilter(params.numberOfEvents).toJSONString() - val chunk = executeRequest(eventBus) { + val chunk = executeRequest(globalErrorReceiver) { apiCall = roomAPI.getRoomMessagesFrom(params.roomId, since, PaginationDirection.BACKWARDS.value, params.numberOfEvents, filter) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt index 4f574e5ead..402602e4d5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt @@ -16,10 +16,10 @@ package org.matrix.android.sdk.internal.session.search -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.search.EventAndSender import org.matrix.android.sdk.api.session.search.SearchResult import org.matrix.android.sdk.api.util.MatrixItem +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.search.request.SearchRequestBody import org.matrix.android.sdk.internal.session.search.request.SearchRequestCategories @@ -47,11 +47,11 @@ internal interface SearchTask : Task { internal class DefaultSearchTask @Inject constructor( private val searchAPI: SearchAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SearchTask { override suspend fun execute(params: SearchTask.Params): SearchResult { - return executeRequest(eventBus) { + return executeRequest(globalErrorReceiver) { val searchRequestBody = SearchRequestBody( searchCategories = SearchRequestCategories( roomEvents = SearchRequestRoomEvents( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt index 3bed0bdbff..2c3cd5d270 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt @@ -20,9 +20,9 @@ import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.internal.auth.SessionParamsStore import org.matrix.android.sdk.internal.auth.data.PasswordLoginParams +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface SignInAgainTask : Task { @@ -35,11 +35,11 @@ internal class DefaultSignInAgainTask @Inject constructor( private val signOutAPI: SignOutAPI, private val sessionParams: SessionParams, private val sessionParamsStore: SessionParamsStore, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SignInAgainTask { override suspend fun execute(params: SignInAgainTask.Params) { - val newCredentials = executeRequest(eventBus) { + val newCredentials = executeRequest(globalErrorReceiver) { apiCall = signOutAPI.loginAgain( PasswordLoginParams.userIdentifier( // Reuse the same userId diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt index 153ea5a6fd..0cb8704782 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt @@ -18,11 +18,11 @@ package org.matrix.android.sdk.internal.session.signout import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.cleanup.CleanupSession import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import timber.log.Timber import java.net.HttpURLConnection import javax.inject.Inject @@ -35,7 +35,7 @@ internal interface SignOutTask : Task { internal class DefaultSignOutTask @Inject constructor( private val signOutAPI: SignOutAPI, - private val eventBus: EventBus, + private val globalErrorReceiver: GlobalErrorReceiver, private val identityDisconnectTask: IdentityDisconnectTask, private val cleanupSession: CleanupSession ) : SignOutTask { @@ -45,7 +45,7 @@ internal class DefaultSignOutTask @Inject constructor( if (params.signOutFromHomeserver) { Timber.d("SignOut: send request...") try { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = signOutAPI.signOut() } } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt index b1b2f65dc2..456b0f9c26 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.sync import io.realm.Realm import io.realm.kotlin.createObject -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.R import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.events.model.Event @@ -55,8 +54,8 @@ import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembers import org.matrix.android.sdk.internal.session.room.membership.RoomMemberEventHandler import org.matrix.android.sdk.internal.session.room.read.FullyReadContent import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater -import org.matrix.android.sdk.internal.session.room.timeline.DefaultTimeline import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection +import org.matrix.android.sdk.internal.session.room.timeline.TimelineInput import org.matrix.android.sdk.internal.session.room.typing.TypingEventContent import org.matrix.android.sdk.internal.session.sync.model.InvitedRoomSync import org.matrix.android.sdk.internal.session.sync.model.RoomSync @@ -75,7 +74,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle private val roomTypingUsersHandler: RoomTypingUsersHandler, private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource, @UserId private val userId: String, - private val eventBus: EventBus) { + private val timelineInput: TimelineInput) { sealed class HandlingStrategy { data class JOINED(val data: Map) : HandlingStrategy() @@ -348,7 +347,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle } } // posting new events to timeline if any is registered - eventBus.post(DefaultTimeline.OnNewTimelineEvents(roomId = roomId, eventIds = eventIds)) + timelineInput.onNewTimelineEvents(roomId = roomId, eventIds = eventIds) return chunkEntity } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt index b4fd6e7386..7c38230065 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt @@ -16,9 +16,9 @@ package org.matrix.android.sdk.internal.session.sync -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.R import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.TimeOutInterceptor import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.DefaultInitialSyncProgressService @@ -48,7 +48,7 @@ internal class DefaultSyncTask @Inject constructor( private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask, private val userStore: UserStore, private val syncTaskSequencer: SyncTaskSequencer, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SyncTask { override suspend fun execute(params: SyncTask.Params) = syncTaskSequencer.post { @@ -81,7 +81,7 @@ internal class DefaultSyncTask @Inject constructor( val readTimeOut = (params.timeout + TIMEOUT_MARGIN).coerceAtLeast(TimeOutInterceptor.DEFAULT_LONG_TIMEOUT) - val syncResponse = executeRequest(eventBus) { + val syncResponse = executeRequest(globalErrorReceiver) { apiCall = syncAPI.sync( params = requestParams, readTimeOut = readTimeOut diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncService.kt index 6d100a71f9..cce169c246 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/job/SyncService.kt @@ -36,6 +36,7 @@ import org.matrix.android.sdk.internal.task.TaskExecutor import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import timber.log.Timber +import java.net.SocketTimeoutException import java.util.concurrent.atomic.AtomicBoolean /** @@ -49,8 +50,9 @@ abstract class SyncService : Service() { private var sessionId: String? = null private var mIsSelfDestroyed: Boolean = false - private var syncTimeoutSeconds: Int = 6 - private var syncDelaySeconds: Int = 60 + private var syncTimeoutSeconds: Int = getDefaultSyncTimeoutSeconds() + private var syncDelaySeconds: Int = getDefaultSyncDelaySeconds() + private var periodic: Boolean = false private var preventReschedule: Boolean = false @@ -68,14 +70,12 @@ abstract class SyncService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Timber.i("## Sync: onStartCommand [$this] $intent with action: ${intent?.action}") - - // We should start we have to ensure we fulfill contract to show notification - // for foreground service (as per design for this service) - // TODO can we check if it's really in foreground - onStart(isInitialSync) when (intent?.action) { ACTION_STOP -> { Timber.i("## Sync: stop command received") + // We should start we have to ensure we fulfill contract to show notification + // for foreground service (as per design for this service) + onStart(isInitialSync) // If it was periodic we ensure that it will not reschedule itself preventReschedule = true // we don't want to cancel initial syncs, let it finish @@ -85,11 +85,12 @@ abstract class SyncService : Service() { } else -> { val isInit = initialize(intent) + onStart(isInitialSync) if (isInit) { periodic = intent?.getBooleanExtra(EXTRA_PERIODIC, false) ?: false val onNetworkBack = intent?.getBooleanExtra(EXTRA_NETWORK_BACK_RESTART, false) ?: false Timber.d("## Sync: command received, periodic: $periodic networkBack: $onNetworkBack") - if (onNetworkBack && !backgroundDetectionObserver.isInBackground) { + if (!isInitialSync && onNetworkBack && !backgroundDetectionObserver.isInBackground) { // the restart after network occurs while the app is in foreground // so just stop. It will be restarted when entering background preventReschedule = true @@ -119,7 +120,11 @@ abstract class SyncService : Service() { serviceScope.coroutineContext.cancelChildren() if (!preventReschedule && periodic && sessionId != null && backgroundDetectionObserver.isInBackground) { Timber.d("## Sync: Reschedule service in $syncDelaySeconds sec") - onRescheduleAsked(sessionId ?: "", false, syncTimeoutSeconds, syncDelaySeconds) + onRescheduleAsked( + sessionId = sessionId ?: "", + syncTimeoutSeconds = syncTimeoutSeconds, + syncDelaySeconds = syncDelaySeconds + ) } super.onDestroy() } @@ -165,10 +170,23 @@ abstract class SyncService : Service() { preventReschedule = true } if (throwable is Failure.NetworkConnection) { - // Network is off, no need to reschedule endless alarms :/ + // Timeout is not critical, so retry as soon as possible. + if (throwable.cause is SocketTimeoutException) { + // For big accounts, computing sync response can take time, but Synapse will cache the + // result for the next request. So keep retrying in loop + Timber.w("Timeout during sync, retry in loop") + doSync() + return + } + // Network might be off, no need to reschedule endless alarms :/ preventReschedule = true - // Instead start a work to restart background sync when network is back - onNetworkError(sessionId ?: "", isInitialSync, syncTimeoutSeconds, syncDelaySeconds) + // Instead start a work to restart background sync when network is on + onNetworkError( + sessionId = sessionId ?: "", + syncTimeoutSeconds = syncTimeoutSeconds, + syncDelaySeconds = syncDelaySeconds, + isPeriodic = periodic + ) } // JobCancellation could be caught here when onDestroy cancels the coroutine context if (isRunning.get()) stopMe() @@ -182,8 +200,8 @@ abstract class SyncService : Service() { } val matrix = Matrix.getInstance(applicationContext) val safeSessionId = intent.getStringExtra(EXTRA_SESSION_ID) ?: return false - syncTimeoutSeconds = intent.getIntExtra(EXTRA_TIMEOUT_SECONDS, 6) - syncDelaySeconds = intent.getIntExtra(EXTRA_DELAY_SECONDS, 60) + syncTimeoutSeconds = intent.getIntExtra(EXTRA_TIMEOUT_SECONDS, getDefaultSyncTimeoutSeconds()) + syncDelaySeconds = intent.getIntExtra(EXTRA_DELAY_SECONDS, getDefaultSyncDelaySeconds()) try { val sessionComponent = matrix.sessionManager.getSessionComponent(safeSessionId) ?: throw IllegalStateException("## Sync: You should have a session to make it work") @@ -202,11 +220,15 @@ abstract class SyncService : Service() { } } + abstract fun getDefaultSyncTimeoutSeconds(): Int + + abstract fun getDefaultSyncDelaySeconds(): Int + abstract fun onStart(isInitialSync: Boolean) - abstract fun onRescheduleAsked(sessionId: String, isInitialSync: Boolean, timeout: Int, delay: Int) + abstract fun onRescheduleAsked(sessionId: String, syncTimeoutSeconds: Int, syncDelaySeconds: Int) - abstract fun onNetworkError(sessionId: String, isInitialSync: Boolean, timeout: Int, delay: Int) + abstract fun onNetworkError(sessionId: String, syncTimeoutSeconds: Int, syncDelaySeconds: Int, isPeriodic: Boolean) override fun onBind(intent: Intent?): IBinder? { return null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt index d1393c8b37..26e8d3380a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt @@ -17,11 +17,11 @@ package org.matrix.android.sdk.internal.session.user.accountdata import com.zhuinden.monarchy.Monarchy -import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.internal.database.model.IgnoredUserEntity import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.sync.model.accountdata.IgnoredUsersContent import org.matrix.android.sdk.internal.task.Task @@ -40,7 +40,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor( @SessionDatabase private val monarchy: Monarchy, private val saveIgnoredUsersTask: SaveIgnoredUsersTask, @UserId private val userId: String, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : UpdateIgnoredUserIdsTask { override suspend fun execute(params: UpdateIgnoredUserIdsTask.Params) { @@ -63,7 +63,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor( val list = ignoredUserIds.toList() val body = IgnoredUsersContent.createWithUserIds(list) - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = accountDataApi.setAccountData(userId, UserAccountDataTypes.TYPE_IGNORED_USER_LIST, body) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt index 80ab79b228..dba28253a7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt @@ -24,8 +24,8 @@ import org.matrix.android.sdk.internal.session.sync.model.accountdata.AcceptedTe import org.matrix.android.sdk.internal.session.sync.model.accountdata.BreadcrumbsContent import org.matrix.android.sdk.internal.session.sync.model.accountdata.IdentityServerContent import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UpdateUserAccountDataTask : Task { @@ -100,11 +100,11 @@ internal interface UpdateUserAccountDataTask : Task> { @@ -34,11 +34,11 @@ internal interface SearchUserTask : Task> { internal class DefaultSearchUserTask @Inject constructor( private val searchUserAPI: SearchUserAPI, - private val eventBus: EventBus + private val globalErrorReceiver: GlobalErrorReceiver ) : SearchUserTask { override suspend fun execute(params: SearchUserTask.Params): List { - val response = executeRequest(eventBus) { + val response = executeRequest(globalErrorReceiver) { apiCall = searchUserAPI.searchUsers(SearchUsersParams(params.search, params.limit)) } return response.users.map { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt index 422615af2d..ae807ce30f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt @@ -25,10 +25,10 @@ import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFie import org.matrix.android.sdk.internal.database.query.whereStateKey import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface CreateWidgetTask : Task { @@ -43,10 +43,10 @@ internal interface CreateWidgetTask : Task { internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase private val monarchy: Monarchy, private val roomAPI: RoomAPI, @UserId private val userId: String, - private val eventBus: EventBus) : CreateWidgetTask { + private val globalErrorReceiver: GlobalErrorReceiver) : CreateWidgetTask { override suspend fun execute(params: CreateWidgetTask.Params) { - executeRequest(eventBus) { + executeRequest(globalErrorReceiver) { apiCall = roomAPI.sendStateEvent( roomId = params.roomId, stateEventType = EventType.STATE_ROOM_WIDGET_LEGACY, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/MatrixWorkerFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/MatrixWorkerFactory.kt index c6647f7572..b58cab99b5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/MatrixWorkerFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/MatrixWorkerFactory.kt @@ -20,6 +20,7 @@ import android.content.Context import androidx.work.ListenableWorker import androidx.work.WorkerFactory import androidx.work.WorkerParameters +import timber.log.Timber import javax.inject.Inject import javax.inject.Provider @@ -32,6 +33,8 @@ class MatrixWorkerFactory @Inject constructor( workerClassName: String, workerParameters: WorkerParameters ): ListenableWorker? { + Timber.d("MatrixWorkerFactory.createWorker for $workerClassName") + val foundEntry = workerFactories.entries.find { Class.forName(workerClassName).isAssignableFrom(it.key) } val factoryProvider = foundEntry?.value diff --git a/matrix-sdk-android/src/main/res/values-cs/strings.xml b/matrix-sdk-android/src/main/res/values-cs/strings.xml index 50dea12b09..adb3517927 100644 --- a/matrix-sdk-android/src/main/res/values-cs/strings.xml +++ b/matrix-sdk-android/src/main/res/values-cs/strings.xml @@ -242,4 +242,30 @@ • Server shodující se s %s je zakázán. Nastavili jste ACL serveru pro tuto místnost. %s nastavili ACL serveru pro tuto místnost. + Změnili jste adresy pro tuto místnost. + %1$s změnili adresy pro tuto místnost. + Změnili jste hlavní a alternativní adresu pro tuto místnost. + %1$s změnili hlavní a alternativní adresu pro tuto místnost. + Změnili jste alternativní adresu pro tuto místnost. + %1$s změnili alternativní adresu pro tuto místnost. + + Odstranili jste alternativní adresu %1$s pro tuto místnost. + Odstranili jste alternativní adresy %1$s pro tuto místnost. + Odstranili jste alternativní adresy %1$s pro tuto místnost. + + + %1$s odstranili alternativní adresu %2$s pro tuto místnost. + %1$s odstranili alternativní adresy %2$s pro tuto místnost. + %1$s odstranili alternativní adresy %2$s pro tuto místnost. + + + Přidali jste alternativní adresu %1$s pro tuto místnost. + Přidali jste alternativní adresy %1$s pro tuto místnost. + Přidali jste alternativní adresy %1$s pro tuto místnost. + + + %1$s přidali alternativní adresu %2$s pro tuto místnost. + %1$s přidali alternativní adresy %2$s pro tuto místnost. + %1$s přidali alternativní adresy %2$s pro tuto místnost. + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-et/strings.xml b/matrix-sdk-android/src/main/res/values-et/strings.xml index 957c0b9955..af2cc33b99 100644 --- a/matrix-sdk-android/src/main/res/values-et/strings.xml +++ b/matrix-sdk-android/src/main/res/values-et/strings.xml @@ -47,7 +47,7 @@ Sõnumi saatja seade ei ole selle sõnumi jaoks saatnud dekrüptimisvõtmeid. Ei saanud muuta sõnumit Sõnumi saatmine ei õnnestunud - Faili üles laadimine ei õnnestunud + Pildi üleslaadimine ei õnnestunud Võrguühenduse viga Matrix\'i viga Hetkel ei ole võimalik uuesti liituda tühja jututoaga. @@ -236,4 +236,26 @@ • Lubatud on serverid, mille ip-aadress vastab mustrile. • Lubatud on serverid, mille nimes leidub %s. • Keelatud on serverid, mille nimes leidub %s. + %1$s muutis selle jututoa aadresse. + Sa muutsid selle jututoa põhiaadressi ja täiendavaid aadresse. + %1$s muutis selle jututoa täiendavaid aadresse. + Sa muutsid selle jututoa täiendavaid aadresse. + %1$s muutis selle jututoa põhiaadressi ja täiendavaid aadresse. + + Sa eemaldasid selle jututoa täiendava aadressi %1$s. + Sa eemaldasid selle jututoa täiendavad aadressid %1$s. + + + %1$s eemaldas selle jututoa täiendava aadressi %2$s. + %1$s eemaldas selle jututoa täiendavad aadressid %2$s. + + + Sa lisasid sellele jututoale täiendava aadressi %1$s. + Sa lisasid sellele jututoale täiendavad aadressid %1$s. + + + %1$s lisas sellele jututoale täiendava aadressi %2$s. + %1$s lisas sellele jututoale täiendavad aadressid %2$s. + + Sa muutsid selle jututoa aadresse. \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-fa/strings.xml b/matrix-sdk-android/src/main/res/values-fa/strings.xml index 8f8059067e..50446b9708 100644 --- a/matrix-sdk-android/src/main/res/values-fa/strings.xml +++ b/matrix-sdk-android/src/main/res/values-fa/strings.xml @@ -218,4 +218,5 @@ %1$s، %2$s، %3$s و %4$d نفر دیگر %1$s، %2$s و %3$s + %1$s، %2$s، %3$s و %4$s \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-it/strings.xml b/matrix-sdk-android/src/main/res/values-it/strings.xml index c1a5cf85cb..ec19cd5c17 100644 --- a/matrix-sdk-android/src/main/res/values-it/strings.xml +++ b/matrix-sdk-android/src/main/res/values-it/strings.xml @@ -102,7 +102,7 @@ %1$s ha rimosso %2$s come indirizzo per questa stanza. - %1$s ha rimosso %3$s come indirizzi per questa stanza. + %1$s ha rimosso %2$s come indirizzi per questa stanza. %1$s ha aggiunto %2$s e rimosso %3$s come indirizzi per questa stanza. %1$s ha impostato l\'indirizzo principale per questa stanza a %2$s. @@ -237,4 +237,26 @@ • I server che corrispondono a %s sono banditi. Hai impostato le ACL del server per questa stanza. %s ha impostato le ACL del server per questa stanza. + Hai cambiato gli indirizzi per questa stanza. + %1$s ha cambiato gli indirizzi per questa stanza. + Hai cambiato gli indirizzi principali ed alternativi per questa stanza. + %1$s ha cambiato gli indirizzi principali ed alternativi per questa stanza. + Hai cambiato gli indirizzi alternativi per questa stanza. + %1$s ha cambiato gli indirizzi alternativi per questa stanza. + + Hai rimosso l\'indirizzo alternativo %1$s per questa stanza. + Hai rimosso gli indirizzi alternativi %1$s per questa stanza. + + + %1$s ha rimosso l\'indirizzo alternativo %2$s per questa stanza. + %1$s ha rimosso gli indirizzi alternativi %2$s per questa stanza. + + + Hai aggiunto l\'indirizzo alternativo %1$s per questa stanza. + Hai aggiunto gli indirizzi alternativi %1$s per questa stanza. + + + %1$s ha aggiunto l\'indirizzo alternativo %2$s per questa stanza. + %1$s ha aggiunto gli indirizzi alternativi %2$s per questa stanza. + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-lv/strings.xml b/matrix-sdk-android/src/main/res/values-lv/strings.xml index b14cbb4b00..ec107b47d6 100644 --- a/matrix-sdk-android/src/main/res/values-lv/strings.xml +++ b/matrix-sdk-android/src/main/res/values-lv/strings.xml @@ -1,8 +1,7 @@ - + %1$s: %2$s %1$s nosūtīja attēlu. - %s\'s uzaicinājums %1$s uzaicināja %2$s %1$s uzaicināja tevi @@ -30,46 +29,56 @@ ikviens. nezināms (%s). %1$s ieslēdza ierīce-ierīce šifrēšanu (%2$s) - %1$s vēlas VoIP konferenci VoIP konference sākusies VoIP konference ir beigusies - (arī profila attēls mainījās) %1$s dzēsa istabas nosaukumu %1$s dzēsa istabas tēmas nosaukumu %1$s atjaunoja profila informāciju %2$s %1$s nosūtīja uzaicinājumu %2$s pievienoties istabai %1$s apstiprināja uzaicinājumu priekš %2$s - ** Nav iespējams atkodēt: %s ** Sūtītāja ierīce mums nenosūtīja atslēgas priekš šīs ziņas. - Nevarēja rediģēt Nav iespējams nosūtīt ziņu - Neizdevās augšuplādēt attēlu - Tīkla kļūda Matrix kļūda - Šobrīd nav iespējams atkārtoti pievienoties tukšai istabai. - Šifrēta ziņa - Epasta adrese Telefona numurs - Uzaicinājums no %s Uzaicinājums uz istabu %1$s un %2$s Tukša istaba - %1$s un 1 cits %1$s un %2$d citi %1$s un %2$d citu - - - + Tu nomainīji savu attēlojamo vārdu no %1$s uz %2$s + Tu nomainījis savu attēlojamo vārdu uz %1$s + Tu nomainīji savu avataru + Tu atsauci %1$s uzaicinājumu + Tu nobanoji %1$s + Tu atbanoji %1$s + Tu izspēri %1$s + Tu noraidīji uzaicinājumu + Tu pameti telpu + %1$s atstāja telpu + Tu atstāji telpu + Tu pievienojies + %1$s pievienojās telpai + Tu pievienojies telpai + Tu uzaicināji %1$s + Tu izveidoji apspriedi (diskusiju) + %1$s izveidoja apspriedi (diskusiju) + Tu izveidoji istabu + %1$s izveidoja telpu + Tavs uzaicinājums + Tu nosūtīji uzlīmi/lipekli. + %1$s nosūtīja uzlīmi/lipekli. + Tu nosūtīji attēlu. + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-nb/strings.xml b/matrix-sdk-android/src/main/res/values-nb/strings.xml new file mode 100644 index 0000000000..07cf4226e0 --- /dev/null +++ b/matrix-sdk-android/src/main/res/values-nb/strings.xml @@ -0,0 +1,11 @@ + + + Du opprettet diskusjonen + Du opprettet rommet + Invitasjonen din + Du sendte et klistremerke. + %1$s sendte et klistremerke. + Du sendte et bilde. + %1$s sendte et bilde. + %1$s: %2$s + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-nn/strings.xml b/matrix-sdk-android/src/main/res/values-nn/strings.xml index d986e697ad..441d568fc3 100644 --- a/matrix-sdk-android/src/main/res/values-nn/strings.xml +++ b/matrix-sdk-android/src/main/res/values-nn/strings.xml @@ -1,12 +1,9 @@ - + Kryptert melding - - %1$s: %2$s %1$s sende eit bilæte. %1$s sende eit klistremerke. - %s si innbjoding %1$s inviterte %2$s %1$s inviterte deg @@ -34,53 +31,38 @@ kven som heldst. uvisst (%s). %1$s skrudde ende-til-ende-kryptering på (%2$s) - %1$s bad um ei VoIP-gruppasamtala VoIP-gruppasamtala er starta VoIP-gruppasamtala er ferdug - (avataren vart au byta) %1$s tok burt romnamnet %1$s tok burt romemnet %1$s gjorde um på skildringi si %2$s %1$s inviterte %2$s til rommet %1$s sa ja til innbjodingi til %2$s - ** Fekk ikkje til å dekryptera: %s ** Avsendareiningi hev ikkje sendt oss nyklane fyr denna meldingi. - Kunde ikkje gjera um - Fekk ikkje å senda meldingi - + Fekk ikkje til å senda meldingi Fekk ikkje til å lasta biletet upp - Noko gjekk gale med netverket Noko gjekk gale med Matrix - Det lèt seg fyrebils ikkje gjera å fara inn att i eit tomt rom. - Epostadresse Telefonnummer - Innbjoding frå %s Rominnbjoding %1$s og %2$s - %1$s og 1 til %1$s og %2$d til - Tomt rom - Ei melding vart stroki %1$s strauk meldingi Meldingi vart stroki [av di: %1$s] %1$s strauk meldingi [av di: %2$s] - %s oppgraderte rommet. - Nullstill sendingskø - %1$s forlot rommet. Grunn: %2$s - + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-pt-rBR/strings.xml b/matrix-sdk-android/src/main/res/values-pt-rBR/strings.xml index e6c93cb55c..5e3282a305 100644 --- a/matrix-sdk-android/src/main/res/values-pt-rBR/strings.xml +++ b/matrix-sdk-android/src/main/res/values-pt-rBR/strings.xml @@ -178,7 +178,7 @@ %1$s removeu %2$s como um endereço desta sala. - %1$s removeu %3$s como endereços desta sala. + %1$s removeu %2$s como endereços desta sala. Você removeu %1$s como um endereço desta sala. @@ -244,4 +244,26 @@ • Servidores correspondentes à %s estão banidos. Você definiu a lista de controle de acesso (ACL) do servidor para esta sala. %s definiu a lista de controle de acesso (ACL) do servidor para esta sala. + Você alterou os endereços alternativos desta sala. + %1$s alterou os endereços alternativos desta sala. + + Você removeu o endereço alternativo %1$s para esta sala. + Você removeu os endereços alternativos %1$s para esta sala. + + + %1$s removeu o endereço alternativo %2$s para esta sala. + %1$s removeu os endereços alternativos %2$s para esta sala. + + + Você adicionou o endereço alternativo %1$s para esta sala. + Você adicionou os endereços alternativos %1$s para esta sala. + + + %1$s adicionou o endereço alternativo %2$s para esta sala. + %1$s adicionou os endereços alternativos %2$s para esta sala. + + Você alterou os endereços desta sala. + %1$s alterou os endereços desta sala. + Você alterou os endereços principal e alternativos desta sala. + %1$s alterou os endereços principal e alternativos desta sala. \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-ru/strings.xml b/matrix-sdk-android/src/main/res/values-ru/strings.xml index 5ef5a4f447..f2e0bd668f 100644 --- a/matrix-sdk-android/src/main/res/values-ru/strings.xml +++ b/matrix-sdk-android/src/main/res/values-ru/strings.xml @@ -252,4 +252,34 @@ %s изменил права доступа сервера (ACL) для этой комнаты. Вы настроили права доступа сервера (ACL) для этой комнаты. %s устанавливает права доступа сервера (ACL) для этой комнаты. + Вы изменили адреса этой комнаты. + %1$s изменил(а) адреса этой комнаты. + Вы изменили основной и альтернативный адреса этой комнаты. + %1$s изменил(а) основной и альтернативный адреса этой комнаты. + Вы изменили альтернативные адреса для этой комнаты. + %1$s изменил(а) альтернативные адреса для этой комнаты. + + Вы удалили альтернативный адрес %1$s для этой комнаты. + Вы удалили альтернативные адреса %1$s для этой комнаты. + Вы удалили альтернативные адреса %1$s для этой комнаты. + Вы удалили альтернативные адреса %1$s для этой комнаты. + + + %1$s удалил(а) альтернативный адрес %2$s для этой комнаты. + %1$s удалил(а) альтернативные адреса %2$s для этой комнаты. + %1$s удалил(а) альтернативные адреса %2$s для этой комнаты. + %1$s удалил(а) альтернативные адреса %2$s для этой комнаты. + + + Вы добавили альтернативный адрес %1$s для этой комнаты. + Вы добавили альтернативные адреса %1$s для этой комнаты. + Вы добавили альтернативные адреса %1$s для этой комнаты. + Вы добавили альтернативные адреса %1$s для этой комнаты. + + + %1$s добавил(а) альтернативный адрес %2$s для этой комнаты. + %1$s добавил(а) альтернативные адреса %2$s для этой комнаты. + %1$s добавил(а) альтернативные адреса %2$s для этой комнаты. + %1$s добавил(а) альтернативные адреса %2$s для этой комнаты. + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-sk/strings.xml b/matrix-sdk-android/src/main/res/values-sk/strings.xml index 15924d02e1..a40654f7bf 100644 --- a/matrix-sdk-android/src/main/res/values-sk/strings.xml +++ b/matrix-sdk-android/src/main/res/values-sk/strings.xml @@ -197,4 +197,16 @@ %1$s povolil/a E2E šifrovanie (Nerozpoznaný algorytmus %2$s). Povolili ste E2E šifrovanie (Nerozpoznaný algorytmus %1$s). %s požaduje overenie vašich šifrovacích kľúčov, ale váš klient nepodporuje overenie kľúčov v konverzácii. Budete musieť použiť zastaralú metódu overenia. + nastavili ste na servery pravidlá ACL tejto miestnosti. + %s nastavil(a) na servery pravidlá ACL tejto miestnosti. + Aktualizovali ste sem. + %s aktualizoval(a) sem. + %1$s sprístupnil(a) budúce správy %2$s + Sprístupnili ste budúce správy %1$s + Opustili ste miestnosť + %1$s opustil(a) miestnosť + Vstúpili ste + %1$s vstúpil(a) + Vytvorili ste konverzáciu + %1$s vytvoril(a) konverzáciu \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-sq/strings.xml b/matrix-sdk-android/src/main/res/values-sq/strings.xml index 58ba8877bb..0d4b2888ba 100644 --- a/matrix-sdk-android/src/main/res/values-sq/strings.xml +++ b/matrix-sdk-android/src/main/res/values-sq/strings.xml @@ -101,7 +101,7 @@ %1$s hoqi %2$s si adresë për këtë dhomë. - %1$s hoqi %3$s si adresa për këtë dhomë. + %1$s hoqi %2$s si adresa për këtë dhomë. %1$s shtoi %2$s dhe hoqi %3$s si adresa për këtë dhomë. %1$s caktoi %2$s si adresë kryesore për këtë dhomë. @@ -232,4 +232,26 @@ • Shërbyesit që kanë përputhje me %s tani janë të ndaluar. • Shërbyesit që kanë përputhje me %s janë të ndaluar. • Shërbyesit që kanë përputhje me %s janë të ndaluar. + Ndryshuat adresat për këtë dhomë. + %1$s ndryshoi adresat për këtë dhomë. + Ndryshuat adresat kryesore dhe alternative për këtë dhomë. + %1$s ndryshoi adresat kryesore dhe alternative për këtë dhomë. + Ndryshuat adresat alternative për këtë dhomë. + %1$s ndryshoi adresat alternative për këtë dhomë. + + Hoqët adresën alternative %1$s për këtë dhomë. + Hoqët adresat alternative %1$s për këtë dhomë. + + + %1$s hoqët adresën alternative %2$s për këtë dhomë. + %1$s hoqët adresat alternative %2$s për këtë dhomë. + + + Shtuat adresën alternative %1$s për këtë dhomë. + Shtuat adresat alternative %1$s për këtë dhomë. + + + %1$s shtoi adresën alternative %2$s për këtë dhomë. + %1$s shtoi adresat alternative %2$s për këtë dhomë. + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-sv/strings.xml b/matrix-sdk-android/src/main/res/values-sv/strings.xml index d42c6ba2ca..91d874591f 100644 --- a/matrix-sdk-android/src/main/res/values-sv/strings.xml +++ b/matrix-sdk-android/src/main/res/values-sv/strings.xml @@ -213,4 +213,49 @@ %1$s gick med Du skapade diskussionen %1$s skapade diskussionen + Du ändrade adresserna för det här rummet. + %1$s ändrade adresserna för det här rummet. + Du ändrade huvudadressen och de alternativa adresserna för det här rummet. + %1$s ändrade huvudadressen och de alternativa adresserna för det här rummet. + Du ändrade de alternativa adresserna för det här rummet. + %1$s ändrade de alternativa adresserna för det här rummet. + + Du tog bort den alternativa adressen %1$s för det här rummet. + Du tog bort de alternativa adresserna %1$s för det här rummet. + + + %1$s tog bort den alternativa adressen %2$s för det här rummet. + %1$s tog bort de alternativa adresserna %2$s för det här rummet. + + + Du lade till den alternativa adressen %1$s för det här rummet. + Du lade till de alternativa adresserna %1$s för det här rummet. + + + %1$s lade till den alternativa adressen %2$s för det här rummet. + %1$s lade till de alternativa adresserna %2$s för det här rummet. + + Tomt rum (var %s) + + %1$s, %2$s, %3$s och %4$d till + %1$s, %2$s, %3$s och %4$d till + + %1$s, %2$s, %3$s och %4$s + %1$s, %2$s och %3$s + 🎉 Alla servrar har bannats från att delta! Det här rummet kan inte användas längre. + Ingen ändring. + • Servrar som matchar IP-adresser är nu bannade. + • Servrar som matchar IP-adresser är nu tillåtna. + • Servrar som matchar %s togs bort från tillåtelselistan. + • Servrar som matchar %s är nu tillåtna. + • Servrar som matchar %s togs bort från bannlistan. + • Servrar som matchar %s är nu bannade. + Du ändrade server-ACLer för det här rummet. + %s ändrade server-ACLer för det här rummet. + • Servrar som matchar IP-adresser är tillåtna. + • Servrar som matchar IP-adresser är bannade. + • Servrar som matchar %s är tillåtna. + • Servrar som matchar %s är bannade. + Du satte server-ACLer för det här rummet. + %s satte server-ACLer för det här rummet. \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-szl/strings.xml b/matrix-sdk-android/src/main/res/values-szl/strings.xml new file mode 100644 index 0000000000..a6b3daec93 --- /dev/null +++ b/matrix-sdk-android/src/main/res/values-szl/strings.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-uk/strings.xml b/matrix-sdk-android/src/main/res/values-uk/strings.xml index 2477487379..0f45a7182c 100644 --- a/matrix-sdk-android/src/main/res/values-uk/strings.xml +++ b/matrix-sdk-android/src/main/res/values-uk/strings.xml @@ -13,7 +13,7 @@ %1$s надіслав(ла) наліпку. %1$s запросив(ла) Вас %1$s приєднується - %1$s покинув(ла) + %1$s покидає кімнату %1$s відхилив(ла) запрошення %1$s копнув(ла) %2$s %1$s розблокував(ла) %2$s @@ -65,4 +65,23 @@ Повідомлення видалено %1$s видалили повідомлення Повідомлення видалено [причина: %1$s] + Початкове налаштування: +\nІмпортування даних облікового запису + Ви покинули. Причина: %1$s + %1$s покидає. Причина: %2$s + Ви покинули кімнату. Причина: %1$s + %1$s покидає кімнату. Причина: %2$s + %1$s покидає кімнату + Ви покинули кімнату + Ви покинули кімнату + Ви змінили адреси цієї кімнати. + Ви змінили основну та альтернативну адреси цієї кімнати. + Ви змінили альтернативні адреси для цієї кімнати. + Ви змінили рівень доступу на %1$s. + Ви змінили серверні списки контролю доступу для цієї кімнати. + Ви змінили назву кімнати на: %1$s + Ви змінили світлину кімнати + Ви змінили тему на: %1$s + Ви змінили показуване ім\'я з %1$s на %2$s + Ви змінили світлину профілю \ No newline at end of file diff --git a/matrix-sdk-android/src/main/res/values-zh-rTW/strings.xml b/matrix-sdk-android/src/main/res/values-zh-rTW/strings.xml index 08050b400d..5038e8aab2 100644 --- a/matrix-sdk-android/src/main/res/values-zh-rTW/strings.xml +++ b/matrix-sdk-android/src/main/res/values-zh-rTW/strings.xml @@ -98,7 +98,7 @@ %1$s 新增了 %2$s 為此聊天室的地址。 - %1$s 移除了此聊天室的 %3$s 地址。 + %1$s 移除了此聊天室的 %2$s 地址。 %1$s 為此聊天室新增 %2$s 並移除 %3$s 地址。 %1$s 為此聊天室設定了 %2$s 為主地址。 @@ -230,4 +230,22 @@ • 已禁止伺服器符合 %s。 您為此聊天是設定了伺服器 ACL。 %s 為此聊天是設定了伺服器 ACL。 + 您變更了此聊天室的地址。 + %1$s 變更了此聊天室的地址。 + 您為此聊天室變更了主要及備用地址。 + %1$s 為此聊天室變更了主要及備用地址。 + 您為此聊天室變更了備用地址。 + %1$s 變更了此聊天室的備用地址。 + + 您為此聊天室移除了備用地址 %1$s。 + + + %1$s 已為此聊天室移除備用地址 %2$s。 + + + 您為此聊天室新增了備用地址 %1$s。 + + + %1$s 已為此聊天室新增了備用地址 %2$s。 + \ No newline at end of file diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt index 667e0b2471..74b6c03d93 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/task/CoroutineSequencersTest.kt @@ -38,19 +38,16 @@ class CoroutineSequencersTest: MatrixTest { val jobs = listOf( GlobalScope.launch(dispatcher) { - sequencer.post { suspendingMethod("#1") }.also { - results.add(it) - } + sequencer.post { suspendingMethod("#1") } + .also { results.add(it) } }, GlobalScope.launch(dispatcher) { - sequencer.post { suspendingMethod("#2") }.also { - results.add(it) - } + sequencer.post { suspendingMethod("#2") } + .also { results.add(it) } }, GlobalScope.launch(dispatcher) { - sequencer.post { suspendingMethod("#3") }.also { - results.add(it) - } + sequencer.post { suspendingMethod("#3") } + .also { results.add(it) } } ) runBlocking { @@ -70,19 +67,16 @@ class CoroutineSequencersTest: MatrixTest { val results = ArrayList() val jobs = listOf( GlobalScope.launch(dispatcher) { - sequencer1.post { suspendingMethod("#1") }.also { - results.add(it) - } + sequencer1.post { suspendingMethod("#1") } + .also { results.add(it) } }, GlobalScope.launch(dispatcher) { - sequencer2.post { suspendingMethod("#2") }.also { - results.add(it) - } + sequencer2.post { suspendingMethod("#2") } + .also { results.add(it) } }, GlobalScope.launch(dispatcher) { - sequencer3.post { suspendingMethod("#3") }.also { - results.add(it) - } + sequencer3.post { suspendingMethod("#3") } + .also { results.add(it) } } ) runBlocking { @@ -97,20 +91,17 @@ class CoroutineSequencersTest: MatrixTest { val results = ArrayList() val jobs = listOf( GlobalScope.launch(dispatcher) { - sequencer.post { suspendingMethod("#1") }.also { - results.add(it) - } + sequencer.post { suspendingMethod("#1") } + .also { results.add(it) } }, GlobalScope.launch(dispatcher) { - val result = sequencer.post { suspendingMethod("#2") }.also { - results.add(it) - } - println("Result: $result") + sequencer.post { suspendingMethod("#2") } + .also { results.add(it) } + .also { println("Result: $it") } }, GlobalScope.launch(dispatcher) { - sequencer.post { suspendingMethod("#3") }.also { - results.add(it) - } + sequencer.post { suspendingMethod("#3") } + .also { results.add(it) } } ) // We are canceling the second job diff --git a/multipicker/build.gradle b/multipicker/build.gradle index 7c29a5539f..c58c4586b2 100644 --- a/multipicker/build.gradle +++ b/multipicker/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' android { compileSdkVersion 29 diff --git a/tools/check/forbidden_strings_in_code.txt b/tools/check/forbidden_strings_in_code.txt index fc510e585c..2306eaed8b 100644 --- a/tools/check/forbidden_strings_in_code.txt +++ b/tools/check/forbidden_strings_in_code.txt @@ -109,9 +109,6 @@ import retrofit2\.adapter\.rxjava\.HttpException ### This is generally not necessary, no need to reset the padding if there is no drawable setCompoundDrawablePadding\(0\) -### Deprecated use class form SDK API 26 -ButterKnife\.findById\( - # Change thread with Rx # DISABLED #runOnUiThread @@ -164,7 +161,7 @@ Formatter\.formatShortFileSize===1 # android\.text\.TextUtils ### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If the enum is not used as a Json class, change the value in file forbidden_strings_in_code.txt -enum class===84 +enum class===85 ### Do not import temporary legacy classes import org.matrix.android.sdk.internal.legacy.riot===3 @@ -175,3 +172,6 @@ getSystemService\(Context ### Use DefaultSharedPreferences.getInstance() instead for better performance PreferenceManager\.getDefaultSharedPreferences==2 + +### Use ViewBindings +# findViewById diff --git a/tools/templates/ElementFeature/root/src/app_package/Fragment.kt.ftl b/tools/templates/ElementFeature/root/src/app_package/Fragment.kt.ftl index 7e6eac65c8..38f8132d24 100644 --- a/tools/templates/ElementFeature/root/src/app_package/Fragment.kt.ftl +++ b/tools/templates/ElementFeature/root/src/app_package/Fragment.kt.ftl @@ -3,7 +3,7 @@ package ${escapeKotlinIdentifiers(packageName)} import android.os.Bundle <#if createFragmentArgs> import android.os.Parcelable -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize import com.airbnb.mvrx.args import android.view.View @@ -36,8 +36,8 @@ class ${fragmentClass} @Inject constructor( } override fun onDestroyView() { - super.onDestroyView() // Clear your view, unsubscribe... + super.onDestroyView() } override fun invalidate() = withState(viewModel) { state -> diff --git a/vector/build.gradle b/vector/build.gradle index 70d38b1c2a..f6ba5d6e27 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -3,21 +3,17 @@ import com.android.build.OutputFile apply plugin: 'com.android.application' apply plugin: 'com.google.android.gms.oss-licenses-plugin' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' kapt { correctErrorTypes = true } -androidExtensions { - experimental = true -} - // Note: 2 digits max for each value ext.versionMajor = 1 ext.versionMinor = 0 -ext.versionPatch = 13 +ext.versionPatch = 14 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct' @@ -280,6 +276,10 @@ android { java.srcDirs += "src/sharedTest/java" } } + + buildFeatures { + viewBinding true + } } dependencies { @@ -386,10 +386,6 @@ dependencies { implementation 'com.otaliastudios:autocomplete:1.1.0' - // Butterknife - implementation 'com.jakewharton:butterknife:10.2.0' - kapt 'com.jakewharton:butterknife-compiler:10.2.0' - // Shake detection implementation 'com.squareup:seismic:1.0.2' diff --git a/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt b/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt index 6b30700116..58b596b05f 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/UiAllScreensSanityTest.kt @@ -76,7 +76,9 @@ class UiAllScreensSanityTest { private val uiTestBase = UiTestBase() - // Last passing: 2020-11-09 + // Last passing: + // 2020-11-09 + // 2020-12-16 After ViewBinding huge change @Test fun allScreensTest() { // Create an account @@ -245,6 +247,7 @@ class UiAllScreensSanityTest { // Room settings clickListItem(R.id.matrixProfileRecyclerView, 3) + navigateToRoomParameters() pressBack() // Notifications @@ -283,6 +286,31 @@ class UiAllScreensSanityTest { pressBack() } + private fun navigateToRoomParameters() { + // Room addresses + clickListItem(R.id.roomSettingsRecyclerView, 4) + onView(isRoot()).perform(waitForView(withText(R.string.room_alias_published_alias_title))) + pressBack() + + // Room permissions + clickListItem(R.id.roomSettingsRecyclerView, 6) + onView(isRoot()).perform(waitForView(withText(R.string.room_permissions_title))) + clickOn(R.string.room_permissions_change_room_avatar) + clickDialogNegativeButton() + // Toggle + clickOn(R.string.show_advanced) + clickOn(R.string.hide_advanced) + pressBack() + + // Room history readability + clickListItem(R.id.roomSettingsRecyclerView, 8) + pressBack() + + // Room access + clickListItem(R.id.roomSettingsRecyclerView, 10) + pressBack() + } + private fun navigateToInvite() { assertDisplayed(R.id.inviteUsersButton) clickOn(R.id.inviteUsersButton) diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt index 6c4bb925dd..8df1feab1e 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt @@ -24,26 +24,27 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.snackbar.Snackbar import im.vector.app.R import im.vector.app.core.utils.toast -import kotlinx.android.synthetic.debug.activity_test_material_theme.* +import im.vector.app.databinding.ActivityTestMaterialThemeBinding // Rendering is not the same with VectorBaseActivity abstract class DebugMaterialThemeActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_test_material_theme) + val views = ActivityTestMaterialThemeBinding.inflate(layoutInflater) + setContentView(views.root) - debugShowSnackbar.setOnClickListener { - Snackbar.make(debugMaterialCoordinator, "Snackbar!", Snackbar.LENGTH_SHORT) + views.debugShowSnackbar.setOnClickListener { + Snackbar.make(views.coordinatorLayout, "Snackbar!", Snackbar.LENGTH_SHORT) .setAction("Action") { } .show() } - debugShowToast.setOnClickListener { + views.debugShowToast.setOnClickListener { toast("Toast") } - debugShowDialog.setOnClickListener { + views.debugShowDialog.setOnClickListener { AlertDialog.Builder(this) .setMessage("Dialog content") .setIcon(R.drawable.ic_settings_x) @@ -53,7 +54,7 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() { .show() } - debugShowBottomSheet.setOnClickListener { + views.debugShowBottomSheet.setOnClickListener { BottomSheetDialogFragment().show(supportFragmentManager, "TAG") } } diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt index 9cca462d1a..8699b238ec 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt @@ -24,7 +24,6 @@ import android.os.Build import androidx.core.app.NotificationCompat import androidx.core.app.Person import androidx.core.content.getSystemService -import butterknife.OnClick import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ScreenComponent @@ -35,16 +34,17 @@ import im.vector.app.core.utils.PERMISSION_REQUEST_CODE_LAUNCH_CAMERA import im.vector.app.core.utils.allGranted import im.vector.app.core.utils.checkPermissions import im.vector.app.core.utils.toast +import im.vector.app.databinding.ActivityDebugMenuBinding import im.vector.app.features.debug.sas.DebugSasEmojiActivity import im.vector.app.features.qrcode.QrCodeScannerActivity import org.matrix.android.sdk.internal.crypto.verification.qrcode.toQrCodeData -import kotlinx.android.synthetic.debug.activity_debug_menu.* + import timber.log.Timber import javax.inject.Inject -class DebugMenuActivity : VectorBaseActivity() { +class DebugMenuActivity : VectorBaseActivity() { - override fun getLayoutRes() = R.layout.activity_debug_menu + override fun getBinding() = ActivityDebugMenuBinding.inflate(layoutInflater) @Inject lateinit var activeSessionHolder: ActiveSessionHolder @@ -66,24 +66,32 @@ class DebugMenuActivity : VectorBaseActivity() { val string = buffer.toString(Charsets.ISO_8859_1) renderQrCode(string) + setupViews() + } + + private fun setupViews() { + views.debugTestTextViewLink.setOnClickListener { testTextViewLink() } + views.debugShowSasEmoji.setOnClickListener { showSasEmoji() } + views.debugTestNotification.setOnClickListener { testNotification() } + views.debugTestMaterialThemeLight.setOnClickListener { testMaterialThemeLight() } + views.debugTestMaterialThemeDark.setOnClickListener { testMaterialThemeDark() } + views.debugTestCrash.setOnClickListener { testCrash() } + views.debugScanQrCode.setOnClickListener { scanQRCode() } } private fun renderQrCode(text: String) { - debug_qr_code.setData(text) + views.debugQrCode.setData(text) } - @OnClick(R.id.debug_test_text_view_link) - fun testTextViewLink() { + private fun testTextViewLink() { startActivity(Intent(this, TestLinkifyActivity::class.java)) } - @OnClick(R.id.debug_show_sas_emoji) - fun showSasEmoji() { + private fun showSasEmoji() { startActivity(Intent(this, DebugSasEmojiActivity::class.java)) } - @OnClick(R.id.debug_test_notification) - fun testNotification() { + private fun testNotification() { val notificationManager = getSystemService()!! // Create channel first @@ -166,23 +174,19 @@ class DebugMenuActivity : VectorBaseActivity() { ) } - @OnClick(R.id.debug_test_material_theme_light) - fun testMaterialThemeLight() { + private fun testMaterialThemeLight() { startActivity(Intent(this, DebugMaterialThemeLightActivity::class.java)) } - @OnClick(R.id.debug_test_material_theme_dark) - fun testMaterialThemeDark() { + private fun testMaterialThemeDark() { startActivity(Intent(this, DebugMaterialThemeDarkActivity::class.java)) } - @OnClick(R.id.debug_test_crash) - fun testCrash() { + private fun testCrash() { throw RuntimeException("Application crashed from user demand") } - @OnClick(R.id.debug_scan_qr_code) - fun scanQRCode() { + private fun scanQRCode() { if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, this, PERMISSION_REQUEST_CODE_LAUNCH_CAMERA)) { doScanQRCode() } diff --git a/vector/src/debug/java/im/vector/app/features/debug/TestLinkifyActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/TestLinkifyActivity.kt index fd28aabd49..88e55d6760 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/TestLinkifyActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/TestLinkifyActivity.kt @@ -19,28 +19,18 @@ package im.vector.app.features.debug import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.LinearLayout -import android.widget.TextView import androidx.appcompat.app.AppCompatActivity -import androidx.coordinatorlayout.widget.CoordinatorLayout -import butterknife.BindView -import butterknife.ButterKnife import im.vector.app.R +import im.vector.app.databinding.ActivityTestLinkifyBinding +import im.vector.app.databinding.ItemTestLinkifyBinding class TestLinkifyActivity : AppCompatActivity() { - @BindView(R.id.test_linkify_content_view) - lateinit var scrollContent: LinearLayout - - @BindView(R.id.test_linkify_coordinator) - lateinit var coordinatorLayout: CoordinatorLayout - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_test_linkify) - ButterKnife.bind(this) - - scrollContent.removeAllViews() + val views = ActivityTestLinkifyBinding.inflate(layoutInflater) + setContentView(views.root) + views.testLinkifyContentView.removeAllViews() listOf( "https://www.html5rocks.com/en/tutorials/webrtc/basics/ |", @@ -89,43 +79,42 @@ class TestLinkifyActivity : AppCompatActivity() { ) .forEach { textContent -> val item = LayoutInflater.from(this) - .inflate(R.layout.item_test_linkify, scrollContent, false) - - item.findViewById(R.id.test_linkify_auto_text) - ?.apply { - text = textContent - /* TODO Use BetterLinkMovementMethod when the other PR is merged - movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { - override fun onURLClick(uri: Uri?) { - Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) - .setAction("open") { - openUrlInExternalBrowser(this@TestLinkifyActivity, uri) - } - .show() - } - }) - */ + .inflate(R.layout.item_test_linkify, views.testLinkifyContentView, false) + val subViews = ItemTestLinkifyBinding.bind(item) + subViews.testLinkifyAutoText.apply { + text = textContent + /* TODO Use BetterLinkMovementMethod when the other PR is merged + movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { + override fun onURLClick(uri: Uri?) { + Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) + .setAction("open") { + openUrlInExternalBrowser(this@TestLinkifyActivity, uri) + } + .show() } + }) + */ + } - item.findViewById(R.id.test_linkify_custom_text) - ?.apply { - text = textContent - /* TODO Use BetterLinkMovementMethod when the other PR is merged - movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { - override fun onURLClick(uri: Uri?) { - Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) - .setAction("open") { - openUrlInExternalBrowser(this@TestLinkifyActivity, uri) - } - .show() - } - }) - */ - - // TODO Call VectorLinkify.addLinks(text) + subViews.testLinkifyCustomText.apply { + text = textContent + /* TODO Use BetterLinkMovementMethod when the other PR is merged + movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { + override fun onURLClick(uri: Uri?) { + Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) + .setAction("open") { + openUrlInExternalBrowser(this@TestLinkifyActivity, uri) + } + .show() } + }) + */ - scrollContent.addView(item, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) + // TODO Call VectorLinkify.addLinks(text) + } + + views.testLinkifyContentView + .addView(item, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } } } diff --git a/vector/src/debug/java/im/vector/app/features/debug/sas/DebugSasEmojiActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/sas/DebugSasEmojiActivity.kt index 869058eff6..4d7005aca8 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/sas/DebugSasEmojiActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/sas/DebugSasEmojiActivity.kt @@ -18,24 +18,26 @@ package im.vector.app.features.debug.sas import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import im.vector.app.R import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith +import im.vector.app.databinding.FragmentGenericRecyclerBinding import org.matrix.android.sdk.api.crypto.getAllVerificationEmojis -import kotlinx.android.synthetic.main.fragment_generic_recycler.* class DebugSasEmojiActivity : AppCompatActivity() { + private lateinit var views: FragmentGenericRecyclerBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.fragment_generic_recycler) + views = FragmentGenericRecyclerBinding.inflate(layoutInflater) + setContentView(views.root) val controller = SasEmojiController() - genericRecyclerView.configureWith(controller) + views.genericRecyclerView.configureWith(controller) controller.setData(SasState(getAllVerificationEmojis())) } override fun onDestroy() { - genericRecyclerView.cleanup() + views.genericRecyclerView.cleanup() super.onDestroy() } } diff --git a/vector/src/debug/res/layout/activity_debug_menu.xml b/vector/src/debug/res/layout/activity_debug_menu.xml index 9a95085a07..6a41488987 100644 --- a/vector/src/debug/res/layout/activity_debug_menu.xml +++ b/vector/src/debug/res/layout/activity_debug_menu.xml @@ -1,6 +1,7 @@ + android:name=".features.home.HomeActivity" /> Copyright (c) 2017 -
  • - Butterknife -
    - Copyright 2013 Jake Wharton -
  • seismic
    @@ -337,11 +332,6 @@ SOFTWARE.
    Copyright 2018 The diff-match-patch Authors. https://github.com/google/diff-match-patch
  • -
  • - EventBus -
    - Copyright (C) 2012-2017 Markus Junginger, greenrobot (http://greenrobot.org) -
  • LazyThreeTenBp
    diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index 87ab875746..407aa2fc73 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -84,6 +84,7 @@ import im.vector.app.features.roomprofile.banned.RoomBannedMemberListFragment import im.vector.app.features.roomprofile.members.RoomMemberListFragment import im.vector.app.features.roomprofile.settings.RoomSettingsFragment import im.vector.app.features.roomprofile.alias.RoomAliasFragment +import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment import im.vector.app.features.roomprofile.uploads.files.RoomUploadsFilesFragment import im.vector.app.features.roomprofile.uploads.media.RoomUploadsMediaFragment @@ -364,6 +365,11 @@ interface FragmentModule { @FragmentKey(RoomAliasFragment::class) fun bindRoomAliasFragment(fragment: RoomAliasFragment): Fragment + @Binds + @IntoMap + @FragmentKey(RoomPermissionsFragment::class) + fun bindRoomPermissionsFragment(fragment: RoomPermissionsFragment): Fragment + @Binds @IntoMap @FragmentKey(RoomMemberProfileFragment::class) diff --git a/vector/src/main/java/im/vector/app/core/dialogs/ConfirmationDialogBuilder.kt b/vector/src/main/java/im/vector/app/core/dialogs/ConfirmationDialogBuilder.kt index 0d9fb9d93d..ed429b30c6 100644 --- a/vector/src/main/java/im/vector/app/core/dialogs/ConfirmationDialogBuilder.kt +++ b/vector/src/main/java/im/vector/app/core/dialogs/ConfirmationDialogBuilder.kt @@ -21,7 +21,7 @@ import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog import androidx.core.view.isVisible import im.vector.app.R -import kotlinx.android.synthetic.main.dialog_confirmation_with_reason.view.* +import im.vector.app.databinding.DialogConfirmationWithReasonBinding object ConfirmationDialogBuilder { @@ -33,25 +33,26 @@ object ConfirmationDialogBuilder { @StringRes reasonHintRes: Int, confirmation: (String?) -> Unit) { val layout = activity.layoutInflater.inflate(R.layout.dialog_confirmation_with_reason, null) - layout.dialogConfirmationText.setText(confirmationRes) + val views = DialogConfirmationWithReasonBinding.bind(layout) + views.dialogConfirmationText.setText(confirmationRes) - layout.dialogReasonCheck.isVisible = askForReason - layout.dialogReasonTextInputLayout.isVisible = askForReason + views.dialogReasonCheck.isVisible = askForReason + views.dialogReasonTextInputLayout.isVisible = askForReason - layout.dialogReasonCheck.setOnCheckedChangeListener { _, isChecked -> - layout.dialogReasonTextInputLayout.isEnabled = isChecked + views.dialogReasonCheck.setOnCheckedChangeListener { _, isChecked -> + views.dialogReasonTextInputLayout.isEnabled = isChecked } if (askForReason && reasonHintRes != 0) { - layout.dialogReasonInput.setHint(reasonHintRes) + views.dialogReasonInput.setHint(reasonHintRes) } AlertDialog.Builder(activity) .setTitle(titleRes) .setView(layout) .setPositiveButton(positiveRes) { _, _ -> - val reason = layout.dialogReasonInput.text.toString() + val reason = views.dialogReasonInput.text.toString() .takeIf { askForReason } - ?.takeIf { layout.dialogReasonCheck.isChecked } + ?.takeIf { views.dialogReasonCheck.isChecked } ?.takeIf { it.isNotBlank() } confirmation(reason) } diff --git a/vector/src/main/java/im/vector/app/core/dialogs/ExportKeysDialog.kt b/vector/src/main/java/im/vector/app/core/dialogs/ExportKeysDialog.kt index b4087d5ce1..e137eb1b70 100644 --- a/vector/src/main/java/im/vector/app/core/dialogs/ExportKeysDialog.kt +++ b/vector/src/main/java/im/vector/app/core/dialogs/ExportKeysDialog.kt @@ -18,14 +18,11 @@ package im.vector.app.core.dialogs import android.app.Activity import android.text.Editable -import android.widget.Button -import android.widget.ImageView import androidx.appcompat.app.AlertDialog -import com.google.android.material.textfield.TextInputEditText -import com.google.android.material.textfield.TextInputLayout import im.vector.app.R import im.vector.app.core.extensions.showPassword import im.vector.app.core.platform.SimpleTextWatcher +import im.vector.app.databinding.DialogExportE2eKeysBinding class ExportKeysDialog { @@ -33,48 +30,44 @@ class ExportKeysDialog { fun show(activity: Activity, exportKeyDialogListener: ExportKeyDialogListener) { val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_export_e2e_keys, null) + val views = DialogExportE2eKeysBinding.bind(dialogLayout) val builder = AlertDialog.Builder(activity) .setTitle(R.string.encryption_export_room_keys) .setView(dialogLayout) - val passPhrase1EditText = dialogLayout.findViewById(R.id.exportDialogEt) - val passPhrase2EditText = dialogLayout.findViewById(R.id.exportDialogEtConfirm) - val passPhrase2Til = dialogLayout.findViewById(R.id.exportDialogTilConfirm) - val exportButton = dialogLayout.findViewById