Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gitri-ms committed Aug 10, 2023
1 parent c312a22 commit cbf915d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions webapi/Controllers/ChatHistoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public async Task<IActionResult> GetChatSessionByIdAsync(Guid chatId)
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetAllChatSessionsAsync(string userId)
{
// TODO: [Issue #141] Remove this once we remove userId from route
if (!userId.Equals(this._authInfo.UserId, StringComparison.Ordinal))
{
return this.Forbid("User id does not match request.");
Expand Down
16 changes: 8 additions & 8 deletions webapi/Controllers/ChatParticipantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ public ChatParticipantController(
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> JoinChatAsync(
Guid chatId,
[FromServices] IHubContext<MessageRelayHub> messageRelayHubContext,
[FromServices] IAuthInfo authInfo)
[FromServices] IAuthInfo authInfo,
[FromBody] ChatParticipant chatParticipantParam)
{
var chatIdString = chatId.ToString();
var userId = authInfo.UserId;
string chatId = chatParticipantParam.ChatId;
string userId = authInfo.UserId;

// Make sure the chat session exists.
if (!await this._chatSessionRepository.TryFindByIdAsync(chatIdString, v => _ = v))
if (!await this._chatSessionRepository.TryFindByIdAsync(chatId, v => _ = v))
{
return this.BadRequest("Chat session does not exist.");
}

// Make sure the user is not already in the chat session.
if (await this._chatParticipantRepository.IsUserInChatAsync(userId, chatIdString))
if (await this._chatParticipantRepository.IsUserInChatAsync(userId, chatId))
{
return this.BadRequest("User is already in the chat session.");
}

var chatParticipant = new ChatParticipant(userId, chatIdString);
var chatParticipant = new ChatParticipant(userId, chatId);
await this._chatParticipantRepository.CreateAsync(chatParticipant);

// Broadcast the user joined event to all the connected clients.
// Note that the client who initiated the request may not have joined the group.
await messageRelayHubContext.Clients.Group(chatIdString).SendAsync(UserJoinedClientCall, chatIdString, userId);
await messageRelayHubContext.Clients.Group(chatId).SendAsync(UserJoinedClientCall, chatId, userId);

return this.Ok(chatParticipant);
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/libs/hooks/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const useChat = () => {
const joinChat = async (chatId: string) => {
const accessToken = await AuthHelper.getSKaaSAccessToken(instance, inProgress);
try {
await chatService.joinChatAsync(chatId, accessToken).then(async (result: IChatSession) => {
await chatService.joinChatAsync(userId, chatId, accessToken).then(async (result: IChatSession) => {
// Get chat messages
const chatMessages = await chatService.getChatMessagesAsync(result.id, 0, 100, accessToken);

Expand Down

0 comments on commit cbf915d

Please sign in to comment.