mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-30 22:30:49 +00:00
join open group from received invitation
This commit is contained in:
parent
f51268b587
commit
2f0509a03b
@ -643,7 +643,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
if (updateMessageData.getKind() instanceof UpdateMessageData.Kind.OpenGroupInvitation) {
|
if (updateMessageData.getKind() instanceof UpdateMessageData.Kind.OpenGroupInvitation) {
|
||||||
UpdateMessageData.Kind.OpenGroupInvitation data = (UpdateMessageData.Kind.OpenGroupInvitation)updateMessageData.getKind();
|
UpdateMessageData.Kind.OpenGroupInvitation data = (UpdateMessageData.Kind.OpenGroupInvitation)updateMessageData.getKind();
|
||||||
name = data.getGroupName();
|
name = data.getGroupName();
|
||||||
url = OpenGroupUrlParser.INSTANCE.trimParameter(data.getGroupUrl());
|
url = data.getGroupUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
openGroupInvitationViewStub.get().setOpenGroup(name, url, messageRecord.isOutgoing());
|
openGroupInvitationViewStub.get().setOpenGroup(name, url, messageRecord.isOutgoing());
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package org.thoughtcrime.securesms.loki.views
|
package org.thoughtcrime.securesms.loki.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.utilities.GroupUtil
|
||||||
|
import org.session.libsession.utilities.OpenGroupUrlParser
|
||||||
import org.session.libsignal.utilities.logging.Log
|
import org.session.libsignal.utilities.logging.Log
|
||||||
import java.io.IOException
|
import org.thoughtcrime.securesms.groups.GroupManager
|
||||||
|
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
|
||||||
|
|
||||||
class OpenGroupInvitationView : FrameLayout {
|
class OpenGroupInvitationView : FrameLayout {
|
||||||
|
|
||||||
@ -22,7 +25,9 @@ class OpenGroupInvitationView : FrameLayout {
|
|||||||
private val joinButton: ImageView
|
private val joinButton: ImageView
|
||||||
private val openGroupIcon: ImageView
|
private val openGroupIcon: ImageView
|
||||||
private val groupName: TextView
|
private val groupName: TextView
|
||||||
private val groupUrl: TextView
|
private val displayedUrl: TextView
|
||||||
|
|
||||||
|
private var groupUrl: String = ""
|
||||||
|
|
||||||
constructor(context: Context): this(context, null)
|
constructor(context: Context): this(context, null)
|
||||||
|
|
||||||
@ -33,14 +38,15 @@ class OpenGroupInvitationView : FrameLayout {
|
|||||||
joinButton = findViewById(R.id.join_open_group)
|
joinButton = findViewById(R.id.join_open_group)
|
||||||
openGroupIcon = findViewById(R.id.open_group_icon)
|
openGroupIcon = findViewById(R.id.open_group_icon)
|
||||||
groupName = findViewById(R.id.group_name)
|
groupName = findViewById(R.id.group_name)
|
||||||
groupUrl = findViewById(R.id.group_url)
|
displayedUrl = findViewById(R.id.group_url)
|
||||||
|
|
||||||
joinButton.setOnClickListener { }
|
joinButton.setOnClickListener { joinPublicGroup(groupUrl) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOpenGroup(name: String, url: String, isOutgoing: Boolean = false) {
|
fun setOpenGroup(name: String, url: String, isOutgoing: Boolean = false) {
|
||||||
groupName.text = name
|
groupName.text = name
|
||||||
groupUrl.text = url
|
displayedUrl.text = OpenGroupUrlParser.trimParameter(url)
|
||||||
|
groupUrl = url
|
||||||
|
|
||||||
if(isOutgoing) {
|
if(isOutgoing) {
|
||||||
joinButton.visibility = View.GONE
|
joinButton.visibility = View.GONE
|
||||||
@ -51,8 +57,32 @@ class OpenGroupInvitationView : FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun joinPublicGroup(url: String) {
|
private fun joinPublicGroup(url: String) {
|
||||||
|
val openGroup = OpenGroupUrlParser.parseUrl(url)
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
builder.setTitle(context.getString(R.string.ConversationActivity_join_open_group, groupName.text.toString()))
|
||||||
|
builder.setIconAttribute(R.attr.dialog_info_icon)
|
||||||
|
builder.setCancelable(true)
|
||||||
|
|
||||||
|
var message: String =
|
||||||
|
context.getString(R.string.ConversationActivity_join_open_group_confirmation_message, groupName.text.toString())
|
||||||
|
|
||||||
|
builder.setMessage(message)
|
||||||
|
builder.setPositiveButton(R.string.yes) { dialog, which ->
|
||||||
|
try {
|
||||||
|
val group = OpenGroupUtilities.addGroup(context, openGroup.server, openGroup.room, openGroup.serverPublicKey)
|
||||||
|
val threadID = GroupManager.getOpenGroupThreadID(group.id, context)
|
||||||
|
val groupID = GroupUtil.getEncodedOpenGroupID(group.id.toByteArray())
|
||||||
|
|
||||||
|
MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(context)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("JoinPublicChatActivity", "Failed to join open group.", e)
|
||||||
|
Toast.makeText(context, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setNegativeButton(R.string.no, null)
|
||||||
|
builder.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -152,6 +152,9 @@
|
|||||||
<string name="ConversationActivity_quick_camera_unavailable">L’appareil photo n’est pas disponible</string>
|
<string name="ConversationActivity_quick_camera_unavailable">L’appareil photo n’est pas disponible</string>
|
||||||
<string name="ConversationActivity_unable_to_record_audio">Impossible d’enregistrer l’audio !</string>
|
<string name="ConversationActivity_unable_to_record_audio">Impossible d’enregistrer l’audio !</string>
|
||||||
<string name="ConversationActivity_invite_to_open_group">Ajouter des membres</string>
|
<string name="ConversationActivity_invite_to_open_group">Ajouter des membres</string>
|
||||||
|
<string name="ConversationActivity_join_open_group">Rejoindre %s</string>
|
||||||
|
<string name="ConversationActivity_join_open_group_confirmation_message">Êtes-vous sûr de vouloir rejoindre le group public <b>%s</b>?</string>
|
||||||
|
|
||||||
<string name="ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device">Il n’y a aucune appli pour gérer ce lien sur votre appareil.</string>
|
<string name="ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device">Il n’y a aucune appli pour gérer ce lien sur votre appareil.</string>
|
||||||
<string name="ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone">Pour envoyer des messages audio, autorisez Session à accéder à votre microphone.</string>
|
<string name="ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone">Pour envoyer des messages audio, autorisez Session à accéder à votre microphone.</string>
|
||||||
<string name="ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages">Session exige l’autorisation Microphone afin d’envoyer des messages audio, mais elle a été refusée définitivement. Veuillez accéder au menu des paramètres des applis, sélectionner « Autorisations » et activer « Microphone ».</string>
|
<string name="ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages">Session exige l’autorisation Microphone afin d’envoyer des messages audio, mais elle a été refusée définitivement. Veuillez accéder au menu des paramètres des applis, sélectionner « Autorisations » et activer « Microphone ».</string>
|
||||||
|
@ -176,6 +176,8 @@
|
|||||||
<string name="ConversationActivity_unable_to_record_audio">Unable to record audio!</string>
|
<string name="ConversationActivity_unable_to_record_audio">Unable to record audio!</string>
|
||||||
<string name="ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device">There is no app available to handle this link on your device.</string>
|
<string name="ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device">There is no app available to handle this link on your device.</string>
|
||||||
<string name="ConversationActivity_invite_to_open_group">Add members</string>
|
<string name="ConversationActivity_invite_to_open_group">Add members</string>
|
||||||
|
<string name="ConversationActivity_join_open_group">Join %s</string>
|
||||||
|
<string name="ConversationActivity_join_open_group_confirmation_message">Are you sure you want to join the <b>%s</b> open group?</string>
|
||||||
|
|
||||||
<string name="ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone">Session needs microphone access to send audio messages.</string>
|
<string name="ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone">Session needs microphone access to send audio messages.</string>
|
||||||
<string name="ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages">Session needs microphone access to send audio messages, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Microphone\".</string>
|
<string name="ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages">Session needs microphone access to send audio messages, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Microphone\".</string>
|
||||||
|
@ -12,6 +12,7 @@ object OpenGroupUrlParser {
|
|||||||
object InvalidPublicKeyProvided : Error("Invalid public key provided.")
|
object InvalidPublicKeyProvided : Error("Invalid public key provided.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val suffix = "/"
|
||||||
private const val queryPrefix = "public_key"
|
private const val queryPrefix = "public_key"
|
||||||
|
|
||||||
fun parseUrl(stringUrl: String): OpenGroupRoom {
|
fun parseUrl(stringUrl: String): OpenGroupRoom {
|
||||||
@ -20,7 +21,7 @@ object OpenGroupUrlParser {
|
|||||||
// If the URL is malformed, it will throw an exception
|
// If the URL is malformed, it will throw an exception
|
||||||
val httpUrl = HttpUrl.parse(url) ?: throw Error.MalformedUrl()
|
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
|
// Test if the room is specified in the URL
|
||||||
val room = httpUrl.pathSegments().firstOrNull { !it.isNullOrEmpty() } ?: throw Error.NoRoomSpecified
|
val room = httpUrl.pathSegments().firstOrNull { !it.isNullOrEmpty() } ?: throw Error.NoRoomSpecified
|
||||||
// Test if the query is specified in the URL
|
// Test if the query is specified in the URL
|
||||||
@ -28,7 +29,7 @@ object OpenGroupUrlParser {
|
|||||||
// Public key must be 64 characters
|
// Public key must be 64 characters
|
||||||
if (publicKey.length != 64) throw Error.InvalidPublicKeyProvided
|
if (publicKey.length != 64) throw Error.InvalidPublicKeyProvided
|
||||||
|
|
||||||
return OpenGroupRoom(host,room,publicKey)
|
return OpenGroupRoom(server,room,publicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun trimParameter(stringUrl: String): String {
|
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() {
|
fun parseUrlTest() {
|
||||||
val inputUrl = "https://sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val inputUrl = "https://sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val expectedHost = "sessionopengroup.co"
|
val expectedHost = "https://sessionopengroup.co"
|
||||||
val expectedRoom = "main"
|
val expectedRoom = "main"
|
||||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||||
assertEquals(expectedHost, result.serverHost)
|
assertEquals(expectedHost, result.server)
|
||||||
assertEquals(expectedRoom, result.room)
|
assertEquals(expectedRoom, result.room)
|
||||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||||
}
|
}
|
||||||
@ -23,12 +23,12 @@ class OpenGroupUrlParserTest {
|
|||||||
fun parseUrlNoHttpTest() {
|
fun parseUrlNoHttpTest() {
|
||||||
val inputUrl = "sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val inputUrl = "sessionopengroup.co/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val expectedHost = "sessionopengroup.co"
|
val expectedHost = "http://sessionopengroup.co"
|
||||||
val expectedRoom = "main"
|
val expectedRoom = "main"
|
||||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||||
assertEquals(expectedHost, result.serverHost)
|
assertEquals(expectedHost, result.server)
|
||||||
assertEquals(expectedRoom, result.room)
|
assertEquals(expectedRoom, result.room)
|
||||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ class OpenGroupUrlParserTest {
|
|||||||
fun parseUrlWithIpTest() {
|
fun parseUrlWithIpTest() {
|
||||||
val inputUrl = "https://143.198.213.255:80/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
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 expectedRoom = "main"
|
||||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||||
assertEquals(expectedHost, result.serverHost)
|
assertEquals(expectedHost, result.server)
|
||||||
assertEquals(expectedRoom, result.room)
|
assertEquals(expectedRoom, result.room)
|
||||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||||
}
|
}
|
||||||
@ -51,12 +51,12 @@ class OpenGroupUrlParserTest {
|
|||||||
fun parseUrlWithIpAndNoHttpTest() {
|
fun parseUrlWithIpAndNoHttpTest() {
|
||||||
val inputUrl = "143.198.213.255/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
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 expectedRoom = "main"
|
||||||
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
val expectedPublicKey = "658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c"
|
||||||
|
|
||||||
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
val result = OpenGroupUrlParser.parseUrl(inputUrl)
|
||||||
assertEquals(expectedHost, result.serverHost)
|
assertEquals(expectedHost, result.server)
|
||||||
assertEquals(expectedRoom, result.room)
|
assertEquals(expectedRoom, result.room)
|
||||||
assertEquals(expectedPublicKey, result.serverPublicKey)
|
assertEquals(expectedPublicKey, result.serverPublicKey)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user