Skip to content
Snippets Groups Projects
Commit fb90a69b authored by Pierre Nicolas's avatar Pierre Nicolas :joy:
Browse files

contact: fix race-condition

Fix a race-condition which was leading to a loadMore and a swarmLoaded called between setMode and conversationStarted.
GitLab: #1682

Change-Id: Ie75ddd880808213b7abff7ee6ab3cbe740c9cebe
parent 67e54aa5
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ class Account( ...@@ -95,7 +95,7 @@ class Account(
fun isContact(uri: Uri): Boolean = getContact(uri) != null fun isContact(uri: Uri): Boolean = getContact(uri) != null
fun conversationStarted(conversation: Conversation) { fun conversationStarted(conversation: Conversation, newMode: Conversation.Mode? = null) {
//Log.w(TAG, "conversationStarted ${conversation.accountId} ${conversation.uri} ${conversation.isSwarm} ${conversation.contacts.size} ${conversation.mode.blockingFirst()}") //Log.w(TAG, "conversationStarted ${conversation.accountId} ${conversation.uri} ${conversation.isSwarm} ${conversation.contacts.size} ${conversation.mode.blockingFirst()}")
synchronized(conversations) { synchronized(conversations) {
if (conversation.isSwarm) { if (conversation.isSwarm) {
...@@ -103,7 +103,11 @@ class Account( ...@@ -103,7 +103,11 @@ class Account(
swarmConversations[conversation.uri.rawRingId] = conversation swarmConversations[conversation.uri.rawRingId] = conversation
} }
conversations[conversation.uri.uri] = conversation conversations[conversation.uri.uri] = conversation
if (conversation.isSwarm && conversation.mode.blockingFirst() === Conversation.Mode.OneToOne) {
if (newMode != null) conversation.setMode(newMode)
val mode = newMode ?: conversation.mode.blockingFirst()
if (conversation.isSwarm && mode === Conversation.Mode.OneToOne) {
try { try {
val contact = conversation.contact!! val contact = conversation.contact!!
val key = contact.uri.uri val key = contact.uri.uri
......
...@@ -1448,10 +1448,8 @@ class AccountService( ...@@ -1448,10 +1448,8 @@ class AccountService(
} }
if (!conversation.lastElementLoadedSubject.hasValue()) if (!conversation.lastElementLoadedSubject.hasValue())
conversation.lastElementLoadedSubject.onSuccess(loadMore(conversation, 8).ignoreElement().cache()) conversation.lastElementLoadedSubject.onSuccess(loadMore(conversation, 8).ignoreElement().cache())
if (setMode)
conversation.setMode(mode)
} }
account.conversationStarted(conversation) account.conversationStarted(conversation, if (setMode) mode else null)
loadMore(conversation, 2) loadMore(conversation, 2)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment