From 8840d082bae00fde2f053b77368677b203598629 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 30 Aug 2014 08:31:05 +0200 Subject: [PATCH 1/9] brought npe catcher back for kxml parser --- src/eu/siacs/conversations/xml/XmlReader.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/eu/siacs/conversations/xml/XmlReader.java b/src/eu/siacs/conversations/xml/XmlReader.java index 1c7e94e66..cf6b8c73a 100644 --- a/src/eu/siacs/conversations/xml/XmlReader.java +++ b/src/eu/siacs/conversations/xml/XmlReader.java @@ -90,6 +90,10 @@ public class XmlReader { throw new IOException("xml parser mishandled ArrayIndexOufOfBounds", e); } catch (StringIndexOutOfBoundsException e) { throw new IOException("xml parser mishandled StringIndexOufOfBounds", e); + } catch (NullPointerException e) { + throw new IOException("xml parser mishandled NullPointerException", e); + } catch (IndexOutOfBoundsException e) { + throw new IOException("xml parser mishandled IndexOutOfBound", e); } return null; } From 9ad5c6925d103f5d0a030bd7af76cb8d15551189 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 30 Aug 2014 08:51:55 +0200 Subject: [PATCH 2/9] version bump to 0.6 with changelogs --- AndroidManifest.xml | 6 +-- CHANGELOG.md | 7 +++ .../generator/AbstractGenerator.java | 45 +++++++------------ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5133041be..16d1476ef 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="25" + android:versionName="0.6" > - \ No newline at end of file + diff --git a/CHANGELOG.md b/CHANGELOG.md index 37e3c9204..298bb37d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ###Changelog +####Version 0.6 +* Support for server side avatars +* save images in gallery +* show contact name and picture in non-anonymous conferences +* reworked account creation +* various bug fixes + ####Version 0.5.2 * minor bug fixes diff --git a/src/eu/siacs/conversations/generator/AbstractGenerator.java b/src/eu/siacs/conversations/generator/AbstractGenerator.java index d98395725..ecee82531 100644 --- a/src/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/eu/siacs/conversations/generator/AbstractGenerator.java @@ -12,40 +12,29 @@ public abstract class AbstractGenerator { public final String[] FEATURES = { "urn:xmpp:jingle:1", "urn:xmpp:jingle:apps:file-transfer:3", "urn:xmpp:jingle:transports:s5b:1", - "urn:xmpp:jingle:transports:ibb:1", - "urn:xmpp:receipts", - "urn:xmpp:chat-markers:0", - "http://jabber.org/protocol/muc", - "jabber:x:conference", - "http://jabber.org/protocol/caps", + "urn:xmpp:jingle:transports:ibb:1", "urn:xmpp:receipts", + "urn:xmpp:chat-markers:0", "http://jabber.org/protocol/muc", + "jabber:x:conference", "http://jabber.org/protocol/caps", "http://jabber.org/protocol/disco#info", - "urn:xmpp:avatar:metadata+notify"}; - public final String IDENTITY_NAME = "Conversations 0.5"; + "urn:xmpp:avatar:metadata+notify" }; + public final String IDENTITY_NAME = "Conversations 0.6"; public final String IDENTITY_TYPE = "phone"; - /*public final String[] FEATURES = { "http://jabber.org/protocol/muc","http://jabber.org/protocol/disco#info", "http://jabber.org/protocol/disco#items", "http://jabber.org/protocol/caps" }; - - public final String IDENTITY_NAME = "Exodus 0.9.1"; - public final String IDENTITY_TYPE = "pc";*/ - - - - + public String getCapHash() { StringBuilder s = new StringBuilder(); - s.append("client/"+IDENTITY_TYPE+"//"+IDENTITY_NAME+"<"); + s.append("client/" + IDENTITY_TYPE + "//" + IDENTITY_NAME + "<"); MessageDigest md = null; - try { - md = MessageDigest.getInstance("SHA-1"); - } - catch(NoSuchAlgorithmException e) { - return null; - } - List features = Arrays.asList(FEATURES); + try { + md = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + return null; + } + List features = Arrays.asList(FEATURES); Collections.sort(features); - for(String feature : features) { - s.append(feature+"<"); - } + for (String feature : features) { + s.append(feature + "<"); + } byte[] sha1 = md.digest(s.toString().getBytes()); - return new String(Base64.encode(sha1, Base64.DEFAULT)).trim(); + return new String(Base64.encode(sha1, Base64.DEFAULT)).trim(); } } From 265bd062500dcd9524a0a5f70acf88350266ac26 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 26 Aug 2014 17:43:44 +0200 Subject: [PATCH 3/9] added basic csi --- .../services/XmppConnectionService.java | 48 +++++++++++++++++++ .../conversations/xmpp/XmppConnection.java | 18 +++++++ .../xmpp/stanzas/csi/ActivePacket.java | 10 ++++ .../xmpp/stanzas/csi/InactivePacket.java | 10 ++++ 4 files changed, 86 insertions(+) create mode 100644 src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java create mode 100644 src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index c535f1a3c..ccf703fcc 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -911,6 +911,9 @@ public class XmppConnectionService extends Service { public void setOnConversationListChangedListener( OnConversationUpdate listener) { + if (checkListeners()) { + switchToForeground(); + } this.mOnConversationUpdate = listener; this.convChangedListenerCount++; } @@ -919,10 +922,16 @@ public class XmppConnectionService extends Service { this.convChangedListenerCount--; if (this.convChangedListenerCount == 0) { this.mOnConversationUpdate = null; + if (checkListeners()) { + switchToBackground(); + } } } public void setOnAccountListChangedListener(OnAccountUpdate listener) { + if (checkListeners()) { + switchToForeground(); + } this.mOnAccountUpdate = listener; this.accountChangedListenerCount++; } @@ -931,15 +940,54 @@ public class XmppConnectionService extends Service { this.accountChangedListenerCount--; if (this.accountChangedListenerCount == 0) { this.mOnAccountUpdate = null; + if (checkListeners()) { + switchToBackground(); + } } } public void setOnRosterUpdateListener(OnRosterUpdate listener) { + if (checkListeners()) { + switchToForeground(); + } this.mOnRosterUpdate = listener; } public void removeOnRosterUpdateListener() { this.mOnRosterUpdate = null; + if (checkListeners()) { + switchToBackground(); + } + } + + private boolean checkListeners() { + return (this.mOnAccountUpdate == null && this.mOnConversationUpdate == null && this.mOnRosterUpdate == null); + } + + private void switchToForeground() { + Log.d(LOGTAG,"going into foreground"); + for(Account account : getAccounts()) { + if (account.getStatus() == Account.STATUS_ONLINE) { + XmppConnection connection = account.getXmppConnection(); + if (connection != null && connection.getFeatures().csi()) { + connection.sendActive(); + Log.d(LOGTAG,account.getJid() + " sending csi//active"); + } + } + } + } + + private void switchToBackground() { + Log.d(LOGTAG,"going into background"); + for(Account account : getAccounts()) { + if (account.getStatus() == Account.STATUS_ONLINE) { + XmppConnection connection = account.getXmppConnection(); + if (connection != null && connection.getFeatures().csi()) { + connection.sendInactive(); + Log.d(LOGTAG,account.getJid() + " sending csi//inactive"); + } + } + } } public void connectMultiModeConversations(Account account) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index ba7a9245d..3fece7814 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -47,6 +47,8 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; +import eu.siacs.conversations.xmpp.stanzas.csi.ActivePacket; +import eu.siacs.conversations.xmpp.stanzas.csi.InactivePacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket; @@ -900,6 +902,14 @@ public class XmppConnection implements Runnable { } } + public boolean csi() { + if (connection.streamFeatures == null) { + return false; + } else { + return connection.streamFeatures.hasChild("csi"); + } + } + public boolean pubsub() { return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish"); } @@ -942,4 +952,12 @@ public class XmppConnection implements Runnable { public long getLastPacketReceived() { return this.lastPaketReceived; } + + public void sendActive() { + this.sendPacket(new ActivePacket(), null); + } + + public void sendInactive() { + this.sendPacket(new InactivePacket(), null); + } } diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java new file mode 100644 index 000000000..6dd6b2e8f --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java @@ -0,0 +1,10 @@ +package eu.siacs.conversations.xmpp.stanzas.csi; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class ActivePacket extends AbstractStanza { + public ActivePacket() { + super("active"); + setAttribute("xmlns", "urn:xmpp:csi"); + } +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java new file mode 100644 index 000000000..f3cf5ce03 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java @@ -0,0 +1,10 @@ +package eu.siacs.conversations.xmpp.stanzas.csi; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class InactivePacket extends AbstractStanza { + public InactivePacket() { + super("inactive"); + setAttribute("xmlns", "urn:xmpp:csi"); + } +} From 6d82a69ba367cc2efd34de3b22d1a76b0f583d95 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 28 Aug 2014 22:23:18 +0200 Subject: [PATCH 4/9] send inactive or active on every connect and resume --- .../services/XmppConnectionService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index ccf703fcc..438fff5fb 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -146,6 +146,7 @@ public class XmppConnectionService extends Service { @Override public void onStatusChanged(Account account) { + XmppConnection connection = account.getXmppConnection(); if (mOnAccountUpdate != null) { mOnAccountUpdate.onAccountUpdate();; } @@ -164,6 +165,15 @@ public class XmppConnectionService extends Service { sendUnsendMessages(conversations.get(i)); } } + if (connection!=null && connection.getFeatures().csi()) { + if (checkListeners()) { + Log.d(LOGTAG,account.getJid() + " sending csi//inactive"); + connection.sendInactive(); + } else { + Log.d(LOGTAG,account.getJid() + " sending csi//active"); + connection.sendActive(); + } + } syncDirtyContacts(account); scheduleWakeupCall(PING_MAX_INTERVAL, true); } else if (account.getStatus() == Account.STATUS_OFFLINE) { @@ -177,7 +187,6 @@ public class XmppConnectionService extends Service { reconnectAccount(account, true); } else if ((account.getStatus() != Account.STATUS_CONNECTING) && (account.getStatus() != Account.STATUS_NO_INTERNET)) { - XmppConnection connection = account.getXmppConnection(); if (connection!=null) { int next = connection.getTimeToNextAttempt(); Log.d(LOGTAG, account.getJid() @@ -965,7 +974,6 @@ public class XmppConnectionService extends Service { } private void switchToForeground() { - Log.d(LOGTAG,"going into foreground"); for(Account account : getAccounts()) { if (account.getStatus() == Account.STATUS_ONLINE) { XmppConnection connection = account.getXmppConnection(); @@ -978,7 +986,6 @@ public class XmppConnectionService extends Service { } private void switchToBackground() { - Log.d(LOGTAG,"going into background"); for(Account account : getAccounts()) { if (account.getStatus() == Account.STATUS_ONLINE) { XmppConnection connection = account.getXmppConnection(); From 9de77b190bc5f92bc2bcdf24ba060d09cc425277 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 29 Aug 2014 12:21:29 +0200 Subject: [PATCH 5/9] proper namespaces for xep-0352 --- src/eu/siacs/conversations/xmpp/XmppConnection.java | 2 +- src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java | 2 +- src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 3fece7814..9fd435d1f 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -906,7 +906,7 @@ public class XmppConnection implements Runnable { if (connection.streamFeatures == null) { return false; } else { - return connection.streamFeatures.hasChild("csi"); + return connection.streamFeatures.hasChild("csi","urn:xmpp:csi:0"); } } diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java index 6dd6b2e8f..78ab66d8f 100644 --- a/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java +++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java @@ -5,6 +5,6 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; public class ActivePacket extends AbstractStanza { public ActivePacket() { super("active"); - setAttribute("xmlns", "urn:xmpp:csi"); + setAttribute("xmlns", "urn:xmpp:csi:0"); } } diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java index f3cf5ce03..f109280f1 100644 --- a/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java +++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java @@ -5,6 +5,6 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; public class InactivePacket extends AbstractStanza { public InactivePacket() { super("inactive"); - setAttribute("xmlns", "urn:xmpp:csi"); + setAttribute("xmlns", "urn:xmpp:csi:0"); } } From 4a6a6c84031585ec7985fa16cbc86988d58e8b43 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 26 Aug 2014 16:52:42 +0200 Subject: [PATCH 6/9] basic message acking --- .../services/XmppConnectionService.java | 296 ++++++++++-------- .../xmpp/OnMessageAcknowledged.java | 7 + .../conversations/xmpp/XmppConnection.java | 28 +- 3 files changed, 200 insertions(+), 131 deletions(-) create mode 100644 src/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index c535f1a3c..0e2054ebe 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -49,6 +49,7 @@ import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnBindListener; import eu.siacs.conversations.xmpp.OnContactStatusChanged; import eu.siacs.conversations.xmpp.OnIqPacketReceived; +import eu.siacs.conversations.xmpp.OnMessageAcknowledged; import eu.siacs.conversations.xmpp.OnStatusChanged; import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager; @@ -95,7 +96,7 @@ public class XmppConnectionService extends Service { public static final long CARBON_GRACE_PERIOD = 60000L; private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; - + private MemorizingTrustManager mMemorizingTrustManager; private MessageParser mMessageParser = new MessageParser(this); @@ -103,7 +104,7 @@ public class XmppConnectionService extends Service { private IqParser mIqParser = new IqParser(this); private MessageGenerator mMessageGenerator = new MessageGenerator(); private PresenceGenerator mPresenceGenerator = new PresenceGenerator(); - + private List accounts; private CopyOnWriteArrayList conversations = null; private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager( @@ -118,7 +119,7 @@ public class XmppConnectionService extends Service { @Override public void onContactStatusChanged(Contact contact, boolean online) { - Conversation conversation = find(getConversations(),contact); + Conversation conversation = find(getConversations(), contact); if (conversation != null) { conversation.endOtrIfNeeded(); if (online && (contact.getPresences().size() == 1)) { @@ -147,13 +148,14 @@ public class XmppConnectionService extends Service { @Override public void onStatusChanged(Account account) { if (mOnAccountUpdate != null) { - mOnAccountUpdate.onAccountUpdate();; + mOnAccountUpdate.onAccountUpdate(); + ; } if (account.getStatus() == Account.STATUS_ONLINE) { - for(Conversation conversation : account.pendingConferenceLeaves) { + for (Conversation conversation : account.pendingConferenceLeaves) { leaveMuc(conversation); } - for(Conversation conversation : account.pendingConferenceJoins) { + for (Conversation conversation : account.pendingConferenceJoins) { joinMuc(conversation); } mJingleConnectionManager.cancelInTransmission(); @@ -178,13 +180,12 @@ public class XmppConnectionService extends Service { } else if ((account.getStatus() != Account.STATUS_CONNECTING) && (account.getStatus() != Account.STATUS_NO_INTERNET)) { XmppConnection connection = account.getXmppConnection(); - if (connection!=null) { + if (connection != null) { int next = connection.getTimeToNextAttempt(); Log.d(LOGTAG, account.getJid() - + ": error connecting account. try again in " + next - + "s for the " - + (connection.getAttempt() + 1) - + " time"); + + ": error connecting account. try again in " + + next + "s for the " + + (connection.getAttempt() + 1) + " time"); scheduleWakeupCall((int) (next * 1.2), false); } } @@ -209,19 +210,38 @@ public class XmppConnectionService extends Service { private PowerManager pm; private OnBindListener mOnBindListener = new OnBindListener() { - @Override - public void onBind(final Account account) { - account.getRoster().clearPresences(); - account.clearPresences(); // self presences - account.pendingConferenceJoins.clear(); - account.pendingConferenceLeaves.clear(); - fetchRosterFromServer(account); - fetchBookmarks(account); - sendPresencePacket(account, mPresenceGenerator.sendPresence(account)); - connectMultiModeConversations(account); - updateConversationUi(); + @Override + public void onBind(final Account account) { + account.getRoster().clearPresences(); + account.clearPresences(); // self presences + account.pendingConferenceJoins.clear(); + account.pendingConferenceLeaves.clear(); + fetchRosterFromServer(account); + fetchBookmarks(account); + sendPresencePacket(account, + mPresenceGenerator.sendPresence(account)); + connectMultiModeConversations(account); + updateConversationUi(); + } + }; + + private OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() { + + @Override + public void onMessageAcknowledged(Account account, String uuid) { + for (Conversation conversation : getConversations()) { + if (conversation.getAccount() == account) { + for (Message message : conversation.getMessages()) { + if (message.getStatus() == Message.STATUS_UNSEND + && message.getUuid().equals(uuid)) { + markMessage(message, Message.STATUS_SEND); + return; + } + } + } } - }; + } + }; public PgpEngine getPgpEngine() { if (pgpServiceConnection.isBound()) { @@ -274,11 +294,11 @@ public class XmppConnectionService extends Service { } public Conversation find(Bookmark bookmark) { - return find(bookmark.getAccount(),bookmark.getJid()); + return find(bookmark.getAccount(), bookmark.getJid()); } - + public Conversation find(Account account, String jid) { - return find(getConversations(),account,jid); + return find(getConversations(), account, jid); } public class XmppConnectionBinder extends Binder { @@ -320,8 +340,10 @@ public class XmppConnectionService extends Service { } } if (account.getStatus() == Account.STATUS_ONLINE) { - long lastReceived = account.getXmppConnection().getLastPacketReceived(); - long lastSent = account.getXmppConnection().getLastPingSent(); + long lastReceived = account.getXmppConnection() + .getLastPacketReceived(); + long lastSent = account.getXmppConnection() + .getLastPingSent(); if (lastSent - lastReceived >= PING_TIMEOUT * 1000) { Log.d(LOGTAG, account.getJid() + ": ping timeout"); this.reconnectAccount(account, true); @@ -369,7 +391,8 @@ public class XmppConnectionService extends Service { ExceptionHelper.init(getApplicationContext()); PRNGFixes.apply(); this.mRandom = new SecureRandom(); - this.mMemorizingTrustManager = new MemorizingTrustManager(getApplicationContext()); + this.mMemorizingTrustManager = new MemorizingTrustManager( + getApplicationContext()); this.databaseBackend = DatabaseBackend .getInstance(getApplicationContext()); this.fileBackend = new FileBackend(getApplicationContext()); @@ -466,10 +489,11 @@ public class XmppConnectionService extends Service { connection.setOnMessagePacketReceivedListener(this.mMessageParser); connection.setOnStatusChangedListener(this.statusListener); connection.setOnPresencePacketReceivedListener(this.mPresenceParser); - connection - .setOnUnregisteredIqPacketReceivedListener(this.mIqParser); + connection.setOnUnregisteredIqPacketReceivedListener(this.mIqParser); connection.setOnJinglePacketReceivedListener(this.jingleListener); connection.setOnBindListener(this.mOnBindListener); + connection + .setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener); return connection; } @@ -514,8 +538,7 @@ public class XmppConnectionService extends Service { .getUserID()); packet = mMessageGenerator.generateOtrChat(message); send = true; - message.setStatus(Message.STATUS_SEND); - + } else if (message.getPresence() == null) { message.setStatus(Message.STATUS_WAITING); } @@ -523,14 +546,10 @@ public class XmppConnectionService extends Service { message.getConversation().endOtrIfNeeded(); failWaitingOtrMessages(message.getConversation()); packet = mMessageGenerator.generatePgpChat(message); - message.setStatus(Message.STATUS_SEND); send = true; } else { message.getConversation().endOtrIfNeeded(); failWaitingOtrMessages(message.getConversation()); - if (message.getConversation().getMode() == Conversation.MODE_SINGLE || message.getType() == Message.TYPE_PRIVATE) { - message.setStatus(Message.STATUS_SEND); - } packet = mMessageGenerator.generateChat(message); send = true; } @@ -562,11 +581,14 @@ public class XmppConnectionService extends Service { databaseBackend.createMessage(message); } conv.getMessages().add(message); - updateConversationUi(); if ((send) && (packet != null)) { + if (!account.getXmppConnection().getFeatures().sm() + && conv.getMode() != Conversation.MODE_MULTI) { + message.setStatus(Message.STATUS_SEND); + } sendMessagePacket(account, packet); } - + updateConversationUi(); } private void sendUnsendMessages(Conversation conversation) { @@ -632,7 +654,7 @@ public class XmppConnectionService extends Service { } } if (packet != null) { - sendMessagePacket(account,packet); + sendMessagePacket(account, packet); markMessage(message, Message.STATUS_SEND); } } @@ -661,29 +683,31 @@ public class XmppConnectionService extends Service { } }); } - + public void fetchBookmarks(Account account) { IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET); Element query = iqPacket.query("jabber:iq:private"); query.addChild("storage", "storage:bookmarks"); OnIqPacketReceived callback = new OnIqPacketReceived() { - + @Override public void onIqPacketReceived(Account account, IqPacket packet) { Element query = packet.query(); List bookmarks = new CopyOnWriteArrayList(); - Element storage = query.findChild("storage", "storage:bookmarks"); - if (storage!=null) { - for(Element item : storage.getChildren()) { + Element storage = query.findChild("storage", + "storage:bookmarks"); + if (storage != null) { + for (Element item : storage.getChildren()) { if (item.getName().equals("conference")) { - Bookmark bookmark = Bookmark.parse(item,account); + Bookmark bookmark = Bookmark.parse(item, account); bookmarks.add(bookmark); Conversation conversation = find(bookmark); - if (conversation!=null) { + if (conversation != null) { conversation.setBookmark(bookmark); } else { if (bookmark.autojoin()) { - conversation = findOrCreateConversation(account, bookmark.getJid(), true); + conversation = findOrCreateConversation( + account, bookmark.getJid(), true); conversation.setBookmark(bookmark); joinMuc(conversation); } @@ -695,17 +719,17 @@ public class XmppConnectionService extends Service { } }; sendIqPacket(account, iqPacket, callback); - + } - + public void pushBookmarks(Account account) { IqPacket iqPacket = new IqPacket(IqPacket.TYPE_SET); Element query = iqPacket.query("jabber:iq:private"); Element storage = query.addChild("storage", "storage:bookmarks"); - for(Bookmark bookmark : account.getBookmarks()) { + for (Bookmark bookmark : account.getBookmarks()) { storage.addChild(bookmark.toElement()); } - sendIqPacket(account, iqPacket,null); + sendIqPacket(account, iqPacket, null); } private void mergePhoneContactsWithRoster() { @@ -750,10 +774,10 @@ public class XmppConnectionService extends Service { conv.setMessages(databaseBackend.getMessages(conv, 50)); } } - + return this.conversations; } - + public void populateWithOrderedConversations(List list) { list.clear(); list.addAll(getConversations()); @@ -796,7 +820,8 @@ public class XmppConnectionService extends Service { return null; } - public Conversation find(List haystack, Account account, String jid) { + public Conversation find(List haystack, Account account, + String jid) { for (Conversation conversation : haystack) { if ((conversation.getAccount().equals(account)) && (conversation.getContactJid().split("/")[0].equals(jid))) { @@ -805,15 +830,14 @@ public class XmppConnectionService extends Service { } return null; } - - + public Conversation findOrCreateConversation(Account account, String jid, boolean muc) { Conversation conversation = find(account, jid); if (conversation != null) { return conversation; } - conversation = databaseBackend.findConversation(account,jid); + conversation = databaseBackend.findConversation(account, jid); if (conversation != null) { conversation.setStatus(Conversation.STATUS_AVAILABLE); conversation.setAccount(account); @@ -850,7 +874,7 @@ public class XmppConnectionService extends Service { public void archiveConversation(Conversation conversation) { if (conversation.getMode() == Conversation.MODE_MULTI) { Bookmark bookmark = conversation.getBookmark(); - if (bookmark!=null && bookmark.autojoin()) { + if (bookmark != null && bookmark.autojoin()) { bookmark.setAutojoin(false); pushBookmarks(bookmark.getAccount()); } @@ -890,7 +914,7 @@ public class XmppConnectionService extends Service { } public void deleteAccount(Account account) { - for(Conversation conversation : conversations) { + for (Conversation conversation : conversations) { if (conversation.getAccount() == account) { if (conversation.getMode() == Conversation.MODE_MULTI) { leaveMuc(conversation); @@ -933,7 +957,7 @@ public class XmppConnectionService extends Service { this.mOnAccountUpdate = null; } } - + public void setOnRosterUpdateListener(OnRosterUpdate listener) { this.mOnRosterUpdate = listener; } @@ -958,12 +982,13 @@ public class XmppConnectionService extends Service { account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.STATUS_ONLINE) { - Log.d(LOGTAG,"joining conversation "+conversation.getContactJid()); + Log.d(LOGTAG, + "joining conversation " + conversation.getContactJid()); String nick = conversation.getMucOptions().getProposedNick(); conversation.getMucOptions().setJoinNick(nick); PresencePacket packet = new PresencePacket(); String joinJid = conversation.getMucOptions().getJoinJid(); - packet.setAttribute("to",conversation.getMucOptions().getJoinJid()); + packet.setAttribute("to", conversation.getMucOptions().getJoinJid()); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc"); String sig = account.getPgpSignature(); @@ -975,8 +1000,8 @@ public class XmppConnectionService extends Service { final SimpleDateFormat mDateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - Date date = new Date( - conversation.getLatestMessage().getTimeSent() + 1000); + Date date = new Date(conversation.getLatestMessage() + .getTimeSent() + 1000); x.addChild("history").setAttribute("since", mDateFormat.format(date)); } @@ -1011,10 +1036,11 @@ public class XmppConnectionService extends Service { renameListener.onRename(success); } if (success) { - conversation.setContactJid(conversation.getMucOptions().getJoinJid()); + conversation.setContactJid(conversation.getMucOptions() + .getJoinJid()); databaseBackend.updateConversation(conversation); Bookmark bookmark = conversation.getBookmark(); - if (bookmark!=null) { + if (bookmark != null) { bookmark.setNick(nick); pushBookmarks(bookmark.getAccount()); } @@ -1023,7 +1049,7 @@ public class XmppConnectionService extends Service { }); options.flagAboutToRename(); PresencePacket packet = new PresencePacket(); - packet.setAttribute("to",options.getJoinJid()); + packet.setAttribute("to", options.getJoinJid()); packet.setAttribute("from", conversation.getAccount().getFullJid()); String sig = account.getPgpSignature(); @@ -1031,13 +1057,13 @@ public class XmppConnectionService extends Service { packet.addChild("status").setContent("online"); packet.addChild("x", "jabber:x:signed").setContent(sig); } - sendPresencePacket(account,packet); + sendPresencePacket(account, packet); } else { conversation.setContactJid(options.getJoinJid()); databaseBackend.updateConversation(conversation); if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) { Bookmark bookmark = conversation.getBookmark(); - if (bookmark!=null) { + if (bookmark != null) { bookmark.setNick(nick); pushBookmarks(bookmark.getAccount()); } @@ -1055,10 +1081,11 @@ public class XmppConnectionService extends Service { packet.setAttribute("to", conversation.getMucOptions().getJoinJid()); packet.setAttribute("from", conversation.getAccount().getFullJid()); packet.setAttribute("type", "unavailable"); - sendPresencePacket(conversation.getAccount(),packet); + sendPresencePacket(conversation.getAccount(), packet); conversation.getMucOptions().setOffline(); conversation.deregisterWithBookmark(); - Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid()); + Log.d(LOGTAG, conversation.getAccount().getJid() + " leaving muc " + + conversation.getContactJid()); } else { account.pendingConferenceLeaves.add(conversation); } @@ -1133,7 +1160,7 @@ public class XmppConnectionService extends Service { if (outPacket != null) { msg.setStatus(Message.STATUS_SEND); databaseBackend.updateMessage(msg); - sendMessagePacket(account,outPacket); + sendMessagePacket(account, outPacket); } } else if (msg.getType() == Message.TYPE_IMAGE) { mJingleConnectionManager.createNewConnection(msg); @@ -1160,7 +1187,7 @@ public class XmppConnectionService extends Service { packet.setBody(otrSession .transformSending(CryptoHelper.FILETRANSFER + CryptoHelper.bytesToHex(symmetricKey))); - sendMessagePacket(account,packet); + sendMessagePacket(account, packet); conversation.setSymmetricKey(symmetricKey); return true; } catch (OtrException e) { @@ -1176,26 +1203,30 @@ public class XmppConnectionService extends Service { Account account = contact.getAccount(); if (account.getStatus() == Account.STATUS_ONLINE) { boolean ask = contact.getOption(Contact.Options.ASKING); - boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) + boolean sendUpdates = contact + .getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) && contact.getOption(Contact.Options.PREEMPTIVE_GRANT); IqPacket iq = new IqPacket(IqPacket.TYPE_SET); iq.query("jabber:iq:roster").addChild(contact.asElement()); account.getXmppConnection().sendIqPacket(iq, null); if (sendUpdates) { - sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact)); + sendPresencePacket(account, + mPresenceGenerator.sendPresenceUpdatesTo(contact)); } if (ask) { - sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact)); + sendPresencePacket(account, + mPresenceGenerator.requestPresenceUpdatesFrom(contact)); } } } - - public void publishAvatar(Account account, Uri image, final UiCallback callback) { + public void publishAvatar(Account account, Uri image, + final UiCallback callback) { final Bitmap.CompressFormat format = Defaults.AVATAR_FORMAT; final int size = Defaults.AVATAR_SIZE; - final Avatar avatar = getFileBackend().getPepAvatar(image, size, format); - if (avatar!=null) { + final Avatar avatar = getFileBackend() + .getPepAvatar(image, size, format); + if (avatar != null) { avatar.height = size; avatar.width = size; if (format.equals(Bitmap.CompressFormat.WEBP)) { @@ -1211,27 +1242,33 @@ public class XmppConnectionService extends Service { } IqPacket packet = this.mIqGenerator.publishAvatar(avatar); this.sendIqPacket(account, packet, new OnIqPacketReceived() { - + @Override public void onIqPacketReceived(Account account, IqPacket result) { if (result.getType() == IqPacket.TYPE_RESULT) { - IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar); + IqPacket packet = XmppConnectionService.this.mIqGenerator + .publishAvatarMetadata(avatar); sendIqPacket(account, packet, new OnIqPacketReceived() { - + @Override - public void onIqPacketReceived(Account account, IqPacket result) { + public void onIqPacketReceived(Account account, + IqPacket result) { if (result.getType() == IqPacket.TYPE_RESULT) { if (account.setAvatar(avatar.getFilename())) { databaseBackend.updateAccount(account); } callback.success(avatar); } else { - callback.error(R.string.error_publish_avatar_server_reject, avatar); + callback.error( + R.string.error_publish_avatar_server_reject, + avatar); } } }); } else { - callback.error(R.string.error_publish_avatar_server_reject, avatar); + callback.error( + R.string.error_publish_avatar_server_reject, + avatar); } } }); @@ -1239,55 +1276,60 @@ public class XmppConnectionService extends Service { callback.error(R.string.error_publish_avatar_converting, null); } } - + public void fetchAvatar(Account account, Avatar avatar) { fetchAvatar(account, avatar, null); } - - public void fetchAvatar(Account account, final Avatar avatar, final UiCallback callback) { - Log.d(LOGTAG,account.getJid()+": retrieving avatar for "+avatar.owner); + + public void fetchAvatar(Account account, final Avatar avatar, + final UiCallback callback) { + Log.d(LOGTAG, account.getJid() + ": retrieving avatar for " + + avatar.owner); IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar); sendIqPacket(account, packet, new OnIqPacketReceived() { - + @Override public void onIqPacketReceived(Account account, IqPacket result) { avatar.image = mIqParser.avatarData(result); - if (avatar.image!=null) { + if (avatar.image != null) { if (getFileBackend().save(avatar)) { if (account.getJid().equals(avatar.owner)) { if (account.setAvatar(avatar.getFilename())) { databaseBackend.updateAccount(account); } } else { - Contact contact = account.getRoster().getContact(avatar.owner); + Contact contact = account.getRoster().getContact( + avatar.owner); contact.setAvatar(avatar.getFilename()); } - if (callback!=null) { + if (callback != null) { callback.success(avatar); } return; } } - if (callback!=null) { + if (callback != null) { callback.error(0, null); } } }); } - - public void checkForAvatar(Account account, final UiCallback callback) { + + public void checkForAvatar(Account account, + final UiCallback callback) { IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null); this.sendIqPacket(account, packet, new OnIqPacketReceived() { - + @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE_RESULT) { - Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub"); - if (pubsub!=null) { + Element pubsub = packet.findChild("pubsub", + "http://jabber.org/protocol/pubsub"); + if (pubsub != null) { Element items = pubsub.findChild("items"); - if (items!=null) { + if (items != null) { Avatar avatar = Avatar.parseMetadata(items); - if (avatar!=null) { + if (avatar != null) { avatar.owner = account.getJid(); if (fileBackend.isAvatarCached(avatar)) { if (account.setAvatar(avatar.getFilename())) { @@ -1295,7 +1337,7 @@ public class XmppConnectionService extends Service { } callback.success(avatar); } else { - fetchAvatar(account, avatar,callback); + fetchAvatar(account, avatar, callback); } return; } @@ -1306,7 +1348,7 @@ public class XmppConnectionService extends Service { } }); } - + public void deleteContactOnServer(Contact contact) { contact.resetOption(Contact.Options.PREEMPTIVE_GRANT); contact.resetOption(Contact.Options.DIRTY_PUSH); @@ -1347,7 +1389,7 @@ public class XmppConnectionService extends Service { public void invite(Conversation conversation, String contact) { MessagePacket packet = mMessageGenerator.invite(conversation, contact); - sendMessagePacket(conversation.getAccount(),packet); + sendMessagePacket(conversation.getAccount(), packet); } public boolean markMessage(Account account, String recipient, String uuid, @@ -1395,19 +1437,19 @@ public class XmppConnectionService extends Service { getConversations(), conversation, notify); } } - + public void updateConversationUi() { if (mOnConversationUpdate != null) { mOnConversationUpdate.onConversationUpdate(); } } - + public void updateAccountUi() { if (mOnAccountUpdate != null) { mOnAccountUpdate.onAccountUpdate(); } } - + public void updateRosterUi() { if (mOnRosterUpdate != null) { mOnRosterUpdate.onRosterUpdate(); @@ -1422,7 +1464,7 @@ public class XmppConnectionService extends Service { } return null; } - + public Conversation findConversationByUuid(String uuid) { for (Conversation conversation : getConversations()) { if (conversation.getUuid().equals(uuid)) { @@ -1438,10 +1480,11 @@ public class XmppConnectionService extends Service { if (confirmMessages() && id != null) { Account account = conversation.getAccount(); String to = conversation.getContactJid(); - this.sendMessagePacket(conversation.getAccount(), mMessageGenerator.confirm(account, to, id)); + this.sendMessagePacket(conversation.getAccount(), + mMessageGenerator.confirm(account, to, id)); } } - + public void failWaitingOtrMessages(Conversation conversation) { for (Message message : conversation.getMessages()) { if (message.getEncryption() == Message.ENCRYPTION_OTR @@ -1454,7 +1497,7 @@ public class XmppConnectionService extends Service { public SecureRandom getRNG() { return this.mRandom; } - + public MemorizingTrustManager getMemorizingTrustManager() { return this.mMemorizingTrustManager; } @@ -1467,7 +1510,7 @@ public class XmppConnectionService extends Service { if (account.getStatus() == Account.STATUS_ONLINE) { MessagePacket error = this.mMessageGenerator .generateNotAcceptable(packet); - sendMessagePacket(account,error); + sendMessagePacket(account, error); } } @@ -1512,43 +1555,44 @@ public class XmppConnectionService extends Service { } return mucServers; } - + public void sendMessagePacket(Account account, MessagePacket packet) { account.getXmppConnection().sendMessagePacket(packet); } - + public void sendPresencePacket(Account account, PresencePacket packet) { account.getXmppConnection().sendPresencePacket(packet); } - - public void sendIqPacket(Account account, IqPacket packet, OnIqPacketReceived callback) { + + public void sendIqPacket(Account account, IqPacket packet, + OnIqPacketReceived callback) { account.getXmppConnection().sendIqPacket(packet, callback); } - + public MessageGenerator getMessageGenerator() { return this.mMessageGenerator; } - + public PresenceGenerator getPresenceGenerator() { return this.mPresenceGenerator; } - + public IqGenerator getIqGenerator() { - return this.mIqGenerator ; + return this.mIqGenerator; } - + public JingleConnectionManager getJingleConnectionManager() { return this.mJingleConnectionManager; } - + public interface OnConversationUpdate { public void onConversationUpdate(); } - + public interface OnAccountUpdate { public void onAccountUpdate(); } - + public interface OnRosterUpdate { public void onRosterUpdate(); } diff --git a/src/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java b/src/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java new file mode 100644 index 000000000..5f670d933 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/OnMessageAcknowledged.java @@ -0,0 +1,7 @@ +package eu.siacs.conversations.xmpp; + +import eu.siacs.conversations.entities.Account; + +public interface OnMessageAcknowledged { + public void onMessageAcknowledged(Account account, String id); +} diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index ba7a9245d..378e7d62a 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -31,6 +31,7 @@ import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.SystemClock; import android.util.Log; +import android.util.SparseArray; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; @@ -74,6 +75,7 @@ public class XmppConnection implements Runnable { private String streamId = null; private int smVersion = 3; + private SparseArray messageReceipts = new SparseArray(); private boolean usingCompression = false; @@ -98,6 +100,7 @@ public class XmppConnection implements Runnable { private OnMessagePacketReceived messageListener = null; private OnStatusChanged statusListener = null; private OnBindListener bindListener = null; + private OnMessageAcknowledged acknowledgedListener = null; private MemorizingTrustManager mMemorizingTrustManager; public XmppConnection(Account account, XmppConnectionService service) { @@ -248,7 +251,6 @@ public class XmppConnection implements Runnable { challange,mRandom)); tagWriter.writeElement(response); } else if (nextTag.isStart("enabled")) { - this.stanzasSent = 0; Element enabled = tagReader.readElement(nextTag); if ("true".equals(enabled.getAttribute("resume"))) { this.streamId = enabled.getAttribute("id"); @@ -276,8 +278,12 @@ public class XmppConnection implements Runnable { Element ack = tagReader.readElement(nextTag); lastPaketReceived = SystemClock.elapsedRealtime(); int serverSequence = Integer.parseInt(ack.getAttribute("h")); - if (serverSequence > this.stanzasSent) { - this.stanzasSent = serverSequence; + String msgId = this.messageReceipts.get(serverSequence); + if (msgId != null) { + if (this.acknowledgedListener != null) { + this.acknowledgedListener.onMessageAcknowledged(account, msgId); + } + this.messageReceipts.remove(serverSequence); } } else if (nextTag.isStart("failed")) { tagReader.readElement(nextTag); @@ -610,10 +616,12 @@ public class XmppConnection implements Runnable { smVersion = 3; EnablePacket enable = new EnablePacket(smVersion); tagWriter.writeStanzaAsync(enable); + stanzasSent = 0; } else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) { smVersion = 2; EnablePacket enable = new EnablePacket(smVersion); tagWriter.writeStanzaAsync(enable); + stanzasSent = 0; } sendServiceDiscoveryInfo(account.getServer()); sendServiceDiscoveryItems(account.getServer()); @@ -751,9 +759,15 @@ public class XmppConnection implements Runnable { private synchronized void sendPacket(final AbstractStanza packet, PacketReceived callback) { - // TODO dont increment stanza count if packet = request packet or ack; - ++stanzasSent; + if (packet.getName().equals("iq") || packet.getName().equals("message") || packet.getName().equals("presence")) { + ++stanzasSent; + } tagWriter.writeStanzaAsync(packet); + if (packet instanceof MessagePacket && packet.getId() != null && this.streamId != null) { + Log.d(LOGTAG,"request delivery report for stanza "+stanzasSent); + this.messageReceipts.put(stanzasSent, packet.getId()); + tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion)); + } if (callback != null) { if (packet.getId() == null) { packet.setId(nextRandomId()); @@ -801,6 +815,10 @@ public class XmppConnection implements Runnable { public void setOnBindListener(OnBindListener listener) { this.bindListener = listener; } + + public void setOnMessageAcknowledgeListener(OnMessageAcknowledged listener) { + this.acknowledgedListener = listener; + } public void disconnect(boolean force) { changeStatus(Account.STATUS_OFFLINE); From 9075d3854dc8fd02a35bf628807b3982815ef7ad Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 27 Aug 2014 14:51:00 +0200 Subject: [PATCH 7/9] properly set stanza count on session resume --- .../conversations/xmpp/XmppConnection.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 378e7d62a..bc1cd7088 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -266,9 +266,27 @@ public class XmppConnection implements Runnable { tagWriter.writeStanzaAsync(r); } else if (nextTag.isStart("resumed")) { lastPaketReceived = SystemClock.elapsedRealtime(); - Log.d(LOGTAG, account.getJid() + ": session resumed"); - tagReader.readElement(nextTag); - sendPing(); + Element resumed = tagReader.readElement(nextTag); + String h = resumed.getAttribute("h"); + try { + int serverCount = Integer.parseInt(h); + if (serverCount!=stanzasSent) { + Log.d(LOGTAG,account.getJid() + ": session resumed with lost packages"); + stanzasSent = serverCount; + } else { + Log.d(LOGTAG, account.getJid() + ": session resumed"); + } + if (acknowledgedListener!=null) { + for(int i = 0; i < messageReceipts.size(); ++i) { + if (serverCount>=messageReceipts.keyAt(i)) { + acknowledgedListener.onMessageAcknowledged(account, messageReceipts.valueAt(i)); + } + } + } + messageReceipts.clear(); + } catch (NumberFormatException e) { + + } changeStatus(Account.STATUS_ONLINE); } else if (nextTag.isStart("r")) { tagReader.readElement(nextTag); From 4435b0055e9a8b8014a89f3bdec602b8106f992e Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 27 Aug 2014 19:25:58 +0200 Subject: [PATCH 8/9] reset unsend messages to waiting --- .../services/XmppConnectionService.java | 17 +++++++++++++++-- .../conversations/xmpp/XmppConnection.java | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 0e2054ebe..c949826ac 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -169,11 +169,11 @@ public class XmppConnectionService extends Service { syncDirtyContacts(account); scheduleWakeupCall(PING_MAX_INTERVAL, true); } else if (account.getStatus() == Account.STATUS_OFFLINE) { + resetSendingToWaiting(account); if (!account.isOptionSet(Account.OPTION_DISABLED)) { int timeToReconnect = mRandom.nextInt(50) + 10; scheduleWakeupCall(timeToReconnect, false); } - } else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) { databaseBackend.updateAccount(account); reconnectAccount(account, true); @@ -232,7 +232,8 @@ public class XmppConnectionService extends Service { for (Conversation conversation : getConversations()) { if (conversation.getAccount() == account) { for (Message message : conversation.getMessages()) { - if (message.getStatus() == Message.STATUS_UNSEND + if ((message.getStatus() == Message.STATUS_UNSEND || message + .getStatus() == Message.STATUS_WAITING) && message.getUuid().equals(uuid)) { markMessage(message, Message.STATUS_SEND); return; @@ -1391,6 +1392,18 @@ public class XmppConnectionService extends Service { MessagePacket packet = mMessageGenerator.invite(conversation, contact); sendMessagePacket(conversation.getAccount(), packet); } + + public void resetSendingToWaiting(Account account) { + for(Conversation conversation : getConversations()) { + if (conversation.getAccount() == account) { + for(Message message : conversation.getMessages()) { + if (message.getStatus() == Message.STATUS_UNSEND) { + markMessage(message, Message.STATUS_WAITING); + } + } + } + } + } public boolean markMessage(Account account, String recipient, String uuid, int status) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index bc1cd7088..961611fd8 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -635,11 +635,13 @@ public class XmppConnection implements Runnable { EnablePacket enable = new EnablePacket(smVersion); tagWriter.writeStanzaAsync(enable); stanzasSent = 0; + messageReceipts.clear(); } else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) { smVersion = 2; EnablePacket enable = new EnablePacket(smVersion); tagWriter.writeStanzaAsync(enable); stanzasSent = 0; + messageReceipts.clear(); } sendServiceDiscoveryInfo(account.getServer()); sendServiceDiscoveryItems(account.getServer()); From 9eafb1008676747a3ff315fb820178641c7b09f3 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 30 Aug 2014 09:26:01 +0200 Subject: [PATCH 9/9] version bump to 0.7-alpha --- AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 16d1476ef..786496a1a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="26" + android:versionName="0.7-alpha" >