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 <ChatVm> GetFullChatInformationAsync(long chatId, NodeConnection nodeConnection) { try { GetFullChatInformationNodeRequest request = new GetFullChatInformationNodeRequest(chatId); SendRequest(nodeConnection, request); ChatsNodeResponse response = (ChatsNodeResponse) await GetResponseAsync(request).ConfigureAwait(false); return(response.Chats.FirstOrDefault()); } catch (Exception ex) { Logger.WriteLog(ex); return(null); } }
public async Task HandleAsync() { try { ChatVm chat = await loadChatsService.GetChatByIdAsync(request.ChatId).ConfigureAwait(false); ChatsNodeResponse response = new ChatsNodeResponse(request.RequestId, new List <ChatVm> { chat }); NodeWebSocketCommunicationManager.SendResponse(response, current); } catch (Exception ex) { Logger.WriteLog(ex); NodeWebSocketCommunicationManager.SendResponse(new ResultNodeResponse(request.RequestId, ErrorCode.UnknownError), current); } }
public ChatsNodeResponseHandler(NodeResponse response, NodeConnection nodeConnection, ICrossNodeService crossNodeService) { this.response = (ChatsNodeResponse)response; this.crossNodeService = crossNodeService; this.nodeConnection = nodeConnection; }