Fixed participant added/removed toast

This commit is contained in:
Sylvain Berfini 2024-04-08 17:36:47 +02:00
parent f5bdaf85fd
commit 4d8b74ee41

View file

@ -104,8 +104,9 @@ class ConversationInfoViewModel @UiThread constructor() : AbstractConversationVi
@WorkerThread
override fun onParticipantAdded(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A participant has been added to the group [${chatRoom.subject}]")
val message = AppUtils.getString(
R.string.toast_participant_added_to_conversation
val message = AppUtils.getFormattedString(
R.string.toast_participant_added_to_conversation,
getParticipant(eventLog)
)
showGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle)))
@ -116,8 +117,9 @@ class ConversationInfoViewModel @UiThread constructor() : AbstractConversationVi
@WorkerThread
override fun onParticipantRemoved(chatRoom: ChatRoom, eventLog: EventLog) {
Log.i("$TAG A participant has been removed from the group [${chatRoom.subject}]")
val message = AppUtils.getString(
R.string.toast_participant_removed_from_conversation
val message = AppUtils.getFormattedString(
R.string.toast_participant_removed_from_conversation,
getParticipant(eventLog)
)
showGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle)))
@ -130,24 +132,15 @@ 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.getFormattedString(
R.string.toast_participant_has_been_granted_admin_rights,
participant
getParticipant(eventLog)
)
} else {
AppUtils.getFormattedString(
R.string.toast_participant_no_longer_has_admin_rights,
participant
getParticipant(eventLog)
)
}
showGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle)))
@ -576,4 +569,17 @@ class ConversationInfoViewModel @UiThread constructor() : AbstractConversationVi
// Will trigger the conference creation/update automatically
conferenceScheduler.info = conferenceInfo
}
@WorkerThread
private fun getParticipant(eventLog: EventLog): String {
val participantAddress = eventLog.participantAddress
return if (participantAddress != null) {
val model = participants.value.orEmpty().find {
it.address.weakEqual(participantAddress)
}
model?.avatarModel?.contactName ?: LinphoneUtils.getDisplayName(participantAddress)
} else {
""
}
}
}