Beispiel #1
0
        /// <summary>
        /// 群组发送消息
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public Task ClientSendMsgToGroup(ClientToGroupMessage message)
        {
            //先生成groupid
            var groupId = GroupHelper.CreateGroup().CreateName(message.to.id);

            message.roomid = groupId;
            //保存消息
            Task.Run(() => {
                MessageFactory.CreateInstance(ChatMessageSaveType.SearchEngine).Send(message);
            });
            //处理保存消息业务
            //发送给客户端
            ClientToClientReceivedMessage tomessage = new ClientToClientReceivedMessage
            {
                fromid   = message.mine.id,
                id       = message.to.id,        //注意,这里的群组发送人,就应该是群id了
                avatar   = message.mine.avatar,  //发送人头像
                content  = message.mine.content, //发送内容
                type     = message.to.type,      //类型 这里一定是friend
                username = message.mine.username //发送人姓名
            };
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg     = tomessage,
                other   = null,
                msgtype = ChatToClientType.ClientToGroup//这里是群组类型
            };

            return(Clients.Group(groupId).receiveMessage(result));
        }
Beispiel #2
0
        /// <summary>
        /// 客户端聊天消息
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public Task ClientSendMsgToClient(ClientToClientMessage message)
        {
            //先生成groupid
            var groupId = GroupHelper.CreateGroup().CreateName(message.mine.id, message.to.id);

            message.roomid = groupId;
            //处理保存消息业务
            Task.Run(() => {
                ElasticMessage.Instance.Send(message);
            });
            #region  //发送给客户端

            ClientToClientReceivedMessage tomessage = new ClientToClientReceivedMessage
            {
                fromid   = message.mine.id,
                id       = message.mine.id,      //发送人id
                avatar   = message.mine.avatar,  //发送人头像
                content  = message.mine.content, //发送内容
                type     = message.to.type,      //类型 这里一定是friend
                username = message.mine.username //发送人姓名
            };
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg = tomessage, other = null, msgtype = ChatToClientType.ClientToClient
            };
            #endregion
            return(Clients.Group(groupId).receiveMessage(result));
        }