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 @@ -273,6 +273,9 @@ public class ConversationScope internal constructor(
kaliumLogger
)

public val markConversationAsReadLocally: MarkConversationAsReadLocallyUseCase
get() = MarkConversationAsReadLocallyUseCaseImpl(conversationRepository)

public val updateConversationAccess: UpdateConversationAccessRoleUseCase
get() = UpdateConversationAccessRoleUseCaseImpl(conversationRepository, conversationGroupRepository, syncManager)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

package com.wire.kalium.logic.feature.conversation

import com.wire.kalium.common.error.StorageFailure
import com.wire.kalium.common.functional.Either
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.id.ConversationId
import kotlinx.datetime.Instant

/**
* Use case to immediately update the conversation read date in the local database
*
* This is useful for immediately clearing the unread badge when the user
* leaves a conversation, while the debounced [UpdateConversationReadDateUseCase]
* handles sending confirmations and syncing to other devices.
*/
public interface MarkConversationAsReadLocallyUseCase {
/**
* Updates the conversation read date locally and returns whether
* the conversation still has unread events.
*
* @param conversationId The conversation to mark as read
* @param time The timestamp to set as the last read date
* @return [Either.Right] with true if there are still unread events, false otherwise
* [Either.Left] with [StorageFailure] if the operation failed
*/
public suspend operator fun invoke(
conversationId: ConversationId,
time: Instant
): Either<StorageFailure, Boolean>
}

internal class MarkConversationAsReadLocallyUseCaseImpl internal constructor(
private val conversationRepository: ConversationRepository
) : MarkConversationAsReadLocallyUseCase {

override suspend fun invoke(
conversationId: ConversationId,
time: Instant
): Either<StorageFailure, Boolean> =
conversationRepository.updateReadDateAndGetHasUnreadEvents(conversationId, time)
}
Loading