use async message loading only when called from UI

This commit is contained in:
Daniel Gultsch 2017-04-13 00:12:23 +02:00
parent 0229a1605e
commit 0904ba42f8
8 changed files with 26 additions and 21 deletions

View file

@ -192,7 +192,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
public boolean execute(Account account) { public boolean execute(Account account) {
if (jid != null) { if (jid != null) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false);
if (!conversation.getMucOptions().online()) { if (!conversation.getMucOptions().online()) {
conversation.getMucOptions().setPassword(password); conversation.getMucOptions().setPassword(password);
mXmppConnectionService.databaseBackend.updateConversation(conversation); mXmppConnectionService.databaseBackend.updateConversation(conversation);
@ -415,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) { if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) {
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query, false);
final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI;
if (serverMsgId == null) { if (serverMsgId == null) {

View file

@ -253,7 +253,7 @@ public class PresenceParser extends AbstractParser implements
} else { } else {
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
final Conversation conversation = mXmppConnectionService.findOrCreateConversation( final Conversation conversation = mXmppConnectionService.findOrCreateConversation(
account, contact.getJid().toBareJid(), false); account, contact.getJid().toBareJid(), false, false);
final String statusMessage = packet.findChildContent("status"); final String statusMessage = packet.findChildContent("status");
if (statusMessage != null if (statusMessage != null
&& !statusMessage.isEmpty() && !statusMessage.isEmpty()

View file

@ -1413,7 +1413,7 @@ public class XmppConnectionService extends Service {
if (conversation != null) { if (conversation != null) {
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
} else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) { } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
conversation = findOrCreateConversation(account, bookmark.getJid(), true, true); conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false);
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
} }
} }
@ -1681,15 +1681,15 @@ public class XmppConnectionService extends Service {
return null; return null;
} }
public Conversation findOrCreateConversation(Account account, Jid jid, boolean muc) { public Conversation findOrCreateConversation(Account account, Jid jid, boolean muc, final boolean async) {
return this.findOrCreateConversation(account,jid,muc,false); return this.findOrCreateConversation(account,jid,muc,false, async);
} }
public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate) { public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final boolean async) {
return this.findOrCreateConversation(account, jid, muc, joinAfterCreate, null); return this.findOrCreateConversation(account, jid, muc, joinAfterCreate, null, async);
} }
public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query) { public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query, final boolean async) {
synchronized (this.conversations) { synchronized (this.conversations) {
Conversation conversation = find(account, jid); Conversation conversation = find(account, jid);
if (conversation != null) { if (conversation != null) {
@ -1728,7 +1728,7 @@ public class XmppConnectionService extends Service {
loadMessagesFromDb = false; loadMessagesFromDb = false;
} }
final Conversation c = conversation; final Conversation c = conversation;
mDatabaseExecutor.execute(new Runnable() { final Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
if (loadMessagesFromDb) { if (loadMessagesFromDb) {
@ -1752,7 +1752,12 @@ public class XmppConnectionService extends Service {
joinMuc(c); joinMuc(c);
} }
} }
}); };
if (async) {
mDatabaseExecutor.execute(runnable);
} else {
runnable.run();
}
this.conversations.add(conversation); this.conversations.add(conversation);
updateConversationUi(); updateConversationUi();
return conversation; return conversation;
@ -2454,7 +2459,7 @@ public class XmppConnectionService extends Service {
return false; return false;
} }
final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null); final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true, false); final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
joinMuc(conversation, new OnConferenceJoined() { joinMuc(conversation, new OnConferenceJoined() {
@Override @Override
public void onConferenceJoined(final Conversation conversation) { public void onConferenceJoined(final Conversation conversation) {

View file

@ -482,7 +482,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
protected void startConversation(User user) { protected void startConversation(User user) {
if (user.getRealJid() != null) { if (user.getRealJid() != null) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false); Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false,true);
switchToConversation(conversation); switchToConversation(conversation);
} }
} }

View file

@ -265,7 +265,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
try { try {
conversation = xmppConnectionService conversation = xmppConnectionService
.findOrCreateConversation(account, Jid.fromString(share.contact), false); .findOrCreateConversation(account, Jid.fromString(share.contact), false,true);
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
return; return;
} }

View file

@ -316,7 +316,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void openConversationForContact(Contact contact) { protected void openConversationForContact(Contact contact) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),
contact.getJid(), false); contact.getJid(), false, true);
switchToConversation(conversation); switchToConversation(conversation);
} }
@ -357,7 +357,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
return; return;
} }
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true); Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", true)) { if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", true)) {
bookmark.setAutojoin(true); bookmark.setAutojoin(true);
@ -513,7 +513,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
account.getBookmarks().add(bookmark); account.getBookmarks().add(bookmark);
xmppConnectionService.pushBookmarks(account); xmppConnectionService.pushBookmarks(account);
final Conversation conversation = xmppConnectionService final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, conferenceJid, true, true); .findOrCreateConversation(account, conferenceJid, true, true, true);
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
dialog.dismiss(); dialog.dismiss();
mCurrentDialog = null; mCurrentDialog = null;
@ -521,7 +521,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
} else { } else {
final Conversation conversation = xmppConnectionService final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account,conferenceJid, true, true); .findOrCreateConversation(account,conferenceJid, true, true, true);
dialog.dismiss(); dialog.dismiss();
mCurrentDialog = null; mCurrentDialog = null;
switchToConversation(conversation); switchToConversation(conversation);
@ -582,7 +582,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void switchToConversation(Contact contact, String body) { protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),
contact.getJid(),false); contact.getJid(),false,true);
switchToConversation(conversation, body, false); switchToConversation(conversation, body, false);
} }

View file

@ -100,7 +100,7 @@ public class ExceptionHelper {
Conversation conversation = null; Conversation conversation = null;
try { try {
conversation = service.findOrCreateConversation(finalAccount, conversation = service.findOrCreateConversation(finalAccount,
Jid.fromString(Config.BUG_REPORTS), false); Jid.fromString(Config.BUG_REPORTS), false, true);
} catch (final InvalidJidException ignored) { } catch (final InvalidJidException ignored) {
} }
Message message = new Message(conversation, report Message message = new Message(conversation, report

View file

@ -313,7 +313,7 @@ public class JingleConnection implements Transferable {
this.mJingleStatus = JINGLE_STATUS_INITIATED; this.mJingleStatus = JINGLE_STATUS_INITIATED;
Conversation conversation = this.mXmppConnectionService Conversation conversation = this.mXmppConnectionService
.findOrCreateConversation(account, .findOrCreateConversation(account,
packet.getFrom().toBareJid(), false); packet.getFrom().toBareJid(), false, false);
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
this.message.setStatus(Message.STATUS_RECEIVED); this.message.setStatus(Message.STATUS_RECEIVED);
this.mStatus = Transferable.STATUS_OFFER; this.mStatus = Transferable.STATUS_OFFER;