Skip to content

Commit

Permalink
show indicator if we left an NGC group, and do not send those groups …
Browse files Browse the repository at this point in the history
…to our relay
  • Loading branch information
zoff99 committed Dec 7, 2024
1 parent 0de1106 commit 95bc0ed
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class GroupDB
@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
boolean group_active = false; // is this conference active now? are we invited?

@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
boolean group_we_left = false; // did we "leave" keeping our credentials? (we can rejoin)

@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
@Nullable
boolean notification_silent = false; // show notifications for this conference?
Expand All @@ -78,6 +81,7 @@ static GroupDB deep_copy(GroupDB in)
out.tox_group_number = in.tox_group_number;
out.group_active = in.group_active;
out.notification_silent = in.notification_silent;
out.group_we_left = in.group_we_left;

return out;
}
Expand All @@ -89,6 +93,6 @@ public String toString()
", who_invited__tox_public_key_string=" + who_invited__tox_public_key_string + ", name=" + name +
", topic=" + topic + ", privacy_state=" + privacy_state + ", peer_count=" + peer_count +
", own_peer_number=" + own_peer_number + ", notification_silent=" + notification_silent +
", group_active=" + group_active;
", group_active=" + group_active + ", group_we_left=" + group_we_left;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
import static com.zoffcc.applications.trifa.CameraWrapper.YUV420rotate90;
import static com.zoffcc.applications.trifa.HelperGeneric.display_toast;
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
import static com.zoffcc.applications.trifa.HelperGroup.clear_group_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.set_group_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
import static com.zoffcc.applications.trifa.HelperGroup.update_group_in_groupmessagelist;
import static com.zoffcc.applications.trifa.HelperGroup.update_group_peer_in_db;
Expand Down Expand Up @@ -309,8 +312,9 @@ public void onClick(View v)
try
{
tox_group_reconnect(group_num_);
group_update_connected_status_on_groupinfo(group_num_);
update_savedata_file_wrapper();
clear_group_group_we_left(group_id);
group_update_connected_status_on_groupinfo(group_num_);
}
catch (Exception e)
{
Expand Down Expand Up @@ -493,14 +497,22 @@ private void group_update_connected_status_on_groupinfo(final long group_num)
try
{
final int is_connected = tox_group_is_connected(group_num);
group_connection_status_text.setText(TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.value_str(is_connected));
if (is_connected == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
if (is_group_we_left(group_id))
{
group_reconnect_button.setVisibility(View.GONE);
group_connection_status_text.setText("You left the group, but can rejoin it");
group_reconnect_button.setVisibility(View.VISIBLE);
}
else
{
group_reconnect_button.setVisibility(View.VISIBLE);
group_connection_status_text.setText(TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.value_str(is_connected));
if (is_connected == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
{
group_reconnect_button.setVisibility(View.GONE);
}
else
{
group_reconnect_button.setVisibility(View.VISIBLE);
}
}
}
catch(Exception ignored)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import static com.zoffcc.applications.trifa.HelperGroup.delete_group_all_files;
import static com.zoffcc.applications.trifa.HelperGroup.delete_group_all_messages;
import static com.zoffcc.applications.trifa.HelperGroup.group_identifier_short;
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.set_group_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
import static com.zoffcc.applications.trifa.MainActivity.PREF__dark_mode_pref;
import static com.zoffcc.applications.trifa.MainActivity.context_s;
Expand Down Expand Up @@ -202,21 +204,28 @@ public void bindFriendList(GroupDB fl)

try
{
if (fl.group_active)
if (is_group_we_left(fl.group_identifier))
{
if (tox_group_is_connected(tox_group_by_groupid__wrapper(fl.group_identifier)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
imageView.setImageResource(R.drawable.circle_pink);
}
else
{
if (fl.group_active)
{
imageView.setImageResource(R.drawable.circle_green);
if (tox_group_is_connected(tox_group_by_groupid__wrapper(fl.group_identifier)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
{
imageView.setImageResource(R.drawable.circle_green);
}
else
{
imageView.setImageResource(R.drawable.circle_orange);
}
}
else
{
imageView.setImageResource(R.drawable.circle_orange);
imageView.setImageResource(R.drawable.circle_red);
}
}
else
{
imageView.setImageResource(R.drawable.circle_red);
}
}
catch(Exception ignored)
{
Expand Down Expand Up @@ -395,6 +404,7 @@ public void onClick(DialogInterface dialog, int which)
final long group_num = tox_group_by_groupid__wrapper(f2.group_identifier);
tox_group_disconnect(group_num);
update_savedata_file_wrapper(); // after leaving a conference
set_group_group_we_left(f2.group_identifier);
}

Runnable myRunnable2 = new Runnable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
import static com.zoffcc.applications.trifa.HelperGroup.insert_into_group_message_db;
import static com.zoffcc.applications.trifa.HelperGroup.is_group_active;
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.ngc_get_index_video_incoming_peer_list;
import static com.zoffcc.applications.trifa.HelperGroup.ngc_purge_video_incoming_peer_list;
import static com.zoffcc.applications.trifa.HelperGroup.ngc_set_video_call_icon;
Expand Down Expand Up @@ -1919,22 +1920,28 @@ public void run()
{
try
{
if (is_group_active(group_id_prev))
if (is_group_we_left(group_id_prev))
{
if (tox_group_is_connected(tox_group_by_groupid__wrapper(group_id_prev)) ==
TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
ml_icon.setImageResource(R.drawable.circle_pink);
}
else
{
if (is_group_active(group_id_prev))
{
ml_icon.setImageResource(R.drawable.circle_green);
if (tox_group_is_connected(tox_group_by_groupid__wrapper(group_id_prev)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
{
ml_icon.setImageResource(R.drawable.circle_green);
}
else
{
ml_icon.setImageResource(R.drawable.circle_orange);
}
}
else
{
ml_icon.setImageResource(R.drawable.circle_orange);
ml_icon.setImageResource(R.drawable.circle_red);
}
}
else
{
ml_icon.setImageResource(R.drawable.circle_red);
}
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,53 @@ public static String tox_group_peer_get_public_key__wrapper(long group_num, long
return result;
}

static boolean is_group_we_left(String group_identifier)
{
try
{
return (orma.selectFromGroupDB().
group_identifierEq(group_identifier.toLowerCase()).
toList().get(0).group_we_left);
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}

static void set_group_group_we_left(String group_identifier)
{
try
{
orma.updateGroupDB().
group_identifierEq(group_identifier.toLowerCase()).
group_we_left(true).
execute();
}
catch (Exception e)
{
e.printStackTrace();
Log.i(TAG, "set_group_group_we_left:EE:" + e.getMessage());
}
}

static void clear_group_group_we_left(String group_identifier)
{
try
{
orma.updateGroupDB().
group_identifierEq(group_identifier.toLowerCase()).
group_we_left(false).
execute();
}
catch (Exception e)
{
// e.printStackTrace();
// Log.i(TAG, "clear_group_group_we_left:EE:" + e.getMessage());
}
}

static boolean is_group_active(String group_identifier)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.zoffcc.applications.trifa.HelperGeneric.del_g_opts;
import static com.zoffcc.applications.trifa.HelperGeneric.get_g_opts;
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
import static com.zoffcc.applications.trifa.MainActivity.PREF__allow_push_server_ntfy;
import static com.zoffcc.applications.trifa.MainActivity.tox_conference_invite;
Expand Down Expand Up @@ -259,15 +260,19 @@ static void invite_to_all_groups_own_relay(String relay_public_key_string)
for (int i = 0; i < c.size(); i++)
{
GroupDB conf = c.get(i);
final long group_num = tox_group_by_groupid__wrapper(conf.group_identifier);
int res = tox_group_invite_friend(group_num,
tox_friend_by_public_key__wrapper(relay_public_key_string));
update_savedata_file_wrapper();

byte[] data = HelperGeneric.hex_to_bytes("FF" + conf.group_identifier);
data[0] = (byte) CONTROL_PROXY_MESSAGE_TYPE_GROUP_ID_FOR_PROXY.value;
tox_friend_send_lossless_packet(tox_friend_by_public_key__wrapper(relay_public_key_string),
data, TOX_GROUP_CHAT_ID_SIZE + 1);
if (!is_group_we_left(conf.group_identifier))
{
// only send group to relay, if we have NOT left it
final long group_num = tox_group_by_groupid__wrapper(conf.group_identifier);
int res = tox_group_invite_friend(group_num,
tox_friend_by_public_key__wrapper(relay_public_key_string));
update_savedata_file_wrapper();

byte[] data = HelperGeneric.hex_to_bytes("FF" + conf.group_identifier);
data[0] = (byte) CONTROL_PROXY_MESSAGE_TYPE_GROUP_ID_FOR_PROXY.value;
tox_friend_send_lossless_packet(tox_friend_by_public_key__wrapper(relay_public_key_string),
data, TOX_GROUP_CHAT_ID_SIZE + 1);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,20 @@ public void run()
}
// ----- convert old NULL's into false -----

// ----- convert old NULL's into false -----
try
{
orma.getConnection().execSQL(
"update GroupDB set group_we_left=false" + " where " + " group_we_left is NULL");
Log.i(TAG, "onCreate:migrate_group_we_left");
}
catch (Exception e)
{
e.printStackTrace();
Log.i(TAG, "onCreate:migrate_group_we_left:EE01");
}
// ----- convert old NULL's into false -----


// ----- convert old NULL's into 0 -----
try
Expand Down

0 comments on commit 95bc0ed

Please sign in to comment.