Fixed conversation info toast + participants list not refreshed + events not appearing in messages list when going back

This commit is contained in:
Sylvain Berfini 2024-03-18 10:08:29 +01:00
parent 7f24902fc7
commit 90a2c0539c
4 changed files with 85 additions and 80 deletions

View file

@ -49,7 +49,7 @@ class ConversationParticipantsAdapter : ListAdapter<ParticipantModel, RecyclerVi
}
override fun areContentsTheSame(oldItem: ParticipantModel, newItem: ParticipantModel): Boolean {
return oldItem.avatarModel.id == newItem.avatarModel.id
return oldItem.avatarModel.id == newItem.avatarModel.id && oldItem.isParticipantAdmin == newItem.isParticipantAdmin
}
}
}

View file

@ -117,8 +117,11 @@ class ConversationModel @WorkerThread constructor(
computeComposingLabel()
}
@WorkerThread
override fun onMessagesReceived(chatRoom: ChatRoom, chatMessages: Array<out ChatMessage>) {
override fun onNewEvent(chatRoom: ChatRoom, eventLog: EventLog) {
updateLastUpdatedTime()
}
override fun onNewEvents(chatRoom: ChatRoom, eventLogs: Array<out EventLog>) {
updateLastMessage()
updateLastUpdatedTime()
unreadMessageCount.postValue(chatRoom.unreadMessagesCount)
@ -127,7 +130,6 @@ class ConversationModel @WorkerThread constructor(
@WorkerThread
override fun onChatMessageSending(chatRoom: ChatRoom, eventLog: EventLog) {
updateLastMessage()
updateLastUpdatedTime()
}
@WorkerThread
@ -139,12 +141,10 @@ class ConversationModel @WorkerThread constructor(
override fun onSubjectChanged(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG Conversation subject changed [${chatRoom.subject}]")
subject.postValue(chatRoom.subject)
updateLastUpdatedTime()
}
@WorkerThread
override fun onEphemeralEvent(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG Ephemeral event [${eventLog.type}]")
isEphemeral.postValue(chatRoom.isEphemeralEnabled)
}

View file

@ -130,13 +130,24 @@ class ConversationInfoViewModel @UiThread constructor() : AbstractConversationVi
Log.i(
"$TAG A participant has been given/removed administration rights for group [${chatRoom.subject}]"
)
val participantAddress = eventLog.participantAddress
val participant = if (participantAddress != null) {
val model = participants.value.orEmpty().find {
it.address.weakEqual(participantAddress)
}
model?.avatarModel?.contactName ?: LinphoneUtils.getDisplayName(participantAddress)
} else {
""
}
val message = if (eventLog.type == EventLog.Type.ConferenceParticipantSetAdmin) {
AppUtils.getString(
R.string.toast_participant_has_been_granted_admin_rights
AppUtils.getFormattedString(
R.string.toast_participant_has_been_granted_admin_rights,
participant
)
} else {
AppUtils.getString(
R.string.toast_participant_no_longer_has_admin_rights
AppUtils.getFormattedString(
R.string.toast_participant_no_longer_has_admin_rights,
participant
)
}
showGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle)))

View file

@ -150,32 +150,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
// Prevents auto scroll to go to latest received message
chatRoom.markAsRead()
val list = arrayListOf<EventLogModel>()
list.addAll(eventsList)
val newList = getEventsListFromHistory(
arrayOf(eventLog),
searchFilter.value.orEmpty().trim()
)
val lastEvent = eventsList.lastOrNull()
val newEvent = newList.firstOrNull()
if (lastEvent != null && newEvent != null && shouldWeGroupTwoEvents(
newEvent.eventLog,
lastEvent.eventLog
)
) {
if (lastEvent.model is MessageModel) {
lastEvent.model.groupedWithNextMessage.postValue(true)
}
if (newEvent.model is MessageModel) {
newEvent.model.groupedWithPreviousMessage.postValue(true)
}
}
list.addAll(newList)
eventsList = list
events.postValue(eventsList)
addEvents(arrayOf(eventLog))
}
@WorkerThread
@ -189,31 +164,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
Log.i("$TAG Received [${eventLogs.size}] new message(s)")
computeComposingLabel()
val list = arrayListOf<EventLogModel>()
list.addAll(eventsList)
val lastEvent = list.lastOrNull()
val newList = getEventsListFromHistory(
eventLogs,
searchFilter.value.orEmpty().trim()
)
val newEvent = newList.firstOrNull()
if (lastEvent != null && newEvent != null && shouldWeGroupTwoEvents(
newEvent.eventLog,
lastEvent.eventLog
)
) {
if (lastEvent.model is MessageModel) {
lastEvent.model.groupedWithNextMessage.postValue(true)
}
if (newEvent.model is MessageModel) {
newEvent.model.groupedWithPreviousMessage.postValue(true)
}
}
list.addAll(newList)
eventsList = list
events.postValue(eventsList)
addEvents(eventLogs)
unreadMessagesCount.postValue(chatRoom.unreadMessagesCount)
}
@ -241,6 +192,36 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
computeComposingLabel()
}
@WorkerThread
override fun onParticipantAdded(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A participant was added to the conversation")
addEvents(arrayOf(eventLog))
}
@WorkerThread
override fun onParticipantRemoved(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A participant was removed from the conversation or has left")
addEvents(arrayOf(eventLog))
}
@WorkerThread
override fun onParticipantAdminStatusChanged(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A participant has been granted/removed admin rights")
addEvents(arrayOf(eventLog))
}
@WorkerThread
override fun onSubjectChanged(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG Conversation subject changed [${chatRoom.subject}]")
addEvents(arrayOf(eventLog))
}
@WorkerThread
override fun onSecurityEvent(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A security event was triggered")
addEvents(arrayOf(eventLog))
}
@WorkerThread
override fun onEphemeralEvent(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG Adding new ephemeral event [${eventLog.type}]")
@ -457,25 +438,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
val history = chatRoom.getHistoryRangeEvents(totalItemsCount, upperBound)
val list = getEventsListFromHistory(history, searchFilter.value.orEmpty())
val lastEvent = list.lastOrNull()
val newEvent = eventsList.firstOrNull()
if (lastEvent != null && newEvent != null && shouldWeGroupTwoEvents(
newEvent.eventLog,
lastEvent.eventLog
)
) {
if (lastEvent.model is MessageModel) {
lastEvent.model.groupedWithNextMessage.postValue(true)
}
if (newEvent.model is MessageModel) {
newEvent.model.groupedWithPreviousMessage.postValue(true)
}
}
list.addAll(eventsList)
eventsList = list
events.postValue(eventsList)
val array = arrayOf<EventLog>()
list.toArray(array)
addEvents(array)
}
}
}
@ -569,6 +534,35 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo
}
}
@WorkerThread
private fun addEvents(eventLogs: Array<EventLog>) {
val list = arrayListOf<EventLogModel>()
list.addAll(eventsList)
val lastEvent = list.lastOrNull()
val newList = getEventsListFromHistory(
eventLogs,
searchFilter.value.orEmpty().trim()
)
val newEvent = newList.firstOrNull()
if (lastEvent != null && newEvent != null && shouldWeGroupTwoEvents(
newEvent.eventLog,
lastEvent.eventLog
)
) {
if (lastEvent.model is MessageModel) {
lastEvent.model.groupedWithNextMessage.postValue(true)
}
if (newEvent.model is MessageModel) {
newEvent.model.groupedWithPreviousMessage.postValue(true)
}
}
list.addAll(newList)
eventsList = list
events.postValue(eventsList)
}
@WorkerThread
private fun processGroupedEvents(
groupedEventLogs: ArrayList<EventLog>