aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java5
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java13
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java16
3 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 76519eda8..d503eb95e 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -613,9 +613,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else if (notify) {
if (query != null && query.isCatchup()) {
mXmppConnectionService.getNotificationService().pushFromBacklog(message);
- } else if (account.getXmppConnection().isWaitingForSmCatchup()) {
- account.getXmppConnection().incrementSmCatchupMessageCounter();
- mXmppConnectionService.getNotificationService().pushFromBacklog(message);
} else {
mXmppConnectionService.getNotificationService().push(message);
}
@@ -686,7 +683,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (displayed != null) {
if (packet.fromAccount(account)) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
- if (conversation != null) {
+ if (conversation != null && (query == null || query.isCatchup())) {
mXmppConnectionService.markRead(conversation);
}
} else {
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index 56f0427c0..460779a60 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -45,6 +45,7 @@ import de.pixart.messenger.ui.ManageAccountActivity;
import de.pixart.messenger.ui.TimePreference;
import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.UIHelper;
+import de.pixart.messenger.xmpp.XmppConnection;
public class NotificationService {
@@ -175,6 +176,18 @@ public class NotificationService {
}
public void push(final Message message) {
+ synchronized (message.getConversation().getAccount()) {
+ final XmppConnection connection = message.getConversation().getAccount().getXmppConnection();
+ if (connection.isWaitingForSmCatchup()) {
+ connection.incrementSmCatchupMessageCounter();
+ pushFromBacklog(message);
+ } else {
+ pushNow(message);
+ }
+ }
+ }
+
+ private void pushNow(final Message message) {
mXmppConnectionService.updateUnreadCountBadge();
if (!notify(message)) {
Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().toBareJid() + ": suppressing notification because turned off");
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 3d7961980..f7b826030 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -98,7 +98,7 @@ public class XmppConnection implements Runnable {
private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1;
private static final int PACKET_PRESENCE = 2;
- protected Account account;
+ protected final Account account;
private final WakeLock wakeLock;
private Socket socket;
private XmlReader tagReader;
@@ -136,7 +136,7 @@ public class XmppConnection implements Runnable {
private OnBindListener bindListener = null;
private final ArrayList<OnAdvancedStreamFeaturesLoaded> advancedStreamFeaturesLoadedListeners = new ArrayList<>();
private OnMessageAcknowledged acknowledgedListener = null;
- private XmppConnectionService mXmppConnectionService = null;
+ private final XmppConnectionService mXmppConnectionService;
private EditAccountActivity mEditAccountActivity = null;
private SaslMechanism saslMechanism;
@@ -657,11 +657,13 @@ public class XmppConnection implements Runnable {
final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion);
tagWriter.writeStanzaAsync(ack);
} else if (nextTag.isStart("a")) {
- if (mWaitingForSmCatchup.compareAndSet(true, false)) {
- int count = mSmCatchupMessageCounter.get();
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")");
- if (count > 0) {
- mXmppConnectionService.getNotificationService().finishBacklog(true, account);
+ synchronized (account) {
+ if (mWaitingForSmCatchup.compareAndSet(true, false)) {
+ int count = mSmCatchupMessageCounter.get();
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")");
+ if (count > 0) {
+ mXmppConnectionService.getNotificationService().finishBacklog(true, account);
+ }
}
}
final Element ack = tagReader.readElement(nextTag);