Skip to content

Commit

Permalink
fix: share chat issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed May 18, 2024
1 parent 1e6ddb2 commit 8dac4e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions backend/apps/web/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/routes/s/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8dac4e9

Please sign in to comment.