public async Task HandleAsync() { NodeResponse response; try { switch (request.RequestType) { case Enums.NodeRequestType.GetChats: { IEnumerable <ChatVm> chats = await loadChatsService.GetChatsByIdAsync(request.ObjectsId, request.RequestorUserId).ConfigureAwait(false); response = new ChatsNodeResponse(request.RequestId, chats); } break; case Enums.NodeRequestType.GetUsers: { IEnumerable <UserVm> users = await loadUsersService.GetUsersByIdAsync(request.ObjectsId, request.RequestorUserId).ConfigureAwait(false); users = await privacyService.ApplyPrivacySettingsAsync(users, request.RequestorUserId).ConfigureAwait(false); response = new UsersNodeResponse(request.RequestId, users); } break; case Enums.NodeRequestType.GetChannels: { IEnumerable <ChannelDto> channels = await loadChannelsService.GetChannelsWithSubscribersAsync(request.ObjectsId).ConfigureAwait(false); response = new ChannelsNodeResponse(request.RequestId, channels); } break; case Enums.NodeRequestType.GetFiles: { IEnumerable <FileInfoVm> files = await filesService.GetFilesInfoAsync(request.FilesIds).ConfigureAwait(false); response = new FilesInformationResponse(request.RequestId, files); } break; default: response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.InvalidRequestData, "Unsupported request type."); break; } } catch { response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.UnknownError, "An error occurred while processing the request."); } NodeWebSocketCommunicationManager.SendResponse(response, nodeConnection); }
public async Task <Response> CreateResponseAsync() { IEnumerable <ChatVm> chats = await loadChatsService.GetChatsByIdAsync(request.ChatsId, clientConnection.UserId).ConfigureAwait(false); return(new ChatsResponse(request.RequestId, chats)); }