mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Fetch all unread messages before creating a new notifiable for a chat room
This commit is contained in:
parent
58ec0e7abb
commit
ef1669dd4c
3 changed files with 30 additions and 31 deletions
|
|
@ -140,7 +140,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
override fun onMessagesReceived(
|
||||
core: Core,
|
||||
chatRoom: ChatRoom,
|
||||
messages: Array<out ChatMessage>
|
||||
messages: Array<ChatMessage>
|
||||
) {
|
||||
Log.i("$TAG Received ${messages.size} aggregated messages")
|
||||
if (corePreferences.disableChat) return
|
||||
|
|
@ -499,7 +499,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun getNotifiableForRoom(chatRoom: ChatRoom): Notifiable {
|
||||
private fun getNotifiableForRoom(chatRoom: ChatRoom, messages: Array<ChatMessage>): Notifiable {
|
||||
val address = chatRoom.peerAddress.asStringUriOnly()
|
||||
var notifiable: Notifiable? = chatNotificationsMap[address]
|
||||
if (notifiable == null) {
|
||||
|
|
@ -515,22 +515,26 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notifiable.groupTitle = chatRoom.subject
|
||||
}
|
||||
|
||||
chatNotificationsMap[address] = notifiable
|
||||
for (message in chatRoom.unreadHistory) {
|
||||
if (message.isRead || message.isOutgoing) continue
|
||||
val notifiableMessage = getNotifiableForChatMessage(message)
|
||||
notifiable.messages.add(notifiableMessage)
|
||||
}
|
||||
} else {
|
||||
for (message in messages) {
|
||||
if (message.isRead || message.isOutgoing) continue
|
||||
val notifiableMessage = getNotifiableForChatMessage(message)
|
||||
notifiable.messages.add(notifiableMessage)
|
||||
}
|
||||
}
|
||||
|
||||
chatNotificationsMap[address] = notifiable
|
||||
return notifiable
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun showChatRoomNotification(chatRoom: ChatRoom, messages: Array<out ChatMessage>) {
|
||||
val notifiable = getNotifiableForRoom(chatRoom)
|
||||
|
||||
var updated = false
|
||||
for (message in messages) {
|
||||
if (message.isRead || message.isOutgoing) continue
|
||||
val notifiableMessage = getNotifiableForChatMessage(message)
|
||||
notifiable.messages.add(notifiableMessage)
|
||||
updated = true
|
||||
}
|
||||
private fun showChatRoomNotification(chatRoom: ChatRoom, messages: Array<ChatMessage>) {
|
||||
val notifiable = getNotifiableForRoom(chatRoom, messages)
|
||||
|
||||
if (!chatRoom.hasCapability(ChatRoom.Capabilities.OneToOne.toInt())) {
|
||||
if (chatRoom.subject != notifiable.groupTitle) {
|
||||
|
|
@ -538,13 +542,8 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
"$TAG Updating notification subject from [${notifiable.groupTitle}] to [${chatRoom.subject}]"
|
||||
)
|
||||
notifiable.groupTitle = chatRoom.subject
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
if (!updated) {
|
||||
Log.w("$TAG No changes made to notifiable, do not display it again")
|
||||
return
|
||||
}
|
||||
|
||||
if (notifiable.messages.isNotEmpty()) {
|
||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||
|
|
@ -570,7 +569,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
address: Address,
|
||||
message: ChatMessage
|
||||
) {
|
||||
val notifiable = getNotifiableForRoom(chatRoom)
|
||||
val notifiable = getNotifiableForRoom(chatRoom, arrayOf(message))
|
||||
|
||||
// Check if a previous reaction notifiable exists from the same person & for the same message
|
||||
val from = address.asStringUriOnly()
|
||||
|
|
|
|||
|
|
@ -437,17 +437,6 @@ class MainActivity : GenericActivity() {
|
|||
closeDrawerMenu()
|
||||
}
|
||||
|
||||
if (findNavController().currentDestination?.id == R.id.debugFragment) {
|
||||
Log.i(
|
||||
"$TAG App is already started and in debug fragment, navigating to conversations list"
|
||||
)
|
||||
val action = DebugFragmentDirections.actionDebugFragmentToConversationsListFragment()
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
|
||||
val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph)
|
||||
navGraph.setStartDestination(R.id.conversationsListFragment)
|
||||
|
||||
val paths = deferred.awaitAll()
|
||||
for (path in paths) {
|
||||
Log.i("$TAG Found file to share [$path] in intent")
|
||||
|
|
@ -464,7 +453,17 @@ class MainActivity : GenericActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
findNavController().setGraph(navGraph, intent.extras)
|
||||
if (findNavController().currentDestination?.id == R.id.debugFragment) {
|
||||
Log.i(
|
||||
"$TAG App is already started and in debug fragment, navigating to conversations list"
|
||||
)
|
||||
val action = DebugFragmentDirections.actionDebugFragmentToConversationsListFragment()
|
||||
findNavController().navigate(action)
|
||||
} else {
|
||||
val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph)
|
||||
navGraph.setStartDestination(R.id.conversationsListFragment)
|
||||
findNavController().setGraph(navGraph, intent.extras)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ class ShortcutUtils {
|
|||
|
||||
val intent = Intent(Intent.ACTION_MAIN)
|
||||
intent.setClass(context, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
intent.putExtra("Chat", true)
|
||||
intent.putExtra("RemoteSipUri", peerSipUri)
|
||||
intent.putExtra("LocalSipUri", localSipUri)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue