Proper display of group conversation events

This commit is contained in:
Sylvain Berfini 2023-11-15 13:33:46 +01:00
parent 61bd2967b0
commit 035738f4c5
3 changed files with 71 additions and 3 deletions

View file

@ -172,7 +172,9 @@ class ContactsManager @UiThread constructor(context: Context) {
@WorkerThread
fun findDisplayName(address: Address): String {
return findContactByAddress(address)?.name ?: LinphoneUtils.getDisplayName(address)
return getContactAvatarModelForAddress(address).friend.name ?: LinphoneUtils.getDisplayName(
address
)
}
@WorkerThread

View file

@ -20,8 +20,64 @@
package org.linphone.ui.main.chat.model
import androidx.annotation.WorkerThread
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.EventLog
import org.linphone.utils.AppUtils
class EventModel @WorkerThread constructor(eventLog: EventLog) {
val text = eventLog.type.name // TODO FIXME: use proper translated string instead
class EventModel @WorkerThread constructor(private val eventLog: EventLog) {
val text: String
init {
text = when (eventLog.type) {
EventLog.Type.ConferenceCreated -> AppUtils.getString(
R.string.conversation_event_conference_created
)
EventLog.Type.ConferenceTerminated -> AppUtils.getString(
R.string.conversation_event_conference_destroyed
)
EventLog.Type.ConferenceParticipantAdded -> AppUtils.getFormattedString(
R.string.conversation_event_participant_added,
getName()
)
EventLog.Type.ConferenceParticipantRemoved -> AppUtils.getFormattedString(
R.string.conversation_event_participant_removed,
getName()
)
EventLog.Type.ConferenceSubjectChanged -> AppUtils.getFormattedString(
R.string.conversation_event_subject_changed,
getName()
)
EventLog.Type.ConferenceParticipantSetAdmin -> AppUtils.getFormattedString(
R.string.conversation_event_admin_set,
getName()
)
EventLog.Type.ConferenceParticipantUnsetAdmin -> AppUtils.getFormattedString(
R.string.conversation_event_admin_unset,
getName()
)
EventLog.Type.ConferenceParticipantDeviceAdded -> AppUtils.getFormattedString(
R.string.conversation_event_device_added,
getName()
)
EventLog.Type.ConferenceParticipantDeviceRemoved -> AppUtils.getFormattedString(
R.string.conversation_event_device_removed,
getName()
)
else -> {
eventLog.type.name
}
}
}
@WorkerThread
fun getName(): String {
val address = eventLog.participantAddress ?: eventLog.peerAddress
val name = if (address != null) {
coreContext.contactsManager.findDisplayName(address)
} else {
"<?>"
}
return name
}
}

View file

@ -369,6 +369,16 @@
<string name="conversation_info_admin_menu_set_participant_admin">Give admin rights</string>
<string name="conversation_info_admin_menu_unset_participant_admin">Remove admin rights</string>
<string name="conversation_event_conference_created">You have joined the group</string>
<string name="conversation_event_conference_destroyed">You have left the group</string>
<string name="conversation_event_participant_added">%s has joined</string>
<string name="conversation_event_participant_removed">%s has left</string>
<string name="conversation_event_device_added">new device for %s</string>
<string name="conversation_event_device_removed">device for %s removed</string>
<string name="conversation_event_subject_changed">new subject: %s</string>
<string name="conversation_event_admin_set">%s is admin</string>
<string name="conversation_event_admin_unset">%s is no longer admin</string>
<string name="message_delivery_info_read_title">Read %s</string>
<string name="message_delivery_info_received_title">Received %s</string>
<string name="message_delivery_info_sent_title">Sent %s</string>