Skip to content

Commit 95bc0ed

Browse files
committed
show indicator if we left an NGC group, and do not send those groups to our relay
1 parent 0de1106 commit 95bc0ed

File tree

7 files changed

+131
-32
lines changed

7 files changed

+131
-32
lines changed

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupDB.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class GroupDB
6161
@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
6262
boolean group_active = false; // is this conference active now? are we invited?
6363

64+
@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
65+
boolean group_we_left = false; // did we "leave" keeping our credentials? (we can rejoin)
66+
6467
@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
6568
@Nullable
6669
boolean notification_silent = false; // show notifications for this conference?
@@ -78,6 +81,7 @@ static GroupDB deep_copy(GroupDB in)
7881
out.tox_group_number = in.tox_group_number;
7982
out.group_active = in.group_active;
8083
out.notification_silent = in.notification_silent;
84+
out.group_we_left = in.group_we_left;
8185

8286
return out;
8387
}
@@ -89,6 +93,6 @@ public String toString()
8993
", who_invited__tox_public_key_string=" + who_invited__tox_public_key_string + ", name=" + name +
9094
", topic=" + topic + ", privacy_state=" + privacy_state + ", peer_count=" + peer_count +
9195
", own_peer_number=" + own_peer_number + ", notification_silent=" + notification_silent +
92-
", group_active=" + group_active;
96+
", group_active=" + group_active + ", group_we_left=" + group_we_left;
9397
}
9498
}

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupInfoActivity.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
import static com.zoffcc.applications.trifa.CameraWrapper.YUV420rotate90;
4646
import static com.zoffcc.applications.trifa.HelperGeneric.display_toast;
4747
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
48+
import static com.zoffcc.applications.trifa.HelperGroup.clear_group_group_we_left;
4849
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
50+
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
51+
import static com.zoffcc.applications.trifa.HelperGroup.set_group_group_we_left;
4952
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
5053
import static com.zoffcc.applications.trifa.HelperGroup.update_group_in_groupmessagelist;
5154
import static com.zoffcc.applications.trifa.HelperGroup.update_group_peer_in_db;
@@ -309,8 +312,9 @@ public void onClick(View v)
309312
try
310313
{
311314
tox_group_reconnect(group_num_);
312-
group_update_connected_status_on_groupinfo(group_num_);
313315
update_savedata_file_wrapper();
316+
clear_group_group_we_left(group_id);
317+
group_update_connected_status_on_groupinfo(group_num_);
314318
}
315319
catch (Exception e)
316320
{
@@ -493,14 +497,22 @@ private void group_update_connected_status_on_groupinfo(final long group_num)
493497
try
494498
{
495499
final int is_connected = tox_group_is_connected(group_num);
496-
group_connection_status_text.setText(TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.value_str(is_connected));
497-
if (is_connected == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
500+
if (is_group_we_left(group_id))
498501
{
499-
group_reconnect_button.setVisibility(View.GONE);
502+
group_connection_status_text.setText("You left the group, but can rejoin it");
503+
group_reconnect_button.setVisibility(View.VISIBLE);
500504
}
501505
else
502506
{
503-
group_reconnect_button.setVisibility(View.VISIBLE);
507+
group_connection_status_text.setText(TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.value_str(is_connected));
508+
if (is_connected == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
509+
{
510+
group_reconnect_button.setVisibility(View.GONE);
511+
}
512+
else
513+
{
514+
group_reconnect_button.setVisibility(View.VISIBLE);
515+
}
504516
}
505517
}
506518
catch(Exception ignored)

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupListHolder.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import static com.zoffcc.applications.trifa.HelperGroup.delete_group_all_files;
5151
import static com.zoffcc.applications.trifa.HelperGroup.delete_group_all_messages;
5252
import static com.zoffcc.applications.trifa.HelperGroup.group_identifier_short;
53+
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
54+
import static com.zoffcc.applications.trifa.HelperGroup.set_group_group_we_left;
5355
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
5456
import static com.zoffcc.applications.trifa.MainActivity.PREF__dark_mode_pref;
5557
import static com.zoffcc.applications.trifa.MainActivity.context_s;
@@ -202,21 +204,28 @@ public void bindFriendList(GroupDB fl)
202204

203205
try
204206
{
205-
if (fl.group_active)
207+
if (is_group_we_left(fl.group_identifier))
206208
{
207-
if (tox_group_is_connected(tox_group_by_groupid__wrapper(fl.group_identifier)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
209+
imageView.setImageResource(R.drawable.circle_pink);
210+
}
211+
else
212+
{
213+
if (fl.group_active)
208214
{
209-
imageView.setImageResource(R.drawable.circle_green);
215+
if (tox_group_is_connected(tox_group_by_groupid__wrapper(fl.group_identifier)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
216+
{
217+
imageView.setImageResource(R.drawable.circle_green);
218+
}
219+
else
220+
{
221+
imageView.setImageResource(R.drawable.circle_orange);
222+
}
210223
}
211224
else
212225
{
213-
imageView.setImageResource(R.drawable.circle_orange);
226+
imageView.setImageResource(R.drawable.circle_red);
214227
}
215228
}
216-
else
217-
{
218-
imageView.setImageResource(R.drawable.circle_red);
219-
}
220229
}
221230
catch(Exception ignored)
222231
{
@@ -395,6 +404,7 @@ public void onClick(DialogInterface dialog, int which)
395404
final long group_num = tox_group_by_groupid__wrapper(f2.group_identifier);
396405
tox_group_disconnect(group_num);
397406
update_savedata_file_wrapper(); // after leaving a conference
407+
set_group_group_we_left(f2.group_identifier);
398408
}
399409

400410
Runnable myRunnable2 = new Runnable()

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupMessageListActivity.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
138138
import static com.zoffcc.applications.trifa.HelperGroup.insert_into_group_message_db;
139139
import static com.zoffcc.applications.trifa.HelperGroup.is_group_active;
140+
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
140141
import static com.zoffcc.applications.trifa.HelperGroup.ngc_get_index_video_incoming_peer_list;
141142
import static com.zoffcc.applications.trifa.HelperGroup.ngc_purge_video_incoming_peer_list;
142143
import static com.zoffcc.applications.trifa.HelperGroup.ngc_set_video_call_icon;
@@ -1919,22 +1920,28 @@ public void run()
19191920
{
19201921
try
19211922
{
1922-
if (is_group_active(group_id_prev))
1923+
if (is_group_we_left(group_id_prev))
19231924
{
1924-
if (tox_group_is_connected(tox_group_by_groupid__wrapper(group_id_prev)) ==
1925-
TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
1925+
ml_icon.setImageResource(R.drawable.circle_pink);
1926+
}
1927+
else
1928+
{
1929+
if (is_group_active(group_id_prev))
19261930
{
1927-
ml_icon.setImageResource(R.drawable.circle_green);
1931+
if (tox_group_is_connected(tox_group_by_groupid__wrapper(group_id_prev)) == TRIFAGlobals.TOX_GROUP_CONNECTION_STATUS.TOX_GROUP_CONNECTION_STATUS_CONNECTED.value)
1932+
{
1933+
ml_icon.setImageResource(R.drawable.circle_green);
1934+
}
1935+
else
1936+
{
1937+
ml_icon.setImageResource(R.drawable.circle_orange);
1938+
}
19281939
}
19291940
else
19301941
{
1931-
ml_icon.setImageResource(R.drawable.circle_orange);
1942+
ml_icon.setImageResource(R.drawable.circle_red);
19321943
}
19331944
}
1934-
else
1935-
{
1936-
ml_icon.setImageResource(R.drawable.circle_red);
1937-
}
19381945
}
19391946
catch (Exception e)
19401947
{

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperGroup.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,53 @@ public static String tox_group_peer_get_public_key__wrapper(long group_num, long
482482
return result;
483483
}
484484

485+
static boolean is_group_we_left(String group_identifier)
486+
{
487+
try
488+
{
489+
return (orma.selectFromGroupDB().
490+
group_identifierEq(group_identifier.toLowerCase()).
491+
toList().get(0).group_we_left);
492+
}
493+
catch (Exception e)
494+
{
495+
e.printStackTrace();
496+
return false;
497+
}
498+
}
499+
500+
static void set_group_group_we_left(String group_identifier)
501+
{
502+
try
503+
{
504+
orma.updateGroupDB().
505+
group_identifierEq(group_identifier.toLowerCase()).
506+
group_we_left(true).
507+
execute();
508+
}
509+
catch (Exception e)
510+
{
511+
e.printStackTrace();
512+
Log.i(TAG, "set_group_group_we_left:EE:" + e.getMessage());
513+
}
514+
}
515+
516+
static void clear_group_group_we_left(String group_identifier)
517+
{
518+
try
519+
{
520+
orma.updateGroupDB().
521+
group_identifierEq(group_identifier.toLowerCase()).
522+
group_we_left(false).
523+
execute();
524+
}
525+
catch (Exception e)
526+
{
527+
// e.printStackTrace();
528+
// Log.i(TAG, "clear_group_group_we_left:EE:" + e.getMessage());
529+
}
530+
}
531+
485532
static boolean is_group_active(String group_identifier)
486533
{
487534
try

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/HelperRelay.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static com.zoffcc.applications.trifa.HelperGeneric.del_g_opts;
3030
import static com.zoffcc.applications.trifa.HelperGeneric.get_g_opts;
3131
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
32+
import static com.zoffcc.applications.trifa.HelperGroup.is_group_we_left;
3233
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
3334
import static com.zoffcc.applications.trifa.MainActivity.PREF__allow_push_server_ntfy;
3435
import static com.zoffcc.applications.trifa.MainActivity.tox_conference_invite;
@@ -259,15 +260,19 @@ static void invite_to_all_groups_own_relay(String relay_public_key_string)
259260
for (int i = 0; i < c.size(); i++)
260261
{
261262
GroupDB conf = c.get(i);
262-
final long group_num = tox_group_by_groupid__wrapper(conf.group_identifier);
263-
int res = tox_group_invite_friend(group_num,
264-
tox_friend_by_public_key__wrapper(relay_public_key_string));
265-
update_savedata_file_wrapper();
266-
267-
byte[] data = HelperGeneric.hex_to_bytes("FF" + conf.group_identifier);
268-
data[0] = (byte) CONTROL_PROXY_MESSAGE_TYPE_GROUP_ID_FOR_PROXY.value;
269-
tox_friend_send_lossless_packet(tox_friend_by_public_key__wrapper(relay_public_key_string),
270-
data, TOX_GROUP_CHAT_ID_SIZE + 1);
263+
if (!is_group_we_left(conf.group_identifier))
264+
{
265+
// only send group to relay, if we have NOT left it
266+
final long group_num = tox_group_by_groupid__wrapper(conf.group_identifier);
267+
int res = tox_group_invite_friend(group_num,
268+
tox_friend_by_public_key__wrapper(relay_public_key_string));
269+
update_savedata_file_wrapper();
270+
271+
byte[] data = HelperGeneric.hex_to_bytes("FF" + conf.group_identifier);
272+
data[0] = (byte) CONTROL_PROXY_MESSAGE_TYPE_GROUP_ID_FOR_PROXY.value;
273+
tox_friend_send_lossless_packet(tox_friend_by_public_key__wrapper(relay_public_key_string),
274+
data, TOX_GROUP_CHAT_ID_SIZE + 1);
275+
}
271276
}
272277
}
273278
}

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/TrifaToxService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,20 @@ public void run()
940940
}
941941
// ----- convert old NULL's into false -----
942942

943+
// ----- convert old NULL's into false -----
944+
try
945+
{
946+
orma.getConnection().execSQL(
947+
"update GroupDB set group_we_left=false" + " where " + " group_we_left is NULL");
948+
Log.i(TAG, "onCreate:migrate_group_we_left");
949+
}
950+
catch (Exception e)
951+
{
952+
e.printStackTrace();
953+
Log.i(TAG, "onCreate:migrate_group_we_left:EE01");
954+
}
955+
// ----- convert old NULL's into false -----
956+
943957

944958
// ----- convert old NULL's into 0 -----
945959
try

0 commit comments

Comments
 (0)