update conversation in database background thread

This commit is contained in:
Daniel Gultsch 2016-10-18 13:06:24 +02:00
parent 50780debf7
commit 7226fc0010
5 changed files with 18 additions and 18 deletions

View file

@ -1610,7 +1610,7 @@ public class XmppConnectionService extends Service {
); );
} }
} }
this.databaseBackend.updateConversation(conversation); updateConversation(conversation);
this.conversations.remove(conversation); this.conversations.remove(conversation);
updateConversationUi(); updateConversationUi();
} }
@ -2140,7 +2140,7 @@ public class XmppConnectionService extends Service {
} }
pushBookmarks(conversation.getAccount()); pushBookmarks(conversation.getAccount());
} }
databaseBackend.updateConversation(conversation); updateConversation(conversation);
joinMuc(conversation); joinMuc(conversation);
} }
} }
@ -2860,8 +2860,13 @@ public class XmppConnectionService extends Service {
} }
} }
public void updateConversation(Conversation conversation) { public void updateConversation(final Conversation conversation) {
this.databaseBackend.updateConversation(conversation); mDatabaseExecutor.execute(new Runnable() {
@Override
public void run() {
databaseBackend.updateConversation(conversation);
}
});
} }
private void reconnectAccount(final Account account, final boolean force, final boolean interactive) { private void reconnectAccount(final Account account, final boolean force, final boolean interactive) {

View file

@ -611,10 +611,8 @@ public class ConversationActivity extends XmppActivity
@Override @Override
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int which) { int which) {
conversation conversation.setNextEncryption(Message.ENCRYPTION_NONE);
.setNextEncryption(Message.ENCRYPTION_NONE); xmppConnectionService.updateConversation(conversation);
xmppConnectionService.databaseBackend
.updateConversation(conversation);
selectPresenceToAttachFile(attachmentChoice, Message.ENCRYPTION_NONE); selectPresenceToAttachFile(attachmentChoice, Message.ENCRYPTION_NONE);
} }
}); });
@ -888,7 +886,7 @@ public class ConversationActivity extends XmppActivity
conversation.setNextEncryption(Message.ENCRYPTION_NONE); conversation.setNextEncryption(Message.ENCRYPTION_NONE);
break; break;
} }
xmppConnectionService.databaseBackend.updateConversation(conversation); xmppConnectionService.updateConversation(conversation);
fragment.updateChatMsgHint(); fragment.updateChatMsgHint();
invalidateOptionsMenu(); invalidateOptionsMenu();
refreshUi(); refreshUi();
@ -947,8 +945,7 @@ public class ConversationActivity extends XmppActivity
till = System.currentTimeMillis() + (durations[which] * 1000); till = System.currentTimeMillis() + (durations[which] * 1000);
} }
conversation.setMutedTill(till); conversation.setMutedTill(till);
ConversationActivity.this.xmppConnectionService.databaseBackend ConversationActivity.this.xmppConnectionService.updateConversation(conversation);
.updateConversation(conversation);
updateConversationList(); updateConversationList();
ConversationActivity.this.mConversationFragment.updateMessages(); ConversationActivity.this.mConversationFragment.updateMessages();
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -959,7 +956,7 @@ public class ConversationActivity extends XmppActivity
public void unmuteConversation(final Conversation conversation) { public void unmuteConversation(final Conversation conversation) {
conversation.setMutedTill(0); conversation.setMutedTill(0);
this.xmppConnectionService.databaseBackend.updateConversation(conversation); this.xmppConnectionService.updateConversation(conversation);
updateConversationList(); updateConversationList();
ConversationActivity.this.mConversationFragment.updateMessages(); ConversationActivity.this.mConversationFragment.updateMessages();
invalidateOptionsMenu(); invalidateOptionsMenu();

View file

@ -1262,8 +1262,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
int which) { int which) {
conversation conversation
.setNextEncryption(Message.ENCRYPTION_NONE); .setNextEncryption(Message.ENCRYPTION_NONE);
xmppService.databaseBackend xmppService.updateConversation(conversation);
.updateConversation(conversation);
message.setEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message); xmppService.sendMessage(message);
messageSent(); messageSent();
@ -1291,8 +1290,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
conversation conversation
.setNextEncryption(Message.ENCRYPTION_NONE); .setNextEncryption(Message.ENCRYPTION_NONE);
message.setEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.databaseBackend xmppService.updateConversation(conversation);
.updateConversation(conversation);
xmppService.sendMessage(message); xmppService.sendMessage(message);
messageSent(); messageSent();
} }

View file

@ -574,7 +574,7 @@ public abstract class XmppActivity extends Activity {
xmppConnectionService.sendPresence(account); xmppConnectionService.sendPresence(account);
if (conversation != null) { if (conversation != null) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP); conversation.setNextEncryption(Message.ENCRYPTION_PGP);
xmppConnectionService.databaseBackend.updateConversation(conversation); xmppConnectionService.updateConversation(conversation);
refreshUi(); refreshUi();
} }
if (onSuccess != null) { if (onSuccess != null) {

View file

@ -450,7 +450,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private void loadMoreMessages(Conversation conversation) { private void loadMoreMessages(Conversation conversation) {
conversation.setLastClearHistory(0); conversation.setLastClearHistory(0);
activity.xmppConnectionService.databaseBackend.updateConversation(conversation); activity.xmppConnectionService.updateConversation(conversation);
conversation.setHasMessagesLeftOnServer(true); conversation.setHasMessagesLeftOnServer(true);
conversation.setFirstMamReference(null); conversation.setFirstMamReference(null);
long timestamp = conversation.getLastMessageTransmitted(); long timestamp = conversation.getLastMessageTransmitted();