Skip to content

Commit 67b3169

Browse files
committed
setting to mute notifications for peers in NGC groups
1 parent ac2bed3 commit 67b3169

File tree

5 files changed

+146
-8
lines changed

5 files changed

+146
-8
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ static class group_list_peer
14321432
long peer_num;
14331433
String peer_pubkey;
14341434
int peer_connection_status;
1435+
boolean notification_silent;
14351436
boolean self;
14361437
}
14371438

@@ -1512,6 +1513,14 @@ synchronized void set_peer_names_and_avatars()
15121513
{
15131514
glp.self = false;
15141515
}
1516+
if (peer_from_db != null)
1517+
{
1518+
glp.notification_silent = peer_from_db.notification_silent;
1519+
}
1520+
else
1521+
{
1522+
glp.notification_silent = false;
1523+
}
15151524
glp.peer_pubkey = peer_pubkey_temp;
15161525
glp.peer_num = i;
15171526
glp.peer_name = peer_name_temp;
@@ -1543,7 +1552,7 @@ public int compare(group_list_peer p1, group_list_peer p2)
15431552

15441553
for (group_list_peer peerl : group_peers1)
15451554
{
1546-
add_group_user(peerl.peer_pubkey, peerl.peer_num, peerl.peer_name, peerl.peer_connection_status, peerl.self);
1555+
add_group_user(peerl.peer_pubkey, peerl.peer_num, peerl.peer_name, peerl.peer_connection_status, peerl.self, peerl.notification_silent);
15471556
}
15481557
}
15491558
}
@@ -1588,6 +1597,14 @@ public int compare(group_list_peer p1, group_list_peer p2)
15881597
String peer_name_temp = peerrole + peer_name + " :" + i + ": " + peer_pubkey_temp.substring(0, 6);
15891598

15901599
group_list_peer glp3 = new group_list_peer();
1600+
if (peer_from_db != null)
1601+
{
1602+
glp3.notification_silent = peer_from_db.notification_silent;
1603+
}
1604+
else
1605+
{
1606+
glp3.notification_silent = false;
1607+
}
15911608
glp3.peer_pubkey = peer_pubkey_temp;
15921609
glp3.peer_num = i;
15931610
glp3.peer_name = peer_name_temp;
@@ -1619,7 +1636,7 @@ public int compare(group_list_peer p1, group_list_peer p2)
16191636
for (group_list_peer peerloffline : group_peers_offline)
16201637
{
16211638
add_group_user(peerloffline.peer_pubkey, peerloffline.peer_num, peerloffline.peer_name,
1622-
peerloffline.peer_connection_status, false);
1639+
peerloffline.peer_connection_status, false, peerloffline.notification_silent);
16231640
}
16241641

16251642
}
@@ -1720,6 +1737,13 @@ protected void onResume()
17201737

17211738
MainActivity.group_message_list_activity = this;
17221739
wakeup_tox_thread();
1740+
try
1741+
{
1742+
update_group_all_users();
1743+
}
1744+
catch (Exception e)
1745+
{
1746+
}
17231747
NGC_Group_video_check_incoming_thread = new Thread()
17241748
{
17251749
@Override
@@ -2617,7 +2641,7 @@ synchronized void remove_group_user(String peer_pubkey)
26172641
// TODO: write me
26182642
}
26192643

