aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java6
-rw-r--r--src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java62
2 files changed, 42 insertions, 26 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index ad2c0b99..ce00fb0c 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1271,7 +1271,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
callback.onMoreMessagesLoaded(0, conversation);
}
} else {
- Logging.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)");
+ Logging.d("mam", ((!conversation.hasMessagesLeftOnServer()) ? "no" : "")
+ + " more messages left on server, mam "
+ + ((account.isOnlineAndConnected() && 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);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
index 5ef2eea7..0cbde814 100644
--- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
+++ b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
@@ -10,6 +10,7 @@ import java.util.List;
import de.thedevstack.android.logcat.Logging;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.MessageArchiveService;
@@ -24,10 +25,12 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe
private List<Message> messageList;
private ConversationFragment fragment;
private ConversationMoreMessagesLoadedListener listener;
+ private SwipyRefreshLayout swipeLayout;
public ConversationSwipeRefreshListener(List<Message> messageList, SwipyRefreshLayout swipeLayout, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) {
this.messageList = messageList;
this.fragment = fragment;
+ this.swipeLayout = swipeLayout;
this.listener = new ConversationMoreMessagesLoadedListener(swipeLayout, messageList, fragment, messagesView, messageListAdapter);
}
@@ -35,33 +38,42 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe
public void onRefresh(SwipyRefreshLayoutDirection direction) {
Logging.d(Config.LOGTAG, "Refresh swipe container");
Logging.d(Config.LOGTAG, "Refresh direction " + direction);
- synchronized (this.messageList) {
- long timestamp;
- if (SwipyRefreshLayoutDirection.TOP == direction) { // Load history -> messages sent/received before first message in database
- if (messageList.isEmpty()) {
- timestamp = System.currentTimeMillis();
- } else {
- timestamp = this.messageList.get(0).getTimeSent(); // works only because of the ordering (last msg = first msg in list)
+ final ConversationActivity activity = (ConversationActivity) fragment.getActivity();
+ if (activity.getSelectedConversation().getAccount().getStatus() != Account.State.DISABLED) {
+ synchronized (this.messageList) {
+ long timestamp;
+ if (SwipyRefreshLayoutDirection.TOP == direction) { // Load history -> messages sent/received before first message in database
+ if (messageList.isEmpty()) {
+ timestamp = System.currentTimeMillis();
+ } else {
+ timestamp = this.messageList.get(0).getTimeSent(); // works only because of the ordering (last msg = first msg in list)
+ }
+ this.listener.setLoadHistory(true);
+ activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener);
+ } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { // load messages sent/received between last received or last session establishment and now
+ if (activity.getSelectedConversation().getAccount().isOnlineAndConnected()) {
+ Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)");
+ long lastSessionEstablished = this.getTimestampOfLastSessionEstablished(activity.getSelectedConversation());
+ long lastReceivedMessage = this.getTimestampOfLastReceivedOrTransmittedMessage();
+ long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage);
+ MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis(), this.listener);
+ if (query != null) {
+ this.listener.setLoadHistory(false);
+ } else {
+ Logging.d("mam", "no query built - no messages loaded");
+ this.listener.onMoreMessagesLoaded(0, activity.getSelectedConversation());
+ this.listener.informUser(R.string.no_more_history_on_server);
+ }
+ this.listener.informUser(R.string.fetching_history_from_server);
+ } else {
+ this.listener.informUser(R.string.not_connected_try_again);
+ swipeLayout.setRefreshing(false);
+ }
}
- ConversationActivity activity = (ConversationActivity) fragment.getActivity();
- this.listener.setLoadHistory(true);
- activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener);
- } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { // load messages sent/received between last received or last session establishment and now
- Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)");
- final ConversationActivity activity = (ConversationActivity) fragment.getActivity();
- long lastSessionEstablished = this.getTimestampOfLastSessionEstablished(activity.getSelectedConversation());
- long lastReceivedMessage = this.getTimestampOfLastReceivedOrTransmittedMessage();
- long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage);
- MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis(), this.listener);
- if (query != null) {
- this.listener.setLoadHistory(false);
- } else {
- Logging.d("mam", "no query built - no messages loaded");
- this.listener.onMoreMessagesLoaded(0, activity.getSelectedConversation());
- this.listener.informUser(R.string.no_more_history_on_server);
- }
- this.listener.informUser(R.string.fetching_history_from_server);
}
+ } else {
+ this.listener.informUser(R.string.this_account_is_disabled);
+ swipeLayout.setRefreshing(false);
}
Logging.d(Config.LOGTAG, "End Refresh swipe container");
}