Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Add workaround for notifaction for own answer #372

Merged
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 @@ -36,7 +36,8 @@ interface PushCommunicationDao {
@Transaction
suspend fun insertNotification(
artemisNotification: ArtemisNotification<CommunicationNotificationType>,
generateNotificationId: suspend () -> Int
generateNotificationId: suspend () -> Int,
isPostFromAppUser: suspend (CommunicationNotificationPlaceholderContent) -> Boolean
) {
val parentId = artemisNotification.parentId

Expand All @@ -46,6 +47,12 @@ interface PushCommunicationDao {
notificationPlaceholders = artemisNotification.notificationPlaceholders
) ?: return

if (isPostFromAppUser(content)) {
// As a temporary fix for receiving notifications for own posts.
// See: https://github.com/ls1intum/artemis-android/issues/326
return
}

if (hasPushCommunication(parentId)) {
updatePushCommunication(
parentId = parentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ val pushModule = module {
CommunicationNotificationManagerImpl(
androidContext(),
get(),
get(),
get(),
get(),
get()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import coil3.request.SuccessResult
import coil3.toBitmap
import de.tum.informatics.www1.artemis.native_app.core.common.ArtemisNotificationChannel
import de.tum.informatics.www1.artemis.native_app.core.common.markdown.PushNotificationArtemisMarkdownTransformer
import de.tum.informatics.www1.artemis.native_app.core.data.service.network.AccountDataService
import de.tum.informatics.www1.artemis.native_app.core.datastore.AccountService
import de.tum.informatics.www1.artemis.native_app.core.datastore.ArtemisNotificationManager
import de.tum.informatics.www1.artemis.native_app.core.datastore.ServerConfigurationService
import de.tum.informatics.www1.artemis.native_app.core.datastore.authToken
import de.tum.informatics.www1.artemis.native_app.core.ui.remote_images.ArtemisImageProvider
import de.tum.informatics.www1.artemis.native_app.feature.push.PushCommunicationDatabaseProvider
import de.tum.informatics.www1.artemis.native_app.feature.push.R
Expand All @@ -29,6 +33,7 @@ import de.tum.informatics.www1.artemis.native_app.feature.push.notification_mode
import de.tum.informatics.www1.artemis.native_app.feature.push.notification_model.parentId
import de.tum.informatics.www1.artemis.native_app.feature.push.service.CommunicationNotificationManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.datetime.Instant
Expand All @@ -43,15 +48,26 @@ internal class CommunicationNotificationManagerImpl(
private val context: Context,
private val dbProvider: PushCommunicationDatabaseProvider,
private val artemisImageProvider: ArtemisImageProvider,
private val serverConfigurationService: ServerConfigurationService,
private val accountService: AccountService,
private val accountDataService: AccountDataService,
) : CommunicationNotificationManager, BaseNotificationManager {

override suspend fun popNotification(
artemisNotification: ArtemisNotification<CommunicationNotificationType>
) {
var isPostFromAppUser = false
val (communication, messages) = dbProvider.database.withTransaction {
dbProvider.pushCommunicationDao.insertNotification(artemisNotification) {
ArtemisNotificationManager.getNextNotificationId(context)
}
dbProvider.pushCommunicationDao.insertNotification(
artemisNotification = artemisNotification,
generateNotificationId = {
ArtemisNotificationManager.getNextNotificationId(context)
},
isPostFromAppUser = { content ->
isPostFromAppUser = content.authorId == getClientId().toString()
isPostFromAppUser
}
)

val parentId = artemisNotification.parentId

Expand All @@ -64,11 +80,31 @@ internal class CommunicationNotificationManagerImpl(
communication to messages
}

// Without this check, we would pop previous notifications in the following scenario:
// 1. App user creates post1.
// 2. Other user replies answer1 in post1's thread.
// -> User gets notification for answer1 (desired).
// 3. App user replies answer2 in post1's thread.
// -> User would get not get notification for answer2 (desired).
// -> BUT: Notification for answer1 would be popped again (not desired).
if (isPostFromAppUser) return

if (messages.isEmpty()) return
popCommunicationNotification(communication, messages)
}

private suspend fun getClientId(): Long? {
val serverUrl = serverConfigurationService.serverUrl.first()
val authToken = accountService.authToken.first()

val accountData = accountDataService.getCachedAccountData(
serverUrl = serverUrl,
bearerToken = authToken
)

return accountData?.id
}

override suspend fun addSelfMessage(
parentId: Long,
authorName: String,
Expand Down
Loading