diff options
author | lookshe <github@lookshe.org> | 2015-08-16 18:45:08 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-08-16 18:45:08 +0200 |
commit | 89b28a496542b1995f60efb6b8937d11adf8e425 (patch) | |
tree | 2039e26dd5d3fdd8ce3ce277ff1bff8324f32f6e /src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java | |
parent | a76de90fe7a53220e9358d38fa7b47b63f7694fe (diff) | |
parent | 0321ebb7a6785b4673376f9e6458e41dd96b2230 (diff) |
Merge branch 'trz/rebase' into trz/rename
Conflicts:
src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java index e5125f29..8ff5f0d2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java @@ -382,21 +382,21 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } else { mFileAddingExecutor.execute(new Runnable() { - @Override - public void run() { - try { - getFileBackend().copyFileToPrivateStorage(message, uri); - getFileBackend().updateFileParams(message); - if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { - getPgpEngine().encrypt(message, callback); - } else { - callback.success(message); - } - } catch (FileBackend.FileCopyException e) { - callback.error(e.getResId(), message); - } - } - }); + @Override + public void run() { + try { + getFileBackend().copyFileToPrivateStorage(message, uri); + getFileBackend().updateFileParams(message); + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } + } catch (FileBackend.FileCopyException e) { + callback.error(e.getResId(), message); + } + } + }); } } @@ -851,7 +851,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster"); } iqPacket.query(Xmlns.ROSTER).setAttribute("ver",account.getRosterVersion()); - sendIqPacket(account,iqPacket,mIqParser); + sendIqPacket(account, iqPacket, mIqParser); } public void fetchBookmarks(final Account account) { @@ -1029,24 +1029,25 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } Collections.sort(list, new Comparator<Conversation>() { - @Override - public int compare(Conversation lhs, Conversation rhs) { - Message left = lhs.getLatestMessage(); - Message right = rhs.getLatestMessage(); - if (left.getTimeSent() > right.getTimeSent()) { - return -1; - } else if (left.getTimeSent() < right.getTimeSent()) { - return 1; - } else { - return 0; - } - } - }); + @Override + public int compare(Conversation lhs, Conversation rhs) { + Message left = lhs.getLatestMessage(); + Message right = rhs.getLatestMessage(); + if (left.getTimeSent() > right.getTimeSent()) { + return -1; + } else if (left.getTimeSent() < right.getTimeSent()) { + return 1; + } else { + return 0; + } + } + }); } public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) { Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp)); if (XmppConnectionService.this.getMessageArchiveService().queryInProgress(conversation,callback)) { + Log.d("mam", "Query in progress"); return; } Runnable runnable = new Runnable() { @@ -1054,19 +1055,26 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void run() { final Account account = conversation.getAccount(); List<Message> messages = databaseBackend.getMessages(conversation, 50,timestamp); + Log.d("mam", "runnable load more messages"); if (messages.size() > 0) { + Log.d("mam", "At least one message"); conversation.addAll(0, messages); checkDeletedFiles(conversation); callback.onMoreMessagesLoaded(messages.size(), conversation); } else if (conversation.hasMessagesLeftOnServer() && account.isOnlineAndConnected() && account.getXmppConnection().getFeatures().mam()) { + Log.d("mam", "mam activate, account online and connected and messages left on server"); MessageArchiveService.Query query = getMessageArchiveService().query(conversation,0,timestamp - 1); if (query != null) { query.setCallback(callback); } callback.informUser(R.string.fetching_history_from_server); - } + } else { + Log.d("mam", ((!conversation.hasMessagesLeftOnServer()) ? "no" : "") + " more messages left on server, mam " + ((account.getXmppConnection().getFeatures().mam()) ? "" : "not") + " activated, account is " + ((account.isOnlineAndConnected()) ? "" : "not") + " online or connected)"); + callback.onMoreMessagesLoaded(0, conversation); + callback.informUser(R.string.no_more_history_on_server); + } } }; mDatabaseExecutor.execute(runnable); @@ -2496,7 +2504,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void clearConversationHistory(final Conversation conversation) { conversation.clearMessages(); - conversation.setHasMessagesLeftOnServer(false); //avoid messages getting loaded through mam + /* + * In case the history was loaded completely before. + * The flag "hasMessagesLeftOnServer" is set to false and no messages will be loaded anymore + * Therefore set this flag to true and try to get messages from server + */ + conversation.setHasMessagesLeftOnServer(true); new Thread(new Runnable() { @Override public void run() { |