2620-
synchronized void add_group_user(final String peer_pubkey, final long peernum, String name, int connection_status, boolean self)
2644+
synchronized void add_group_user(final String peer_pubkey, final long peernum, String name, int connection_status, boolean self, boolean notification_silent)
26212645
{
26222646
try
26232647
{
@@ -2673,6 +2697,10 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem)
26732697
{
26742698
new_item.withTextColor(Color.parseColor("#FF5733"));
26752699
}
2700+
else if (notification_silent)
2701+
{
2702+
new_item.withTextColor(Color.parseColor("#d7b442"));
2703+
}
26762704
}
26772705
catch (Exception e)
26782706
{

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public class GroupPeerDB
5151
@Column(indexed = true, defaultExpr = "2", helpers = Column.Helpers.ALL)
5252
int Tox_Group_Role = 2;
5353

54+
@Column(indexed = true, defaultExpr = "false", helpers = Column.Helpers.ALL)
55+
@Nullable
56+
boolean notification_silent = false; // show notifications for this peer?
57+
5458
static GroupPeerDB deep_copy(GroupPeerDB in)
5559
{
5660
GroupPeerDB out = new GroupPeerDB();
@@ -60,6 +64,7 @@ static GroupPeerDB deep_copy(GroupPeerDB in)
6064
out.last_update_timestamp = in.last_update_timestamp;
6165
out.first_join_timestamp = in.first_join_timestamp;
6266
out.Tox_Group_Role = in.Tox_Group_Role;
67+
out.notification_silent = in.notification_silent;
6368
return out;
6469
}
6570

@@ -69,6 +74,7 @@ public String toString()
6974
return "id=" + id + ", group_identifier=" + group_identifier + ", tox_group_peer_pubkey=" +
7075
tox_group_peer_pubkey.substring(0, 4) + ", peer_name=" + peer_name +
7176
", last_update_timestamp=" + last_update_timestamp +
72-
", first_join_timestamp=" + first_join_timestamp + ", Tox_Group_Role=" + Tox_Group_Role;
77+
", first_join_timestamp=" + first_join_timestamp + ", Tox_Group_Role=" + Tox_Group_Role +
78+
", notification_silent=" + notification_silent;
7379
}
7480
}

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@
4646
import static com.zoffcc.applications.trifa.HelperGeneric.long_date_time_format;
4747
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
4848
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
49+
import static com.zoffcc.applications.trifa.HelperGroup.group_notification_silent_peer_get;
50+
import static com.zoffcc.applications.trifa.HelperGroup.group_notification_silent_peer_set;
4951
import static com.zoffcc.applications.trifa.HelperGroup.insert_into_group_message_db;
5052
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
5153
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_peer_get_name__wrapper;
5254
import static com.zoffcc.applications.trifa.HelperGroup.update_group_in_groupmessagelist;
5355
import static com.zoffcc.applications.trifa.HelperGroup.update_group_peer_in_db;
5456
import static com.zoffcc.applications.trifa.MainActivity.context_s;
57+
import static com.zoffcc.applications.trifa.MainActivity.group_message_list_activity;
5558
import static com.zoffcc.applications.trifa.MainActivity.tox_group_mod_kick_peer;
5659
import static com.zoffcc.applications.trifa.MainActivity.tox_group_mod_set_role;
5760
import static com.zoffcc.applications.trifa.MainActivity.tox_group_peer_get_role;
@@ -72,6 +75,7 @@ public class GroupPeerInfoActivity extends AppCompatActivity
7275
TextView group_peerrole_text = null;
7376
TextView peer_first_join_text = null;
7477
AppCompatButton group_kickpeer_button = null;
78+
AppCompatButton group_notification_silent_button = null;
7579
AppCompatSpinner group_peerrole_select = null;
7680
String group_id = null;
7781
private String[] tox_ngc_group_role_items;
@@ -94,6 +98,7 @@ protected void onCreate(Bundle savedInstanceState)
9498
group_peerrole_text = (TextView) findViewById(R.id.group_peerrole_text);
9599
group_send_private_message = (EditText) findViewById(R.id.group_send_private_message);
96100
group_kickpeer_button = findViewById(R.id.group_kickpeer_button);
101+
group_notification_silent_button = findViewById(R.id.group_notification_silent_button);
97102
group_peerrole_select = findViewById(R.id.group_peerrole_select);
98103
group_peerrole_set_button = findViewById(R.id.group_peerrole_set_button);
99104
peer_first_join_text = findViewById(R.id.peer_first_join_text);
@@ -166,6 +171,35 @@ else if (role_str.equals("OBSERVER"))
166171
}
167172
});
168173

174+
boolean notification_silent = group_notification_silent_peer_get(group_id, peer_pubkey);
175+
if (notification_silent) {
176+
group_notification_silent_button.setText("activate Notifications for Peer");
177+
} else {
178+
group_notification_silent_button.setText("mute Notifications for Peer");
179+
}
180+
group_notification_silent_button.setOnClickListener(new View.OnClickListener()
181+
{
182+
@Override
183+
public void onClick(View view)
184+
{
185+
try
186+
{
187+
boolean notification_silent1 = group_notification_silent_peer_get(group_id, peer_pubkey);
188+
group_notification_silent_peer_set(group_id, peer_pubkey, !notification_silent1);
189+
if (!notification_silent1) {
190+
group_notification_silent_button.setText("activate Notifications for Peer");
191+
} else {
192+
group_notification_silent_button.setText("mute Notifications for Peer");
193+
}
194+
}
195+
catch (Exception e)
196+
{
197+
e.printStackTrace();
198+
}
199+
}
200+
});
201+
202+
169203
group_kickpeer_button.setOnClickListener(new View.OnClickListener()
170204
{
171205
@Override
@@ -184,7 +218,6 @@ public void onClick(View view)
184218
peer_pubkey, ToxVars.Tox_Group_Role.TOX_GROUP_ROLE_OBSERVER.value);
185219
update_group_in_groupmessagelist(group_id);
186220
}
187-
188221
}
189222
catch (Exception ignored)
190223
{

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

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,42 @@ static void update_group_peer_in_db(final long group_number, final String group_
744744
}
745745
}
746746

