fix: share chat issue

This commit is contained in:
Timothy J. Baek 2024-05-18 15:23:36 -07:00
parent 1e6ddb2fb3
commit 8dac4e91a5
2 changed files with 17 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import logging
from apps.web.models.users import UserModel, UserUpdateForm, UserRoleUpdateForm, Users
from apps.web.models.auths import Auths
from apps.web.models.chats import Chats
from utils.utils import get_verified_user, get_password_hash, get_admin_user
from constants import ERROR_MESSAGES
@ -80,6 +81,17 @@ class UserResponse(BaseModel):
@router.get("/{user_id}", response_model=UserResponse)
async def get_user_by_id(user_id: str, user=Depends(get_verified_user)):
if user_id.startswith("shared-"):
chat_id = user_id.replace("shared-", "")
chat = Chats.get_chat_by_id(chat_id)
if chat:
user_id = chat.user_id
else:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.USER_NOT_FOUND,
)
user = Users.get_user_by_id(user_id)
if user:

View File

@ -13,6 +13,7 @@
import Messages from '$lib/components/chat/Messages.svelte';
import Navbar from '$lib/components/layout/Navbar.svelte';
import { getUserById } from '$lib/apis/users';
import { error } from '@sveltejs/kit';
const i18n = getContext('i18n');
@ -90,7 +91,10 @@
});
if (chat) {
user = await getUserById(localStorage.token, chat.user_id);
user = await getUserById(localStorage.token, chat.user_id).catch((error) => {
console.error(error);
return null;
});
const chatContent = chat.chat;