Fix some notification related bugs
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
deriveUserIsRoomAdmin,
|
||||
deriveUserRoomMembershipStatus,
|
||||
deriveUserRooms,
|
||||
deriveIsMuted,
|
||||
deriveShouldNotify,
|
||||
MembershipStatus,
|
||||
} from "@app/core/state"
|
||||
import {
|
||||
@@ -58,7 +58,7 @@
|
||||
const userRooms = deriveUserRooms(url)
|
||||
|
||||
const isFavorite = $derived($userRooms.includes(h))
|
||||
const isMuted = deriveIsMuted(url, h)
|
||||
const shouldNotify = deriveShouldNotify(url, h)
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
const toggleMute = () => {
|
||||
const toggleShouldNotify = () => {
|
||||
toggleRoomNotifications(url, h)
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@
|
||||
<input
|
||||
type="checkbox"
|
||||
class="toggle toggle-primary"
|
||||
checked={!isMuted}
|
||||
onchange={toggleMute} />
|
||||
checked={$shouldNotify}
|
||||
onchange={toggleShouldNotify} />
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
deriveUserIsSpaceAdmin,
|
||||
deriveEventsForUrl,
|
||||
notificationSettings,
|
||||
deriveIsMuted,
|
||||
deriveShouldNotify,
|
||||
} from "@app/core/state"
|
||||
import {setSpaceNotifications} from "@app/core/commands"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
@@ -98,10 +98,10 @@
|
||||
|
||||
const addRoom = () => pushModal(RoomCreate, {url}, {replaceState})
|
||||
|
||||
const isMuted = deriveIsMuted(url)
|
||||
const shouldNotify = deriveShouldNotify(url)
|
||||
|
||||
const toggleSpaceNotifications = () => {
|
||||
setSpaceNotifications(url, !isMuted)
|
||||
setSpaceNotifications(url, !$shouldNotify)
|
||||
}
|
||||
|
||||
let showMenu = $state(false)
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="flex items-center justify-between">
|
||||
<strong class="ellipsize flex items-center gap-1">
|
||||
<RelayName {url} />
|
||||
{#if isMuted}
|
||||
{#if $notificationSettings.push && !$shouldNotify}
|
||||
<Icon icon={VolumeCross} size={3} class="opacity-50" />
|
||||
{/if}
|
||||
</strong>
|
||||
@@ -172,8 +172,8 @@
|
||||
<li>
|
||||
{#if $notificationSettings.push}
|
||||
<Button onclick={toggleSpaceNotifications}>
|
||||
<Icon icon={isMuted ? VolumeCross : VolumeLoud} />
|
||||
{isMuted ? "Turn on" : "Turn off"} notifications
|
||||
<Icon icon={$shouldNotify ? VolumeLoud : VolumeCross} />
|
||||
{$shouldNotify ? "Turn off" : "Turn on"} notifications
|
||||
</Button>
|
||||
{:else}
|
||||
<Link href="/settings/alerts">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import RoomNameWithImage from "@app/components/RoomNameWithImage.svelte"
|
||||
import {makeRoomPath} from "@app/util/routes"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
import {deriveIsMuted} from "@app/core/state"
|
||||
import {deriveShouldNotify} from "@app/core/state"
|
||||
|
||||
interface Props {
|
||||
url: any
|
||||
@@ -18,9 +18,9 @@
|
||||
const {url, h, notify = false, replaceState = false}: Props = $props()
|
||||
|
||||
const path = makeRoomPath(url, h)
|
||||
const isSpaceMuted = deriveIsMuted(url)
|
||||
const isRoomMuted = deriveIsMuted(url, h)
|
||||
const showDifferenceIcon = $derived($isRoomMuted !== $isSpaceMuted)
|
||||
const shouldNotifyForSpace = deriveShouldNotify(url)
|
||||
const shouldNotifyForRoom = deriveShouldNotify(url, h)
|
||||
const showDifferenceIcon = $derived($shouldNotifyForRoom !== $shouldNotifyForSpace)
|
||||
</script>
|
||||
|
||||
<SecondaryNavItem
|
||||
@@ -29,6 +29,6 @@
|
||||
notification={notify ? $notifications.has(path) : false}>
|
||||
<RoomNameWithImage {url} {h} />
|
||||
{#if showDifferenceIcon}
|
||||
<Icon icon={isRoomMuted ? VolumeCross : VolumeLoud} size={4} class="opacity-50" />
|
||||
<Icon icon={$shouldNotifyForRoom ? VolumeLoud : VolumeCross} size={4} class="opacity-50" />
|
||||
{/if}
|
||||
</SecondaryNavItem>
|
||||
|
||||
@@ -1002,8 +1002,7 @@ export const parseInviteLink = (invite: string): InviteData | undefined => {
|
||||
|
||||
// Hierarchical notification helpers
|
||||
|
||||
export const isMuted = (url: string, h?: string) => {
|
||||
const {alerts} = getSettings()
|
||||
export const getShouldNotify = ({alerts}: SettingsValues, url: string, h?: string) => {
|
||||
const pref = alerts.find(spec({url}))
|
||||
|
||||
if (!pref) return true
|
||||
@@ -1012,5 +1011,7 @@ export const isMuted = (url: string, h?: string) => {
|
||||
if (!pref.notify) return pref.exceptions.includes(h)
|
||||
}
|
||||
|
||||
export const deriveIsMuted = (url: string, h?: string) =>
|
||||
derived(userSettingsValues, () => isMuted(url, h))
|
||||
export const shouldNotify = (url: string, h?: string) => getShouldNotify(getSettings(), url, h)
|
||||
|
||||
export const deriveShouldNotify = (url: string, h?: string) =>
|
||||
derived(userSettingsValues, $settings => getShouldNotify($settings, url, h))
|
||||
|
||||
@@ -78,7 +78,7 @@ import {
|
||||
getSpaceRoomsFromGroupList,
|
||||
makeCommentFilter,
|
||||
userSpaceUrls,
|
||||
isMuted,
|
||||
shouldNotify,
|
||||
device,
|
||||
} from "@app/core/state"
|
||||
import {kv} from "@app/core/storage"
|
||||
@@ -286,7 +286,7 @@ export const onNotification = call(() => {
|
||||
|
||||
const h = getTagValue("h", event.tags)
|
||||
|
||||
if (Array.from(tracker.getRelays(event.id)).every(url => isMuted(url, h))) {
|
||||
if (Array.from(tracker.getRelays(event.id)).every(url => !shouldNotify(url, h))) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user