-
Notifications
You must be signed in to change notification settings - Fork 742
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
use clipboard hack to get deferred deeplink #7842
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @return first room link in clipboard or null if none is found | ||
*/ | ||
fun getLinkFromClipBoard(): String? | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import android.content.Context | ||
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 androidx.core.content.getSystemService | ||
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,7 @@ class HomeActivityViewModel @AssistedInject constructor( | |
.onEach { status -> | ||
when (status) { | ||
is SyncRequestState.Idle -> { | ||
checkDeferredPermalink() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is preventing this to be executed at each start (i.e. until the Clipboard is flushed?) |
||
maybeVerifyOrBootstrapCrossSigning() | ||
} | ||
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() { | ||
// The contents of this method should only run once | ||
if (hasCheckedBootstrap) return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure to understand why this code is on the SDK side. It should be at the application level.