diff --git a/webapi/Controllers/ChatHistoryController.cs b/webapi/Controllers/ChatHistoryController.cs index 1292ca207..64e77e322 100644 --- a/webapi/Controllers/ChatHistoryController.cs +++ b/webapi/Controllers/ChatHistoryController.cs @@ -139,6 +139,7 @@ public async Task GetChatSessionByIdAsync(Guid chatId) [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task 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."); diff --git a/webapi/Controllers/ChatParticipantController.cs b/webapi/Controllers/ChatParticipantController.cs index d20cba736..661bde5df 100644 --- a/webapi/Controllers/ChatParticipantController.cs +++ b/webapi/Controllers/ChatParticipantController.cs @@ -56,31 +56,31 @@ public ChatParticipantController( [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task JoinChatAsync( - Guid chatId, [FromServices] IHubContext 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); } diff --git a/webapp/src/libs/hooks/useChat.ts b/webapp/src/libs/hooks/useChat.ts index 8f4c13d0c..23559a785 100644 --- a/webapp/src/libs/hooks/useChat.ts +++ b/webapp/src/libs/hooks/useChat.ts @@ -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);