Skip to content

Commit

Permalink
Merge pull request #177 from l3vels/fix/chat-avatar
Browse files Browse the repository at this point in the history
Fix: Chat Avatar
  • Loading branch information
Chkhikvadze authored Sep 27, 2023
2 parents f92a575 + 1903ea0 commit 03e6a1b
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/server/controllers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_chat_messages(is_private_chat: bool, agent_id: Optional[UUID] = None, te
.filter(ChatMessageModel.session_id == session_id)
.order_by(ChatMessageModel.created_on.desc())
.limit(50)
.options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent))
.options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent), joinedload(ChatMessageModel.creator))
.all())

chat_messages = [chat_message.to_dict() for chat_message in chat_messages]
Expand Down Expand Up @@ -286,7 +286,7 @@ def get_chat_messages(agent_id: Optional[UUID] = None, team_id: Optional[UUID] =
.filter(ChatMessageModel.session_id == session_id)
.order_by(ChatMessageModel.created_on.desc())
.limit(50)
.options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent))
.options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent), joinedload(ChatMessageModel.creator))
.all())

chat_messages = [chat_message.to_dict() for chat_message in chat_messages]
Expand Down
5 changes: 4 additions & 1 deletion apps/server/models/chat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ChatMessage(BaseModel):

created_by = Column(UUID, ForeignKey('user.id', name='fk_created_by', ondelete='CASCADE'), nullable=True, index=True)
modified_by = Column(UUID, ForeignKey('user.id', name='fk_modified_by', ondelete='CASCADE'), nullable=True, index=True)
creator = relationship("UserModel", foreign_keys=[created_by], lazy='select')
creator = relationship("UserModel", foreign_keys=[user_id], lazy='select')

@classmethod
def get_chat_message_by_id(cls, db, chat_message_id: UUID, account: AccountOutput):
Expand Down Expand Up @@ -72,4 +72,7 @@ def to_dict(self):
if self.parent:
data['parent'] = self.parent.to_dict()

if self.creator:
data['creator'] = self.creator.to_dict()

return data
1 change: 1 addition & 0 deletions apps/server/typings/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ChatMessageOutput(BaseModel):
team_id: Optional[UUID] = None
team: Optional[Dict] = None
user_id: UUID
creator: Optional[Dict] = None
account_id: UUID
message: Dict
thoughts: Optional[List[Dict]] = None
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/gql/chat/chatMessages.gql
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ query chatMessages($is_private_chat: Boolean!, $agent_id: String!, $team_id: Str
agent
team_id
team
creator
}
}
1 change: 1 addition & 0 deletions apps/ui/src/gql/chat/chatMessagesHistory.gql
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ query chatMessages($is_private_chat: Boolean!, $agent_id: String!, $team_id: Str
agent
team_id
team
creator
}
}
2 changes: 1 addition & 1 deletion apps/ui/src/modals/AIChatModal/components/ChatHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const ChatHistory = () => {
<StyledRoot>
{(agentById || teamById) && (
<StyledMembersWrapper>
<ChatMembers agentById={agentById} teamOfAgents={teamById} />
<ChatMembers agentById={agentById} teamOfAgents={teamById} isHistory />
</StyledMembersWrapper>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import MemberText from './components/MemberText'
const ChatMembers = ({
agentById,
teamOfAgents,
userName,
isHistory,
}: {
agentById?: any
teamOfAgents?: any
userName?: string
isHistory?: boolean
}) => {
const { user } = React.useContext(AuthContext)

Expand Down Expand Up @@ -57,10 +57,10 @@ const ChatMembers = ({
<TabsContext activeTabId={activeTab}>
<TabPanels noAnimation>
<TabPanel>
{userName && (
{!isHistory && user?.name && (
<StyledAgentWrapper>
<AvatarGenerator name={userName} size={30} />
<MemberText name={userName} />
<AvatarGenerator name={user.name} size={30} avatar={user.avatar} />
<MemberText name={user.name} />
</StyledAgentWrapper>
)}

Expand Down Expand Up @@ -129,10 +129,10 @@ const ChatMembers = ({
<TabsContext activeTabId={activeTab}>
<TabPanels noAnimation>
<TabPanel>
{userName && (
{!isHistory && user?.name && (
<StyledAgentWrapper>
<AvatarGenerator name={userName} size={30} />
<MemberText name={userName} />
<AvatarGenerator name={user.name} size={30} avatar={user.avatar} />
<MemberText name={user.name} />
</StyledAgentWrapper>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ChatMessageListV2 = ({
agentName: chat.agent?.name,
teamName: chat.team?.name,
avatar: chat?.agent?.avatar,
creator: chat?.creator,
}
})

Expand Down Expand Up @@ -169,7 +170,7 @@ const ChatMessageListV2 = ({
))}
</StyledReplyMessageContainer>
<HumanMessage
avatarImg={Avatar_3}
avatarImg={chat.creator?.avatar}
userId={chat.user_id}
messageDate={chat.date}
messageText={chat.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const HumanMessage = ({
<>
<StyledMessageWrapper>
<StyledAvatarWrapper>
<AvatarGenerator name={authorName} size={50} />
<AvatarGenerator name={authorName} size={50} avatar={avatarImg} />
</StyledAvatarWrapper>

<StyledMainContent>
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/modals/AIChatModal/components/ChatV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const ChatV2 = ({ isPrivate = false }: ChatV2Props) => {
return (
<StyledWrapper>
<StyledMembersWrapper>
<ChatMembers agentById={agentById} teamOfAgents={teamOfAgents} userName={user.name} />
<ChatMembers agentById={agentById} teamOfAgents={teamOfAgents} />
</StyledMembersWrapper>

<StyledMessages>
Expand Down

0 comments on commit 03e6a1b

Please sign in to comment.