Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start sync #8019

Merged
merged 6 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/ui-strings/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<!-- onboarding english only word play -->
<string name="cut_the_slack_from_teams" translatable="false">Cut the slack from teams.</string>

<string name="command_description_crash_application" translatable="false">Crash the application.</string>

<!-- WIP -->
<string name="location_map_view_copyright" translatable="false">© MapTiler © OpenStreetMap contributors</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class FlowSession(private val session: Session) {

fun liveSyncState(): Flow<SyncState> {
return session.syncService().getSyncStateLive().asFlow()
.startWith(session.coroutineDispatchers.io) {
session.syncService().getSyncState()
}
}

fun livePushers(): Flow<List<Pusher>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* 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 im.vector.app.core.session

import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.startSyncing
import org.matrix.android.sdk.api.session.sync.SyncState
import timber.log.Timber
import javax.inject.Inject

class EnsureSessionSyncingUseCase @Inject constructor(
@ApplicationContext private val context: Context,
private val activeSessionHolder: ActiveSessionHolder,
) {
fun execute() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
if (session.syncService().getSyncState() == SyncState.Idle) {
Timber.w("EnsureSessionSyncingUseCase: start syncing")
session.startSyncing(context)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class Command(
val isDevCommand: Boolean,
val isThreadCommand: Boolean
) {
CRASH_APP("/crash", null, "", R.string.command_description_crash_application, true, true),
EMOTE("/me", null, "<message>", R.string.command_description_emote, false, true),
BAN_USER("/ban", null, "<user-id> [reason]", R.string.command_description_ban_user, false, false),
UNBAN_USER("/unban", null, "<user-id> [reason]", R.string.command_description_unban_user, false, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import im.vector.app.core.extensions.isEmail
import im.vector.app.core.extensions.isMsisdn
import im.vector.app.core.extensions.orEmpty
import im.vector.app.features.home.room.detail.ChatEffect
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.MatrixPatterns
import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl
import org.matrix.android.sdk.api.session.identity.ThreePid
import timber.log.Timber
import javax.inject.Inject

class CommandParser @Inject constructor() {
class CommandParser @Inject constructor(
private val vectorPreferences: VectorPreferences
) {

/**
* Convert the text message into a Slash command.
Expand Down Expand Up @@ -404,6 +407,9 @@ class CommandParser @Inject constructor() {
ParsedCommand.ErrorSyntax(Command.UPGRADE_ROOM)
}
}
Command.CRASH_APP.matches(slashCommand) && vectorPreferences.developerMode() -> {
throw RuntimeException("Application crashed from user demand")
}
else -> {
// Unknown command
ParsedCommand.ErrorUnknownSlashCommand(slashCommand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
import im.vector.app.core.session.EnsureSessionSyncingUseCase
import im.vector.app.features.analytics.AnalyticsConfig
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsType
Expand Down Expand Up @@ -95,6 +96,7 @@ class HomeActivityViewModel @AssistedInject constructor(
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
private val ensureSessionSyncingUseCase: EnsureSessionSyncingUseCase,
) : VectorViewModel<HomeActivityViewState, HomeActivityViewActions, HomeActivityViewEvents>(initialState) {

@AssistedFactory
Expand All @@ -118,6 +120,8 @@ class HomeActivityViewModel @AssistedInject constructor(
private fun initialize() {
if (isInitialized) return
isInitialized = true
// Ensure Session is syncing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment really useful? Not an issue at all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, a bit useless. I added the comment when the use case had another name. Could be removed now (but I will not trigger the CI for that).

ensureSessionSyncingUseCase.execute()
registerUnifiedPushIfNeeded()
cleanupFiles()
observeInitialSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ data class HomeDetailViewState(
val notificationCountRooms: Int = 0,
val notificationHighlightRooms: Boolean = false,
val hasUnreadMessages: Boolean = false,
val syncState: SyncState = SyncState.Idle,
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState = SyncRequestState.IncrementalSyncIdle,
val syncState: SyncState? = null,
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState? = null,
val pushCounter: Int = 0,
val pstnSupportFlag: Boolean = false,
val forceDialPadTab: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ data class RoomDetailViewState(
val formattedTypingUsers: String? = null,
val tombstoneEvent: Event? = null,
val joinUpgradedRoomAsync: Async<String> = Uninitialized,
val syncState: SyncState = SyncState.Idle,
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState = SyncRequestState.IncrementalSyncIdle,
val syncState: SyncState? = null,
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState? = null,
val pushCounter: Int = 0,
val highlightedEventId: String? = null,
val unreadState: UnreadState = UnreadState.Unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute

@SuppressLint("SetTextI18n")
fun render(
newState: SyncState,
incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState,
newState: SyncState?,
incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState?,
pushCounter: Int,
showDebugInfo: Boolean
) {
Expand All @@ -64,8 +64,9 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute
}
}

private fun SyncState.toHumanReadable(): String {
private fun SyncState?.toHumanReadable(): String {
return when (this) {
null -> "Unknown"
SyncState.Idle -> "Idle"
SyncState.InvalidToken -> "InvalidToken"
SyncState.Killed -> "Killed"
Expand All @@ -76,8 +77,9 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute
}
}

private fun SyncRequestState.IncrementalSyncRequestState.toHumanReadable(): String {
private fun SyncRequestState.IncrementalSyncRequestState?.toHumanReadable(): String {
return when (this) {
null -> "Unknown"
SyncRequestState.IncrementalSyncIdle -> "Idle"
is SyncRequestState.IncrementalSyncParsing -> "Parsing ${this.rooms} room(s) ${this.toDevice} toDevice(s)"
SyncRequestState.IncrementalSyncError -> "Error"
Expand Down
38 changes: 20 additions & 18 deletions vector/src/main/res/layout/fragment_timeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:visibility="gone" />
android:visibility="gone"
tools:visibility="visible" />

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/roomToolbar"
Expand All @@ -38,9 +39,9 @@
</com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rootConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rootConstraintLayout">
android:layout_height="match_parent">

<im.vector.app.features.sync.widget.SyncStateView
android:id="@+id/syncStateView"
Expand Down Expand Up @@ -75,7 +76,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:overScrollMode="always"
app:layout_constraintBottom_toTopOf="@id/notificationAreaView"
app:layout_constraintBottom_toTopOf="@id/failedMessagesWarningStub"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/removeJitsiWidgetView"
Expand All @@ -95,16 +96,7 @@
app:closeIcon="@drawable/ic_close_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/removeJitsiWidgetView" />

<im.vector.app.core.ui.views.NotificationAreaView
android:id="@+id/notificationAreaView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/removeJitsiWidgetView"
tools:visibility="visible" />

<ViewStub
Expand All @@ -113,11 +105,21 @@
android:layout_height="wrap_content"
android:inflatedId="@+id/failedMessagesWarningStub"
android:layout="@layout/view_stub_failed_message_warning_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/notificationAreaView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_height="300dp" />

<im.vector.app.core.ui.views.NotificationAreaView
android:id="@+id/notificationAreaView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />

<ViewStub
android:id="@+id/inviteViewStub"
android:layout_width="0dp"
Expand Down Expand Up @@ -208,16 +210,16 @@
android:id="@+id/composerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:translationZ="10dp"
android:background="@android:color/transparent"
android:translationZ="10dp"
app:layout_behavior="im.vector.app.core.utils.ExpandingBottomSheetBehavior" />

<FrameLayout
android:id="@+id/voiceMessageRecorderContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="visible"
android:translationZ="10dp" />
android:translationZ="10dp"
android:visibility="visible" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package im.vector.app.features.command

import im.vector.app.test.fakes.FakeVectorPreferences
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test

private const val A_SPACE_ID = "!my-space-id"

class CommandParserTest {
private val fakeVectorPreferences = FakeVectorPreferences()

@Test
fun parseSlashCommandEmpty() {
test("/", ParsedCommand.ErrorEmptySlashCommand)
Expand Down Expand Up @@ -70,7 +73,7 @@ class CommandParserTest {
}

private fun test(message: String, expectedResult: ParsedCommand) {
val commandParser = CommandParser()
val commandParser = CommandParser(fakeVectorPreferences.instance)
val result = commandParser.parseSlashCommand(message, null, false)
result shouldBeEqualTo expectedResult
}
Expand Down