mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
More work related to ephemeral messages
This commit is contained in:
parent
991a5e695a
commit
c650887c04
4 changed files with 99 additions and 8 deletions
|
|
@ -107,10 +107,23 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
|
|||
unreadMessageCount.postValue(chatRoom.unreadMessagesCount)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onSubjectChanged(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
subject.postValue(chatRoom.subject)
|
||||
updateLastUpdatedTime()
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onEphemeralEvent(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
Log.i("$TAG Ephemeral event received [${eventLog.type}]")
|
||||
isEphemeral.postValue(chatRoom.isEphemeralEnabled)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onEphemeralMessageDeleted(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
Log.i("$TAG An ephemeral message lifetime has expired, updating last displayed message")
|
||||
updateLastMessage()
|
||||
}
|
||||
}
|
||||
|
||||
private val chatMessageListener = object : ChatMessageListenerStub() {
|
||||
|
|
@ -165,6 +178,9 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
|
|||
|
||||
isMuted.postValue(chatRoom.muted)
|
||||
isEphemeral.postValue(chatRoom.isEphemeralEnabled)
|
||||
Log.i(
|
||||
"$TAG Ephemeral chat messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]"
|
||||
)
|
||||
|
||||
updateLastMessage()
|
||||
updateLastUpdatedTime()
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ import org.linphone.utils.LinphoneUtils
|
|||
class EventLogModel @WorkerThread constructor(
|
||||
val eventLog: EventLog,
|
||||
avatarModel: ContactAvatarModel,
|
||||
isFromGroup: Boolean,
|
||||
isGroupedWithPreviousOne: Boolean,
|
||||
isGroupedWithNextOne: Boolean,
|
||||
isFromGroup: Boolean = false,
|
||||
isGroupedWithPreviousOne: Boolean = false,
|
||||
isGroupedWithNextOne: Boolean = false,
|
||||
onContentClicked: ((file: String) -> Unit)? = null,
|
||||
onJoinConferenceClicked: ((uri: String) -> Unit)? = null,
|
||||
onWebUrlClicked: ((url: String) -> Unit)? = null
|
||||
|
|
|
|||
|
|
@ -111,6 +111,12 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
|
|||
// TODO: show toast
|
||||
subject.postValue(chatRoom.subject)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onEphemeralEvent(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
Log.i("$TAG Ephemeral event [${eventLog.type}]")
|
||||
// TODO: show toast
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
@ -331,10 +337,29 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
|
|||
@UiThread
|
||||
fun updateEphemeralLifetime(lifetime: Int) {
|
||||
coreContext.postOnCoreThread {
|
||||
Log.i("$TAG Updating chat messages ephemeral lifetime to [$lifetime]")
|
||||
chatRoom.ephemeralLifetime = lifetime.toLong()
|
||||
chatRoom.isEphemeralEnabled = lifetime != 0
|
||||
ephemeralLifetime.postValue(chatRoom.ephemeralLifetime.toInt())
|
||||
if (lifetime == 0) {
|
||||
if (chatRoom.isEphemeralEnabled) {
|
||||
Log.i("$TAG Disabling ephemeral messages")
|
||||
chatRoom.isEphemeralEnabled = false
|
||||
}
|
||||
} else {
|
||||
if (!chatRoom.isEphemeralEnabled) {
|
||||
Log.i("$TAG Enabling ephemeral messages")
|
||||
chatRoom.isEphemeralEnabled = true
|
||||
}
|
||||
|
||||
val longLifetime = lifetime.toLong()
|
||||
if (chatRoom.ephemeralLifetime != longLifetime) {
|
||||
Log.i("$TAG Updating lifetime to [$longLifetime]")
|
||||
chatRoom.ephemeralLifetime = longLifetime
|
||||
}
|
||||
}
|
||||
ephemeralLifetime.postValue(
|
||||
if (!chatRoom.isEphemeralEnabled) 0 else chatRoom.ephemeralLifetime.toInt()
|
||||
)
|
||||
Log.i(
|
||||
"$TAG Ephemeral chat messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +382,9 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
|
|||
subject.postValue(chatRoom.subject)
|
||||
sipUri.postValue(chatRoom.participants.firstOrNull()?.address?.asStringUriOnly())
|
||||
|
||||
ephemeralLifetime.postValue(chatRoom.ephemeralLifetime.toInt())
|
||||
ephemeralLifetime.postValue(
|
||||
if (!chatRoom.isEphemeralEnabled) 0 else chatRoom.ephemeralLifetime.toInt()
|
||||
)
|
||||
|
||||
computeParticipantsList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,54 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
events.postValue(list)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onNewEvents(chatRoom: ChatRoom, eventLogs: Array<out EventLog>) {
|
||||
Log.i("$TAG Adding [${eventLogs.size}] new events")
|
||||
val list = arrayListOf<EventLogModel>()
|
||||
list.addAll(events.value.orEmpty())
|
||||
val fakeFriend = chatRoom.core.createFriend()
|
||||
val avatarModel = ContactAvatarModel(fakeFriend)
|
||||
for (eventLog in eventLogs) {
|
||||
Log.i("$TAG New event [${eventLog.type}] added")
|
||||
list.add(EventLogModel(eventLog, avatarModel))
|
||||
}
|
||||
events.postValue(list)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onEphemeralEvent(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
Log.i("$TAG Adding new ephemeral event [${eventLog.type}]")
|
||||
// Warning: when 2 ephemeral events are dispatched quickly one after the other,
|
||||
// one will be missing because events.postValue() hasn't completed yet !
|
||||
// TODO FIXME: Missing event !!!
|
||||
val list = arrayListOf<EventLogModel>()
|
||||
list.addAll(events.value.orEmpty())
|
||||
val fakeFriend = chatRoom.core.createFriend()
|
||||
val avatarModel = ContactAvatarModel(fakeFriend)
|
||||
list.add(EventLogModel(eventLog, avatarModel))
|
||||
events.postValue(list)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onEphemeralMessageDeleted(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
val eventsLogs = events.value.orEmpty()
|
||||
val message = eventLog.chatMessage
|
||||
Log.i("$TAG Message [${message?.messageId}] ephemeral lifetime has expired")
|
||||
|
||||
val found = eventsLogs.find {
|
||||
(it.model as? ChatMessageModel)?.chatMessage == message
|
||||
}
|
||||
if (found != null) {
|
||||
val list = arrayListOf<EventLogModel>()
|
||||
list.addAll(eventsLogs)
|
||||
list.remove(found)
|
||||
events.postValue(list)
|
||||
Log.i("$TAG Message was removed from events list")
|
||||
} else {
|
||||
Log.w("$TAG Failed to find matching message in events list")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue