Skip to content
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

button to join the public information group #92

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class TRIFAGlobals
// [email protected]
final static String GROUPBOT_TOXID = "56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855D34D34D37CB5";

// TRIfA public info group
final public static String TOX_TRIFA_PUBLIC_GROUPID = "154b3973bd0e66304fd6179a8a54759073649e09e6e368f0334fc6ed666ab762";

final static boolean ADD_BOTS_ON_STARTUP = true;

final static int USE_MAX_NUMBER_OF_BOOTSTRAP_NODES = 40;
Expand Down
157 changes: 103 additions & 54 deletions src/main/kotlin/org/briarproject/briar/desktop/ui/AddGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.briarproject.briar.desktop.ui

import SnackBarToast
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -29,6 +31,7 @@ import com.zoffcc.applications.trifa.HelperGroup.hex_to_bytes
import com.zoffcc.applications.trifa.MainActivity
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_join
import com.zoffcc.applications.trifa.RandomNameGenerator
import com.zoffcc.applications.trifa.TRIFAGlobals
import com.zoffcc.applications.trifa.TRIFAGlobals.UINT32_MAX_JAVA
import com.zoffcc.applications.trifa.ToxVars
import com.zoffcc.applications.trifa.ToxVars.TOX_GROUP_CHAT_ID_SIZE
Expand All @@ -41,65 +44,111 @@ import java.util.*
fun AddGroup() = Box {
var join_group_id by remember { mutableStateOf("") }
var join_group_button_enabled by remember { mutableStateOf(false) }
Row(modifier = Modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(30.dp))
TextField(singleLine = true,
textStyle = TextStyle(fontSize = 14.sp),
modifier = Modifier.padding(0.dp).width(400.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White),
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.None,
autoCorrect = false,
), value = join_group_id, placeholder = {
Text("enter GroupID to join ...", fontSize = 13.sp)
}, onValueChange = {
join_group_id = it
if (it.length == (ToxVars.TOX_GROUP_CHAT_ID_SIZE * 2))
{
// HINT: correct group id hex length
join_group_button_enabled = true
} else
{
join_group_button_enabled = false
}
})
Spacer(modifier = Modifier.width(30.dp))
Button(
onClick = {
// HINT: join Group
val join_chat_id_buffer: ByteBuffer = ByteBuffer.allocateDirect(TOX_GROUP_CHAT_ID_SIZE)
val data_join: ByteArray = hex_to_bytes(join_group_id.uppercase())
join_chat_id_buffer.put(data_join)
join_chat_id_buffer.rewind()
val new_group_num = tox_group_join(join_chat_id_buffer, TOX_GROUP_CHAT_ID_SIZE.toLong(),
RandomNameGenerator.getFullName(Random()), null)
Column {
Row(modifier = Modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.width(30.dp))
TextField(singleLine = true,
textStyle = TextStyle(fontSize = 14.sp),
modifier = Modifier.padding(0.dp).width(400.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White),
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.None,
autoCorrect = false,
), value = join_group_id, placeholder = {
Text("enter GroupID to join ...", fontSize = 13.sp)
}, onValueChange = {
join_group_id = it
if (it.length == (ToxVars.TOX_GROUP_CHAT_ID_SIZE * 2))
{
// HINT: correct group id hex length
join_group_button_enabled = true
} else
{
join_group_button_enabled = false
}
})
Spacer(modifier = Modifier.width(30.dp))
Button(
onClick = {
// HINT: join Group
val join_chat_id_buffer: ByteBuffer = ByteBuffer.allocateDirect(TOX_GROUP_CHAT_ID_SIZE)
val data_join: ByteArray = hex_to_bytes(join_group_id.uppercase())
join_chat_id_buffer.put(data_join)
join_chat_id_buffer.rewind()
val new_group_num = tox_group_join(join_chat_id_buffer, TOX_GROUP_CHAT_ID_SIZE.toLong(),
RandomNameGenerator.getFullName(Random()), null)

update_savedata_file_wrapper()

if ((new_group_num >= 0) && (new_group_num < UINT32_MAX_JAVA))
{
// HINT: joined Group
join_group_id = ""
join_group_button_enabled = false
try
{
val new_privacy_state = MainActivity.tox_group_get_privacy_state(new_group_num)
val group_name = "Group #" + new_group_num
val group_num_peers = MainActivity.tox_group_peer_count(new_group_num)
groupstore.add(item = GroupItem(numPeers = group_num_peers.toInt(),
name = group_name!!, isConnected = 0,
groupId = join_group_id.lowercase(),
privacyState = new_privacy_state))
} catch (_: Exception)
{
}
SnackBarToast("You joined new Group")
} else
{
// some error on joining group
}
}, colors = ButtonDefaults.buttonColors(), enabled = join_group_button_enabled) {
Text("join Group")
}
}
Spacer(modifier = Modifier.height(30.dp))
Row {
Spacer(modifier = Modifier.width(50.dp))
Text("or")
}
Spacer(modifier = Modifier.height(30.dp))
Row {
Spacer(modifier = Modifier.width(30.dp))
Button(
onClick = {
// HINT: join Group
val join_chat_id_buffer: ByteBuffer = ByteBuffer.allocateDirect(TOX_GROUP_CHAT_ID_SIZE)
val data_join: ByteArray = hex_to_bytes(TRIFAGlobals.TOX_TRIFA_PUBLIC_GROUPID.uppercase())
join_chat_id_buffer.put(data_join)
join_chat_id_buffer.rewind()
val new_group_num = tox_group_join(join_chat_id_buffer, TOX_GROUP_CHAT_ID_SIZE.toLong(),
RandomNameGenerator.getFullName(Random()), null)

update_savedata_file_wrapper()
update_savedata_file_wrapper()

if ((new_group_num >= 0) && (new_group_num < UINT32_MAX_JAVA))
{
// HINT: joined Group
join_group_id = ""
join_group_button_enabled = false
try
if ((new_group_num >= 0) && (new_group_num < UINT32_MAX_JAVA))
{
val new_privacy_state = MainActivity.tox_group_get_privacy_state(new_group_num)
val group_name = "Group #" + new_group_num
val group_num_peers = MainActivity.tox_group_peer_count(new_group_num)
groupstore.add(item = GroupItem(numPeers = group_num_peers.toInt(),
name = group_name!!, isConnected = 0,
groupId = join_group_id.lowercase(),
privacyState = new_privacy_state))
} catch (_: Exception)
// HINT: joined Group
try
{
val new_privacy_state = MainActivity.tox_group_get_privacy_state(new_group_num)
val group_name = "TRIfA Info Group"
val group_num_peers = MainActivity.tox_group_peer_count(new_group_num)
groupstore.add(item = GroupItem(numPeers = group_num_peers.toInt(),
name = group_name!!, isConnected = 0,
groupId = TRIFAGlobals.TOX_TRIFA_PUBLIC_GROUPID.lowercase(),
privacyState = new_privacy_state))
} catch (_: Exception)
{
}
SnackBarToast("You joined the Public Information Group")
} else
{
// some error on joining group
}
SnackBarToast("You joined new Group")
} else
{
// some error on joining group
}
}, colors = ButtonDefaults.buttonColors(), enabled = join_group_button_enabled) {
Text("join Group")
}, colors = ButtonDefaults.buttonColors()) {
Text("join the Public Information Group")
}
}
}
}
Expand Down
Loading