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