Show notification top bar when MWI messages are waiting

This commit is contained in:
Sylvain Berfini 2024-12-09 14:37:33 +01:00
parent e5f227ba35
commit f9cf90fecd
3 changed files with 36 additions and 0 deletions

View file

@ -40,6 +40,7 @@ import org.linphone.core.ChatRoom
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.GlobalState
import org.linphone.core.MessageWaitingIndication
import org.linphone.core.RegistrationState
import org.linphone.core.VFS
import org.linphone.core.tools.Log
@ -53,6 +54,7 @@ class MainViewModel @UiThread constructor() : ViewModel() {
private const val TAG = "[Main ViewModel]"
const val NONE = 0
const val MWI_MESSAGES_WAITING = 4
const val NON_DEFAULT_ACCOUNT_NOTIFICATIONS = 5
const val NON_DEFAULT_ACCOUNT_NOT_CONNECTED = 10
const val SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED = 17
@ -288,6 +290,32 @@ class MainViewModel @UiThread constructor() : ViewModel() {
lastAccountRemovedEvent.postValue(Event(true))
}
}
@WorkerThread
override fun onMessageWaitingIndicationChanged(
core: Core,
event: org.linphone.core.Event,
mwi: MessageWaitingIndication
) {
if (mwi.hasMessageWaiting()) {
val summaries = mwi.summaries
Log.i(
"$TAG MWI NOTIFY received, messages are waiting ([${summaries.size}] summaries)"
)
if (summaries.isNotEmpty()) {
val summary = summaries.first()
val label = AppUtils.getStringWithPlural(
R.plurals.mwi_messages_are_waiting,
summary.nbNew,
summary.nbNew.toString()
)
addAlert(MWI_MESSAGES_WAITING, label)
}
} else {
Log.i("$TAG MWI NOTIFY received, no message is waiting")
removeAlert(MWI_MESSAGES_WAITING)
}
}
}
init {

View file

@ -743,6 +743,10 @@
<string name="generic_address_picker_contacts_list_title">Contacts</string>
<string name="generic_address_picker_suggestions_list_title">Suggestions</string>
<string name="post_notifications_permission_not_granted">La permission de poster des notifications n\'est pas donnée !</string>
<plurals name="mwi_messages_are_waiting">
<item quantity="one">%s message vocal en attente</item>
<item quantity="other">%s messages vocaux en attente</item>
</plurals>
<!-- Keep <u></u> in the following strings translations! -->
<string name="welcome_carousel_skip"><u>Passer</u></string>

View file

@ -781,6 +781,10 @@
<string name="generic_address_picker_contacts_list_title">Contacts</string>
<string name="generic_address_picker_suggestions_list_title">Suggestions</string>
<string name="post_notifications_permission_not_granted">Post notifications permission not granted!</string>
<plurals name="mwi_messages_are_waiting">
<item quantity="one">%s new voice message</item>
<item quantity="other">%s new voice messages</item>
</plurals>
<!-- Keep <u></u> in the following strings translations! -->
<string name="welcome_carousel_skip"><u>Skip</u></string>