Skip to content
Snippets Groups Projects
Commit fd4b04f2 authored by Pierre Nicolas's avatar Pierre Nicolas :joy:
Browse files

notification: propage activecalls to notifications

Make swarm:group notification disapear when the call is finished.
GitLab: #1464

Change-Id: I1415be6abfc223b43d03de13d7c4ae1d9ab97a09
parent c3edd5f3
No related branches found
No related tags found
No related merge requests found
......@@ -487,22 +487,30 @@ class NotificationServiceImpl(
/**
* Function to show a group call notification.
*/
override fun showGroupCallNotification(conversation: Conversation) {
override fun showGroupCallNotification(conversation: Conversation, remove: Boolean) {
// Call the showGroupCallNotification function with the loaded conversation.
mContactService.getLoadedConversation(conversation)
.subscribe({ cvm -> showGroupCallNotification(cvm) })
.subscribe({ cvm -> showGroupCallNotification(cvm, remove) })
{ e: Throwable -> Log.w(TAG, "Can't load contact", e) }
}
/**
* Function to show a group call notification.
*/
private fun showGroupCallNotification(cvm: ConversationItemViewModel) {
private fun showGroupCallNotification(cvm: ConversationItemViewModel, remove: Boolean) {
// Obtain the conversation path and key
val cpath = ConversationPath(cvm.accountId, cvm.uri)
val path = cpath.toUri()
val key = cpath.toKey()
// Generate a unique notification ID
val notificationId = getTextNotificationId(cpath.accountId, cvm.uri)
if (remove) { // Remove the notification if the call is no longer in progress.
CarNotificationManager.from(mContext).cancel(notificationId)
return
}
// Get the conversation profile
val conversationProfile = getProfile(cvm)
......@@ -535,8 +543,6 @@ class NotificationServiceImpl(
.setColor(ResourcesCompat.getColor(mContext.resources, R.color.color_primary_dark, null))
.setLargeIcon(conversationProfile.first)
// Generate a unique notification ID
val notificationId = getTextNotificationId(cpath.accountId, cvm.uri)
// Notify the notification
CarNotificationManager.from(mContext).notify(notificationId, messageNotificationBuilder)
// Save the notification builder for future reference
......
......@@ -912,8 +912,8 @@ class Account(
mDataTransfers[fileId] = transfer
}
fun setActiveCalls(conversationId: String, activeCalls: List<Map<String, String>>) =
getSwarm(conversationId)?.setActiveCalls(activeCalls.map { Conversation.ActiveCall(it) })
fun setActiveCalls(conversationId: String, activeCalls: List<Conversation.ActiveCall>) =
getSwarm(conversationId)?.setActiveCalls(activeCalls)
private fun updateUnreadConversations() {
var unread = 0
......
......@@ -84,6 +84,18 @@ class AccountService(
private var mHasRingAccount = false
private val accountsSubject = BehaviorSubject.create<List<Account>>()
private val observableAccounts: Subject<Account> = PublishSubject.create()
private val activeCallsSubject: Subject<ConversationActiveCalls> =
PublishSubject.create()
val activeCallsObservable: Observable<ConversationActiveCalls> =
activeCallsSubject
data class ConversationActiveCalls(
val accountId: String,
val conversationId: String,
val activeCalls: List<Conversation.ActiveCall>
)
val currentAccountSubject: Observable<Account> = accountsSubject
.filter { l -> l.isNotEmpty() }
.map { l -> l[0] }
......@@ -1042,7 +1054,17 @@ class AccountService(
accountId: String,
conversationId: String,
activeCalls: List<Map<String, String>>,
) = getAccount(accountId)?.setActiveCalls(conversationId, activeCalls)
) {
val activeCallList = activeCalls.map { Conversation.ActiveCall(it) }
activeCallsSubject.onNext(
ConversationActiveCalls(
accountId,
conversationId,
activeCallList
)
)
getAccount(accountId)?.setActiveCalls(conversationId, activeCallList)
}
fun accountProfileReceived(accountId: String, name: String?, photo: String?) {
val account = getAccount(accountId) ?: return
......
......@@ -771,10 +771,21 @@ class ConversationFacade(
mDisposableBag.add(mAccountService.dataTransfers
.subscribe({ transfer: DataTransfer -> handleDataTransferEvent(transfer) },
{ e: Throwable -> Log.e(TAG, "Error adding data transfer", e) }))
mDisposableBag.add(mAccountService.incomingGroupCall
.subscribe({ c -> mNotificationService.showGroupCallNotification(c) },
{ e: Throwable -> Log.e(TAG, "Error showing group call notification", e) }))
mDisposableBag.add(
mAccountService.activeCallsObservable.subscribe(
{ conversationActiveCall ->
mAccountService.getAccount(accountId = conversationActiveCall.accountId)
?.getByUri(uri = conversationActiveCall.conversationId)
?.let {
mNotificationService.showGroupCallNotification(
conversation = it,
remove = conversationActiveCall.activeCalls.isEmpty()
)
}
},
{ e: Throwable -> Log.e(TAG, "Error showing group call notification", e) }
)
)
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ interface NotificationService {
fun preparePendingScreenshare(conference: Conference, callback: () -> Unit)
fun startPendingScreenshare(confId: String)
fun showMissedCallNotification(call: Call)
fun showGroupCallNotification(conversation: Conversation)
fun showGroupCallNotification(conversation: Conversation, remove: Boolean = false)
fun showTextNotification(conversation: Conversation)
fun cancelTextNotification(accountId: String, contact: Uri)
fun cancelAll()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment