Skip to content
Snippets Groups Projects
Commit 33e34ca2 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

conversation: unify lock managment

Change-Id: Ic97c434ada28e5cc3c342808270c072aeb0bf948
parent 43b9d12c
Branches
Tags
No related merge requests found
......@@ -346,12 +346,14 @@ class Account(
Log.d(TAG, "Account onDataTransferEvent " + transfer.messageId)
val conversation = transfer.conversation as Conversation
val transferEventCode = transfer.status
synchronized(conversation) {
if (transferEventCode == InteractionStatus.TRANSFER_CREATED) {
conversation.addFileTransfer(transfer)
updated(conversation)
} else {
conversation.updateFileTransfer(transfer, transferEventCode)
}
}
return conversation
}
......
......@@ -267,6 +267,7 @@ class Conversation : ConversationHistory {
return null
}
@Synchronized
fun addCall(call: Call) {
if (!isSwarm && callHistory.contains(call)) {
return
......@@ -400,28 +401,26 @@ class Conversation : ConversationHistory {
}
}
@Synchronized
fun sortHistory() {
if (mDirty) {
//Log.w(TAG, "sortHistory()")
synchronized(aggregateHistory) {
aggregateHistory.sortWith { c1, c2 -> c1.timestamp.compareTo(c2.timestamp) }
for (i in aggregateHistory.asReversed())
if (i.type != Interaction.InteractionType.INVALID) {
lastEventSubject.onNext(aggregateHistory.last())
break
}
}
mDirty = false
}
}
val lastEvent: Interaction?
@Synchronized
get() {
synchronized(aggregateHistory) {
sortHistory()
return aggregateHistory.lastOrNull { it.type != Interaction.InteractionType.INVALID }
}
}
val currentCall: Conference?
get() = if (currentCalls.isEmpty()) null else currentCalls[0]
......@@ -439,12 +438,14 @@ class Conversation : ConversationHistory {
get() {
val texts = TreeMap<Long, TextMessage>()
if (isSwarm) {
synchronized(this) {
for (j in aggregateHistory.indices.reversed()) {
val i = aggregateHistory[j]
if (i !is TextMessage) continue
if (i.isRead || i.isNotified) break
texts[i.timestamp] = i
}
}
} else {
for ((key, value) in rawHistory.descendingMap()) {
if (value.type == Interaction.InteractionType.TEXT) {
......@@ -493,6 +494,7 @@ class Conversation : ConversationHistory {
* Clears the conversation cache.
* @param delete true if you do not want to re-add contact events
*/
@Synchronized
fun clearHistory(delete: Boolean) {
aggregateHistory.clear()
rawHistory.clear()
......@@ -502,6 +504,7 @@ class Conversation : ConversationHistory {
clearedSubject.onNext(aggregateHistory)
}
@Synchronized
fun setHistory(loadedConversation: List<Interaction>) {
aggregateHistory.ensureCapacity(loadedConversation.size)
for (i in loadedConversation) {
......@@ -514,6 +517,7 @@ class Conversation : ConversationHistory {
mDirty = false
}
@Synchronized
fun addElement(interaction: Interaction) {
setInteractionProperties(interaction)
when (interaction.type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment