do not explicitly request MAM archive for blocked contacts

This commit is contained in:
Daniel Gultsch 2018-01-29 01:39:46 +01:00
parent e48788e821
commit 2f1f9f2c2c
2 changed files with 44 additions and 44 deletions

View File

@ -1641,29 +1641,31 @@ public class XmppConnectionService extends Service {
return; return;
} }
Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp)); Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp));
Runnable runnable = new Runnable() { final Runnable runnable = () -> {
@Override final Account account = conversation.getAccount();
public void run() { List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp);
final Account account = conversation.getAccount(); if (messages.size() > 0) {
List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp); conversation.addAll(0, messages);
if (messages.size() > 0) { checkDeletedFiles(conversation);
conversation.addAll(0, messages); callback.onMoreMessagesLoaded(messages.size(), conversation);
checkDeletedFiles(conversation); } else if (conversation.hasMessagesLeftOnServer()
callback.onMoreMessagesLoaded(messages.size(), conversation); && account.isOnlineAndConnected()
} else if (conversation.hasMessagesLeftOnServer() && conversation.getLastClearHistory().getTimestamp() == 0) {
&& account.isOnlineAndConnected() final boolean mamAvailable;
&& conversation.getLastClearHistory().getTimestamp() == 0) { if (conversation.getMode() == Conversation.MODE_SINGLE) {
if ((conversation.getMode() == Conversation.MODE_SINGLE && account.getXmppConnection().getFeatures().mam()) mamAvailable = account.getXmppConnection().getFeatures().mam() && !conversation.getContact().isBlocked();
|| (conversation.getMode() == Conversation.MODE_MULTI && conversation.getMucOptions().mamSupport())) { } else {
MessageArchiveService.Query query = getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false); mamAvailable = conversation.getMucOptions().mamSupport();
if (query != null) { }
query.setCallback(callback); if (mamAvailable) {
callback.informUser(R.string.fetching_history_from_server); MessageArchiveService.Query query = getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false);
} else { if (query != null) {
callback.informUser(R.string.not_fetching_history_retention_period); query.setCallback(callback);
} callback.informUser(R.string.fetching_history_from_server);
} else {
callback.informUser(R.string.not_fetching_history_retention_period);
} }
} }
} }
}; };
@ -1754,29 +1756,27 @@ public class XmppConnectionService extends Service {
loadMessagesFromDb = false; loadMessagesFromDb = false;
} }
final Conversation c = conversation; final Conversation c = conversation;
final Runnable runnable = new Runnable() { final Runnable runnable = () -> {
@Override if (loadMessagesFromDb) {
public void run() { c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE));
if (loadMessagesFromDb) { updateConversationUi();
c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE)); c.messagesLoaded.set(true);
updateConversationUi(); }
c.messagesLoaded.set(true); if (account.getXmppConnection() != null
} && !c.getContact().isBlocked()
if (account.getXmppConnection() != null && account.getXmppConnection().getFeatures().mam()
&& account.getXmppConnection().getFeatures().mam() && !muc) {
&& !muc) { if (query == null) {
if (query == null) { mMessageArchiveService.query(c);
mMessageArchiveService.query(c); } else {
} else { if (query.getConversation() == null) {
if (query.getConversation() == null) { mMessageArchiveService.query(c, query.getStart(), query.isCatchup());
mMessageArchiveService.query(c, query.getStart(), query.isCatchup());
}
} }
} }
checkDeletedFiles(c); }
if (joinAfterCreate) { checkDeletedFiles(c);
joinMuc(c); if (joinAfterCreate) {
} joinMuc(c);
} }
}; };
if (async) { if (async) {

View File

@ -1453,7 +1453,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
private boolean showLoadMoreMessages(final Conversation c) { private boolean showLoadMoreMessages(final Conversation c) {
final boolean mam = hasMamSupport(c); final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService(); final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService();
return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c))); return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c)));
} }