// send message in channel public void SendMessageInChannel(string sender, Message message, string channelId, string workspaceName) { try { //////////////////////Notification Work////////////////////////////////////// var cache = RedisConnectorHelper.Connection.GetDatabase(); var stringifiedUserState = cache.StringGetAsync($"{sender}"); var UserStateObject = JsonConvert.DeserializeObject <UserState>(stringifiedUserState.Result); UserStateObject.ListOfWorkspaceState.Find(w => w.WorkspaceName == workspaceName). ListOfChannelState.Find(c => c.channelId == channelId).UnreadMessageCount = 0; UserStateObject.ListOfWorkspaceState.Find(w => w.WorkspaceName == workspaceName). ListOfChannelState.Find(c => c.channelId == channelId).LastTimestamp = message.Timestamp; string jsonString = JsonConvert.SerializeObject(UserStateObject); cache.StringSetAsync($"{sender}", jsonString); /////////////////////////////////////////////////////////////////////////////// Groups.AddToGroupAsync(Context.ConnectionId, channelId); var newMessage = iservice.AddMessageToChannel(message, channelId, sender).Result; Clients.Group(channelId).SendAsync("SendMessageInChannel", sender, newMessage); } catch (Exception e) { Console.Write(e.Message); } }
public IActionResult AddMessageToChannel([FromBody] Message message, string channelId, string senderMail) // frombody workspace object or string name { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // call service to add message in channel var newMessage = iservice.AddMessageToChannel(message, channelId, senderMail).Result; return(new ObjectResult(newMessage)); }