mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-12 11:07:42 +00:00
join open group from received invitation
This commit is contained in:
@@ -12,6 +12,7 @@ object OpenGroupUrlParser {
|
||||
object InvalidPublicKeyProvided : Error("Invalid public key provided.")
|
||||
}
|
||||
|
||||
private const val suffix = "/"
|
||||
private const val queryPrefix = "public_key"
|
||||
|
||||
fun parseUrl(stringUrl: String): OpenGroupRoom {
|
||||
@@ -20,7 +21,7 @@ object OpenGroupUrlParser {
|
||||
// If the URL is malformed, it will throw an exception
|
||||
val httpUrl = HttpUrl.parse(url) ?: throw Error.MalformedUrl()
|
||||
|
||||
val host = httpUrl.host()
|
||||
val server = HttpUrl.Builder().scheme(httpUrl.scheme()).host(httpUrl.host()).port(httpUrl.port()).build().toString().removeSuffix(suffix)
|
||||
// Test if the room is specified in the URL
|
||||
val room = httpUrl.pathSegments().firstOrNull { !it.isNullOrEmpty() } ?: throw Error.NoRoomSpecified
|
||||
// Test if the query is specified in the URL
|
||||
@@ -28,7 +29,7 @@ object OpenGroupUrlParser {
|
||||
// Public key must be 64 characters
|
||||
if (publicKey.length != 64) throw Error.InvalidPublicKeyProvided
|
||||
|
||||
return OpenGroupRoom(host,room,publicKey)
|
||||
return OpenGroupRoom(server,room,publicKey)
|
||||
}
|
||||
|
||||
fun trimParameter(stringUrl: String): String {
|
||||
@@ -36,4 +37,4 @@ object OpenGroupUrlParser {
|
||||
}
|
||||
}
|
||||
|
||||
class OpenGroupRoom(val serverHost: String, val room: String, val serverPublicKey: String) { }
|
||||
class OpenGroupRoom(val server: String, val room: String, val serverPublicKey: String) {}
|
||||
|
@@ -9,12 +9,12 @@ class OpenGroupUrlParserTest {
|
||||
fun parseUrlTest() {
|
||||
val inputUrl = "https://sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val expectedHost = "sessionopengroup.co"
|
||||
val expectedHost = "https://sessionopengroup.co"
|
||||
val expectedRoom = "main"
|
||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||
assertEquals(expectedHost, result.serverHost)
|
||||
assertEquals(expectedHost, result.server)
|
||||
assertEquals(expectedRoom, result.room)
|
||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||
}
|
||||
@@ -23,12 +23,12 @@ class OpenGroupUrlParserTest {
|
||||
fun parseUrlNoHttpTest() {
|
||||
val inputUrl = "sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val expectedHost = "sessionopengroup.co"
|
||||
val expectedHost = "http://sessionopengroup.co"
|
||||
val expectedRoom = "main"
|
||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||
assertEquals(expectedHost, result.serverHost)
|
||||
assertEquals(expectedHost, result.server)
|
||||
assertEquals(expectedRoom, result.room)
|
||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||
}
|
||||
@@ -37,12 +37,12 @@ class OpenGroupUrlParserTest {
|
||||
fun parseUrlWithIpTest() {
|
||||
val inputUrl = "https://143.198.213.255:80/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val expectedHost = "143.198.213.255"
|
||||
val expectedHost = "https://143.198.213.255:80"
|
||||
val expectedRoom = "main"
|
||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||
assertEquals(expectedHost, result.serverHost)
|
||||
assertEquals(expectedHost, result.server)
|
||||
assertEquals(expectedRoom, result.room)
|
||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||
}
|
||||
@@ -51,12 +51,12 @@ class OpenGroupUrlParserTest {
|
||||
fun parseUrlWithIpAndNoHttpTest() {
|
||||
val inputUrl = "143.198.213.255/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val expectedHost = "143.198.213.255"
|
||||
val expectedHost = "http://143.198.213.255"
|
||||
val expectedRoom = "main"
|
||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||
|
||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||
assertEquals(expectedHost, result.serverHost)
|
||||
assertEquals(expectedHost, result.server)
|
||||
assertEquals(expectedRoom, result.room)
|
||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||
}
|
||||
|
Reference in New Issue
Block a user