Skip to content

Commit f7303d6

Browse files
committed
Fix bean definitions and use strict equality check
1 parent 682e1f2 commit f7303d6

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

backend/src/main/kotlin/hu/bme/sch/cmsch/component/pushnotification/FirebaseMessagingConfiguration.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.springframework.retry.policy.SimpleRetryPolicy
1313
import org.springframework.retry.support.RetryTemplate
1414

1515
@Configuration
16+
@ConditionalOnBean(PushNotificationComponent::class)
1617
class FirebaseMessagingConfiguration {
1718
private val messagingScope = "https://www.googleapis.com/auth/firebase.messaging"
1819

backend/src/main/kotlin/hu/bme/sch/cmsch/component/pushnotification/MessagingTokenEntity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package hu.bme.sch.cmsch.component.pushnotification
22

33
import jakarta.persistence.*
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
45

56
@Entity
67
@Table(
78
name = "messaging_tokens",
89
indexes = [Index(columnList = "userId"), Index(columnList = "userId,token", unique = true)]
910
)
11+
@ConditionalOnBean(PushNotificationComponent::class)
1012
class MessagingTokenEntity(
1113
@Id
1214
@GeneratedValue(strategy = GenerationType.SEQUENCE)

backend/src/main/kotlin/hu/bme/sch/cmsch/component/pushnotification/MessagingTokenRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package hu.bme.sch.cmsch.component.pushnotification
22

33
import hu.bme.sch.cmsch.model.RoleType
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
45
import org.springframework.data.jpa.repository.JpaRepository
56
import org.springframework.data.jpa.repository.Query
67

8+
@ConditionalOnBean(PushNotificationComponent::class)
79
interface MessagingTokenRepository : JpaRepository<MessagingTokenEntity, Long> {
810

911
@Query("select m.token from MessagingTokenEntity m")

frontend/src/common-components/EnableNotifications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useConfigContext } from '../api/contexts/config/ConfigContext.tsx'
44
export const EnableNotifications = () => {
55
const { isOpen, onClose } = useDisclosure({ defaultIsOpen: true })
66
const config = useConfigContext()
7-
if (Notification.permission != 'default') return null // we cannot ask again
7+
if (Notification.permission !== 'default') return null // we cannot ask again
88

99
const component = config.components.pushnotification
1010
if (!component?.notificationsEnabled || !isOpen || !shouldShowAlert(component.permissionAllowNeverShowAgain)) return null

frontend/src/util/configs/firebase.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ export async function initNotifications(messaging: Messaging, onNotification: (p
3737
await axios.post(ApiPaths.ADD_PUSH_NOTIFICATION_TOKEN, { token })
3838
}
3939

40-
export async function disableNotifications() {
41-
return unregisterServiceWorker()
42-
}
40+
export const disableNotifications = () => unregisterServiceWorker()
4341

4442
export async function unsubscribeFromNotifications() {
45-
if (Notification.permission != 'granted') return // There is nothing to unsubscribe from
43+
if (Notification.permission !== 'granted') return // We cannot obtain a messaging token if the permission is not granted
4644

4745
try {
4846
const messaging = getCloudMessaging()

0 commit comments

Comments
 (0)