Should improve chat rooms list display performances a bit
This commit is contained in:
parent
10e29db302
commit
0f67ca79dd
1 changed files with 16 additions and 22 deletions
|
@ -43,7 +43,7 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
override val showGroupChatAvatar: Boolean
|
override val showGroupChatAvatar: Boolean
|
||||||
get() = conferenceChatRoom && !oneToOneChatRoom
|
get() = !oneToOneChatRoom
|
||||||
override val presenceStatus: MutableLiveData<ConsolidatedPresence> = MutableLiveData<ConsolidatedPresence>()
|
override val presenceStatus: MutableLiveData<ConsolidatedPresence> = MutableLiveData<ConsolidatedPresence>()
|
||||||
override val coroutineScope: CoroutineScope = coreContext.coroutineScope
|
override val coroutineScope: CoroutineScope = coreContext.coroutineScope
|
||||||
|
|
||||||
|
@ -77,10 +77,6 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
|
chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
private val conferenceChatRoom: Boolean by lazy {
|
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt())
|
|
||||||
}
|
|
||||||
|
|
||||||
val encryptedChatRoom: Boolean by lazy {
|
val encryptedChatRoom: Boolean by lazy {
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.Encrypted.toInt())
|
chatRoom.hasCapability(ChatRoomCapabilities.Encrypted.toInt())
|
||||||
}
|
}
|
||||||
|
@ -89,15 +85,18 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
override fun onContactsUpdated() {
|
override fun onContactsUpdated() {
|
||||||
if (oneToOneChatRoom && contact.value == null) {
|
if (oneToOneChatRoom && contact.value == null) {
|
||||||
searchMatchingContact()
|
searchMatchingContact()
|
||||||
if (contact.value != null) {
|
}
|
||||||
formatLastMessage(chatRoom.lastMessageInHistory)
|
if (!oneToOneChatRoom && contact.value != null) {
|
||||||
}
|
formatLastMessage(chatRoom.lastMessageInHistory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
coreContext.contactsManager.addListener(contactsListener)
|
coreContext.contactsManager.addListener(contactsListener)
|
||||||
|
|
||||||
|
lastUpdate.value = "00:00"
|
||||||
|
presenceStatus.value = ConsolidatedPresence.Offline
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
|
@ -106,7 +105,6 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
unreadMessagesCount.value = chatRoom.unreadMessagesCount
|
unreadMessagesCount.value = chatRoom.unreadMessagesCount
|
||||||
presenceStatus.value = ConsolidatedPresence.Offline
|
|
||||||
|
|
||||||
subject.value = chatRoom.subject
|
subject.value = chatRoom.subject
|
||||||
updateSecurityIcon()
|
updateSecurityIcon()
|
||||||
|
@ -140,19 +138,10 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun contactLookup() {
|
private fun contactLookup() {
|
||||||
displayName.value = when {
|
|
||||||
basicChatRoom -> LinphoneUtils.getDisplayName(
|
|
||||||
chatRoom.peerAddress
|
|
||||||
)
|
|
||||||
oneToOneChatRoom -> LinphoneUtils.getDisplayName(
|
|
||||||
chatRoom.participants.firstOrNull()?.address ?: chatRoom.peerAddress
|
|
||||||
)
|
|
||||||
conferenceChatRoom -> chatRoom.subject.orEmpty()
|
|
||||||
else -> chatRoom.peerAddress.asStringUriOnly()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oneToOneChatRoom) {
|
if (oneToOneChatRoom) {
|
||||||
searchMatchingContact()
|
searchMatchingContact()
|
||||||
|
} else {
|
||||||
|
displayName.value = chatRoom.subject ?: chatRoom.peerAddress.asStringUriOnly()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +157,7 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remoteAddress != null) {
|
if (remoteAddress != null) {
|
||||||
val friend = coreContext.contactsManager.findContactByAddress(remoteAddress)
|
val friend = coreContext.contactsManager.findContactByAddress(remoteAddress)
|
||||||
if (friend != null) {
|
if (friend != null) {
|
||||||
|
@ -176,13 +166,16 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
friend.addListener {
|
friend.addListener {
|
||||||
presenceStatus.value = it.consolidatedPresence
|
presenceStatus.value = it.consolidatedPresence
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
displayName.value = LinphoneUtils.getDisplayName(remoteAddress)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
displayName.value = chatRoom.peerAddress.asStringUriOnly()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatLastMessage(msg: ChatMessage?) {
|
private fun formatLastMessage(msg: ChatMessage?) {
|
||||||
val lastUpdateTime = chatRoom.lastUpdateTime
|
val lastUpdateTime = chatRoom.lastUpdateTime
|
||||||
lastUpdate.value = "00:00"
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
lastUpdate.postValue(TimestampUtils.toString(lastUpdateTime, true))
|
lastUpdate.postValue(TimestampUtils.toString(lastUpdateTime, true))
|
||||||
|
@ -218,10 +211,12 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
val body = AppUtils.getString(R.string.conference_invitation)
|
val body = AppUtils.getString(R.string.conference_invitation)
|
||||||
builder.append(body)
|
builder.append(body)
|
||||||
builder.setSpan(StyleSpan(Typeface.ITALIC), builder.length - body.length, builder.length, 0)
|
builder.setSpan(StyleSpan(Typeface.ITALIC), builder.length - body.length, builder.length, 0)
|
||||||
|
break
|
||||||
} else if (content.isVoiceRecording) {
|
} else if (content.isVoiceRecording) {
|
||||||
val body = AppUtils.getString(R.string.chat_message_voice_recording)
|
val body = AppUtils.getString(R.string.chat_message_voice_recording)
|
||||||
builder.append(body)
|
builder.append(body)
|
||||||
builder.setSpan(StyleSpan(Typeface.ITALIC), builder.length - body.length, builder.length, 0)
|
builder.setSpan(StyleSpan(Typeface.ITALIC), builder.length - body.length, builder.length, 0)
|
||||||
|
break
|
||||||
} else if (content.isFile || content.isFileTransfer) {
|
} else if (content.isFile || content.isFileTransfer) {
|
||||||
builder.append(content.name + " ")
|
builder.append(content.name + " ")
|
||||||
} else if (content.isText) {
|
} else if (content.isText) {
|
||||||
|
@ -253,7 +248,6 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun areNotificationsMuted(): Boolean {
|
private fun areNotificationsMuted(): Boolean {
|
||||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
|
||||||
return corePreferences.chatRoomMuted(id)
|
return corePreferences.chatRoomMuted(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue