From 7cd4ed78b2a7bcc72f9ac388fa3857ba98324f88 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 19 May 2017 13:30:57 +0200 Subject: [PATCH] synchronize on dedicated lock for catchup instead of account --- .../siacs/conversations/services/NotificationService.java | 4 +++- .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index d1e41a746..5305ae5a4 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -52,6 +52,8 @@ import eu.siacs.conversations.xmpp.XmppConnection; public class NotificationService { + public static final Object CATCHUP_LOCK = new Object(); + private static final String CONVERSATIONS_GROUP = "eu.siacs.conversations"; private final XmppConnectionService mXmppConnectionService; @@ -173,7 +175,7 @@ public class NotificationService { } public void push(final Message message) { - synchronized (message.getConversation().getAccount()) { + synchronized (CATCHUP_LOCK) { final XmppConnection connection = message.getConversation().getAccount().getXmppConnection(); if (connection.isWaitingForSmCatchup()) { connection.incrementSmCatchupMessageCounter(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 90585d9f3..fc4bf3102 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -64,6 +64,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.ServiceDiscoveryResult; import eu.siacs.conversations.generator.IqGenerator; +import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.DNSHelper; import eu.siacs.conversations.utils.SSLSocketHelper; @@ -617,15 +618,20 @@ public class XmppConnection implements Runnable { final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); tagWriter.writeStanzaAsync(ack); } else if (nextTag.isStart("a")) { - synchronized (account) { + boolean accountUiNeedsRefresh = false; + synchronized (NotificationService.CATCHUP_LOCK) { if (mWaitingForSmCatchup.compareAndSet(true, false)) { int count = mSmCatchupMessageCounter.get(); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")"); + accountUiNeedsRefresh = true; if (count > 0) { mXmppConnectionService.getNotificationService().finishBacklog(true, account); } } } + if (accountUiNeedsRefresh) { + mXmppConnectionService.updateAccountUi(); + } final Element ack = tagReader.readElement(nextTag); lastPacketReceived = SystemClock.elapsedRealtime(); try {