/// <summary> /// Informs the users of a channel that a message was edited. /// </summary> /// <param name="channelId">The id of the channel</param> /// <param name="message">The message to be edited</param> /// <returns>A task instance</returns> public async Task PutChannelMessage(int channelId, Message message) { var httpContext = Context.GetHttpContext(); var monad = await _channelsService.PutMessageAsync(httpContext, channelId, message); var signalGroup = ChannelSignalName(channelId); switch (monad) { case Success <Message, Error> success: var payload = new Payload <Message>(signalGroup, success.Value); await Clients.Groups(signalGroup).ChannelMessageEdited(payload); break; case Failure <Message, Error> failure: var errorPayload = new Payload <Error>(signalGroup, failure.Value); await Clients.Caller.ChannelMessageEdited(errorPayload); break; default: var exceptionPayload = new Payload <Error>(signalGroup, SystemErrors.Exception()); await Clients.Caller.ChannelMessageEdited(exceptionPayload); break; } }
/// <summary> /// Propagates the changes to a user's info to all of his connections and groups. /// </summary> /// <param name="user">The updated user instance</param> /// <returns>A Task instance</returns> public async Task UpdateMyInfo() { var httpContext = Context.GetHttpContext(); var monad = await _userService.GetAsync(httpContext); switch (monad) { case Success <User, Error> success: await Clients.Groups(Context.ConnectionId).UserUpdated(success.Value); await Clients.Caller.UserUpdated(success.Value); break; case Failure <User, Error> failure: await Clients.Caller.UserUpdated(failure.Value); break; default: await Clients.Caller.UserUpdated(SystemErrors.Exception()); break; } }
/// <summary> /// Sends a new message to the caller that contains either all the messages posted to a /// group or an error explaining why the operation wasn't completed properly. /// </summary> /// <param name="groupId">The id of the target group</param> /// <returns>A task instance</returns> public async Task GetAllPrivateGroupMessages(long groupId) { var httpContext = Context.GetHttpContext(); var monad = await _privateGroupMessagingService.GetAllAsync(httpContext, groupId); var signalGroup = PrivateGroupSignalName(groupId); switch (monad) { case Success <IEnumerable <Message>, Error> success: var payload = new Payload <IEnumerable <Message> >(signalGroup, success.Value); await Clients.Caller.AllPrivateGroupMessages(payload); break; case Failure <IEnumerable <Message>, Error> failure: var failurePayload = new Payload <Error>(signalGroup, failure.Value); await Clients.Caller.AllPrivateGroupMessages(failurePayload); break; default: var exceptionPayload = new Payload <Error>(signalGroup, SystemErrors.Exception()); await Clients.Caller.AllPrivateGroupMessages(exceptionPayload); break; } }
/// <summary> /// This method will add a new message to a direct messaging entry. /// </summary> /// <param name="userId">The id of the requesting user</param> /// <param name="directMessagingId">The id of the target direct messaging entry</param> /// <param name="message">The message instance that will be used for the insertion</param> /// <returns>An either monad</returns> public Either <Message, Error> InsertMessage(long userId, long directMessagingId, Message message) { try { return(Get(userId, directMessagingId).Bind <Message>(directMessaging => { var user = _burstChatContext .Users .FirstOrDefault(u => u.Id == userId); if (user is null || message is null) { return new Failure <Message, Error>(DirectMessagingErrors.DirectMessagesNotFound()); } var newMessage = new Message { User = user, Links = message.GetLinksFromContent(), Content = message.RemoveLinksFromContent(), Edited = false, DatePosted = message.DatePosted }; directMessaging.Messages.Add(newMessage); _burstChatContext.SaveChanges(); return new Success <Message, Error>(newMessage); })); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Message, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will fetch all information about direct messaging entry. /// </summary> /// <param name="userId">The id of the requesting user</param> /// <param name="firstParticipantId">The user id of the first participant</param> /// <param name="secondParticipantId">The user id of the second participant</param> /// <returns>An either monad</returns> public Either <DirectMessaging, Error> Get(long userId, long firstParticipantId, long secondParticipantId) { try { if (userId != firstParticipantId && userId != secondParticipantId) { return(new Failure <DirectMessaging, Error>(DirectMessagingErrors.DirectMessagingNotFound())); } var directMessaging = _burstChatContext .DirectMessaging .Include(dm => dm.FirstParticipantUser) .Include(dm => dm.SecondParticipantUser) .FirstOrDefault(dm => (dm.FirstParticipantUserId == firstParticipantId && dm.SecondParticipantUserId == secondParticipantId) || (dm.FirstParticipantUserId == secondParticipantId && dm.SecondParticipantUserId == firstParticipantId)); return(directMessaging is not null ? new Success <DirectMessaging, Error>(directMessaging) : new Failure <DirectMessaging, Error>(DirectMessagingErrors.DirectMessagesNotFound())); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <DirectMessaging, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will delete a message from the direct messaging entry. /// </summary> /// <param name="userId">The id of the requesting user</param> /// <param name="directMessagingId">The id of the direct messaging entry</param> /// <param name="messageId">The id of the message to be deleted</param> /// <returns>An either monad</returns> public Either <Message, Error> DeleteMessage(long userId, long directMessagingId, long messageId) { try { return(Get(userId, directMessagingId).Bind <Message>(_ => { var directMessaging = _burstChatContext .DirectMessaging .Include(dm => dm.Messages.Where(m => m.Id == messageId)) .First(dm => dm.Id == directMessagingId); if (!directMessaging.Messages.Any()) { return new Failure <Message, Error>(DirectMessagingErrors.DirectMessagesNotFound()); } var message = directMessaging.Messages.First() !; directMessaging.Messages.Remove(message); _burstChatContext.SaveChanges(); return new Success <Message, Error>(message); })); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Message, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will return the instance of a server based on the provided user and channel id. /// </summary> /// <param name="userId">The id of the target user</param> /// <param name="channelId">the id of the target channel</param> /// <returns>An instance of a Server or null</returns> private Either <Server, Error> GetServer(long userId, int channelId) { try { var server = _burstChatContext .Servers .Include(s => s.Channels) .Include(s => s.Subscriptions) .AsQueryable() .FirstOrDefault(s => s.Subscriptions.Any(sub => sub.UserId == userId) && s.Channels.Any(c => c.Id == channelId)); if (server is null) { return(new Failure <Server, Error>(ChannelErrors.ChannelNotFound())); } else { return(new Success <Server, Error>(server)); } } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Server, Error>(SystemErrors.Exception())); } }
/// <summary> /// Sends a new message to all users from the parameters provided. /// </summary> /// <param name="message">The message to be sent to connected users</param> /// <returns>A task instance</returns> public async Task PostPrivateGroupMessage(long groupId, Message message) { var httpContext = Context.GetHttpContext(); var monad = await _privateGroupMessagingService.PostAsync(httpContext, groupId, message); var signalGroup = PrivateGroupSignalName(groupId); switch (monad) { case Success <Unit, Error> _: var payload = new Payload <Message>(signalGroup, message); await Clients.Group(signalGroup).PrivateGroupMessageReceived(payload); break; case Failure <Unit, Error> failure: var failurePayload = new Payload <Error>(signalGroup, failure.Value); await Clients.Caller.PrivateGroupMessageReceived(failurePayload); break; default: var exceptionPayload = new Payload <Error>(signalGroup, SystemErrors.Exception()); await Clients.Caller.PrivateGroupMessageReceived(exceptionPayload); break; } }
/// <summary> /// Informs a direct messaging chat about a message that was deleted from a user. /// </summary> /// <param name="directMessageId">The id of the direct messaging chat</param> /// <param name="message">The message to be updated</param> /// <returns>A Task instance</returns> public async Task DeleteDirectMessage(long directMessageId, Message message) { var httpContext = Context.GetHttpContext(); var monad = await _directMessagingService.DeleteMessageAsync(httpContext, directMessageId, message); var signalGroup = DirectMessagingName(directMessageId); switch (monad) { case Success <Message, Error> success: var payload = new Payload <Message>(signalGroup, success.Value); await Clients.Groups(signalGroup).DirectMessageDeleted(payload); break; case Failure <Message, Error> failure: var errorPayload = new Payload <Error>(signalGroup, failure.Value); await Clients.Caller.DirectMessageDeleted(errorPayload); break; default: var exceptionPayload = new Payload <Error>(signalGroup, SystemErrors.Exception()); await Clients.Caller.DirectMessageDeleted(exceptionPayload); break; } }
/// <summary> /// This method will fetch all messages of a channels based on the provided id. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="channelId">The id of the channel</param> /// <param name="searchTerm">A term that needs to be present on all returned messages</param> /// <param name="lastMessageId">The id of the interval message for the rest</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <IEnumerable <Message>, Error> > GetMessagesAsync(HttpContext context, int channelId, string?searchTerm = null, long?lastMessageId = null) { try { var method = HttpMethod.Get; var url = $"api/channels/{channelId}/messages"; var query = HttpUtility.ParseQueryString(string.Empty); if (searchTerm is not null) { query[nameof(searchTerm)] = searchTerm; } if (lastMessageId is not null) { query[nameof(lastMessageId)] = lastMessageId.Value.ToString(); } if (query.Count > 0) { url += $"/?{query}"; } return(await _apiInteropService.SendAsync <IEnumerable <Message> >(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <IEnumerable <Message>, Error>(SystemErrors.Exception())); } }
/// <summary> /// Sends to a user a new server invitation. /// </summary> /// <param name="server">The id of the server the invitation is from</param> /// <param name="username">The name of the user the invitation will be sent</param> /// <returns>A Task instance</returns> public async Task SendInvitation(int serverId, string username) { var httpContext = Context.GetHttpContext(); var requestingUserId = httpContext.GetUserId().ToString(); var monad = await _userService.InsertInvitationAsync(httpContext, serverId, username); switch (monad) { case Success <Invitation, Error> success: var userId = success.Value.UserId.ToString(); await Clients.Groups(userId).NewInvitation(success.Value); break; case Failure <Invitation, Error> failure: await Clients.Caller.NewInvitation(failure.Value); break; default: await Clients.Caller.NewInvitation(SystemErrors.Exception()); break; } }
/// <summary> /// Sends an Http request to a remote Asterisk server in order to create a new /// pjsip endpoint. /// </summary> /// <param name="endpoint">The endpoint name</param> /// <returns>A task of an either monad</returns> private async Task <Either <Unit, Error> > PostEndpointAsync(string endpoint) { try { var parameters = new { id = endpoint, transport = "transport-ws", aors = endpoint, auth = $"auth{endpoint}", context = "burst", disallow = "all", allow = "opus", dtlsAutoGenerateCert = true, webrtc = true }; await _connection.ExecuteAsync(InsertEndpoint, parameters); return(new Success <Unit, Error>(Unit.New())); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Unit, Error>(SystemErrors.Exception())); } }
/// <summary> /// Informs the caller of all messages posted to a direct messaging chat. /// </summary> /// <param name="directMessagingId">The id of the target direct messaging chat</param> /// <param name="searchTerm">A search term that needs to be present in all returned messages</param> /// <param name="lastMessageId">The message id from which all previous messages will be fetched</param> /// <returns>A Task instance</returns> public async Task GetAllDirectMessages(long directMessagingId, string?searchTerm, long?lastMessageId) { var httpContext = Context.GetHttpContext(); var monad = await _directMessagingService.GetMessagesAsync(httpContext, directMessagingId, searchTerm, lastMessageId); var signalGroup = DirectMessagingName(directMessagingId); switch (monad) { case Success <IEnumerable <Message>, Error> success: var payload = new Payload <IEnumerable <Message> >(signalGroup, success.Value); await Clients.Caller.AllDirectMessagesReceived(payload); break; case Failure <IEnumerable <Message>, Error> failure: var errorPayload = new Payload <Error>(signalGroup, failure.Value); await Clients.Caller.AllDirectMessagesReceived(errorPayload); break; default: var exceptionPayload = new Payload <Error>(signalGroup, SystemErrors.Exception()); await Clients.Caller.AllDirectMessagesReceived(exceptionPayload); break; } }
/// <summary> /// Removes a user from an existing BurstChat server. /// </summary> /// <param name="serverId">The id of the server</param> /// <param name="subscription">The subscription to be removed</param> /// <returns>A task instance</returns> public async Task DeleteSubscription(int serverId, Subscription subscription) { var httpContext = Context.GetHttpContext(); var monad = await _serverService.DeleteSubscription(httpContext, serverId, subscription); switch (monad) { case Success <Subscription, Error> success: var signalGroup = ServerSignalName(serverId); var data = new dynamic[] { serverId, subscription }; await Clients.Group(signalGroup).SubscriptionDeleted(data); break; case Failure <Subscription, Error> failure: await Clients.Caller.SubscriptionDeleted(failure.Value); break; default: await Clients.Caller.SubscriptionDeleted(SystemErrors.Exception()); break; } }
/// <summary> /// This method will create a new direct messaging entry. /// </summary> /// <param name="userId">The id of the requesting user</param> /// <param name="firstParticipantId">The user id of the first participant</param> /// <param name="secondParticipantId">The user id of the second participant</param> /// <returns>An either monad</returns> public Either <DirectMessaging, Error> Insert(long userId, long firstParticipantId, long secondParticipantId) { try { var isProperUser = firstParticipantId == userId || secondParticipantId == userId; var directMessaging = _burstChatContext .DirectMessaging .FirstOrDefault(dm => (dm.FirstParticipantUserId == firstParticipantId && dm.SecondParticipantUserId == secondParticipantId) || (dm.FirstParticipantUserId == secondParticipantId && dm.SecondParticipantUserId == firstParticipantId)); if (!isProperUser || directMessaging is not null) { return(new Failure <DirectMessaging, Error>(DirectMessagingErrors.DirectMessagingAlreadyExists())); } var newDirectMessaging = new DirectMessaging { FirstParticipantUserId = firstParticipantId, SecondParticipantUserId = secondParticipantId, }; _burstChatContext .DirectMessaging .Add(newDirectMessaging); _burstChatContext.SaveChanges(); return(new Success <DirectMessaging, Error>(newDirectMessaging)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <DirectMessaging, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will invoke a call to the BurstChat API for the deletion of a channel. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="channelId">The id of the channel</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <Channel, Error> > DeleteAsync(HttpContext context, int channelId) { try { var method = HttpMethod.Delete; var url = $"api/channels/{channelId}"; return(await _apiInteropService.SendAsync <Channel>(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Channel, Error>(SystemErrors.Exception())); } }
/// <summary> /// Sends an Http request to a remore Asterisk server and returns information /// about a pjsip endpoint, if that exists. /// </summary> /// <param name="endpoint">The endpoint name</param> /// <returns>A task of an either monad</returns> public async Task <Either <AsteriskEndpoint, Error> > GetAsync(string endpoint) { try { var info = await _connection .QueryFirstAsync <AsteriskEndpoint>(GetEndpointCredentials, new { endpoint }); return(new Success <AsteriskEndpoint, Error>(info)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <AsteriskEndpoint, Error>(SystemErrors.Exception())); } }
/// <summary> /// Fetches all available information about a direct messaging entry based on the provided id. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="directMessagingId">The id of the target entry</param> /// <returns>An either monad</returns> public async Task <Either <DirectMessaging, Error> > GetAsync(HttpContext context, long directMessagingId) { try { var method = HttpMethod.Get; var url = $"/api/direct/{directMessagingId}"; return(await _apiInteropService.SendAsync <DirectMessaging>(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <DirectMessaging, Error>(SystemErrors.Exception())); } }
/// <summary> /// Fetches information about a server based on the provided parameters. /// </summary> /// <param name="context">The current http context</param> /// <param name="serverId">The id of the target server</param> /// <returns>A task of an either monad</returns> public async Task <Either <Server, Error> > GetAsync(HttpContext context, int serverId) { try { var method = HttpMethod.Get; var url = $"/api/servers/{serverId}"; return(await _apiInteropService.SendAsync <Server>(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Server, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will fetch all messages of a private group based on the provided id. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="groupId">The id of the private group</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <IEnumerable <Message>, Error> > GetAllAsync(HttpContext context, long groupId) { try { var url = $"/api/groups/{groupId}"; var method = HttpMethod.Get; return(await _apiInteropService.SendAsync <IEnumerable <Message> >(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <IEnumerable <Message>, Error>(SystemErrors.Exception())); } }
/// <summary> /// Fetches all invitations sent to an authenticated user. /// </summary> /// <param name="context">The current http context</param> /// <returns>An either monad</returns> public async Task <Either <IEnumerable <Invitation>, Error> > GetAllInvitationsAsync(HttpContext context) { try { var method = HttpMethod.Get; var url = $"api/user/invitations"; return(await _apiInteropService.SendAsync <IEnumerable <Invitation> >(context, method, url)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <IEnumerable <Invitation>, Error>(SystemErrors.Exception())); } }
/// <summary> /// Creates a new server invitation for a user based on the provided parameters. /// </summary> /// <param name="context">The current http context</param> /// <param name="server">The id of the server the invitation is from</param> /// <param name="username">The name of the user the invitation will be sent</param> /// <returns>A task of an either monad</returns> public async Task <Either <Invitation, Error> > InsertInvitationAsync(HttpContext context, int serverId, string username) { try { var method = HttpMethod.Post; var url = $"api/servers/{serverId}/invitation"; var content = new StringContent($"\"{username}\"", Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Invitation>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Invitation, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will invoke a call to the BurstChat API inorder to update information about /// a channel. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="channel">The updated information of the channel</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <Channel, Error> > PutAsync(HttpContext context, Channel channel) { try { var method = HttpMethod.Put; var url = "api/channels"; var jsonMessage = JsonSerializer.Serialize(channel); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Channel>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Channel, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will delete an existing message from a channel based on the provided channel id /// and message. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="channelId">The id of the channel</param> /// <param name="message">The message to be deleted</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <Message, Error> > DeleteMessageAsync(HttpContext context, int channelId, Message message) { try { var method = HttpMethod.Delete; var url = $"api/channels/{channelId}/messages"; var jsonMessage = JsonSerializer.Serialize(message.Id); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Message>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Message, Error>(SystemErrors.Exception())); } }
/// <summary> /// Updates a sent invitations based on the provided parameters. /// </summary> /// <param name="context">The current http context</param> /// <param name="invitation">The invitations instance to be updated</param> /// <returns>A task of an either monad</returns> public async Task <Either <Invitation, Error> > UpdateInvitationAsync(HttpContext context, UpdateInvitation invitation) { try { var method = HttpMethod.Put; var url = $"/api/user/invitation"; var jsonMessage = JsonSerializer.Serialize(invitation); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Invitation>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Invitation, Error>(SystemErrors.Exception())); } }
/// <summary> /// This method will post a new message to a private group based on the provided group id /// and message. /// </summary> /// <param name="context">The http context of the current request</param> /// <param name="groupId">The id of the group</param> /// <param name="message">The message to be posted</param> /// <returns>A task that encapsulates an either monad</returns> public async Task <Either <Unit, Error> > PostAsync(HttpContext context, long groupId, Message message) { try { var url = $"/api/groups/{groupId}/messages"; var method = HttpMethod.Post; var jsonMessage = JsonConvert.SerializeObject(message); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Unit, Error>(SystemErrors.Exception())); } }
/// <summary> /// Requests the createion of a new server based on the provided id. /// </summary> /// <param name="context">The current http context</param> /// <param name="server">The server instance to be created</param> /// <returns>A task of an either monad</returns> public async Task <Either <Server, Error> > PostAsync(HttpContext context, Server server) { try { var method = HttpMethod.Post; var url = $"/api/servers"; var jsonMessage = JsonSerializer.Serialize(server); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Server>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Server, Error>(SystemErrors.Exception())); } }
/// <summary> /// Removes a subscription from an existing server. /// </summary> /// <param name="context">The current http context</param> /// <param name="serverId">The id of the server</param> /// <param name="subscription">The subscription to be removed</param> /// <returns>A task of an either monad</returns> public async Task <Either <Subscription, Error> > DeleteSubscription(HttpContext context, int serverId, Subscription subscription) { try { var method = HttpMethod.Delete; var url = $"/api/servers/{serverId}/subscriptions"; var jsonMessage = JsonSerializer.Serialize(subscription); var content = new StringContent(jsonMessage, Encoding.UTF8, "application/json"); return(await _apiInteropService.SendAsync <Subscription>(context, method, url, content)); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <Subscription, Error>(SystemErrors.Exception())); } }
/// <summary> /// Adds a new direct messaging entry, if it does not already exist, and also assings the callers /// connection id to a signalr group based on the resulting direct messaging id. /// </summary> /// <param name="firstParticipantId">The user id of the first participant</param> /// <param name="secondParticipantId">The user id of the second participant</param> /// <returns>A Task instance</returns> public async Task PostNewDirectMessaging(long firstParticipantId, long secondParticipantId) { // Trying to find an existing direct messaging entry based on the users provided. var httpContext = Context.GetHttpContext(); var getMonad = await _directMessagingService.GetAsync(httpContext, firstParticipantId, secondParticipantId); if (getMonad is Success <DirectMessaging, Error> success) { var signalGroup = DirectMessagingName(success.Value.Id); var payload = new Payload <DirectMessaging>(signalGroup, success.Value); await Groups.AddToGroupAsync(Context.ConnectionId, signalGroup); await Clients.Caller.NewDirectMessaging(payload); } // Creates a new direct messaging entry between two users. var directMessaging = new DirectMessaging { FirstParticipantUserId = firstParticipantId, SecondParticipantUserId = secondParticipantId }; var monad = await _directMessagingService.PostAsync(httpContext, directMessaging); switch (monad) { case Success <DirectMessaging, Error> postSuccess: var signalGroup = DirectMessagingName(postSuccess.Value.Id); var payload = new Payload <DirectMessaging>(signalGroup, postSuccess.Value); await Groups.AddToGroupAsync(Context.ConnectionId, signalGroup); await Clients.Caller.NewDirectMessaging(payload); break; case Failure <DirectMessaging, Error> failure: await Clients.Caller.NewDirectMessaging(failure.Value); break; default: await Clients.Caller.NewDirectMessaging(SystemErrors.Exception()); break; } }
/// <summary> /// This method will delete a direct messaging entry. /// </summary> /// <param name="userId">The id of the requesting user</param> /// <param name="directMessagingId">The id of the group</param> /// <returns>An either monad</returns> public Either <DirectMessaging, Error> Delete(long userId, long directMessagingId) { try { return(Get(userId, directMessagingId).Bind(directMessaging => { _burstChatContext .DirectMessaging .Remove(directMessaging); return new Success <DirectMessaging, Error>(directMessaging); })); } catch (Exception e) { _logger.LogError(e.Message); return(new Failure <DirectMessaging, Error>(SystemErrors.Exception())); } }