Exemplo n.º 1
0
        // sends a message to a room, conversation or user
        public async Task <IHttpActionResult> SendChatMessage(ChatMessageModel message)
        {
            message.FromID    = CurrentUser.UserID;
            message.CreatedOn = DateTime.Now;
            ModelState.Remove("message.FromID");
            ModelState.Remove("message.CreatedOn");
            message.PostedByName   = CurrentUser.FullName;
            message.PostedByAvatar = CurrentUser.ProfilePicture;

            if (ModelState.IsValid)
            {
                try
                {
                    BroadcastChatMessage model = _chat.SendChatMessage(message);
                    await _broadcaster.SendChatMessage(model, message.broadCastType);

                    return(Ok(model.ChatMessage));
                }
                catch (Exception ex)
                {
                    Logs.Error("Error adding message to page", ex);
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState.JsonValidation()));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// broadcast message to page
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task BroadcastChatMessageToWeb(BroadcastChatMessage model)
        {
            IList <string> connectionIDs = _user.GetFollowerList(model.ChatMessage.FromID, model.ChatMessage.ToID, model.ChatMessage.PageType, Enums.FriendshipStatus.FA)
                                           .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList();

            await _chatBroadCaster.Clients.Clients(connectionIDs)
            .sendMessage(model.ChatMessage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Select a broad casting way to new comment to a post
        /// </summary>
        /// <param name="post"></param>
        public async Task SendChatMessage(BroadcastChatMessage model, Enums.BroadCastType BroadCastType)
        {
            try
            {
                switch (BroadCastType)
                {
                case Enums.BroadCastType.Web:
                    await BroadcastChatMessageToWeb(model);

                    break;
                }
            }
            catch (Exception ex)
            {
                ExceptionService.LogError("Error broadcasting comment to post", ex);
            }
        }
Exemplo n.º 4
0
        // sends a message to a room, conversation or user
        public void sendMessage(ChatMessageModel message)//int roomId, long conversationId, long otherUserId, string messageText, string clientGuid)
        {
            try
            {
                message.FromID         = CurrentUser.UserID;
                message.CreatedOn      = DateTime.Now;
                message.PostedByName   = CurrentUser.FullName;
                message.PostedByAvatar = CurrentUser.ProfilePicture;
                message.FromName       = CurrentUser.UserName;

                BroadcastChatMessage model = _hub.SendChatMessage(message);

                IList <string> connectionIDs = new BusinessLogic.UserAccess().GetFollowerList(model.ChatMessage.FromID, model.ChatMessage.ToID, model.ChatMessage.PageType, Enums.FriendshipStatus.FA)
                                               .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList();

                Clients.Clients(connectionIDs).sendMessage(model.ChatMessage);
            }
            catch (Exception ex)
            {
                Logs.Error("Error while sending message.", ex);
            }
        }