Skip to content

Commit

Permalink
fix(notification): clean up notification usecase (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Jan 6, 2023
1 parent 91663e5 commit 6b1453b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package com.wire.kalium.logic.feature.message

import com.wire.kalium.logic.data.connection.ConnectionRepository
import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.message.MessageMapper
import com.wire.kalium.logic.data.message.MessageRepository
import com.wire.kalium.logic.data.notification.LocalNotificationConversation
import com.wire.kalium.logic.data.notification.LocalNotificationMessageMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.di.MapperProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.buffer
Expand All @@ -31,20 +27,13 @@ interface GetNotificationsUseCase {
*
* @param connectionRepository connectionRepository for observing connectionRequests that user should be notified about
* @param messageRepository MessageRepository for getting Messages that user should be notified about
* @param userRepository UserRepository for getting SelfUser data, Self userId and OtherUser data (authors of messages)
* @param conversationRepository ConversationRepository for getting conversations that have messages that user should be notified about
* @param messageMapper MessageMapper for mapping Message object into LocalNotificationMessage
* @param localNotificationMessageMapper LocalNotificationMessageMapper for mapping PublicUser object into LocalNotificationMessageAuthor
*/
@Suppress("LongParameterList")
internal class GetNotificationsUseCaseImpl internal constructor(
private val connectionRepository: ConnectionRepository,
private val messageRepository: MessageRepository,
private val userRepository: UserRepository,
private val conversationRepository: ConversationRepository,
private val ephemeralNotificationsManager: EphemeralNotificationsMgr,
private val selfUserId: UserId,
private val messageMapper: MessageMapper = MapperProvider.messageMapper(selfUserId),
private val localNotificationMessageMapper: LocalNotificationMessageMapper = MapperProvider.localNotificationMessageMapper()
) : GetNotificationsUseCase {

Expand All @@ -67,11 +56,4 @@ internal class GetNotificationsUseCaseImpl internal constructor(
.map { localNotificationMessageMapper.fromConnectionToLocalNotificationConversation(it) }
}
}

// TODO: will consider these values in query lever after SQLDelight added window functions
companion object {
private const val DEFAULT_MESSAGE_LIMIT = 100
private const val DEFAULT_MESSAGE_OFFSET = 0
private const val NOTIFICATION_DATE_OFFSET = 1000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ class MessageScope internal constructor(
get() = GetNotificationsUseCaseImpl(
connectionRepository = connectionRepository,
messageRepository = messageRepository,
userRepository = userRepository,
conversationRepository = conversationRepository,
selfUserId = selfUserId,
ephemeralNotificationsManager = EphemeralNotificationsManager
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ class GetNotificationsUseCaseTest {
val getNotificationsUseCase: GetNotificationsUseCase = GetNotificationsUseCaseImpl(
connectionRepository = connectionRepository,
messageRepository = messageRepository,
userRepository = userRepository,
conversationRepository = conversationRepository,
selfUserId = SELF_USER_ID,
ephemeralNotificationsManager = ephemeralNotifications
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ interface ConnectionDAO {
suspend fun deleteConnectionDataAndConversation(conversationId: QualifiedIDEntity)
suspend fun getConnectionRequestsForNotification(): Flow<List<ConnectionEntity>>
suspend fun updateNotificationFlag(flag: Boolean, userId: QualifiedIDEntity)
suspend fun updateAllNotificationFlags(flag: Boolean)
suspend fun setAllConnectionsAsNotified()
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class ConnectionDAOImpl(
)
}

override suspend fun insertConnections(conversationList: List<ConnectionEntity>) {
override suspend fun insertConnections(users: List<ConnectionEntity>) {
connectionsQueries.transaction {
for (connectionEntity: ConnectionEntity in conversationList) {
for (connectionEntity: ConnectionEntity in users) {
connectionsQueries.insertConnection(
from_id = connectionEntity.from,
conversation_id = connectionEntity.conversationId,
Expand Down Expand Up @@ -142,14 +142,6 @@ class ConnectionDAOImpl(
connectionsQueries.updateNotificationFlag(flag, userId)
}

override suspend fun updateAllNotificationFlags(flag: Boolean) {
connectionsQueries.transaction {
connectionsQueries.selectConnectionRequests()
.executeAsList()
.forEach { connectionsQueries.updateNotificationFlag(flag, it.qualified_to) }
}
}

override suspend fun setAllConnectionsAsNotified() {
connectionsQueries.setAllConnectionsAsNotified()
}
Expand Down

0 comments on commit 6b1453b

Please sign in to comment.