mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Update chat room shortcuts each time a notification is about to be created + report 'use' when opening a conversation
This commit is contained in:
parent
50c922b581
commit
5ad7b5da14
3 changed files with 56 additions and 6 deletions
|
|
@ -318,11 +318,6 @@ class NotificationsManager
|
||||||
Log.i("$TAG Received ${messages.size} aggregated messages")
|
Log.i("$TAG Received ${messages.size} aggregated messages")
|
||||||
if (corePreferences.disableChat) return
|
if (corePreferences.disableChat) return
|
||||||
|
|
||||||
if (!ShortcutUtils.isShortcutToChatRoomAlreadyCreated(context, chatRoom)) {
|
|
||||||
Log.i("$TAG A message was received in a chat room for which there is no dynamic shortcut, let's create it")
|
|
||||||
ShortcutUtils.createDynamicShortcutToChatRoom(context, chatRoom)
|
|
||||||
}
|
|
||||||
|
|
||||||
val id = LinphoneUtils.getConversationId(chatRoom)
|
val id = LinphoneUtils.getConversationId(chatRoom)
|
||||||
if (currentlyDisplayedChatRoomId.isNotEmpty() && id == currentlyDisplayedChatRoomId) {
|
if (currentlyDisplayedChatRoomId.isNotEmpty() && id == currentlyDisplayedChatRoomId) {
|
||||||
Log.i(
|
Log.i(
|
||||||
|
|
@ -1057,6 +1052,12 @@ class NotificationsManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notifiable.messages.count() == messages.size) {
|
||||||
|
Log.i("$TAG Creating or updating chat room shortcut")
|
||||||
|
// Only do it the first time we create the notification
|
||||||
|
ShortcutUtils.createOrUpdateChatRoomShortcut(context, chatRoom)
|
||||||
|
}
|
||||||
|
|
||||||
if (notifiable.messages.isNotEmpty()) {
|
if (notifiable.messages.isNotEmpty()) {
|
||||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||||
val pendingIntent = getChatRoomPendingIntent(chatRoom, notifiable.notificationId)
|
val pendingIntent = getChatRoomPendingIntent(chatRoom, notifiable.notificationId)
|
||||||
|
|
@ -1124,6 +1125,11 @@ class NotificationsManager
|
||||||
notifiable.messages.add(notifiableMessage)
|
notifiable.messages.add(notifiableMessage)
|
||||||
|
|
||||||
if (notifiable.messages.isNotEmpty()) {
|
if (notifiable.messages.isNotEmpty()) {
|
||||||
|
if (notifiable.messages.count() == 1) {
|
||||||
|
// Only do it the first time we create the notification
|
||||||
|
ShortcutUtils.createOrUpdateChatRoomShortcut(context, chatRoom)
|
||||||
|
}
|
||||||
|
|
||||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||||
val pendingIntent = getChatRoomPendingIntent(chatRoom, notifiable.notificationId)
|
val pendingIntent = getChatRoomPendingIntent(chatRoom, notifiable.notificationId)
|
||||||
val notification = createMessageNotification(
|
val notification = createMessageNotification(
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ import org.linphone.utils.showKeyboard
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import org.linphone.ui.main.chat.adapter.ConversationParticipantsAdapter
|
import org.linphone.ui.main.chat.adapter.ConversationParticipantsAdapter
|
||||||
import org.linphone.ui.main.chat.model.MessageDeleteDialogModel
|
import org.linphone.ui.main.chat.model.MessageDeleteDialogModel
|
||||||
|
import org.linphone.utils.ShortcutUtils
|
||||||
import kotlin.collections.arrayListOf
|
import kotlin.collections.arrayListOf
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
@ -529,6 +530,7 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sharedViewModel.displayedChatRoom = viewModel.chatRoom
|
sharedViewModel.displayedChatRoom = viewModel.chatRoom
|
||||||
|
ShortcutUtils.reportChatRoomShortcutHasBeenUsed(requireContext(), viewModel.conversationId)
|
||||||
|
|
||||||
sendMessageViewModel.configureChatRoom(viewModel.chatRoom)
|
sendMessageViewModel.configureChatRoom(viewModel.chatRoom)
|
||||||
adapter.setIsConversationSecured(viewModel.isEndToEndEncrypted.value == true)
|
adapter.setIsConversationSecured(viewModel.isEndToEndEncrypted.value == true)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ShortcutInfo
|
import android.content.pm.ShortcutInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.annotation.AnyThread
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.collection.ArraySet
|
import androidx.collection.ArraySet
|
||||||
import androidx.core.app.Person
|
import androidx.core.app.Person
|
||||||
|
|
@ -101,7 +102,6 @@ class ShortcutUtils {
|
||||||
private fun createChatRoomShortcut(context: Context, chatRoom: ChatRoom): ShortcutInfoCompat? {
|
private fun createChatRoomShortcut(context: Context, chatRoom: ChatRoom): ShortcutInfoCompat? {
|
||||||
val peerAddress = chatRoom.peerAddress
|
val peerAddress = chatRoom.peerAddress
|
||||||
val id = LinphoneUtils.getConversationId(chatRoom)
|
val id = LinphoneUtils.getConversationId(chatRoom)
|
||||||
Log.i("$TAG Creating dynamic shortcut for chat room [$id]")
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val categories: ArraySet<String> = ArraySet()
|
val categories: ArraySet<String> = ArraySet()
|
||||||
|
|
@ -192,5 +192,47 @@ class ShortcutUtils {
|
||||||
Log.d("$TAG Dynamic shortcut for chat room with ID [$id] ${if (found != null) "exists" else "doesn't exists"}")
|
Log.d("$TAG Dynamic shortcut for chat room with ID [$id] ${if (found != null) "exists" else "doesn't exists"}")
|
||||||
return found != null
|
return found != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
fun createOrUpdateChatRoomShortcut(context: Context, chatRoom: ChatRoom) {
|
||||||
|
val id = LinphoneUtils.getConversationId(chatRoom)
|
||||||
|
val found = ShortcutManagerCompat.getDynamicShortcuts(context).find {
|
||||||
|
it.id == id
|
||||||
|
}
|
||||||
|
val shortcut: ShortcutInfoCompat? = createChatRoomShortcut(context, chatRoom)
|
||||||
|
if (shortcut == null) {
|
||||||
|
Log.e("$TAG Failed to create shortcut info for chat room [$id]")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == null) {
|
||||||
|
Log.i("$TAG Created dynamic shortcut for ${shortcut.shortLabel}, pushing it")
|
||||||
|
try {
|
||||||
|
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("$TAG Failed to push dynamic shortcut for ${shortcut.shortLabel}: $e")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.i("$TAG Updating dynamic shortcut for ${shortcut.shortLabel}")
|
||||||
|
try {
|
||||||
|
ShortcutManagerCompat.updateShortcuts(context, listOf(shortcut))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("$TAG Failed to update dynamic shortcut for ${shortcut.shortLabel}: $e")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnyThread
|
||||||
|
fun reportChatRoomShortcutHasBeenUsed(context: Context, chatRoomId: String) {
|
||||||
|
val found = ShortcutManagerCompat.getDynamicShortcuts(context).find {
|
||||||
|
it.id == chatRoomId
|
||||||
|
}
|
||||||
|
if (found != null) {
|
||||||
|
Log.i("$TAG Reporting shortcut for chat room [$chatRoomId] was used")
|
||||||
|
ShortcutManagerCompat.reportShortcutUsed(context, chatRoomId)
|
||||||
|
} else {
|
||||||
|
Log.w("$TAG No shortcut was found for chat room [$chatRoomId]")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue