mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Move notification sound and badge settings to settings store
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
deriveAlertStatus,
|
||||
userInboxRelays,
|
||||
getAlertFeed,
|
||||
showUnreadBadge,
|
||||
playAlertSound,
|
||||
userSettingsValues,
|
||||
} from "@app/core/state"
|
||||
import {deleteAlert, createDmAlert} from "@app/core/commands"
|
||||
import {clearBadges} from "../util/notifications"
|
||||
@@ -74,15 +73,15 @@
|
||||
}
|
||||
|
||||
const onShowBadgeOnUnreadToggle = async () => {
|
||||
$showUnreadBadge = !$showUnreadBadge
|
||||
$userSettingsValues.show_notifications_badge = !$userSettingsValues.show_notifications_badge
|
||||
|
||||
if (!$showUnreadBadge) {
|
||||
if (!$userSettingsValues.show_notifications_badge) {
|
||||
await clearBadges()
|
||||
}
|
||||
}
|
||||
|
||||
const onDirectMessagesNotificationSoundToggle = async () => {
|
||||
$playAlertSound = !$playAlertSound
|
||||
$userSettingsValues.play_notification_sound = !$userSettingsValues.play_notification_sound
|
||||
}
|
||||
|
||||
let directMessagesNotificationToggle: HTMLInputElement
|
||||
@@ -123,7 +122,7 @@
|
||||
<input
|
||||
type="checkbox"
|
||||
class="toggle toggle-primary"
|
||||
checked={Boolean($showUnreadBadge)}
|
||||
checked={Boolean($userSettingsValues.show_notifications_badge)}
|
||||
oninput={onShowBadgeOnUnreadToggle} />
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
@@ -131,7 +130,7 @@
|
||||
<input
|
||||
type="checkbox"
|
||||
class="toggle toggle-primary"
|
||||
checked={Boolean($playAlertSound)}
|
||||
checked={Boolean($userSettingsValues.play_notification_sound)}
|
||||
oninput={onDirectMessagesNotificationSoundToggle} />
|
||||
</div>
|
||||
{#if $dmStatus}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {playAlertSound} from "@app/core/state"
|
||||
import {userSettingsValues} from "@app/core/state"
|
||||
import {notifications} from "../util/notifications"
|
||||
|
||||
let audioElement: HTMLAudioElement
|
||||
@@ -8,7 +8,7 @@
|
||||
let notificationCount = $state($notifications.size)
|
||||
|
||||
const playSound = () => {
|
||||
if ($playAlertSound) {
|
||||
if ($userSettingsValues.play_notification_sound) {
|
||||
audioElement.play()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +338,8 @@ export type SettingsValues = {
|
||||
report_errors: boolean
|
||||
send_delay: number
|
||||
font_size: number
|
||||
play_notification_sound: boolean
|
||||
show_notifications_badge: boolean
|
||||
}
|
||||
|
||||
export type Settings = {
|
||||
@@ -353,6 +355,8 @@ export const defaultSettings = {
|
||||
report_errors: true,
|
||||
send_delay: 0,
|
||||
font_size: 1,
|
||||
play_notification_sound: true,
|
||||
show_notifications_badge: true,
|
||||
}
|
||||
|
||||
export const settings = deriveEventsMapped<Settings>(repository, {
|
||||
@@ -425,18 +429,6 @@ export const dmAlert = derived(alerts, $alerts =>
|
||||
}),
|
||||
)
|
||||
|
||||
export const showUnreadBadge = synced({
|
||||
key: "showUnreadBadge",
|
||||
defaultValue: true,
|
||||
storage: preferencesStorageProvider,
|
||||
})
|
||||
|
||||
export const playAlertSound = synced({
|
||||
key: "playAlertSound",
|
||||
defaultValue: true,
|
||||
storage: preferencesStorageProvider,
|
||||
})
|
||||
|
||||
// Alert Statuses
|
||||
|
||||
export type AlertStatus = {
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
getUrlsForEvent,
|
||||
userRoomsByUrl,
|
||||
repositoryStore,
|
||||
showUnreadBadge,
|
||||
userSettingsValues,
|
||||
} from "@app/core/state"
|
||||
import {preferencesStorageProvider} from "@src/lib/storage"
|
||||
import {Badge} from "@capawesome/capacitor-badge"
|
||||
@@ -168,7 +168,7 @@ export const badgeCount = derived(notifications, notifications => {
|
||||
})
|
||||
|
||||
export const handleBadgeCountChanges = async (count: number) => {
|
||||
if (get(showUnreadBadge)) {
|
||||
if (get(userSettingsValues).show_notifications_badge) {
|
||||
await Badge.set({count})
|
||||
} else {
|
||||
await clearBadges()
|
||||
|
||||
Reference in New Issue
Block a user