forked from coracle/flotilla
Generally just refactor alerts, upgrade some deps
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
--ignore-dir=build
|
||||
--ignore-dir=ios/DerivedData
|
||||
--ignore-dir=ios/App/App/public
|
||||
--ignore-dir=ios/App/Pods
|
||||
--ignore-file=match:.svg
|
||||
--ignore-file=match:package-lock.json
|
||||
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
include ':capacitor-android'
|
||||
project(':capacitor-android').projectDir = new File('../node_modules/.pnpm/@capacitor+android@7.4.3_@capacitor+core@7.4.3/node_modules/@capacitor/android/capacitor')
|
||||
project(':capacitor-android').projectDir = new File('../node_modules/.pnpm/@capacitor+android@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor/android/capacitor')
|
||||
|
||||
include ':capacitor-community-safe-area'
|
||||
project(':capacitor-community-safe-area').projectDir = new File('../node_modules/.pnpm/@capacitor-community+safe-area@7.0.0-alpha.1_@capacitor+core@7.4.3/node_modules/@capacitor-community/safe-area/android')
|
||||
project(':capacitor-community-safe-area').projectDir = new File('../node_modules/.pnpm/@capacitor-community+safe-area@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor-community/safe-area/android')
|
||||
|
||||
include ':capacitor-app'
|
||||
project(':capacitor-app').projectDir = new File('../node_modules/.pnpm/@capacitor+app@7.1.0_@capacitor+core@7.4.3/node_modules/@capacitor/app/android')
|
||||
project(':capacitor-app').projectDir = new File('../node_modules/.pnpm/@capacitor+app@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/app/android')
|
||||
|
||||
include ':capacitor-filesystem'
|
||||
project(':capacitor-filesystem').projectDir = new File('../node_modules/.pnpm/@capacitor+filesystem@7.1.4_@capacitor+core@7.4.3/node_modules/@capacitor/filesystem/android')
|
||||
project(':capacitor-filesystem').projectDir = new File('../node_modules/.pnpm/@capacitor+filesystem@8.1.0_@capacitor+core@8.0.1/node_modules/@capacitor/filesystem/android')
|
||||
|
||||
include ':capacitor-keyboard'
|
||||
project(':capacitor-keyboard').projectDir = new File('../node_modules/.pnpm/@capacitor+keyboard@7.0.3_@capacitor+core@7.4.3/node_modules/@capacitor/keyboard/android')
|
||||
project(':capacitor-keyboard').projectDir = new File('../node_modules/.pnpm/@capacitor+keyboard@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/keyboard/android')
|
||||
|
||||
include ':capacitor-preferences'
|
||||
project(':capacitor-preferences').projectDir = new File('../node_modules/.pnpm/@capacitor+preferences@7.0.2_@capacitor+core@7.4.3/node_modules/@capacitor/preferences/android')
|
||||
project(':capacitor-preferences').projectDir = new File('../node_modules/.pnpm/@capacitor+preferences@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/preferences/android')
|
||||
|
||||
include ':capacitor-push-notifications'
|
||||
project(':capacitor-push-notifications').projectDir = new File('../node_modules/.pnpm/@capacitor+push-notifications@7.0.3_@capacitor+core@7.4.3/node_modules/@capacitor/push-notifications/android')
|
||||
project(':capacitor-push-notifications').projectDir = new File('../node_modules/.pnpm/@capacitor+push-notifications@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/push-notifications/android')
|
||||
|
||||
include ':capawesome-capacitor-android-dark-mode-support'
|
||||
project(':capawesome-capacitor-android-dark-mode-support').projectDir = new File('../node_modules/.pnpm/@capawesome+capacitor-android-dark-mode-support@7.0.0_@capacitor+core@7.4.3/node_modules/@capawesome/capacitor-android-dark-mode-support/android')
|
||||
project(':capawesome-capacitor-android-dark-mode-support').projectDir = new File('../node_modules/.pnpm/@capawesome+capacitor-android-dark-mode-support@8.0.0_@capacitor+core@8.0.1/node_modules/@capawesome/capacitor-android-dark-mode-support/android')
|
||||
|
||||
include ':capawesome-capacitor-badge'
|
||||
project(':capawesome-capacitor-badge').projectDir = new File('../node_modules/.pnpm/@capawesome+capacitor-badge@7.0.1_@capacitor+core@7.4.3/node_modules/@capawesome/capacitor-badge/android')
|
||||
project(':capawesome-capacitor-badge').projectDir = new File('../node_modules/.pnpm/@capawesome+capacitor-badge@8.0.0_@capacitor+core@8.0.1/node_modules/@capawesome/capacitor-badge/android')
|
||||
|
||||
include ':nostr-signer-capacitor-plugin'
|
||||
project(':nostr-signer-capacitor-plugin').projectDir = new File('../node_modules/.pnpm/nostr-signer-capacitor-plugin@0.0.4_@capacitor+core@7.4.3/node_modules/nostr-signer-capacitor-plugin/android')
|
||||
project(':nostr-signer-capacitor-plugin').projectDir = new File('../node_modules/.pnpm/nostr-signer-capacitor-plugin@0.0.4_@capacitor+core@8.0.1/node_modules/nostr-signer-capacitor-plugin/android')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
ext {
|
||||
minSdkVersion = 23
|
||||
compileSdkVersion = 35
|
||||
targetSdkVersion = 35
|
||||
compileSdkVersion = 36
|
||||
targetSdkVersion = 36
|
||||
androidxActivityVersion = '1.9.2'
|
||||
//https://github.com/ionic-team/capacitor/issues/7866
|
||||
// androidxAppCompatVersion = '1.7.0'
|
||||
|
||||
+11
-11
@@ -1,4 +1,4 @@
|
||||
require_relative '../../node_modules/.pnpm/@capacitor+ios@7.4.3_@capacitor+core@7.4.3/node_modules/@capacitor/ios/scripts/pods_helpers'
|
||||
require_relative '../../node_modules/.pnpm/@capacitor+ios@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor/ios/scripts/pods_helpers'
|
||||
|
||||
platform :ios, '14.0'
|
||||
use_frameworks!
|
||||
@@ -9,16 +9,16 @@ use_frameworks!
|
||||
install! 'cocoapods', :disable_input_output_paths => true
|
||||
|
||||
def capacitor_pods
|
||||
pod 'Capacitor', :path => '../../node_modules/.pnpm/@capacitor+ios@7.4.3_@capacitor+core@7.4.3/node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCordova', :path => '../../node_modules/.pnpm/@capacitor+ios@7.4.3_@capacitor+core@7.4.3/node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCommunitySafeArea', :path => '../../node_modules/.pnpm/@capacitor-community+safe-area@7.0.0-alpha.1_@capacitor+core@7.4.3/node_modules/@capacitor-community/safe-area'
|
||||
pod 'CapacitorApp', :path => '../../node_modules/.pnpm/@capacitor+app@7.1.0_@capacitor+core@7.4.3/node_modules/@capacitor/app'
|
||||
pod 'CapacitorFilesystem', :path => '../../node_modules/.pnpm/@capacitor+filesystem@7.1.4_@capacitor+core@7.4.3/node_modules/@capacitor/filesystem'
|
||||
pod 'CapacitorKeyboard', :path => '../../node_modules/.pnpm/@capacitor+keyboard@7.0.3_@capacitor+core@7.4.3/node_modules/@capacitor/keyboard'
|
||||
pod 'CapacitorPreferences', :path => '../../node_modules/.pnpm/@capacitor+preferences@7.0.2_@capacitor+core@7.4.3/node_modules/@capacitor/preferences'
|
||||
pod 'CapacitorPushNotifications', :path => '../../node_modules/.pnpm/@capacitor+push-notifications@7.0.3_@capacitor+core@7.4.3/node_modules/@capacitor/push-notifications'
|
||||
pod 'CapawesomeCapacitorBadge', :path => '../../node_modules/.pnpm/@capawesome+capacitor-badge@7.0.1_@capacitor+core@7.4.3/node_modules/@capawesome/capacitor-badge'
|
||||
pod 'NostrSignerCapacitorPlugin', :path => '../../node_modules/.pnpm/nostr-signer-capacitor-plugin@0.0.4_@capacitor+core@7.4.3/node_modules/nostr-signer-capacitor-plugin'
|
||||
pod 'Capacitor', :path => '../../node_modules/.pnpm/@capacitor+ios@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCordova', :path => '../../node_modules/.pnpm/@capacitor+ios@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCommunitySafeArea', :path => '../../node_modules/.pnpm/@capacitor-community+safe-area@8.0.1_@capacitor+core@8.0.1/node_modules/@capacitor-community/safe-area'
|
||||
pod 'CapacitorApp', :path => '../../node_modules/.pnpm/@capacitor+app@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/app'
|
||||
pod 'CapacitorFilesystem', :path => '../../node_modules/.pnpm/@capacitor+filesystem@8.1.0_@capacitor+core@8.0.1/node_modules/@capacitor/filesystem'
|
||||
pod 'CapacitorKeyboard', :path => '../../node_modules/.pnpm/@capacitor+keyboard@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/keyboard'
|
||||
pod 'CapacitorPreferences', :path => '../../node_modules/.pnpm/@capacitor+preferences@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/preferences'
|
||||
pod 'CapacitorPushNotifications', :path => '../../node_modules/.pnpm/@capacitor+push-notifications@8.0.0_@capacitor+core@8.0.1/node_modules/@capacitor/push-notifications'
|
||||
pod 'CapawesomeCapacitorBadge', :path => '../../node_modules/.pnpm/@capawesome+capacitor-badge@8.0.0_@capacitor+core@8.0.1/node_modules/@capawesome/capacitor-badge'
|
||||
pod 'NostrSignerCapacitorPlugin', :path => '../../node_modules/.pnpm/nostr-signer-capacitor-plugin@0.0.4_@capacitor+core@8.0.1/node_modules/nostr-signer-capacitor-plugin'
|
||||
end
|
||||
|
||||
target 'Flotilla Chat' do
|
||||
|
||||
+12
-12
@@ -37,18 +37,18 @@
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@capacitor-community/safe-area": "7.0.0-alpha.1",
|
||||
"@capacitor/android": "^7.4.3",
|
||||
"@capacitor/app": "^7.1.0",
|
||||
"@capacitor/cli": "^7.4.3",
|
||||
"@capacitor/core": "^7.4.3",
|
||||
"@capacitor/filesystem": "^7.1.4",
|
||||
"@capacitor/ios": "^7.4.3",
|
||||
"@capacitor/keyboard": "^7.0.3",
|
||||
"@capacitor/preferences": "^7.0.2",
|
||||
"@capacitor/push-notifications": "^7.0.3",
|
||||
"@capawesome/capacitor-android-dark-mode-support": "^7.0.0",
|
||||
"@capawesome/capacitor-badge": "^7.0.1",
|
||||
"@capacitor-community/safe-area": "^8.0.1",
|
||||
"@capacitor/android": "^8.0.1",
|
||||
"@capacitor/app": "^8.0.0",
|
||||
"@capacitor/cli": "^8.0.1",
|
||||
"@capacitor/core": "^8.0.1",
|
||||
"@capacitor/filesystem": "^8.1.0",
|
||||
"@capacitor/ios": "^8.0.1",
|
||||
"@capacitor/keyboard": "^8.0.0",
|
||||
"@capacitor/preferences": "^8.0.0",
|
||||
"@capacitor/push-notifications": "^8.0.0",
|
||||
"@capawesome/capacitor-android-dark-mode-support": "^8.0.0",
|
||||
"@capawesome/capacitor-badge": "^8.0.0",
|
||||
"@getalby/lightning-tools": "^6.0.0",
|
||||
"@getalby/sdk": "^5.1.2",
|
||||
"@pomade/core": "^0.0.12",
|
||||
|
||||
Generated
+916
-815
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {userSettingsValues} from "@app/core/state"
|
||||
import {notifications} from "../util/notifications"
|
||||
import {onNotification} from "@app/util/notifications"
|
||||
|
||||
let audioElement: HTMLAudioElement
|
||||
|
||||
@@ -15,24 +15,16 @@
|
||||
}
|
||||
})
|
||||
|
||||
let notificationCount = $state($notifications.size)
|
||||
|
||||
const playSound = () => {
|
||||
if (enabled && $userSettingsValues.alerts_sound) {
|
||||
audioElement?.play()
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if ($notifications.size > notificationCount) {
|
||||
playSound()
|
||||
}
|
||||
|
||||
notificationCount = $notifications.size
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
audioElement.load()
|
||||
|
||||
const unsubscribe = onNotification(() => {
|
||||
if (enabled && $userSettingsValues.alerts_sound) {
|
||||
audioElement?.play()
|
||||
}
|
||||
})
|
||||
|
||||
return unsubscribe
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-sm opacity-75">
|
||||
<div class="flex flex-col justify-between text-sm opacity-75 sm:flex-row">
|
||||
<p>
|
||||
Logged in with
|
||||
{#if $session.method === SessionMethod.Nip01}
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
</script>
|
||||
|
||||
<div bind:this={element} class="flex h-full flex-col justify-between">
|
||||
<SecondaryNavSection>
|
||||
<SecondaryNavSection class="pb-0">
|
||||
<div>
|
||||
<Button
|
||||
class="flex w-full flex-col rounded-xl p-3 transition-all hover:bg-base-100"
|
||||
@@ -172,7 +172,7 @@
|
||||
</Popover>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex max-h-[calc(100vh-250px)] min-h-0 flex-col gap-1 overflow-auto">
|
||||
<div class="flex max-h-[calc(100vh-150px)] min-h-0 flex-col gap-1 overflow-auto">
|
||||
{#if hasNip29($relay)}
|
||||
<SecondaryNavItem {replaceState} href={makeSpacePath(url, "recent")}>
|
||||
<Icon icon={History} /> Recent Activity
|
||||
@@ -239,7 +239,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
</SecondaryNavSection>
|
||||
<div class="flex flex-col gap-2 p-4">
|
||||
<div class="flex flex-col gap-2 p-4 pt-0">
|
||||
<Button class="btn btn-neutral btn-sm" onclick={showDetail}>
|
||||
<SocketStatusIndicator {url} />
|
||||
</Button>
|
||||
|
||||
@@ -15,11 +15,6 @@ import {
|
||||
import {
|
||||
EVENT_TIME,
|
||||
RELAY_INVITE,
|
||||
ALERT_EMAIL,
|
||||
ALERT_WEB,
|
||||
ALERT_IOS,
|
||||
ALERT_ANDROID,
|
||||
ALERT_STATUS,
|
||||
matchFilters,
|
||||
getTagValue,
|
||||
getAddress,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import twColors from "tailwindcss/colors"
|
||||
import {context as pomadeContext} from "@pomade/core"
|
||||
import {Capacitor} from "@capacitor/core"
|
||||
import {get, derived, readable, writable} from "svelte/store"
|
||||
import {derived, readable, writable} from "svelte/store"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {
|
||||
on,
|
||||
@@ -323,11 +323,9 @@ export const settingsByPubkey = deriveItemsByKey({
|
||||
|
||||
export const getSettingsByPubkey = getter(settingsByPubkey)
|
||||
|
||||
export const getSettings = (pubkey: string) => getSettingsByPubkey().get(pubkey)
|
||||
|
||||
export const loadSettings = makeLoadItem(
|
||||
makeOutboxLoader(APP_DATA, {"#d": [SETTINGS]}),
|
||||
getSettings,
|
||||
(pubkey: string) => getSettingsByPubkey().get(pubkey),
|
||||
)
|
||||
|
||||
export const userSettings = makeUserData(settingsByPubkey, loadSettings)
|
||||
@@ -336,7 +334,9 @@ export const loadUserSettings = makeUserLoader(loadSettings)
|
||||
|
||||
export const userSettingsValues = derived(userSettings, $s => $s?.values || defaultSettings)
|
||||
|
||||
export const getSetting = <T>(key: keyof Settings["values"]) => get(userSettingsValues)[key] as T
|
||||
export const getSettings = getter(userSettingsValues)
|
||||
|
||||
export const getSetting = <T>(key: keyof Settings["values"]) => getSettings()[key] as T
|
||||
|
||||
// Relays sending events with empty signatures that the user has to choose to trust
|
||||
|
||||
@@ -346,11 +346,11 @@ export const relaysPendingTrust = writable<string[]>([])
|
||||
|
||||
export const relaysMostlyRestricted = writable<Record<string, string>>({})
|
||||
|
||||
// Alerts
|
||||
// Push notifications
|
||||
|
||||
export const alertToken = writable<string | undefined>()
|
||||
export const pushToken = writable<string | undefined>()
|
||||
|
||||
export const alertSecret = writable<string | undefined>()
|
||||
export const pushSecret = writable<string | undefined>()
|
||||
|
||||
// Chats
|
||||
|
||||
|
||||
+186
-143
@@ -1,4 +1,4 @@
|
||||
import type {Unsubscriber} from "svelte/store"
|
||||
import type {Unsubscriber, Subscriber} from "svelte/store"
|
||||
import {derived, get} from "svelte/store"
|
||||
import {Capacitor} from "@capacitor/core"
|
||||
import {Badge} from "@capawesome/capacitor-badge"
|
||||
@@ -14,17 +14,19 @@ import {
|
||||
publishThunk,
|
||||
getPubkeyRelays,
|
||||
loadRelay,
|
||||
waitForThunkError,
|
||||
} from "@welshman/app"
|
||||
import type {Maybe
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
on,
|
||||
call,
|
||||
assoc,
|
||||
poll,
|
||||
prop,
|
||||
sha256,
|
||||
textEncoder,
|
||||
parseJson,
|
||||
ms,
|
||||
maybe,
|
||||
int,
|
||||
MINUTE,
|
||||
flatten,
|
||||
find,
|
||||
spec,
|
||||
@@ -32,18 +34,12 @@ import {
|
||||
identity,
|
||||
now,
|
||||
groupBy,
|
||||
hash,
|
||||
tryCatch,
|
||||
postJson,
|
||||
fetchJson,
|
||||
} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {
|
||||
deriveEventsByIdByUrl,
|
||||
deriveEventsById,
|
||||
deriveEventsDesc,
|
||||
deriveDeduplicated,
|
||||
} from "@welshman/store"
|
||||
import type {TrustedEvent, Filter} from "@welshman/util"
|
||||
import {deriveEventsByIdByUrl} from "@welshman/store"
|
||||
import {
|
||||
ZAP_GOAL,
|
||||
EVENT_TIME,
|
||||
@@ -73,16 +69,18 @@ import {
|
||||
MESSAGE_KINDS,
|
||||
PUSH_BRIDGE,
|
||||
PUSH_SERVER,
|
||||
alertToken,
|
||||
alertSecret,
|
||||
pushToken,
|
||||
pushSecret,
|
||||
chatsById,
|
||||
hasNip29,
|
||||
getSetting,
|
||||
getSettings,
|
||||
userSettingsValues,
|
||||
userGroupList,
|
||||
getSpaceUrlsFromGroupList,
|
||||
getSpaceRoomsFromGroupList,
|
||||
makeCommentFilter,
|
||||
userSpaceUrls,
|
||||
makeRoomId,
|
||||
} from "@app/core/state"
|
||||
import {kv} from "@app/core/storage"
|
||||
import {goto} from "$app/navigation"
|
||||
@@ -104,7 +102,7 @@ export const setChecked = (key: string) => checked.update(state => ({...state, [
|
||||
const goalCommentFilters = [{kinds: [COMMENT], "#K": [String(ZAP_GOAL)]}]
|
||||
const threadCommentFilters = [{kinds: [COMMENT], "#K": [String(THREAD)]}]
|
||||
const calendarCommentFilters = [{kinds: [COMMENT], "#K": [String(EVENT_TIME)]}]
|
||||
const messageFilters = [{kinds: CONTENT_KINDS}]
|
||||
const messageFilters = [{kinds: MESSAGE_KINDS}]
|
||||
const dmFilters = [{kinds: DM_KINDS}]
|
||||
const allFilters = flatten([
|
||||
goalCommentFilters,
|
||||
@@ -114,11 +112,6 @@ const allFilters = flatten([
|
||||
dmFilters,
|
||||
])
|
||||
|
||||
export const latestNotification = deriveDeduplicated(
|
||||
deriveEventsDesc(deriveEventsById({repository, filters: allFilters})),
|
||||
first,
|
||||
)
|
||||
|
||||
export const notifications = derived(
|
||||
throttled(
|
||||
1000,
|
||||
@@ -268,55 +261,107 @@ export const notifications = derived(
|
||||
},
|
||||
)
|
||||
|
||||
// Badges
|
||||
export const onNotification = call(() => {
|
||||
const filters = allFilters.map(assoc("since", now()))
|
||||
const subscribers: Subscriber<TrustedEvent>[] = []
|
||||
|
||||
export const badgeCount = derived(notifications, notifications => {
|
||||
return notifications.size
|
||||
let unsubscribe: Unsubscriber | undefined
|
||||
|
||||
return (f: (event: TrustedEvent) => void) => {
|
||||
subscribers.push(f)
|
||||
|
||||
if (!unsubscribe) {
|
||||
unsubscribe = on(repository, "update", ({added}) => {
|
||||
const $pubkey = pubkey.get()
|
||||
const {muted_rooms} = getSettings()
|
||||
|
||||
for (const event of added) {
|
||||
if (event.pubkey == $pubkey) {
|
||||
continue
|
||||
}
|
||||
|
||||
const h = getTagValue("h", event.tags)
|
||||
const muted = Array.from(tracker.getRelays(event.id)).every(
|
||||
url => h && muted_rooms.includes(makeRoomId(url, h)),
|
||||
)
|
||||
|
||||
if (muted) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (matchFilters(filters, event)) {
|
||||
for (const f of subscribers) {
|
||||
f(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return () => {
|
||||
subscribers.splice(subscribers.indexOf(f), 1)
|
||||
|
||||
if (subscribers.length === 0) {
|
||||
unsubscribe?.()
|
||||
unsubscribe = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const handleBadgeCountChanges = async (count: number) => {
|
||||
if (getSetting<boolean>("alerts_badge")) {
|
||||
try {
|
||||
await Badge.set({count})
|
||||
} catch (err) {
|
||||
// failed to set badge
|
||||
}
|
||||
} else {
|
||||
await clearBadges()
|
||||
}
|
||||
}
|
||||
// Badges
|
||||
|
||||
export const syncBadges = () =>
|
||||
derived([notifications, userSettingsValues], identity).subscribe(
|
||||
async ([$notifications, {alerts_badge}]) => {
|
||||
if (alerts_badge) {
|
||||
try {
|
||||
await Badge.set({count: $notifications.size})
|
||||
} catch (err) {
|
||||
// pass - firefox doesn't support badges
|
||||
}
|
||||
} else {
|
||||
await clearBadges()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
export const clearBadges = async () => {
|
||||
try {
|
||||
await Badge.clear()
|
||||
} catch (e) {
|
||||
// Pass - firefox doesn't support this
|
||||
// pass - firefox doesn't support this
|
||||
}
|
||||
}
|
||||
|
||||
// Local notifications
|
||||
|
||||
interface IAlertsAdapter {
|
||||
interface IPushAdapter {
|
||||
request: () => Promise<string>
|
||||
start: () => Unsubscriber
|
||||
}
|
||||
|
||||
class CapacitorNotifications implements IAlertsAdapter {
|
||||
async ensureSubscription() {
|
||||
const token = get(alertToken)
|
||||
class CapacitorNotifications implements IPushAdapter {
|
||||
async sync() {
|
||||
const token = get(pushToken)
|
||||
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
|
||||
const info = await tryCatch(async () => {
|
||||
const secret = get(alertSecret)
|
||||
const info: Maybe<{
|
||||
secret: string
|
||||
callback: string
|
||||
}> = await tryCatch(async () => {
|
||||
const secret = get(pushSecret)
|
||||
|
||||
if (secret) {
|
||||
const {callback} = await fetchJson(`${PUSH_SERVER}/subscription/${secret}`)
|
||||
|
||||
if (callback) {
|
||||
return {secret, callback}
|
||||
} else {
|
||||
pushSecret.set(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,92 +373,85 @@ class CapacitorNotifications implements IAlertsAdapter {
|
||||
const json = await postJson(`${PUSH_SERVER}/subscription/${channel}`, data)
|
||||
|
||||
if (json) {
|
||||
return {
|
||||
secret: json.sk,
|
||||
callback: json.callback,
|
||||
} as {
|
||||
secret: string
|
||||
callback: string
|
||||
}
|
||||
pushSecret.set(json.sk)
|
||||
|
||||
return {secret: json.sk, callback: json.callback}
|
||||
}
|
||||
})
|
||||
|
||||
if (info) {
|
||||
alertSecret.set(info.secret)
|
||||
if (!info) {
|
||||
return
|
||||
}
|
||||
|
||||
const getPushStuff = async (url: string) => {
|
||||
let relay = await loadRelay(url)
|
||||
const getPushStuff = async (url: string) => {
|
||||
let relay = await loadRelay(url)
|
||||
|
||||
if (!relay?.self || !relay?.supported_nips?.includes("9a")) {
|
||||
relay = await loadRelay(PUSH_BRIDGE)
|
||||
}
|
||||
|
||||
if (relay?.self) {
|
||||
return {url: relay.url, pubkey: relay.self}
|
||||
}
|
||||
if (!relay?.self || !relay?.supported_nips?.includes("9a")) {
|
||||
relay = await loadRelay(PUSH_BRIDGE)
|
||||
}
|
||||
|
||||
for (const url of get(userSpaceUrls)) {
|
||||
const stuff = await getPushStuff(url)
|
||||
if (relay?.self) {
|
||||
return {url: relay.url, pubkey: relay.self}
|
||||
}
|
||||
}
|
||||
|
||||
if (!stuff) {
|
||||
console.warn(`Failed to subscribe ${url} to space notifications`)
|
||||
continue
|
||||
}
|
||||
const syncSubscription = async (
|
||||
key: string,
|
||||
relay: string,
|
||||
filters: Filter[],
|
||||
ignore: Filter[] = [],
|
||||
) => {
|
||||
const stuff = await getPushStuff(relay)
|
||||
|
||||
const filters = [{kinds: MESSAGE_KINDS}, makeCommentFilter(CONTENT_KINDS)]
|
||||
// const ignore = [] todo - muted rooms
|
||||
if (!stuff) {
|
||||
console.warn(`Failed to subscribe ${relay} to ${key} notifications: unsupported`)
|
||||
} else {
|
||||
const {url, pubkey} = stuff
|
||||
const identifier = await sha256(textEncoder.encode(info.callback + relay + key))
|
||||
|
||||
publishThunk({
|
||||
relays: [stuff.url],
|
||||
const thunk = publishThunk({
|
||||
relays: [url],
|
||||
event: makeEvent(30390, {
|
||||
content: await signer.get().nip44.encrypt(
|
||||
stuff.pubkey,
|
||||
JSON.stringify([
|
||||
["relay", url],
|
||||
["callback", info.callback],
|
||||
// ...ignore.map(filter => ["ignore", JSON.stringify(filter)]),
|
||||
...filters.map(filter => ["filter", JSON.stringify(filter)]),
|
||||
]),
|
||||
),
|
||||
content: await signer
|
||||
.get()
|
||||
.nip44.encrypt(
|
||||
pubkey,
|
||||
JSON.stringify([
|
||||
["relay", relay],
|
||||
["callback", info.callback],
|
||||
...ignore.map(filter => ["ignore", JSON.stringify(filter)]),
|
||||
...filters.map(filter => ["filter", JSON.stringify(filter)]),
|
||||
]),
|
||||
),
|
||||
tags: [
|
||||
["d", await sha256(textEncoder.encode(info.callback + url + "spaces"))],
|
||||
["p", stuff.pubkey],
|
||||
["d", identifier],
|
||||
["p", pubkey],
|
||||
],
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
const $pubkey = pubkey.get()!
|
||||
const error = await waitForThunkError(thunk)
|
||||
|
||||
for (const url of getPubkeyRelays($pubkey, RelayMode.Messaging)) {
|
||||
const stuff = await getPushStuff(url)
|
||||
|
||||
if (!stuff) {
|
||||
console.warn(`Failed to subscribe ${url} to messaging notifications`)
|
||||
continue
|
||||
if (error) {
|
||||
console.warn(`Failed to subscribe ${relay} to ${key} notifications:`, error)
|
||||
}
|
||||
|
||||
publishThunk({
|
||||
relays: [stuff.url],
|
||||
event: makeEvent(30390, {
|
||||
content: await signer.get().nip44.encrypt(
|
||||
stuff.pubkey,
|
||||
JSON.stringify([
|
||||
["relay", url],
|
||||
["callback", info.callback],
|
||||
["filter", JSON.stringify({kinds: DM_KINDS, "#p": [$pubkey]})],
|
||||
]),
|
||||
),
|
||||
tags: [
|
||||
["d", await sha256(textEncoder.encode(info.callback + url + "messages"))],
|
||||
["p", stuff.pubkey],
|
||||
],
|
||||
}),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
alertSecret.set(undefined)
|
||||
}
|
||||
|
||||
for (const relay of get(userSpaceUrls)) {
|
||||
const {muted_rooms} = getSettings()
|
||||
const filters = [{kinds: MESSAGE_KINDS}, makeCommentFilter(CONTENT_KINDS)]
|
||||
const ignore = [{"#h": [muted_rooms]}]
|
||||
|
||||
syncSubscription("spaces", relay, filters, ignore)
|
||||
}
|
||||
|
||||
const $pubkey = pubkey.get()!
|
||||
|
||||
for (const relay of getPubkeyRelays($pubkey, RelayMode.Messaging)) {
|
||||
const filters = [{kinds: DM_KINDS, "#p": [$pubkey]}]
|
||||
|
||||
syncSubscription("messages", relay, filters)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,18 +483,18 @@ class CapacitorNotifications implements IAlertsAdapter {
|
||||
})
|
||||
|
||||
if (token) {
|
||||
alertToken.set(token)
|
||||
pushToken.set(token)
|
||||
|
||||
return "granted"
|
||||
}
|
||||
|
||||
alertToken.set(undefined)
|
||||
pushToken.set(undefined)
|
||||
|
||||
return "denied"
|
||||
}
|
||||
|
||||
start() {
|
||||
this.ensureSubscription().then(() => {
|
||||
this.sync().then(() => {
|
||||
PushNotifications.addListener(
|
||||
"pushNotificationActionPerformed",
|
||||
async (action: ActionPerformed) => {
|
||||
@@ -472,7 +510,7 @@ class CapacitorNotifications implements IAlertsAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
class WebNotifications implements IAlertsAdapter {
|
||||
class WebNotifications implements IPushAdapter {
|
||||
async request() {
|
||||
if (Notification?.permission === "default") {
|
||||
await Notification.requestPermission()
|
||||
@@ -506,21 +544,19 @@ class WebNotifications implements IAlertsAdapter {
|
||||
}
|
||||
|
||||
start() {
|
||||
let initialized = false
|
||||
return onNotification(event => {
|
||||
const {alerts_messages, alerts_mentions, alerts_spaces} = getSettings()
|
||||
|
||||
return latestNotification.subscribe(event => {
|
||||
if (!initialized) {
|
||||
initialized = true
|
||||
} else if (event && document.hidden && Notification?.permission === "granted") {
|
||||
if (getSetting<boolean>("alerts_messages") && matchFilters(dmFilters, event)) {
|
||||
if (document.hidden && Notification?.permission === "granted") {
|
||||
if (alerts_messages && matchFilters(dmFilters, event)) {
|
||||
this.notify(event, "New direct message", "Someone sent you a direct message.")
|
||||
} else if (
|
||||
alerts_mentions &&
|
||||
event.pubkey !== pubkey.get() &&
|
||||
getSetting<boolean>("alerts_mentions") &&
|
||||
getPubkeyTagValues(event.tags).includes(pubkey.get()!)
|
||||
) {
|
||||
this.notify(event, "Someone mentioned you", "Someone tagged you in a message.")
|
||||
} else if (getSetting<boolean>("alerts_spaces")) {
|
||||
} else if (alerts_spaces) {
|
||||
this.notify(event, "New activity", "Someone posted a new message.")
|
||||
}
|
||||
}
|
||||
@@ -528,49 +564,56 @@ class WebNotifications implements IAlertsAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
export class Alerts {
|
||||
static _adapter: IAlertsAdapter | undefined
|
||||
export class Push {
|
||||
static _adapter: IPushAdapter | undefined
|
||||
static _unsubscriber: Unsubscriber | undefined
|
||||
|
||||
static _getAdapter() {
|
||||
if (!Alerts._adapter) {
|
||||
if (!Push._adapter) {
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
Alerts._adapter = new CapacitorNotifications()
|
||||
Push._adapter = new CapacitorNotifications()
|
||||
} else {
|
||||
Alerts._adapter = new WebNotifications()
|
||||
Push._adapter = new WebNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
return Alerts._adapter
|
||||
return Push._adapter
|
||||
}
|
||||
|
||||
static start() {
|
||||
return Alerts._getAdapter().start()
|
||||
return Push._getAdapter().start()
|
||||
}
|
||||
|
||||
static request() {
|
||||
return Alerts._getAdapter().request()
|
||||
return Push._getAdapter().request()
|
||||
}
|
||||
|
||||
static resume() {
|
||||
if (getSetting<boolean>("alerts_push")) {
|
||||
const promise = Alerts.request()
|
||||
const controller = new AbortController()
|
||||
const unsubscribe = userSettingsValues.subscribe(({alerts_push}) => {
|
||||
if (alerts_push) {
|
||||
const promise = Push.request()
|
||||
const controller = new AbortController()
|
||||
|
||||
promise.then(permissions => {
|
||||
if (permissions === "granted" && !controller.signal.aborted) {
|
||||
controller.signal.addEventListener("abort", Alerts.start())
|
||||
}
|
||||
})
|
||||
promise.then(permissions => {
|
||||
if (permissions === "granted" && !controller.signal.aborted) {
|
||||
controller.signal.addEventListener("abort", Push.start())
|
||||
}
|
||||
})
|
||||
|
||||
Alerts._unsubscriber = () => controller.abort()
|
||||
Push._unsubscriber = () => controller.abort()
|
||||
} else {
|
||||
Push.stop()
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsubscribe()
|
||||
Push.stop()
|
||||
}
|
||||
|
||||
return Alerts.stop
|
||||
}
|
||||
|
||||
static stop() {
|
||||
Alerts._unsubscriber?.()
|
||||
Alerts._unsubscriber = undefined
|
||||
Push._unsubscriber?.()
|
||||
Push._unsubscriber = undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
replaceState?: boolean
|
||||
disabled?: boolean
|
||||
class?: string
|
||||
'data-tip'?: string
|
||||
"data-tip"?: string
|
||||
} = $props()
|
||||
|
||||
const go = (e: Event) => {
|
||||
|
||||
@@ -123,13 +123,13 @@
|
||||
unsubscribers.push(setupHistory(), setupAnalytics(), syncApplicationData())
|
||||
|
||||
// Subscribe to badge count for changes
|
||||
unsubscribers.push(notifications.badgeCount.subscribe(notifications.handleBadgeCountChanges))
|
||||
unsubscribers.push(notifications.syncBadges)
|
||||
|
||||
// Initialize keyboard state tracking
|
||||
unsubscribers.push(syncKeyboard())
|
||||
|
||||
// Initialize background notifications
|
||||
unsubscribers.push(notifications.Alerts.resume())
|
||||
unsubscribers.push(notifications.Push.resume())
|
||||
|
||||
// Listen for signer errors, report to user via toast
|
||||
unsubscribers.push(
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
import cx from "classnames"
|
||||
import {sleep, remove} from "@welshman/lib"
|
||||
import {displayRelayUrl} from "@welshman/util"
|
||||
import {Capacitor} from "@capacitor/core"
|
||||
import {Badge} from "@capawesome/capacitor-badge"
|
||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||
import {preventDefault} from "@lib/html"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import RoomName from "@app/components/RoomName.svelte"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {Alerts, clearBadges} from "@app/util/notifications"
|
||||
import {Push, clearBadges} from "@app/util/notifications"
|
||||
import {userSettingsValues, splitRoomId} from "@app/core/state"
|
||||
import {publishSettings} from "@app/core/commands"
|
||||
|
||||
@@ -24,7 +26,7 @@
|
||||
|
||||
const onAlertsPushChange = () => {
|
||||
if (settings.alerts_push) {
|
||||
Alerts.request().then(permissions => {
|
||||
Push.request().then(permissions => {
|
||||
if (permissions !== "granted") {
|
||||
sleep(300).then(() => {
|
||||
settings.alerts_push = false
|
||||
@@ -46,12 +48,6 @@
|
||||
const onsubmit = preventDefault(async () => {
|
||||
await publishSettings($state.snapshot(settings))
|
||||
|
||||
if (settings.alerts_push) {
|
||||
await Alerts.start()
|
||||
} else {
|
||||
await Alerts.stop()
|
||||
}
|
||||
|
||||
pushToast({message: "Your settings have been saved!"})
|
||||
})
|
||||
|
||||
@@ -61,18 +57,26 @@
|
||||
<form class="content column gap-4" {onsubmit}>
|
||||
<div class="card2 bg-alt col-4 shadow-md">
|
||||
<strong class="text-lg">Alert Settings</strong>
|
||||
<div class="flex justify-between">
|
||||
<p>Show badge for unread alerts</p>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="toggle toggle-primary"
|
||||
bind:checked={settings.alerts_badge}
|
||||
onchange={onAlertsBadgeChange} />
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<p>Play sound for new activity</p>
|
||||
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.alerts_sound} />
|
||||
</div>
|
||||
{#await Badge.isSupported()}
|
||||
<!-- pass -->
|
||||
{:then { isSupported }}
|
||||
{#if isSupported}
|
||||
<div class="flex justify-between">
|
||||
<p>Show badge for unread alerts</p>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="toggle toggle-primary"
|
||||
bind:checked={settings.alerts_badge}
|
||||
onchange={onAlertsBadgeChange} />
|
||||
</div>
|
||||
{/if}
|
||||
{/await}
|
||||
{#if !Capacitor.isNativePlatform()}
|
||||
<div class="flex justify-between">
|
||||
<p>Play sound for new activity</p>
|
||||
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.alerts_sound} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex justify-between">
|
||||
<p>Enable push notifications</p>
|
||||
<input
|
||||
@@ -82,7 +86,11 @@
|
||||
onchange={onAlertsPushChange} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card2 bg-alt col-4 shadow-md">
|
||||
<div
|
||||
class={cx("card2 bg-alt col-4 shadow-md", {
|
||||
"pointer-events-none opacity-50":
|
||||
!settings.alerts_badge && !settings.alerts_sound && !settings.alerts_push,
|
||||
})}>
|
||||
<strong class="text-lg">Alert Types</strong>
|
||||
<div class="flex justify-between">
|
||||
<p>Notify me about new activity</p>
|
||||
@@ -100,7 +108,11 @@
|
||||
bind:checked={settings.alerts_messages} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card2 bg-alt col-4 shadow-md">
|
||||
<div
|
||||
class={cx("card2 bg-alt col-4 shadow-md", {
|
||||
"pointer-events-none opacity-50":
|
||||
!settings.alerts_badge && !settings.alerts_sound && !settings.alerts_push,
|
||||
})}>
|
||||
<strong class="text-lg">Muted Rooms</strong>
|
||||
{#each settings.muted_rooms as id (id)}
|
||||
{@const [url, h] = splitRoomId(id)}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import cx from "classnames"
|
||||
import {readable, derived as _derived} from "svelte/store"
|
||||
import {onMount, onDestroy} from "svelte"
|
||||
import {page} from "$app/stores"
|
||||
@@ -76,7 +75,14 @@
|
||||
const isFavorite = $derived($userRooms.includes(h))
|
||||
const membershipStatus = deriveUserRoomMembershipStatus(url, h)
|
||||
const isMuted = $derived($userSettingsValues.muted_rooms.includes($room.id))
|
||||
const hasAlerts = throttled(800, _derived(userSettingsValues, ({alerts_spaces, alerts_push, alerts_sound, alerts_badge}) => alerts_spaces && (alerts_push || alerts_sound || alerts_badge)))
|
||||
const hasAlerts = throttled(
|
||||
800,
|
||||
_derived(
|
||||
userSettingsValues,
|
||||
({alerts_spaces, alerts_push, alerts_sound, alerts_badge}) =>
|
||||
alerts_spaces && (alerts_push || alerts_sound || alerts_badge),
|
||||
),
|
||||
)
|
||||
|
||||
const showRoomDetail = () => pushModal(RoomDetail, {url, h})
|
||||
|
||||
@@ -371,22 +377,22 @@
|
||||
class="btn btn-neutral btn-sm tooltip tooltip-left"
|
||||
data-tip="Notifications are turned off"
|
||||
onclick={unmuteRoom}>
|
||||
<Icon size={4} icon={VolumeLoud} />
|
||||
<Icon size={4} icon={VolumeCross} />
|
||||
</Button>
|
||||
{:else}
|
||||
<Button
|
||||
class="btn btn-neutral btn-sm tooltip tooltip-left"
|
||||
data-tip="Notifications are turned on"
|
||||
onclick={muteRoom}>
|
||||
<Icon size={4} icon={VolumeLoud} class="text-primary" />
|
||||
<Icon size={4} icon={VolumeLoud} />
|
||||
</Button>
|
||||
{/if}
|
||||
{#if isFavorite}
|
||||
<Button
|
||||
class="btn btn-neutral btn-sm tooltip tooltip-left"
|
||||
class="btn btn-neutral btn-sm tooltip tooltip-left text-secondary"
|
||||
data-tip="Remove Favorite"
|
||||
onclick={removeFavorite}>
|
||||
<Icon size={4} icon={Bookmark} class="text-primary" />
|
||||
<Icon size={4} icon={Bookmark} />
|
||||
</Button>
|
||||
{:else}
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user