Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ import { useRouter, useLocalSearchParams } from 'expo-router'
* Handles thread creation and message sending with real-time updates.
*/
const ShareScreen: React.FC = () => {
const { threadUuid } = useLocalSearchParams<{ threadUuid?: string }>()
const { shareThreadId } = useLocalSearchParams<{ shareThreadId?: string }>()
const dispatch = useDispatch<AppDispatch>()
const { abortRequest } = useChat()
const router = useRouter()

// Fetches thread details on threadId change
useEffect(() => {
if (threadUuid && Helpers.isValidateUUID(threadUuid)) {
dispatch(fetchSharedThread(threadUuid))
if (shareThreadId) {
dispatch(fetchSharedThread(shareThreadId))
.unwrap()
.catch(() => {
.catch((error) => {
router.push('/404')
})
} else {
router.push('/404')
}
}, [threadUuid, dispatch, router])
}, [shareThreadId, dispatch, router])

// Clean up the abort controller on unmount or when the component is no longer active
useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/share/SharePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { CheckIcon, CloseIcon } from '@/components/svg'
import { useChat, useDirection, useScreenInfo } from '@/hooks'
import { AppDispatch, RootState } from '@/store'
import { getShareThreadUUID } from '@/store/actions/chatActions'
import { getShareThreadId } from '@/store/actions/chatActions'
import { createGeneralThemedStyles, GetEnv } from '@/utils'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -44,11 +44,11 @@ const SharePopup: React.FC<Props> = ({ visible, onClose }) => {
const threadId = activeThread?.id
setIsCopying(1)
const response = await dispatch(
getShareThreadUUID({
getShareThreadId({
threadId: threadId!,
}),
).unwrap()
Clipboard.setString(`${shareURL}/share/${response?.share_uuid}`)
Clipboard.setString(`${shareURL}/share/${response?.share_id}`)
setIsCopying(2)
setTimeout(() => {
setIsCopying(0)
Expand Down
14 changes: 7 additions & 7 deletions src/services/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ChatService {
}
}

async getShareThreadUUID(threadId: string, dispatch: Dispatch<UnknownAction>): Promise<ShareThreadResponse> {
async getShareThreadId(threadId: string, dispatch: Dispatch<UnknownAction>): Promise<ShareThreadResponse> {
const response = await this.fetchWithAuthRetry(
`${this.baseURL}/share/${threadId}`,
{
Expand All @@ -196,16 +196,16 @@ class ChatService {
)

if (!response.ok) {
throw new Error('Error getting share uuid for a thread')
throw new Error('Error getting share id for a thread')
}

return await response.json()
}

async getSharedThread(sharedThreadUUID: string, dispatch: Dispatch<UnknownAction>): Promise<Thread> {
async getSharedThread(shareThreadId: string, dispatch: Dispatch<UnknownAction>): Promise<Thread> {
// This is a public sharing endpoint which doesn't require an access token
const response = await this.fetchWithAuthRetry(
`${this.baseURL}/share/${sharedThreadUUID}`,
`${this.baseURL}/share/${shareThreadId}`,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -214,17 +214,17 @@ class ChatService {
dispatch,
)
if (!response.ok) {
throw new ApplicationError('Error fetching shared thread ' + sharedThreadUUID)
throw new ApplicationError('Error fetching shared thread ' + shareThreadId)
}
const data = await response.json()

if (Helpers.isBlank(data)) {
throw new NotFoundError('Unable to load shared thread ' + sharedThreadUUID)
throw new NotFoundError('Unable to load shared thread ' + shareThreadId)
} else {
// The API returns { thread_id: 1 } and we need to convert it to the Thread type
// No messages are returned in the creation response, so initializing with an empty array
const thread: Thread = {
id: String(sharedThreadUUID), // Convert thread_id to a string to match the Thread interface
id: String(shareThreadId), // Convert thread_id to a string to match the Thread interface
name: data.content.thread_name ?? null, // API response doesn't include name
messages: data.content.messages, // Initialize with an empty array since the API response doesn't include messages
}
Expand Down
16 changes: 8 additions & 8 deletions src/store/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ export const setThreadName = createAsyncThunk(
)

/**
* Get Share uuid for a thread asynchronously.
* Get Share id for a thread asynchronously.
*
* @param threadId - The ID of the thread.
* @returns A Promise that resolves when the share thread uuid generated successfully.
* @returns A Promise that resolves when the share thread id generated successfully.
*/
export const getShareThreadUUID = createAsyncThunk(
'chat/getShareThreadUUID',
export const getShareThreadId = createAsyncThunk(
'chat/getShareThreadId',
async ({ threadId }: { threadId: string }, { dispatch, getState }) => {
try {
const { isAuthenticated, accessToken } = (getState() as RootState).auth
const chatService = new ChatService(isAuthenticated, accessToken)
dispatch(setLoading(true))
const response = await chatService.getShareThreadUUID(threadId, dispatch)
const response = await chatService.getShareThreadId(threadId, dispatch)
if (response.status === 'success') {
return response as ShareThreadResponse
}
Expand All @@ -245,7 +245,7 @@ export const getShareThreadUUID = createAsyncThunk(
/**
* Fetches a shared thread from the chat service.
*
* @param sharedThreadUUID - The uuid of the shared thread to fetch.
* @param shareThreadId - The id of the shared thread to fetch.
* @param dispatch - The dispatch function from the Redux store.
* @param getState - The getState function from the Redux store.
* @returns A Promise that resolves to the fetched thread.
Expand All @@ -254,12 +254,12 @@ export const getShareThreadUUID = createAsyncThunk(
*/
export const fetchSharedThread = createAsyncThunk(
'chat/fetchSharedThread',
async (sharedThreadUUID: string, { dispatch, getState }) => {
async (shareThreadId: string, { dispatch, getState }) => {
try {
const { isAuthenticated, accessToken } = (getState() as RootState).auth
const chatService = new ChatService(isAuthenticated, accessToken)
dispatch(setLoading(true))
const thread = await chatService.getSharedThread(sharedThreadUUID, dispatch)
const thread = await chatService.getSharedThread(shareThreadId, dispatch)
if (!thread.messages) {
throw NotFoundError
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export {
sendFeedback,
setThreadName,
fetchSharedThread,
getShareThreadUUID,
getShareThreadId,
} from './chatActions'
2 changes: 1 addition & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type Error = {
// Type for ShareThred response data
export type ShareThreadResponse = {
status: string
share_uuid: string
share_id: string
}

export type ResetPasswordResponse = { status: string }