Compare commits
2 Commits
develop
...
feature/nf
Author | SHA1 | Date |
---|---|---|
NIkita Fedrunov | 03be46961e | |
NIkita Fedrunov | 2dc103f7ee |
|
@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.session.identity.IdentityService
|
||||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||||
import org.matrix.android.sdk.api.session.media.MediaService
|
import org.matrix.android.sdk.api.session.media.MediaService
|
||||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.DeferredPermalinkService
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||||
import org.matrix.android.sdk.api.session.presence.PresenceService
|
import org.matrix.android.sdk.api.session.presence.PresenceService
|
||||||
import org.matrix.android.sdk.api.session.profile.ProfileService
|
import org.matrix.android.sdk.api.session.profile.ProfileService
|
||||||
|
@ -248,6 +249,11 @@ interface Session {
|
||||||
*/
|
*/
|
||||||
fun permalinkService(): PermalinkService
|
fun permalinkService(): PermalinkService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the deferredPermalinkService service associated with the session.
|
||||||
|
*/
|
||||||
|
fun deferredPermalinkService(): DeferredPermalinkService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the search service associated with the session.
|
* Returns the search service associated with the session.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 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.permalinks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to handle deferred links, e.g. when user open link to the room but the app is not installed yet.
|
||||||
|
*/
|
||||||
|
interface DeferredPermalinkService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks system clipboard for matrix.to links and returns first room link if any found.
|
||||||
|
* @return first room link in clipboard or null if none is found
|
||||||
|
*/
|
||||||
|
fun getLinkFromClipBoard(): String?
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ import org.matrix.android.sdk.api.session.identity.IdentityService
|
||||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||||
import org.matrix.android.sdk.api.session.media.MediaService
|
import org.matrix.android.sdk.api.session.media.MediaService
|
||||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.DeferredPermalinkService
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||||
import org.matrix.android.sdk.api.session.presence.PresenceService
|
import org.matrix.android.sdk.api.session.presence.PresenceService
|
||||||
import org.matrix.android.sdk.api.session.profile.ProfileService
|
import org.matrix.android.sdk.api.session.profile.ProfileService
|
||||||
|
@ -135,6 +136,7 @@ internal class DefaultSession @Inject constructor(
|
||||||
@UnauthenticatedWithCertificate
|
@UnauthenticatedWithCertificate
|
||||||
private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>,
|
private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>,
|
||||||
private val sessionState: SessionState,
|
private val sessionState: SessionState,
|
||||||
|
private val deferredPermalinkService: Lazy<DeferredPermalinkService>,
|
||||||
) : Session,
|
) : Session,
|
||||||
GlobalErrorHandler.Listener {
|
GlobalErrorHandler.Listener {
|
||||||
|
|
||||||
|
@ -222,6 +224,8 @@ internal class DefaultSession @Inject constructor(
|
||||||
override fun eventStreamService(): EventStreamService = eventStreamService.get()
|
override fun eventStreamService(): EventStreamService = eventStreamService.get()
|
||||||
override fun fileService(): FileService = defaultFileService.get()
|
override fun fileService(): FileService = defaultFileService.get()
|
||||||
override fun permalinkService(): PermalinkService = permalinkService.get()
|
override fun permalinkService(): PermalinkService = permalinkService.get()
|
||||||
|
override fun deferredPermalinkService(): DeferredPermalinkService = deferredPermalinkService.get()
|
||||||
|
|
||||||
override fun widgetService(): WidgetService = widgetService.get()
|
override fun widgetService(): WidgetService = widgetService.get()
|
||||||
override fun mediaService(): MediaService = mediaService.get()
|
override fun mediaService(): MediaService = mediaService.get()
|
||||||
override fun integrationManagerService(): IntegrationManagerService = integrationManagerService.get()
|
override fun integrationManagerService(): IntegrationManagerService = integrationManagerService.get()
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.events.EventService
|
import org.matrix.android.sdk.api.session.events.EventService
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.DeferredPermalinkService
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||||
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageService
|
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageService
|
||||||
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
||||||
|
@ -83,6 +84,7 @@ import org.matrix.android.sdk.internal.session.homeserver.DefaultHomeServerCapab
|
||||||
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
|
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
|
||||||
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManager
|
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManager
|
||||||
import org.matrix.android.sdk.internal.session.openid.DefaultOpenIdService
|
import org.matrix.android.sdk.internal.session.openid.DefaultOpenIdService
|
||||||
|
import org.matrix.android.sdk.internal.session.permalinks.DefaultDeferredPermalinkService
|
||||||
import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService
|
import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService
|
||||||
import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor
|
import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor
|
||||||
import org.matrix.android.sdk.internal.session.room.aggregation.poll.DefaultPollAggregationProcessor
|
import org.matrix.android.sdk.internal.session.room.aggregation.poll.DefaultPollAggregationProcessor
|
||||||
|
@ -405,4 +407,7 @@ internal abstract class SessionModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindPollAggregationProcessor(processor: DefaultPollAggregationProcessor): PollAggregationProcessor
|
abstract fun bindPollAggregationProcessor(processor: DefaultPollAggregationProcessor): PollAggregationProcessor
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindDeferredPermalinkService(service: DefaultDeferredPermalinkService): DeferredPermalinkService
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 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.permalinks
|
||||||
|
|
||||||
|
import android.content.ClipboardManager
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.DeferredPermalinkService
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
||||||
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DefaultDeferredPermalinkService @Inject constructor(
|
||||||
|
private val context: Context
|
||||||
|
) : DeferredPermalinkService {
|
||||||
|
|
||||||
|
override fun getLinkFromClipBoard(): String? {
|
||||||
|
val clipboard = context.getSystemService<ClipboardManager>()
|
||||||
|
clipboard?.primaryClip?.let { clip ->
|
||||||
|
if (clip.itemCount == 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
for (i in 0 until clip.itemCount) {
|
||||||
|
val clipText = clip.getItemAt(i).text.toString()
|
||||||
|
val data = PermalinkParser.parse(clipText)
|
||||||
|
if (data is PermalinkData.RoomLink) {
|
||||||
|
return clipText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
|
@ -267,6 +267,7 @@ class HomeActivity :
|
||||||
HomeActivityViewEvents.NotifyUserForThreadsMigration -> handleNotifyUserForThreadsMigration()
|
HomeActivityViewEvents.NotifyUserForThreadsMigration -> handleNotifyUserForThreadsMigration()
|
||||||
is HomeActivityViewEvents.MigrateThreads -> migrateThreadsIfNeeded(it.checkSession)
|
is HomeActivityViewEvents.MigrateThreads -> migrateThreadsIfNeeded(it.checkSession)
|
||||||
is HomeActivityViewEvents.AskUserForPushDistributor -> askUserToSelectPushDistributor()
|
is HomeActivityViewEvents.AskUserForPushDistributor -> askUserToSelectPushDistributor()
|
||||||
|
is HomeActivityViewEvents.NavigatePermalink -> handleNavigatePermalink(it.permalink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
homeActivityViewModel.onEach { renderState(it) }
|
homeActivityViewModel.onEach { renderState(it) }
|
||||||
|
@ -279,6 +280,17 @@ class HomeActivity :
|
||||||
homeActivityViewModel.handle(HomeActivityViewActions.ViewStarted)
|
homeActivityViewModel.handle(HomeActivityViewActions.ViewStarted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleNavigatePermalink(permalink: String) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
permalinkHandler.launch(
|
||||||
|
fragmentActivity = this@HomeActivity,
|
||||||
|
deepLink = permalink,
|
||||||
|
navigationInterceptor = this@HomeActivity,
|
||||||
|
buildTask = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun askUserToSelectPushDistributor() {
|
private fun askUserToSelectPushDistributor() {
|
||||||
unifiedPushHelper.showSelectDistributorDialog(this) { selection ->
|
unifiedPushHelper.showSelectDistributorDialog(this) { selection ->
|
||||||
homeActivityViewModel.handle(HomeActivityViewActions.RegisterPushDistributor(selection))
|
homeActivityViewModel.handle(HomeActivityViewActions.RegisterPushDistributor(selection))
|
||||||
|
|
|
@ -40,4 +40,5 @@ sealed interface HomeActivityViewEvents : VectorViewEvents {
|
||||||
object StartRecoverySetupFlow : HomeActivityViewEvents
|
object StartRecoverySetupFlow : HomeActivityViewEvents
|
||||||
data class ForceVerification(val sendRequest: Boolean) : HomeActivityViewEvents
|
data class ForceVerification(val sendRequest: Boolean) : HomeActivityViewEvents
|
||||||
object AskUserForPushDistributor : HomeActivityViewEvents
|
object AskUserForPushDistributor : HomeActivityViewEvents
|
||||||
|
data class NavigatePermalink(val permalink: String) : HomeActivityViewEvents
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,6 +293,7 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||||
.onEach { status ->
|
.onEach { status ->
|
||||||
when (status) {
|
when (status) {
|
||||||
is SyncRequestState.Idle -> {
|
is SyncRequestState.Idle -> {
|
||||||
|
checkDeferredPermalink()
|
||||||
maybeVerifyOrBootstrapCrossSigning()
|
maybeVerifyOrBootstrapCrossSigning()
|
||||||
}
|
}
|
||||||
else -> Unit
|
else -> Unit
|
||||||
|
@ -371,6 +372,12 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkDeferredPermalink() {
|
||||||
|
activeSessionHolder.getActiveSession().deferredPermalinkService().getLinkFromClipBoard()?.let { roomPermalink ->
|
||||||
|
_viewEvents.post(HomeActivityViewEvents.NavigatePermalink(permalink = roomPermalink))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun maybeVerifyOrBootstrapCrossSigning() {
|
private fun maybeVerifyOrBootstrapCrossSigning() {
|
||||||
// The contents of this method should only run once
|
// The contents of this method should only run once
|
||||||
if (hasCheckedBootstrap) return
|
if (hasCheckedBootstrap) return
|
||||||
|
|
Loading…
Reference in New Issue