Allow users to opt-in to spaces that strip signatures
This commit is contained in:
@@ -9,11 +9,23 @@
|
||||
import {dev} from "$app/environment"
|
||||
import {goto} from "$app/navigation"
|
||||
import {sync, localStorageProvider} from "@welshman/store"
|
||||
import {identity, memoize, spec, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
|
||||
import {
|
||||
identity,
|
||||
call,
|
||||
memoize,
|
||||
spec,
|
||||
sleep,
|
||||
on,
|
||||
defer,
|
||||
ago,
|
||||
WEEK,
|
||||
TaskQueue,
|
||||
} from "@welshman/lib"
|
||||
import type {TrustedEvent, StampedEvent} from "@welshman/util"
|
||||
import {
|
||||
WRAP,
|
||||
EVENT_TIME,
|
||||
APP_DATA,
|
||||
THREAD,
|
||||
MESSAGE,
|
||||
INBOX_RELAYS,
|
||||
@@ -28,8 +40,14 @@
|
||||
getRelaysFromList,
|
||||
} from "@welshman/util"
|
||||
import {Nip46Broker, makeSecret} from "@welshman/signer"
|
||||
import type {Socket} from "@welshman/net"
|
||||
import {request, defaultSocketPolicies, makeSocketPolicyAuth} from "@welshman/net"
|
||||
import type {Socket, RelayMessage} from "@welshman/net"
|
||||
import {
|
||||
request,
|
||||
defaultSocketPolicies,
|
||||
makeSocketPolicyAuth,
|
||||
SocketEvent,
|
||||
isRelayEvent,
|
||||
} from "@welshman/net"
|
||||
import {
|
||||
loadRelay,
|
||||
db,
|
||||
@@ -64,9 +82,11 @@
|
||||
import {
|
||||
INDEXER_RELAYS,
|
||||
userMembership,
|
||||
userSettingValues,
|
||||
userSettingsValues,
|
||||
relaysPendingTrust,
|
||||
ensureUnwrapped,
|
||||
canDecrypt,
|
||||
getSetting,
|
||||
} from "@app/core/state"
|
||||
import {loadUserData, listenForNotifications} from "@app/core/requests"
|
||||
import {theme} from "@app/util/theme"
|
||||
@@ -162,9 +182,9 @@
|
||||
})
|
||||
|
||||
// Sync font size
|
||||
userSettingValues.subscribe($userSettingValues => {
|
||||
userSettingsValues.subscribe($userSettingsValues => {
|
||||
// @ts-ignore
|
||||
document.documentElement.style["font-size"] = `${$userSettingValues.font_size}rem`
|
||||
document.documentElement.style["font-size"] = `${$userSettingsValues.font_size}rem`
|
||||
})
|
||||
|
||||
if (!db) {
|
||||
@@ -214,9 +234,16 @@
|
||||
repository,
|
||||
rankEvent: (e: TrustedEvent) => {
|
||||
if (
|
||||
[PROFILE, FOLLOWS, MUTES, RELAYS, BLOSSOM_SERVERS, INBOX_RELAYS, ROOMS].includes(
|
||||
e.kind,
|
||||
)
|
||||
[
|
||||
PROFILE,
|
||||
FOLLOWS,
|
||||
MUTES,
|
||||
RELAYS,
|
||||
BLOSSOM_SERVERS,
|
||||
INBOX_RELAYS,
|
||||
ROOMS,
|
||||
APP_DATA,
|
||||
].includes(e.kind)
|
||||
) {
|
||||
return 1
|
||||
}
|
||||
@@ -239,6 +266,40 @@
|
||||
sign: (event: StampedEvent) => signer.get()?.sign(event),
|
||||
shouldAuth: (socket: Socket) => true,
|
||||
}),
|
||||
(socket: Socket) => {
|
||||
const buffer: RelayMessage[] = []
|
||||
|
||||
const unsubscribers = [
|
||||
// When the socket goes from untrusted to trusted, receive all buffered messages
|
||||
userSettingsValues.subscribe($settings => {
|
||||
if ($settings.trusted_relays.includes(socket.url)) {
|
||||
for (const message of buffer.splice(0)) {
|
||||
socket._recvQueue.push(message)
|
||||
}
|
||||
}
|
||||
}),
|
||||
// When we get an event with no signature from an untrusted relay, remove it from
|
||||
// the receive queue. If trust status is undefined, buffer it for later.
|
||||
on(socket, SocketEvent.Receiving, (message: RelayMessage) => {
|
||||
if (isRelayEvent(message) && !message[2]?.sig) {
|
||||
const isTrusted = getSetting<string[]>("trusted_relays").includes(socket.url)
|
||||
|
||||
if (!isTrusted) {
|
||||
socket._recvQueue.remove(message)
|
||||
buffer.push(message)
|
||||
|
||||
if (!$relaysPendingTrust.includes(socket.url)) {
|
||||
relaysPendingTrust.update($r => [...$r, socket.url])
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
]
|
||||
|
||||
return () => {
|
||||
unsubscribers.forEach(call)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// Load relay info
|
||||
|
||||
@@ -9,14 +9,7 @@
|
||||
BLOSSOM_SERVERS,
|
||||
} from "@welshman/util"
|
||||
import {Router} from "@welshman/router"
|
||||
import {
|
||||
pubkey,
|
||||
signer,
|
||||
userMutes,
|
||||
tagPubkey,
|
||||
publishThunk,
|
||||
userBlossomServers,
|
||||
} from "@welshman/app"
|
||||
import {userMutes, tagPubkey, publishThunk, userBlossomServers} from "@welshman/app"
|
||||
import {preventDefault} from "@lib/html"
|
||||
import Field from "@lib/components/Field.svelte"
|
||||
import FieldInline from "@lib/components/FieldInline.svelte"
|
||||
@@ -24,38 +17,32 @@
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import ProfileMultiSelect from "@app/components/ProfileMultiSelect.svelte"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {SETTINGS, PLATFORM_NAME, userSettingValues} from "@app/core/state"
|
||||
import {PLATFORM_NAME, userSettingsValues} from "@app/core/state"
|
||||
import {publishSettings} from "@app/core/commands"
|
||||
|
||||
const reset = () => {
|
||||
settings = {...$userSettingValues}
|
||||
settings = {...$userSettingsValues}
|
||||
mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
|
||||
blossomServers = getTagValues("server", getListTags($userBlossomServers))
|
||||
}
|
||||
|
||||
const onsubmit = preventDefault(async () => {
|
||||
const json = JSON.stringify($state.snapshot(settings))
|
||||
const content = await $signer!.nip44.encrypt($pubkey!, json)
|
||||
const relays = Router.get().FromUser().getUrls()
|
||||
|
||||
publishThunk({
|
||||
event: makeEvent(SETTINGS, {content}),
|
||||
relays,
|
||||
})
|
||||
await publishSettings($state.snapshot(settings))
|
||||
|
||||
publishThunk({
|
||||
event: makeEvent(MUTES, {tags: mutedPubkeys.map(tagPubkey)}),
|
||||
relays,
|
||||
relays: Router.get().FromUser().getUrls(),
|
||||
})
|
||||
|
||||
publishThunk({
|
||||
event: makeEvent(BLOSSOM_SERVERS, {tags: blossomServers.map(tagger("server"))}),
|
||||
relays,
|
||||
relays: Router.get().FromUser().getUrls(),
|
||||
})
|
||||
|
||||
pushToast({message: "Your settings have been saved!"})
|
||||
})
|
||||
|
||||
let settings = $state({...$userSettingValues})
|
||||
let settings = $state({...$userSettingsValues})
|
||||
let mutedPubkeys = $state(getPubkeyTagValues(getListTags($userMutes)))
|
||||
let blossomServers = $state(getTagValues("server", getListTags($userBlossomServers)))
|
||||
</script>
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
import {ago, MONTH} from "@welshman/lib"
|
||||
import {ROOM_META, EVENT_TIME, THREAD, COMMENT, MESSAGE} from "@welshman/util"
|
||||
import Page from "@lib/components/Page.svelte"
|
||||
import Dialog from "@lib/components/Dialog.svelte"
|
||||
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
||||
import MenuSpace from "@app/components/MenuSpace.svelte"
|
||||
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
|
||||
import SpaceTrustRelay from "@app/components/SpaceTrustRelay.svelte"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {setChecked} from "@app/util/notifications"
|
||||
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/core/commands"
|
||||
import {decodeRelay, userRoomsByUrl} from "@app/core/state"
|
||||
import {decodeRelay, userRoomsByUrl, relaysPendingTrust} from "@app/core/state"
|
||||
import {pullConservatively} from "@app/core/requests"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
|
||||
@@ -82,3 +84,9 @@
|
||||
{@render children?.()}
|
||||
{/key}
|
||||
</Page>
|
||||
|
||||
{#if $relaysPendingTrust.includes(url)}
|
||||
<Dialog>
|
||||
<SpaceTrustRelay {url} />
|
||||
</Dialog>
|
||||
{/if}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
import ChannelComposeParent from "@app/components/ChannelComposeParent.svelte"
|
||||
import {
|
||||
userRoomsByUrl,
|
||||
userSettingValues,
|
||||
userSettingsValues,
|
||||
decodeRelay,
|
||||
getEventsForUrl,
|
||||
deriveUserMembershipStatus,
|
||||
@@ -128,7 +128,7 @@
|
||||
const thunk = publishThunk({
|
||||
relays: [url],
|
||||
event: makeEvent(MESSAGE, template),
|
||||
delay: $userSettingValues.send_delay,
|
||||
delay: $userSettingsValues.send_delay,
|
||||
})
|
||||
|
||||
pushToast({
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
import ChannelCompose from "@app/components/ChannelCompose.svelte"
|
||||
import ChannelComposeParent from "@app/components/ChannelComposeParent.svelte"
|
||||
import {
|
||||
userSettingValues,
|
||||
userSettingsValues,
|
||||
decodeRelay,
|
||||
getEventsForUrl,
|
||||
PROTECTED,
|
||||
@@ -69,7 +69,7 @@
|
||||
const thunk = publishThunk({
|
||||
relays: [url],
|
||||
event: makeEvent(MESSAGE, template),
|
||||
delay: $userSettingValues.send_delay,
|
||||
delay: $userSettingsValues.send_delay,
|
||||
})
|
||||
|
||||
pushToast({
|
||||
|
||||
Reference in New Issue
Block a user