forked from RocketChat/Rocket.Chat.Android
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from WideChat/ear_shailesh_dynamicLink
Add dynamic link to the invite via another app [originally from Shailesh PR 191]
- Loading branch information
Showing
31 changed files
with
454 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,4 @@ | |
} | ||
], | ||
"configuration_version": "1" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/foss/java/chat/rocket/android/dynamiclinks/DynamicLinksForFirebase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package chat.rocket.android.dynamiclinks | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import javax.inject.Inject | ||
|
||
class DynamicLinksForFirebase @Inject constructor(private val context: Context) : DynamicLinks { | ||
|
||
override fun getDynamicLink(intent: Intent, deepLinkCallback: (Uri?) -> Unit? ) { | ||
deepLinkCallback(null) | ||
} | ||
|
||
override fun createDynamicLink(username: String, server: String, deepLinkCallback: (String?) -> Unit?) { | ||
deepLinkCallback(null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/src/main/java/chat/rocket/android/authentication/domain/model/DeepLinkInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package chat.rocket.android.authentication.domain.model | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Parcelable | ||
import kotlinx.android.parcel.Parcelize | ||
import timber.log.Timber | ||
|
||
// see https://rocket.chat/docs/developer-guides/deeplink/ for documentation | ||
|
||
@SuppressLint("ParcelCreator") | ||
@Parcelize | ||
data class DeepLinkInfo( | ||
val url: String, | ||
val userId: String?, | ||
val token: String?, | ||
val rid: String?, | ||
val roomType: String?, | ||
val roomName: String? | ||
) : Parcelable | ||
|
||
fun Uri.getDeepLinkInfo(): DeepLinkInfo? { | ||
return if (isAuthenticationDeepLink()) { | ||
val host = getQueryParameter("host") | ||
val url = if (host.startsWith("http")) host else "https://$host" | ||
val userId = getQueryParameter("userId") | ||
val token = getQueryParameter("token") | ||
try { | ||
DeepLinkInfo(url, userId, token, null, null, null) | ||
} catch (ex: Exception) { | ||
Timber.d(ex, "Error parsing auth deeplink") | ||
null | ||
} | ||
} else if (isCustomSchemeRoomLink()) { | ||
val hostValue = getQueryParameter("host") | ||
val url = if (hostValue.startsWith("http")) hostValue else "https://$hostValue" | ||
val rid = getQueryParameter("rid") | ||
val pathValue = getQueryParameter("path") | ||
val pathSplit = pathValue.split("/") | ||
val roomType = pathSplit[0] | ||
val roomName = pathSplit[1] | ||
try { | ||
DeepLinkInfo(url, null, null, rid, roomType, roomName) | ||
} catch (ex: Exception) { | ||
Timber.d(ex, "Error parsing custom scheme room link") | ||
null | ||
} | ||
} else if (isWebSchemeRoomLink()) { | ||
val url = "https://$host" | ||
val pathSplit = path.split("/") | ||
val roomType = pathSplit[1] | ||
val roomName = pathSplit[2] | ||
try { | ||
DeepLinkInfo(url, null, null, null, roomType, roomName) | ||
} catch (ex: Exception) { | ||
Timber.d(ex, "Error parsing login deeplink") | ||
null | ||
} | ||
} else null | ||
} | ||
|
||
fun Intent.isSupportedLink(): Boolean { | ||
return (action == Intent.ACTION_VIEW && data != null && | ||
(data.isDynamicLink() || data.isAuthenticationDeepLink() || | ||
data.isCustomSchemeRoomLink() || data.isWebSchemeRoomLink())) | ||
} | ||
|
||
fun Uri.isDynamicLink(): Boolean { | ||
return (host != null && host.contains("page.link", ignoreCase = true)) | ||
} | ||
|
||
// Authentication deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#authentication | ||
private inline fun Uri.isAuthenticationDeepLink(): Boolean { | ||
if (host == "auth") | ||
return true | ||
else if (host == "go.rocket.chat" && path == "/auth") | ||
return true | ||
return false | ||
} | ||
|
||
// Custom scheme room deep link defined here: https://rocket.chat/docs/developer-guides/deeplink/#channel--group--dm | ||
private inline fun Uri.isCustomSchemeRoomLink(): Boolean { | ||
if (scheme.startsWith("rocketchat") && | ||
host == "room") | ||
return true | ||
return false | ||
} | ||
|
||
// http(s) scheme deep link not yet documented. Ex: https://viasatconnect.com/direct/testuser1 | ||
private inline fun Uri.isWebSchemeRoomLink(): Boolean { | ||
val roomType = path.split("/")[1] | ||
if (scheme.startsWith("http") && | ||
(roomType == "channel" || roomType == "group" || roomType == "direct")) | ||
return true | ||
return false | ||
} |
40 changes: 0 additions & 40 deletions
40
app/src/main/java/chat/rocket/android/authentication/domain/model/LoginDeepLinkInfo.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.