Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.notification.LocalNotification
import com.wire.kalium.logic.data.notification.LocalNotificationUpdateMessageAction
import kotlinx.coroutines.delay
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -52,14 +53,16 @@ class MessageNotificationManager
private val notificationManager: NotificationManager,
private val lockCodeTimeManager: LockCodeTimeManager
) {

fun handleNotification(newNotifications: List<LocalNotification>, userId: QualifiedID, userName: String) {
suspend fun handleNotification(newNotifications: List<LocalNotification>, userId: QualifiedID, userName: String) {
if (newNotifications.isEmpty()) return

addNotifications(newNotifications, userId, userName)
updateNotifications(newNotifications, userId)
removeSeenNotifications(newNotifications, userId)

// This delay is required to let notification manager update activeNotifications list
delay(NOTIFICATION_UPDATE_DELAY)

appLogger.i("$TAG: handled notifications: newNotifications size ${newNotifications.size}; ")
}

Expand Down Expand Up @@ -456,6 +459,7 @@ class MessageNotificationManager
companion object {
private const val TAG = "MessageNotificationManager"
private const val MESSAGE_ID_EXTRA = "message_id"
private const val NOTIFICATION_UPDATE_DELAY = 100L

/**
* Update notification by adding [replyText] to the end of messages list with "You" as sender.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.datetime.Instant
import java.net.UnknownHostException
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -476,9 +477,14 @@ class WireNotificationManager @Inject constructor(
)
}

newNotifications.map { it.conversationId }.distinct().forEach { notifiedConversationId ->
markMessagesAsNotified(userId, notifiedConversationId)
}
newNotifications
.filterIsInstance<LocalNotification.Conversation>()
.filter { it.messages.isNotEmpty() }
.forEach { conversation ->
val lastNotified = conversation.messages.maxOf { it.time }
markMessagesAsNotified(userId, conversation.id, lastNotified)
}

markConnectionAsNotified(userId)
}
}
Expand Down Expand Up @@ -521,10 +527,11 @@ class WireNotificationManager @Inject constructor(

private suspend fun markMessagesAsNotified(
userId: QualifiedID,
conversationId: ConversationId? = null
conversationId: ConversationId? = null,
lastNotified: Instant? = null,
) {
val markNotified = conversationId?.let {
MarkMessagesAsNotifiedUseCase.UpdateTarget.SingleConversation(conversationId)
MarkMessagesAsNotifiedUseCase.UpdateTarget.SingleConversation(conversationId, lastNotified)
} ?: MarkMessagesAsNotifiedUseCase.UpdateTarget.AllConversations
coreLogic.getSessionScope(userId)
.messages
Expand Down
Loading