Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
totegamma committed Feb 3, 2025
1 parent 1b60905 commit 54ec6f5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
29 changes: 15 additions & 14 deletions client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
SocketListener,
InMemoryKVS,
GuestAuthProvider,
TimelineReader,
QueryTimelineReader,
} from '@concrnt/client'

import { Schemas, Schema } from "./schemas";
Expand Down Expand Up @@ -216,7 +218,7 @@ export class Client {
this.ackings = await this.user.getAcking()
}

async getUser(id: CCID, hint?: string): Promise<User | null> {
async getUser(id: CCID, hint?: string): Promise<User> {
return await User.load(this, id, hint)
}

Expand Down Expand Up @@ -371,7 +373,6 @@ export class Client {

async createCommunityTimeline(body: CommunityTimelineSchema): Promise<CoreTimeline<CommunityTimelineSchema>> {
if (!this.server) throw new Error('server is not set')
console.log(this.server)
return await this.api.upsertTimeline<CommunityTimelineSchema>(Schemas.communityTimeline, body, {
owner: this.server.csid,
})
Expand Down Expand Up @@ -632,7 +633,6 @@ export class Client {
return new SocketListener(socket)
}

/*
async newTimelineReader(opts?: {withoutSocket: boolean}): Promise<TimelineReader> {
if (opts?.withoutSocket) {
return new TimelineReader(this.api, undefined)
Expand All @@ -644,7 +644,6 @@ export class Client {
async newTimelineQuery(): Promise<QueryTimelineReader> {
return new QueryTimelineReader(this.api)
}
*/
}

export class User implements Omit<CoreEntity, 'parsedAffiliationDoc' | 'parsedTombstoneDoc'> {
Expand Down Expand Up @@ -715,33 +714,35 @@ export class User implements Omit<CoreEntity, 'parsedAffiliationDoc' | 'parsedTo
this.tombstoneSignature = entity.tombstoneSignature
}

static async load(client: Client, id: CCID, hint?: string): Promise<User | null> {
static async load(client: Client, id: CCID, hint?: string): Promise<User> {
const domain = await client.api.resolveDomain(id, hint).catch((_e) => {
return null
throw new Error('domain not found')
})
if (!domain) return null
const entity = await client.api.getEntity(id).catch((_e) => {
return null
throw new Error('entity not found')
})
if (!entity) return null

const profile = await client.api.getProfileBySemanticID<ProfileSchema>('world.concrnt.p', id).catch((_e) => {
return null
throw new Error('profile not found')
})

return new User(client, domain, entity, profile?.parsedDoc.body ?? undefined)
}

async getAcking(): Promise<User[]> {
const acks = await this.client.api.getAcking(this.ccid)
const users = await Promise.all(acks.map((e) => User.load(this.client, e.to)))
return users.filter((e) => e !== null) as User[]
const results = await Promise.allSettled(acks.map((e) => User.load(this.client, e.to)))

const succeeded = results.filter((e) => e.status === 'fulfilled') as PromiseFulfilledResult<User>[]
return succeeded.map((e) => e.value)
}

async getAcker(): Promise<User[]> {
const acks = await this.client.api.getAcker(this.ccid)
const users = await Promise.all(acks.map((e) => User.load(this.client, e.from)))
return users.filter((e) => e !== null) as User[]
const results = await Promise.allSettled(acks.map((e) => User.load(this.client, e.from)))

const succeeded = results.filter((e) => e.status === 'fulfilled') as PromiseFulfilledResult<User>[]
return succeeded.map((e) => e.value)
}

async Ack(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/components/QueryTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ErrorBoundary, type FallbackProps } from 'react-error-boundary'
import HeartBrokenIcon from '@mui/icons-material/HeartBroken'
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'
import SyncIcon from '@mui/icons-material/Sync'
import { type Query, type QueryTimelineReader as CoreTimelineReader } from '@concurrent-world/client'
import { type Query, type QueryTimelineReader as CoreTimelineReader } from '@concrnt/client'
import useSound from 'use-sound'
import { usePreference } from '../context/PreferenceContext'
import { VList, type VListHandle } from 'virtua'
Expand Down Expand Up @@ -265,7 +265,7 @@ const timeline = forwardRef((props: TimelineProps, ref: ForwardedRef<VListHandle
resolveHint={e.timelineID.split('@')[1]}
lastUpdated={e.lastUpdate?.getTime() ?? 0}
after={divider}
timestamp={e.cdate}
timestamp={e.created}
/>
)
break
Expand Down
6 changes: 3 additions & 3 deletions src/components/Timeline/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ErrorBoundary, type FallbackProps } from 'react-error-boundary'
import HeartBrokenIcon from '@mui/icons-material/HeartBroken'
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'
import SyncIcon from '@mui/icons-material/Sync'
import { type TimelineReader } from '@concurrent-world/client'
import { type TimelineReader } from '@concrnt/client'
import { useRefWithForceUpdate } from '../../hooks/useRefWithForceUpdate'
import useSound from 'use-sound'
import { usePreference } from '../../context/PreferenceContext'
Expand Down Expand Up @@ -81,7 +81,7 @@ const timeline = forwardRef((props: TimelineProps, ref: ForwardedRef<VListHandle
timelineChanged()
}
t.onRealtimeEvent = (event) => {
if (event.document?.type === 'message') {
if (event.parsedDoc?.type === 'message') {
playBubbleRef.current()
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ const timeline = forwardRef((props: TimelineProps, ref: ForwardedRef<VListHandle
resolveHint={e.timelineID.split('@')[1]}
lastUpdated={e.lastUpdate?.getTime() ?? 0}
after={divider}
timestamp={e.cdate}
timestamp={e.created}
/>
)
break
Expand Down
4 changes: 3 additions & 1 deletion src/components/ui/DomainCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export const DomainCard = (props: DomainCardProps): JSX.Element | null => {

useEffect(() => {
client.api.getDomain(props.domainFQDN).then((e) => {
setDomain(e ?? null)
setDomain(e)
})
}, [props.domainFQDN])

console.log(domain)

if (!domain) {
return null
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export function ListPage(): JSX.Element {

useEffect(() => {
client.api.getSubscription<ListSubscriptionSchema>(id).then((sub) => {
if (!sub) return
setSubscription(sub)
})
}, [id, client, updater])
Expand Down
6 changes: 6 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BuildInfo from 'vite-plugin-info'
import { VitePWA } from 'vite-plugin-pwa'
import basicSsl from '@vitejs/plugin-basic-ssl'
import { visualizer } from 'rollup-plugin-visualizer'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -13,6 +14,11 @@ export default defineConfig({
server: {
host: '0.0.0.0',
},
resolve: {
alias: {
client: path.resolve(__dirname, 'client'),
}
},
plugins: [
react(),
VitePWA({
Expand Down

0 comments on commit 54ec6f5

Please sign in to comment.