747+
static void group_notification_silent_peer_set(final String group_identifier, final String group_peer_pubkey, boolean silent)
748+
{
749+
try
750+
{
751+
if (group_identifier != null)
752+
{
753+
orma.updateGroupPeerDB().group_identifierEq(group_identifier).tox_group_peer_pubkeyEq(group_peer_pubkey).
754+
notification_silent(silent).
755+
last_update_timestamp(System.currentTimeMillis()).
756+
execute();
757+
// Log.i(TAG, "group_notification_silent_peer_set: " + silent);
758+
}
759+
}
760+
catch (Exception e)
761+
{
762+
e.printStackTrace();
763+
}
764+
}
765+
766+
static boolean group_notification_silent_peer_get(final String group_identifier, final String group_peer_pubkey)
767+
{
768+
boolean ret = false;
769+
try
770+
{
771+
if (group_identifier != null)
772+
{
773+
ret = orma.selectFromGroupPeerDB().group_identifierEq(group_identifier).tox_group_peer_pubkeyEq(group_peer_pubkey).get(0).notification_silent;
774+
}
775+
}
776+
catch (Exception ignored)
777+
{
778+
}
779+
// Log.i(TAG, "group_notification_silent_peer_get: " + ret);
780+
return ret;
781+
}
782+
747783
static void update_group_messages_peer_role(String group_identifier, String group_peer_pubkey, int aTox_Group_Role)
748784
{
749785
try
@@ -960,13 +996,19 @@ static void android_tox_callback_group_message_cb_method_wrapper(long group_numb
960996
return;
961997
}
962998

999+
final String peer_pubkey = HelperGroup.tox_group_peer_get_public_key__wrapper(group_number, peer_id);
1000+
9631001
String groupname = null;
9641002
try
9651003
{
9661004
if (group_temp.notification_silent)
9671005
{
9681006
do_notification = false;
9691007
}
1008+
if (group_notification_silent_peer_get(group_id, peer_pubkey))
1009+
{
1010+
do_notification = false;
1011+
}
9701012
groupname = group_temp.name;
9711013
}
9721014
catch (Exception e)
@@ -976,6 +1018,8 @@ static void android_tox_callback_group_message_cb_method_wrapper(long group_numb
9761018
}
9771019

9781020

1021+
1022+
9791023
if (group_message_list_activity != null)
9801024
{
9811025
//Log.i(TAG,
@@ -991,7 +1035,7 @@ static void android_tox_callback_group_message_cb_method_wrapper(long group_numb
9911035
GroupMessage m = new GroupMessage();
9921036
m.is_new = do_badge_update;
9931037
// m.tox_friendnum = friend_number;
994-
m.tox_group_peer_pubkey = HelperGroup.tox_group_peer_get_public_key__wrapper(group_number, peer_id);
1038+
m.tox_group_peer_pubkey = peer_pubkey;
9951039
m.direction = 0; // msg received
9961040
m.TOX_MESSAGE_TYPE = 0;
9971041
m.read = false;
@@ -1155,6 +1199,10 @@ static void group_message_add_from_sync(final String group_identifier, final Str
11551199
{
11561200
do_notification = false;
11571201
}
1202+
if (group_notification_silent_peer_get(group_identifier, peer_pubkey))
1203+
{
1204+
do_notification = false;
1205+
}
11581206
groupname = group_temp.name;
11591207
}
11601208
catch (Exception e)
@@ -1621,13 +1669,19 @@ static void handle_incoming_group_file(long group_number, long peer_id, byte[] d
16211669
return;
16221670
}
16231671

1672+
final String peer_pubkey = tox_group_peer_get_public_key__wrapper(group_number, peer_id);
1673+
16241674
String groupname = null;
16251675
try
16261676
{
16271677
if (group_temp.notification_silent)
16281678
{
16291679
do_notification = false;
16301680
}
1681+
if (group_notification_silent_peer_get(group_id, peer_pubkey))
1682+
{
1683+
do_notification = false;
1684+
}
16311685
groupname = group_temp.name;
16321686
}
16331687
catch (Exception e)
@@ -1691,7 +1745,7 @@ static void handle_incoming_group_file(long group_number, long peer_id, byte[] d
16911745

16921746
GroupMessage m = new GroupMessage();
16931747
m.is_new = do_badge_update;
1694-
m.tox_group_peer_pubkey = tox_group_peer_get_public_key__wrapper(group_number, peer_id);
1748+
m.tox_group_peer_pubkey = peer_pubkey;
16951749
m.direction = 0; // msg received
16961750
m.TOX_MESSAGE_TYPE = 0;
16971751
m.read = false;
@@ -2633,7 +2687,10 @@ private static void group_file_add_from_sync(final String group_identifier, fina
26332687
{
26342688
do_notification = false;
26352689
}
2636-
2690+
if (group_notification_silent_peer_get(group_identifier, original_sender_peerpubkey))
2691+
{
2692+
do_notification = false;
2693+
}
26372694
groupname = group_temp.name;
26382695
}
26392696
catch (Exception e)

android-refimpl-app/app/src/main/res/layout/activity_group_peer_info.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@
224224
android:layout_width="match_parent"
225225
android:layout_height="20dp" />
226226

227+
<androidx.appcompat.widget.AppCompatButton
228+
android:id="@+id/group_notification_silent_button"
229+
android:layout_width="wrap_content"
230+
android:layout_height="wrap_content"
231+
android:layout_gravity="center"
232+
android:layout_marginBottom="15dp"
233+
android:inputType="text"
234+
android:text="mute Notifications for Peer"
235+
android:visibility="visible" />
236+
237+
<TextView
238+
android:layout_width="match_parent"
239+
android:layout_height="20dp" />
240+
227241
<TextView
228242
android:id="@+id/dumm_99"
229243
android:layout_width="match_parent"

0 commit comments

Comments
 (0)