Skip to content

Commit

Permalink
feat: create workspace and chat room under system user if no user is …
Browse files Browse the repository at this point in the history
…signed in
  • Loading branch information
HMarzban committed Dec 13, 2024
1 parent c89afbb commit 94988a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useChannel } from '../context/ChannelProvider'
import slugify from 'slugify'
import { TChannelSettings } from '@types'
import { join2Channel } from '@api'

import Config from '@config'
interface UseChannelInitialData {
initialMessagesLoading: boolean
msgLength: number
Expand Down Expand Up @@ -34,12 +34,13 @@ export const useChannelInitialData = (setError: (error: any) => void): UseChanne
const setOrUpdateChannel = useChatStore((state: any) => state.setOrUpdateChannel)

const processChannelData = async (channelId: string) => {
if (currentChannel === null && workspaceId && user) {
if (currentChannel === null && workspaceId) {
let newChannelId = channelId
const userId = user?.id || Config.chat.systemUserId
await upsertChannel({
id: newChannelId,
workspace_id: workspaceId,
created_by: user.id,
created_by: userId,
name: newChannelId,
slug: 'c' + slugify(newChannelId, { strict: true, lower: true })
})
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const config: Config = {
avatarBucketName: 'user_avatars'
}
},
chat: {
systemUserId: '992bb85e-78f8-4747-981a-fd63d9317ff1'
},
editor: {
defaultContent: `<h1>Welcome to Your New Document</h1>
<p>This is the default content for your new document. Feel free to start editing!</p>
Expand Down
5 changes: 5 additions & 0 deletions packages/webapp/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ interface EditorConfig {
getDefaultContent: (Heading: string) => string
}

interface ChatConfig {
systemUserId: string
}

interface Config {
app: AppConfig
editor: EditorConfig
chat: ChatConfig
}

export type { Config }
9 changes: 3 additions & 6 deletions packages/webapp/hooks/useMapDocumentAndWorkspace.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { upsertWorkspace, getChannels } from '@api'
import { useAuthStore, useChatStore } from '@stores'
import { useEffect, useState } from 'react'

import Config from '@config'
let setUpsertWorkspace = false

const useMapDocumentAndWorkspace = (docMetadata: any, channels: any) => {
Expand All @@ -26,7 +26,7 @@ const useMapDocumentAndWorkspace = (docMetadata: any, channels: any) => {
name: docMetadata.title,
description: docMetadata.description,
slug: docMetadata.slug,
created_by: user.id
created_by: user?.id || Config.chat.systemUserId
})

const { data: channels } = await getChannels(docMetadata.documentId)
Expand All @@ -37,11 +37,8 @@ const useMapDocumentAndWorkspace = (docMetadata: any, channels: any) => {
setUpsertWorkspace = true
setLoading(false)
}
// setUpsertWorkspace = true
setLoading(false)
}
if (user) checkworkspace()
else setLoading(false)
checkworkspace()
}, [authLoading, user])

return { loading }
Expand Down

0 comments on commit 94988a7

Please sign in to comment.