Пример #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);
            }
        }
Пример #2
0
        public override void MessageProcess(Message message, Microsoft.AspNet.SignalR.IHubContext hucontext)
        {
            int orgid = -1;
            int depid = -1;
            var ids   = message.ReceiveId.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

            if (ids.Length == 2)
            {
                orgid = Convert.ToInt32(ids[0]);
                depid = Convert.ToInt32(ids[1]);
            }
            else
            {
                orgid = Convert.ToInt32(ids[0]);
            }
            List <Users> groupuser = null;

            if (depid == -1)
            {
                groupuser = userbll.LoadAll(c => c.OrganId == orgid && c.UserId != message.SendId).ToList();
            }
            else
            {
                groupuser = userbll.LoadAll(c => c.OrganId == orgid && c.DepartmentId == depid && c.UserId != message.SendId).ToList();
            }
            groupuser.ForEach(c =>
            {
                if (MyHub.Usermananger.Contains(c.UserId.ToString()))
                {
                    return;
                }
                DepositHelper.ListRightPush(RedisKeyManager.OfflineGroupMessageQueue(c.UserId.ToString()), message);
            });

            hucontext.Clients.Group(message.ReceiveId.ToString()).receive(new
            {
                username  = message.SendName,
                avatar    = message.SendHeadPath,
                type      = message.MessageType,
                id        = message.ReceiveId,
                sendid    = message.SendId,
                content   = message.MessageContent,
                mine      = false,
                timestamp = DateTime.Now
            });
        }