Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-android
Commits
844dcdfc
Commit
844dcdfc
authored
1 month ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
account: reduce contention
Change-Id: I67e22f3ebf82353ff645703badad44f49624a5b4
parent
883e04ed
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt
+46
-39
46 additions, 39 deletions
...d/libjamiclient/src/main/kotlin/net/jami/model/Account.kt
with
46 additions
and
39 deletions
jami-android/libjamiclient/src/main/kotlin/net/jami/model/Account.kt
+
46
−
39
View file @
844dcdfc
...
@@ -127,24 +127,26 @@ class Account(
...
@@ -127,24 +127,26 @@ class Account(
Log
.
e
(
TAG
,
"conversationStarted ${conversation.accountId} ${conversation.uri} ${conversation.contacts} ${conversation.mode.blockingFirst()}"
,
e
)
Log
.
e
(
TAG
,
"conversationStarted ${conversation.accountId} ${conversation.uri} ${conversation.contacts} ${conversation.mode.blockingFirst()}"
,
e
)
}
}
}
}
conversationChanged
()
}
}
conversationChanged
()
}
}
fun
getSwarm
(
conversationId
:
String
):
Conversation
?
{
fun
getSwarm
(
conversationId
:
String
):
Conversation
?
=
synchronized
(
conversations
)
{
return
swarmConversations
[
conversationId
]
}
synchronized
(
conversations
)
{
swarmConversations
[
conversationId
]
}
}
fun
newSwarm
(
conversationId
:
String
,
mode
:
Conversation
.
Mode
):
Conversation
{
fun
newSwarm
(
conversationId
:
String
,
mode
:
Conversation
.
Mode
):
Conversation
{
Log
.
d
(
TAG
,
"newSwarm $conversationId"
)
val
conv
:
Conversation
?
synchronized
(
conversations
)
{
synchronized
(
conversations
)
{
var
c
=
swarmConversations
[
conversationId
]
conv
=
swarmConversations
[
conversationId
]
if
(
c
==
null
)
{
if
(
c
onv
==
null
)
{
c
=
Conversation
(
accountId
,
Uri
(
Uri
.
SWARM_SCHEME
,
conversationId
),
mode
)
val
c
=
Conversation
(
accountId
,
Uri
(
Uri
.
SWARM_SCHEME
,
conversationId
),
mode
)
swarmConversations
[
conversationId
]
=
c
swarmConversations
[
conversationId
]
=
c
return
c
}
}
c
.
setMode
(
mode
)
return
c
}
}
conv
!!
.
setMode
(
mode
)
return
conv
}
}
fun
removeSwarm
(
conversationId
:
String
)
{
fun
removeSwarm
(
conversationId
:
String
)
{
...
@@ -153,14 +155,14 @@ class Account(
...
@@ -153,14 +155,14 @@ class Account(
val
conversation
=
swarmConversations
.
remove
(
conversationId
)
val
conversation
=
swarmConversations
.
remove
(
conversationId
)
if
(
conversation
!=
null
)
{
if
(
conversation
!=
null
)
{
try
{
try
{
val
c
=
conversations
.
remove
(
conversation
.
uri
.
uri
)
val
c
=
conversations
.
remove
(
conversation
.
uri
.
uri
)
!!
val
contact
=
c
!!
.
contact
val
contact
=
c
.
contact
Log
.
w
(
TAG
,
"removeSwarm: adding back contact conversation "
+
contact
+
" "
+
contact
!!
.
conversationUri
.
blockingFirst
()
+
" "
+
c
.
uri
)
Log
.
w
(
TAG
,
"removeSwarm: adding back contact conversation "
+
contact
+
" "
+
contact
!!
.
conversationUri
.
blockingFirst
()
+
" "
+
c
.
uri
)
if
(
contact
.
conversationUri
.
blockingFirst
()
.
equals
(
c
.
uri
)
)
{
if
(
contact
.
conversationUri
.
blockingFirst
()
==
c
.
uri
)
{
contact
.
setConversationUri
(
contact
.
uri
)
contact
.
setConversationUri
(
contact
.
uri
)
contactAdded
(
contact
)
contactAdded
(
contact
)
}
}
}
catch
(
ignored
:
Exception
)
{
}
catch
(
_
:
Exception
)
{
}
}
conversationChanged
()
conversationChanged
()
}
}
...
@@ -238,24 +240,27 @@ class Account(
...
@@ -238,24 +240,27 @@ class Account(
pendingSubject
.
onNext
(
getSortedPending
())
pendingSubject
.
onNext
(
getSortedPending
())
}
}
private
fun
conversationRefreshed
(
conversation
:
Conversation
)
{
private
fun
conversationRefreshed
(
conversation
:
Conversation
,
sorted
:
List
<
Conversation
>
)
{
if
(
historyLoaded
)
{
if
(
historyLoaded
)
{
conversationSubject
.
onNext
(
conversation
)
conversationSubject
.
onNext
(
conversation
)
updateUnreadConversations
()
updateUnreadConversations
(
sorted
)
}
}
}
}
fun
conversationChanged
()
{
fun
conversationChanged
()
{
val
sortedList
:
List
<
Conversation
>?
synchronized
(
conversations
)
{
synchronized
(
conversations
)
{
conversationsChanged
=
true
conversationsChanged
=
true
if
(
historyLoaded
)
{
sortedList
=
if
(
historyLoaded
)
{
ArrayList
(
getSortedConversations
())
}
else
null
conversationsSubject
.
onNext
(
ArrayList
(
getSortedConversations
()))
}
updateUnreadConversations
()
if
(
sortedList
!=
null
)
{
}
conversationsSubject
.
onNext
(
sortedList
)
updateUnreadConversations
(
sortedList
)
}
}
}
}
fun
conversationUpdated
(
conversation
:
Conversation
)
{
fun
conversationUpdated
(
conversation
:
Conversation
)
{
val
sortedList
:
List
<
Conversation
>
synchronized
(
conversations
)
{
synchronized
(
conversations
)
{
if
(!
historyLoaded
)
return
if
(!
historyLoaded
)
return
if
(
conversationsChanged
)
{
if
(
conversationsChanged
)
{
...
@@ -264,11 +269,12 @@ class Account(
...
@@ -264,11 +269,12 @@ class Account(
conversation
.
sortHistory
()
conversation
.
sortHistory
()
sortedConversations
.
sortWith
(
ConversationComparator
())
sortedConversations
.
sortWith
(
ConversationComparator
())
}
}
// TODO: remove next line when profile is updated through dedicated signal
sortedList
=
ArrayList
(
sortedConversations
)
conversationSubject
.
onNext
(
conversation
)
conversationsSubject
.
onNext
(
ArrayList
(
sortedConversations
))
updateUnreadConversations
()
}
}
// TODO: remove next line when profile is updated through dedicated signal
conversationSubject
.
onNext
(
conversation
)
conversationsSubject
.
onNext
(
sortedList
)
updateUnreadConversations
(
sortedList
)
}
}
/**
/**
...
@@ -313,7 +319,8 @@ class Account(
...
@@ -313,7 +319,8 @@ class Account(
if
(
conversation
==
cache
[
key
])
{
if
(
conversation
==
cache
[
key
])
{
if
(
isJami
&&
!
conversation
.
isSwarm
if
(
isJami
&&
!
conversation
.
isSwarm
//&& conversation.contacts.size == 1
//&& conversation.contacts.size == 1
&&
!
conversation
.
contact
!!
.
conversationUri
.
blockingFirst
().
equals
(
conversation
.
uri
))
{
&&
conversation
.
contact
!!
.
conversationUri
.
blockingFirst
()
!=
conversation
.
uri
)
{
return
return
}
}
if
(
mContacts
.
containsKey
(
key
)
||
!
isJami
)
{
if
(
mContacts
.
containsKey
(
key
)
||
!
isJami
)
{
...
@@ -330,7 +337,7 @@ class Account(
...
@@ -330,7 +337,7 @@ class Account(
fun
refreshed
(
conversation
:
Conversation
)
{
fun
refreshed
(
conversation
:
Conversation
)
{
synchronized
(
conversations
)
{
synchronized
(
conversations
)
{
if
(
conversations
.
containsValue
(
conversation
))
{
if
(
conversations
.
containsValue
(
conversation
))
{
conversationRefreshed
(
conversation
)
conversationRefreshed
(
conversation
,
sortedConversations
)
return
return
}
}
}
}
...
@@ -727,9 +734,9 @@ class Account(
...
@@ -727,9 +734,9 @@ class Account(
updated
(
c
)
updated
(
c
)
}
}
historyLoaded
=
true
historyLoaded
=
true
conversationChanged
()
pendingChanged
()
}
}
conversationChanged
()
pendingChanged
()
}
}
private
fun
getSortedConversations
():
List
<
Conversation
>
{
private
fun
getSortedConversations
():
List
<
Conversation
>
{
...
@@ -738,7 +745,8 @@ class Account(
...
@@ -738,7 +745,8 @@ class Account(
if
(
conversations
.
isNotEmpty
())
{
if
(
conversations
.
isNotEmpty
())
{
sortedConversations
.
addAll
(
conversations
.
values
)
sortedConversations
.
addAll
(
conversations
.
values
)
for
(
c
in
sortedConversations
)
c
.
sortHistory
()
for
(
c
in
sortedConversations
)
c
.
sortHistory
()
Collections
.
sort
(
sortedConversations
,
ConversationComparator
())
//Collections.sort(sortedConversations, ConversationComparator())
sortedConversations
.
sortWith
(
ConversationComparator
())
}
}
conversationsChanged
=
false
conversationsChanged
=
false
}
}
...
@@ -778,8 +786,8 @@ class Account(
...
@@ -778,8 +786,8 @@ class Account(
}
}
pendingConversation
.
addContactEvent
(
contact
)
pendingConversation
.
addContactEvent
(
contact
)
}
}
conversationChanged
()
}
}
conversationChanged
()
}
}
private
fun
contactRemoved
(
uri
:
Uri
,
conversationUri
:
Uri
)
{
private
fun
contactRemoved
(
uri
:
Uri
,
conversationUri
:
Uri
)
{
...
@@ -789,8 +797,8 @@ class Account(
...
@@ -789,8 +797,8 @@ class Account(
synchronized
(
pending
)
{
if
(
pending
.
remove
(
key
)
!=
null
)
pendingChanged
()
}
synchronized
(
pending
)
{
if
(
pending
.
remove
(
key
)
!=
null
)
pendingChanged
()
}
conversations
.
remove
(
key
)
conversations
.
remove
(
key
)
//swarmConversations.remove(conversationUri.uri)
//swarmConversations.remove(conversationUri.uri)
conversationChanged
()
}
}
conversationChanged
()
}
}
private
fun
getConversationByCallId
(
callId
:
String
):
Conversation
?
{
private
fun
getConversationByCallId
(
callId
:
String
):
Conversation
?
{
...
@@ -812,8 +820,10 @@ class Account(
...
@@ -812,8 +820,10 @@ class Account(
else
->
Contact
.
PresenceStatus
.
CONNECTED
else
->
Contact
.
PresenceStatus
.
CONNECTED
})
})
synchronized
(
conversations
)
{
synchronized
(
conversations
)
{
conversations
[
contactUri
]
?.
let
{
conversationRefreshed
(
it
)
}
Pair
(
conversations
[
contactUri
],
sortedConversations
)
}
}.
let
{
it
.
first
?.
let
{
conv
->
conversationRefreshed
(
conv
,
it
.
second
)
}}
synchronized
(
pending
)
{
if
(
pending
.
containsKey
(
contactUri
))
pendingRefreshed
()
}
synchronized
(
pending
)
{
if
(
pending
.
containsKey
(
contactUri
))
pendingRefreshed
()
}
}
}
...
@@ -920,13 +930,10 @@ class Account(
...
@@ -920,13 +930,10 @@ class Account(
fun
setActiveCalls
(
conversationId
:
String
,
activeCalls
:
List
<
Conversation
.
ActiveCall
>)
=
fun
setActiveCalls
(
conversationId
:
String
,
activeCalls
:
List
<
Conversation
.
ActiveCall
>)
=
getSwarm
(
conversationId
)
?.
setActiveCalls
(
activeCalls
)
getSwarm
(
conversationId
)
?.
setActiveCalls
(
activeCalls
)
private
fun
updateUnreadConversations
()
{
private
fun
updateUnreadConversations
(
sortedConversations
:
List
<
Conversation
>)
{
var
unread
=
0
unreadConversationsSubject
.
onNext
(
sortedConversations
.
count
{
for
(
model
in
sortedConversations
)
{
it
.
lastEvent
?.
isRead
==
false
val
last
=
model
.
lastEvent
})
if
(
last
!=
null
&&
!
last
.
isRead
)
unread
++
}
unreadConversationsSubject
.
onNext
(
unread
)
}
}
private
class
ConversationComparator
:
Comparator
<
Conversation
>
{
private
class
ConversationComparator
:
Comparator
<
Conversation
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment