aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/Config.java2
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java15
-rw-r--r--src/eu/siacs/conversations/parser/PresenceParser.java2
-rw-r--r--src/eu/siacs/conversations/services/NotificationService.java27
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java3
5 files changed, 32 insertions, 17 deletions
diff --git a/src/eu/siacs/conversations/Config.java b/src/eu/siacs/conversations/Config.java
index 1725eca6..a11e1763 100644
--- a/src/eu/siacs/conversations/Config.java
+++ b/src/eu/siacs/conversations/Config.java
@@ -10,7 +10,7 @@ public final class Config {
public static final int PING_MIN_INTERVAL = 30;
public static final int PING_TIMEOUT = 10;
public static final int CONNECT_TIMEOUT = 90;
- public static final int CARBON_GRACE_PERIOD = 60;
+ public static final int CARBON_GRACE_PERIOD = 120;
public static final int AVATAR_SIZE = 192;
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index 18752659..8d5ca898 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -1,10 +1,7 @@
package eu.siacs.conversations.parser;
-import android.os.SystemClock;
-import android.util.Log;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
-import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
@@ -19,9 +16,6 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class MessageParser extends AbstractParser implements
OnMessagePacketReceived {
-
- private long lastCarbonMessageReceived = -(Config.CARBON_GRACE_PERIOD * 1000);
-
public MessageParser(XmppConnectionService service) {
super(service);
}
@@ -404,8 +398,6 @@ public class MessageParser extends AbstractParser implements
Message message = null;
boolean notify = mXmppConnectionService.getPreferences().getBoolean(
"show_notification", true);
- notify = notify
- && (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000);
boolean alwaysNotifyInConference = notify
&& mXmppConnectionService.getPreferences().getBoolean(
"always_notify_in_conference", false);
@@ -431,8 +423,8 @@ public class MessageParser extends AbstractParser implements
message = this.parseCarbonMessage(packet, account);
if (message != null) {
if (message.getStatus() == Message.STATUS_SEND) {
- lastCarbonMessageReceived = SystemClock
- .elapsedRealtime();
+ mXmppConnectionService.getNotificationService()
+ .activateGracePeriod();
notify = false;
mXmppConnectionService.markRead(
message.getConversation(), false);
@@ -454,7 +446,8 @@ public class MessageParser extends AbstractParser implements
} else {
mXmppConnectionService.markRead(message.getConversation(),
false);
- lastCarbonMessageReceived = SystemClock.elapsedRealtime();
+ mXmppConnectionService.getNotificationService()
+ .activateGracePeriod();
notify = false;
}
}
diff --git a/src/eu/siacs/conversations/parser/PresenceParser.java b/src/eu/siacs/conversations/parser/PresenceParser.java
index 507ebbd2..2c3a7dbc 100644
--- a/src/eu/siacs/conversations/parser/PresenceParser.java
+++ b/src/eu/siacs/conversations/parser/PresenceParser.java
@@ -58,6 +58,8 @@ public class PresenceParser extends AbstractParser implements
Presences.parseShow(packet.findChild("show")));
} else if (type.equals("unavailable")) {
account.removePresence(fromParts[1]);
+ mXmppConnectionService.getNotificationService()
+ .deactivateGracePeriod();
}
}
} else {
diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java
index 9428aa15..53c4707f 100644
--- a/src/eu/siacs/conversations/services/NotificationService.java
+++ b/src/eu/siacs/conversations/services/NotificationService.java
@@ -13,10 +13,12 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.PowerManager;
+import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.text.Html;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@@ -32,6 +34,8 @@ public class NotificationService {
public int NOTIFICATION_ID = 0x2342;
private Conversation mOpenConversation;
private boolean mIsInForeground;
+
+ private long mEndGracePeriod = 0L;
public NotificationService(XmppConnectionService service) {
this.mXmppConnectionService = service;
@@ -44,10 +48,9 @@ public class NotificationService {
PowerManager pm = (PowerManager) mXmppConnectionService
.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
-
if (this.mIsInForeground && isScreenOn
&& this.mOpenConversation == message.getConversation()) {
- return; // simply ignore
+ return;
}
String conversationUuid = message.getConversationUuid();
if (notifications.containsKey(conversationUuid)) {
@@ -57,8 +60,8 @@ public class NotificationService {
mList.add(message);
notifications.put(conversationUuid, mList);
}
- updateNotification(!(this.mIsInForeground && this.mOpenConversation == null)
- || !isScreenOn);
+ updateNotification((!(this.mIsInForeground && this.mOpenConversation == null)
+ || !isScreenOn) && !inGracePeriod());
}
public void clear() {
@@ -161,7 +164,9 @@ public class NotificationService {
}
}
mBuilder.setDeleteIntent(createDeleteIntent());
- mBuilder.setLights(0xffffffff, 2000, 4000);
+ if (!inGracePeriod()) {
+ mBuilder.setLights(0xffffffff, 2000, 4000);
+ }
Notification notification = mBuilder.build();
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
@@ -221,4 +226,16 @@ public class NotificationService {
this.mIsInForeground = foreground;
}
+
+ public void activateGracePeriod() {
+ this.mEndGracePeriod = SystemClock.elapsedRealtime() + (Config.CARBON_GRACE_PERIOD * 1000);
+ }
+
+ public void deactivateGracePeriod() {
+ this.mEndGracePeriod = 0L;
+ }
+
+ private boolean inGracePeriod() {
+ return SystemClock.elapsedRealtime() < this.mEndGracePeriod;
+ }
}
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 073bcdc5..ca69b530 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -970,6 +970,7 @@ public class XmppConnectionService extends Service {
public void setOnConversationListChangedListener(
OnConversationUpdate listener) {
+ this.mNotificationService.deactivateGracePeriod();
if (checkListeners()) {
switchToForeground();
}
@@ -990,6 +991,7 @@ public class XmppConnectionService extends Service {
}
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
+ this.mNotificationService.deactivateGracePeriod();
if (checkListeners()) {
switchToForeground();
}
@@ -1008,6 +1010,7 @@ public class XmppConnectionService extends Service {
}
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
+ this.mNotificationService.deactivateGracePeriod();
if (checkListeners()) {
switchToForeground();
}