Skip to content
Snippets Groups Projects
Verified Commit e98677b2 authored by Torsten Grote's avatar Torsten Grote
Browse files

Do not show a notification for a conversation we are in

parent a1bfe00f
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,7 @@ EventListener { ...@@ -69,6 +69,7 @@ EventListener {
new HashMap<GroupId, Integer>(); new HashMap<GroupId, Integer>();
private int contactTotal = 0, forumTotal = 0; private int contactTotal = 0, forumTotal = 0;
private int nextRequestId = 0; private int nextRequestId = 0;
private ContactId activeContact;
private volatile Settings settings = new Settings(); private volatile Settings settings = new Settings();
...@@ -113,11 +114,14 @@ EventListener { ...@@ -113,11 +114,14 @@ EventListener {
public void showPrivateMessageNotification(ContactId c) { public void showPrivateMessageNotification(ContactId c) {
lock.lock(); lock.lock();
try { try {
Integer count = contactCounts.get(c); // check first if user has this conversation open at the moment
if (count == null) contactCounts.put(c, 1); if (activeContact == null || !activeContact.equals(c)) {
else contactCounts.put(c, count + 1); Integer count = contactCounts.get(c);
contactTotal++; if (count == null) contactCounts.put(c, 1);
updatePrivateMessageNotification(); else contactCounts.put(c, count + 1);
contactTotal++;
updatePrivateMessageNotification();
}
} finally { } finally {
lock.unlock(); lock.unlock();
} }
...@@ -135,6 +139,26 @@ EventListener { ...@@ -135,6 +139,26 @@ EventListener {
} }
} }
public void blockPrivateMessageNotification(ContactId c) {
lock.lock();
try {
activeContact = c;
} finally {
lock.unlock();
}
}
public void unblockPrivateMessageNotification(ContactId c) {
lock.lock();
try {
if (activeContact != null && activeContact.equals(c)) {
activeContact = null;
}
} finally {
lock.unlock();
}
}
// Locking: lock // Locking: lock
private void updatePrivateMessageNotification() { private void updatePrivateMessageNotification() {
if (contactTotal == 0) { if (contactTotal == 0) {
......
...@@ -122,6 +122,7 @@ public class ConversationActivity extends BriarActivity ...@@ -122,6 +122,7 @@ public class ConversationActivity extends BriarActivity
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
eventBus.addListener(this); eventBus.addListener(this);
notificationManager.blockPrivateMessageNotification(contactId);
loadContactAndGroup(); loadContactAndGroup();
loadHeaders(); loadHeaders();
...@@ -133,6 +134,7 @@ public class ConversationActivity extends BriarActivity ...@@ -133,6 +134,7 @@ public class ConversationActivity extends BriarActivity
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
eventBus.removeListener(this); eventBus.removeListener(this);
notificationManager.unblockPrivateMessageNotification(contactId);
if (isFinishing()) markMessagesRead(); if (isFinishing()) markMessagesRead();
} }
......
...@@ -14,6 +14,10 @@ public interface AndroidNotificationManager extends Service { ...@@ -14,6 +14,10 @@ public interface AndroidNotificationManager extends Service {
void clearPrivateMessageNotification(ContactId c); void clearPrivateMessageNotification(ContactId c);
void blockPrivateMessageNotification(ContactId c);
void unblockPrivateMessageNotification(ContactId c);
void showForumPostNotification(GroupId g); void showForumPostNotification(GroupId g);
void clearForumPostNotification(GroupId g); void clearForumPostNotification(GroupId g);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment