Beispiel #1
0
        public void PrcoessOfflineMessage(string uid)
        {
            string keya = RedisKeyManager.OfflineMessageQueue(uid);
            string keyb = RedisKeyManager.OfflineGroupMessageQueue(uid);
            //点对点离线消息
            List <Message> usermessage = DepositHelper.GetList <Message>(keya);
            //群聊消息
            List <Message> groupMessage = DepositHelper.GetList <Message>(keyb);

            SignalrClient.BLL.UserBLL user  = new SignalrClient.BLL.UserBLL();
            List <object>             objes = null;

            if (usermessage != null && usermessage.Count > 0)
            {
                var id       = usermessage[0].SendId;
                var sendUser = user.Get(c => c.UserId == id);
                objes = new List <object>();
                usermessage.ForEach(message =>
                {
                    objes.Add(new
                    {
                        username  = sendUser.UserName,
                        avatar    = sendUser.HeadPath,
                        type      = message.MessageType,
                        id        = message.SendId,
                        content   = message.MessageContent,
                        mine      = false,
                        timestamp = message.CreateTime,
                    });
                });
                Clients.User(uid).receiveOffline(objes);
                //发送完则删除
                DepositHelper.RemoveKey(keya);
            }
            if (groupMessage != null && groupMessage.Count > 0)
            {
                objes = new List <object>();
                groupMessage.ForEach(message =>
                {
                    objes.Add(new
                    {
                        username  = message.SendName,
                        avatar    = message.SendHeadPath,
                        type      = message.MessageType,
                        id        = message.ReceiveId,
                        sendid    = message.SendId,
                        content   = message.MessageContent,
                        mine      = false,
                        timestamp = message.CreateTime
                    });
                });

                Clients.User(uid).receiveGroupOffline(objes);
                //发送完则删除
                DepositHelper.RemoveKey(keyb);
            }
        }
Beispiel #2
0
        public override void MessageProcess(Message message, Microsoft.AspNet.SignalR.IHubContext hubcontext)
        {
            var sendUser = user.Get(c => c.UserId == message.SendId);

            if (MyHub.Usermananger.Contains(message.ReceiveId.ToString()))
            {
                var id = Convert.ToInt32(message.ReceiveId);

                hubcontext.Clients.User(message.ReceiveId.ToString()).receive(new{
                    username  = message.SendName,
                    avatar    = message.SendHeadPath,
                    type      = message.MessageType,
                    id        = message.SendId,
                    content   = message.MessageContent,
                    mine      = false,
                    timestamp = DateTime.Now
                });
            }
            else
            {
                DepositHelper.ListRightPush(RedisKeyManager.OfflineMessageQueue(message.ReceiveId.ToString()), message);
            }
        }