Skip to content

Commit

Permalink
Fix some outbox/inbox relay confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
cesardeazevedo committed Feb 7, 2025
1 parent 1803827 commit 22d4224
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/elements/Editor/EditorBroadcaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const EditorBroadcaster = observer(function EditorBroadcaster(props: Prop
</Text>
</Stack>
<Stack horizontal wrap gap={0.5}>
{store.myInboxRelays.map(({ relay }) => (
{store.myOutboxRelays.map(({ relay }) => (
<RelayInputChip renderConnectedIcon key={relay} url={relay} onDelete={() => store.excludeRelay(relay)} />
))}
{/* <RelayChipAdd onSubmit={(relay) => store.includeRelay(relay)} /> */}
Expand Down
18 changes: 13 additions & 5 deletions src/components/elements/Relays/RelayMailboxList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Divider } from '@/components/ui/Divider/Divider'
import { Stack } from '@/components/ui/Stack/Stack'
import { Text } from '@/components/ui/Text/Text'
import { formatRelayUrl } from '@/core/helpers/formatRelayUrl'
import type { WRITE } from '@/nostr/types'
import { READ } from '@/nostr/types'
import type { READ } from '@/nostr/types'
import { WRITE } from '@/nostr/types'
import type { User } from '@/stores/users/user'
import { palette } from '@/themes/palette.stylex'
import { shape } from '@/themes/shape.stylex'
Expand All @@ -27,8 +27,12 @@ type Props = {

export const RelayMailboxList = observer(function RelayMailboxList(props: Props) {
const { user, permission, isEditing } = props
const label = permission === READ ? 'Outbox' : 'Inbox'
const relays = (permission === READ ? user?.outboxRelays : user?.inboxRelays) || []
const label = permission === WRITE ? 'Outbox' : 'Inbox'
const description =
permission === WRITE
? 'These are the relays you are writing notes to'
: 'These are the relays where others will reply or tag you'
const relays = (permission === WRITE ? user?.outboxRelays : user?.inboxRelays) || []

const [input, setInput] = useState('')
const [pending, onSubmit] = usePublishRelayList()
Expand All @@ -55,10 +59,13 @@ export const RelayMailboxList = observer(function RelayMailboxList(props: Props)
return (
<PaperContainer>
<Stack horizontal={false}>
<Stack gap={0.5} sx={styles.header} justify='space-between'>
<Stack horizontal={false} gap={0.5} sx={styles.header} justify='space-between'>
<Text variant='title' size='md'>
{label} Relays {total !== 0 && <html.span style={styles.total}>{`(${total})`}</html.span>}
</Text>
<Text variant='body' size='md'>
{description}
</Text>
</Stack>
<Divider />
<Stack gap={2}>
Expand Down Expand Up @@ -99,6 +106,7 @@ const styles = css.create({
},
header: {
padding: spacing.padding2,
paddingBlock: spacing.padding1,
},
total: {
opacity: 0.5,
Expand Down
9 changes: 4 additions & 5 deletions src/components/elements/Relays/RelayPopoverSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { observer } from 'mobx-react-lite'
import { css, html } from 'react-strict-dom'
import { RelayIconButton } from './RelayIconButton'
import { RelaySelectPopover } from './RelaySelectPopover'
import { RelayUserChipList } from './RelayUserChipList'

export const RelayPopoverSummary = observer(function RelayPopoverSummary() {
Expand Down Expand Up @@ -53,7 +52,7 @@ export const RelayPopoverSummary = observer(function RelayPopoverSummary() {
)}>
{user && (
<Stack gap={1} horizontal={false} sx={styles.content}>
<Text>These are the relays you are reading from</Text>
<Text>These are the relays you are writing notes to</Text>
<RelayUserChipList relays={user.outboxRelays} />
</Stack>
)}
Expand All @@ -73,7 +72,7 @@ export const RelayPopoverSummary = observer(function RelayPopoverSummary() {
)}>
{user && (
<Stack gap={1} horizontal={false} sx={styles.content}>
<Text>These are the relays you are writing notes to</Text>
<Text>These are the relays where others will reply or tag you</Text>
<RelayUserChipList relays={user.outboxRelays} />
</Stack>
)}
Expand All @@ -84,7 +83,7 @@ export const RelayPopoverSummary = observer(function RelayPopoverSummary() {
<>
<Stack gap={1} onClick={() => expand(!expanded)} sx={styles.subheader}>
<IconButton size='sm' icon={expanded ? <IconChevronDown /> : <IconChevronRight />} />
<IconDatabaseSearch size={22} strokeWidth='1.5' />
{/* <IconDatabaseSearch size={22} strokeWidth='1.5' /> */}
<Text variant='label' size='lg'>
Local Cache Relays
</Text>
Expand All @@ -95,7 +94,7 @@ export const RelayPopoverSummary = observer(function RelayPopoverSummary() {
<Stack gap={1} horizontal={false} sx={styles.content} align='flex-start'>
<Text>Local cache relays runs in your machine only, it's used to cache events and faster lookups</Text>
<Chip icon={<IconDatabaseSearch size={18} strokeWidth='1.5' />} variant='filter' label='Browser Relay' />
<RelaySelectPopover onSubmit={() => {}} />
{/* <RelaySelectPopover onSubmit={() => {}} /> */}
</Stack>
</Expandable>
{/* eslint-disable-next-line no-constant-binary-expression */}
Expand Down
2 changes: 1 addition & 1 deletion src/nostr/publish/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function publish(
const pub = new NostrPublisher(event, {
...options,
signer: client.signer,
relays: options.relays || client.inbox$,
relays: options.relays || client.outbox$,
inbox: !options.relays ? client.inboxTracker.subscribe.bind(client.inboxTracker) : () => EMPTY,
})

Expand Down
6 changes: 3 additions & 3 deletions src/stores/editor/editor.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class EditorStore {
makeAutoObservable(this, {
event: computed.struct,
rawEvent: computed.struct,
myInboxRelays: computed.struct,
myOutboxRelays: computed.struct,
otherInboxRelays: computed.struct,
allRelays: computed.struct,
mentions: computed.struct,
Expand Down Expand Up @@ -219,7 +219,7 @@ export class EditorStore {
return JSON.parse(JSON.stringify(this.event))
}

get myInboxRelays() {
get myOutboxRelays() {
if (this.context?.user) {
return userRelayStore.select(this.context.user.pubkey, {
permission: WRITE,
Expand Down Expand Up @@ -287,7 +287,7 @@ export class EditorStore {
}

get allRelays() {
return [...this.myInboxRelays, ...this.otherInboxRelays]
return [...this.myOutboxRelays, ...this.otherInboxRelays]
}

get title() {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class User {
}

get outboxRelays() {
return this.userRelays?.filter((x) => !!(x.permission & READ)) || []
return this.userRelays?.filter((x) => !!(x.permission & WRITE)) || []
}

get inboxRelays() {
return this.userRelays?.filter((x) => !!(x.permission & WRITE)) || []
return this.userRelays?.filter((x) => !!(x.permission & READ)) || []
}

get relays() {
Expand Down

0 comments on commit 22d4224

Please sign in to comment.