Browse Source

update Hivetalk links

imwald
Silberengel 4 weeks ago
parent
commit
fb2c459bac
  1. 17
      src/components/NoteOptions/useMenuActions.tsx
  2. 5
      src/components/ProfileOptions/index.tsx
  3. 7
      src/components/ScheduleVideoCallDialog/ScheduleVideoCallDialog.tsx
  4. 29
      src/lib/hivetalk.test.ts
  5. 25
      src/lib/hivetalk.ts

17
src/components/NoteOptions/useMenuActions.tsx

@ -4,7 +4,7 @@ import { getLongFormArticleMetadataFromEvent } from '@/lib/event-metadata'
import { buildHiveTalkJoinUrl } from '@/lib/hivetalk' import { buildHiveTalkJoinUrl } from '@/lib/hivetalk'
import { toAlexandria, encodeArticleLikePublicationNaddr, openAlexandriaPublicationFromNaddr } from '@/lib/link' import { toAlexandria, encodeArticleLikePublicationNaddr, openAlexandriaPublicationFromNaddr } from '@/lib/link'
import logger from '@/lib/logger' import logger from '@/lib/logger'
import { formatPubkey, pubkeyToNpub } from '@/lib/pubkey' import { pubkeyToNpub } from '@/lib/pubkey'
import { import {
batchFetchPublicationSectionEvents, batchFetchPublicationSectionEvents,
buildPublicationSectionRelayUrls, buildPublicationSectionRelayUrls,
@ -997,9 +997,8 @@ export function useMenuActions({
separator: true, separator: true,
onClick: () => { onClick: () => {
closeDrawer() closeDrawer()
const roomId = `jumble-note-${event.id}` const roomId = `imwald-note-${event.id}`
const displayName = pubkey ? (profile?.username ?? formatPubkey(pubkey)) : 'jumble' const url = buildHiveTalkJoinUrl({ room: roomId })
const url = buildHiveTalkJoinUrl({ room: roomId, name: displayName })
window.open(url, '_blank', 'noopener,noreferrer') window.open(url, '_blank', 'noopener,noreferrer')
} }
}, },
@ -1008,9 +1007,8 @@ export function useMenuActions({
label: t('Copy call invite link'), label: t('Copy call invite link'),
onClick: () => { onClick: () => {
closeDrawer() closeDrawer()
const roomId = `jumble-note-${event.id}` const roomId = `imwald-note-${event.id}`
const displayName = pubkey ? (profile?.username ?? formatPubkey(pubkey)) : 'jumble' const url = buildHiveTalkJoinUrl({ room: roomId })
const url = buildHiveTalkJoinUrl({ room: roomId, name: displayName })
navigator.clipboard.writeText(url) navigator.clipboard.writeText(url)
toast.success(t('Copied to clipboard')) toast.success(t('Copied to clipboard'))
} }
@ -1022,9 +1020,8 @@ export function useMenuActions({
label: t('Send call invite'), label: t('Send call invite'),
onClick: () => { onClick: () => {
closeDrawer() closeDrawer()
const roomId = `jumble-note-${event.id}` const roomId = `imwald-note-${event.id}`
const displayName = pubkey ? (profile?.username ?? formatPubkey(pubkey)) : 'jumble' const url = buildHiveTalkJoinUrl({ room: roomId })
const url = buildHiveTalkJoinUrl({ room: roomId, name: displayName })
onOpenCallInvite(`${t('Join the video call')}: ${url}`) onOpenCallInvite(`${t('Join the video call')}: ${url}`)
} }
} as MenuAction } as MenuAction

5
src/components/ProfileOptions/index.tsx

@ -189,10 +189,7 @@ export default function ProfileOptions({
const callInviteUrl = const callInviteUrl =
accountPubkey && accountPubkey &&
buildHiveTalkJoinUrl({ buildHiveTalkJoinUrl({ room: roomIdForPubkeys(accountPubkey, pubkey) })
room: roomIdForPubkeys(accountPubkey, pubkey),
name: displayName
})
return ( return (
<DropdownMenu> <DropdownMenu>

7
src/components/ScheduleVideoCallDialog/ScheduleVideoCallDialog.tsx

@ -82,7 +82,7 @@ export function ScheduleVideoCallDialog({
if (endUnix != null && endUnix <= startUnix) return null if (endUnix != null && endUnix <= startUnix) return null
const d = 'preview' const d = 'preview'
const roomId = roomIdForScheduledCall(d) const roomId = roomIdForScheduledCall(d)
const defaultJoinUrl = buildHiveTalkJoinUrl({ room: roomId, name: 'Guest' }) const defaultJoinUrl = buildHiveTalkJoinUrl({ room: roomId })
const joinUrl = locationUrl.trim() || defaultJoinUrl const joinUrl = locationUrl.trim() || defaultJoinUrl
return createCalendarEventDraftEvent({ return createCalendarEventDraftEvent({
d, d,
@ -139,10 +139,7 @@ export function ScheduleVideoCallDialog({
const d = `jumble-cal-${randomString(12)}` const d = `jumble-cal-${randomString(12)}`
const roomId = roomIdForScheduledCall(d) const roomId = roomIdForScheduledCall(d)
const defaultJoinUrl = buildHiveTalkJoinUrl({ const defaultJoinUrl = buildHiveTalkJoinUrl({ room: roomId })
room: roomId,
name: 'Guest'
})
const joinUrl = locationUrl.trim() || defaultJoinUrl const joinUrl = locationUrl.trim() || defaultJoinUrl
const calendarDraft = createCalendarEventDraftEvent({ const calendarDraft = createCalendarEventDraftEvent({

29
src/lib/hivetalk.test.ts

@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest'
import { buildHiveTalkJoinUrl, roomIdForPubkeys, roomIdForScheduledCall } from './hivetalk'
describe('buildHiveTalkJoinUrl', () => {
it('returns path-only meet URL without query params', () => {
const id = '16d6d544e487c2cee3eb4c37654ba7dcc841ba4cd0e404c99af8ef4ffa7c020d'
expect(buildHiveTalkJoinUrl({ room: `imwald-note-${id}` })).toBe(
`https://honey.hivetalk.org/meet/imwald-note-${id}`
)
})
it('strips leading slashes from room', () => {
expect(buildHiveTalkJoinUrl({ room: '/my-room' })).toBe('https://honey.hivetalk.org/meet/my-room')
})
})
describe('roomIdForPubkeys', () => {
it('is symmetric', () => {
const a = 'a'.repeat(64)
const b = 'b'.repeat(64)
expect(roomIdForPubkeys(a, b)).toBe(roomIdForPubkeys(b, a))
})
})
describe('roomIdForScheduledCall', () => {
it('prefixes d tag', () => {
expect(roomIdForScheduledCall('abc')).toBe('jumble-cal-abc')
})
})

25
src/lib/hivetalk.ts

@ -2,33 +2,16 @@ import { HIVETALK_BASE_URL } from '@/constants'
export interface HiveTalkJoinParams { export interface HiveTalkJoinParams {
room: string room: string
name: string
roomPassword?: string
audio?: boolean
video?: boolean
screen?: boolean
notify?: boolean
hide?: boolean
token?: string
} }
/** /**
* Build a HiveTalk Honey direct-join URL (`/meet/{room}&name=…&…`). * HiveTalk Honey join URL: `{base}/meet/{room}` (user enters name on the join page).
* Legacy vanilla used `/join?room=…` see https://honey.hivetalk.org * @see https://honey.hivetalk.org/meet/{room}
*/ */
export function buildHiveTalkJoinUrl(params: HiveTalkJoinParams): string { export function buildHiveTalkJoinUrl(params: HiveTalkJoinParams): string {
const base = HIVETALK_BASE_URL.replace(/\/$/, '') const base = HIVETALK_BASE_URL.replace(/\/$/, '')
const query = [ const room = params.room.trim().replace(/^\/+|\/+$/g, '')
`name=${encodeURIComponent(params.name)}`, return `${base}/meet/${room}`
`roomPassword=${encodeURIComponent(params.roomPassword ?? '0')}`,
`audio=${params.audio !== false ? '1' : '0'}`,
`video=${params.video !== false ? '1' : '0'}`,
`screen=${params.screen ? '1' : '0'}`,
`notify=${params.notify !== false ? '1' : '0'}`
]
if (params.hide !== undefined) query.push(`hide=${params.hide ? '1' : '0'}`)
if (params.token) query.push(`token=${encodeURIComponent(params.token)}`)
return `${base}/meet/${encodeURIComponent(params.room)}&${query.join('&')}`
} }
/** Deterministic room id for a 1:1 call between two pubkeys (same room from either side). */ /** Deterministic room id for a 1:1 call between two pubkeys (same room from either side). */

Loading…
Cancel
Save