Exemple #1
0
        /// <summary>
        /// 向用户列表中的在线用户推送信息
        /// </summary>
        /// <param name="p_userIDs">用户列表</param>
        /// <param name="p_msg">待推送信息</param>
        /// <returns>在线推送列表</returns>
        public static async Task <List <long> > Push(List <long> p_userIDs, MsgInfo p_msg)
        {
            if (p_userIDs == null || p_userIDs.Count == 0 || p_msg == null)
            {
                throw new Exception("待推送的用户或信息不可为空!");
            }

            var    onlines   = new List <long>();
            var    offlines  = new List <long>();
            string onlineMsg = p_msg.GetOnlineMsg();
            int    cnt       = await Kit.GetSvcReplicaCount();

            if (cnt > 1)
            {
                // Msg服务多副本推送
                await PushMultipleReplicas(p_userIDs, onlineMsg, onlines, offlines, cnt);
            }
            else
            {
                // 本地单副本推送
                PushLocal(p_userIDs, onlineMsg, onlines, offlines);
            }

            // 离线
            if (offlines.Count > 0)
            {
                // 将消息保存到用户的未推送列表
                var lc = new ListCache <string>(MsgQueueKey);
                foreach (long id in offlines)
                {
                    await lc.RightPush(id, onlineMsg);
                }

                // 推送离线提醒
                if (!string.IsNullOrEmpty(p_msg.Title))
                {
                    Offline.Add(offlines, p_msg);
                }
            }
            return(onlines);
        }
Exemple #2
0
        public RegisterStatus Register(string Username)
        {
            GetUsersResponse resp = api.Helix.Users.GetUsersAsync(logins: new List <string>()
            {
                Username
            }).Result;
            List <UserResponse> user = resp.Users.Select(t => new UserResponse(t)).ToList();

            if (user.Count == 0)
            {
                return(RegisterStatus.UserNotFound);
            }

            if (Tracking.Contains(user[0].Id))
            {
                return(RegisterStatus.AlreadyTracking);
            }

            Tracking.Add(user[0].Id);
            Offline.Add(user[0].Id);
            UserDatabase.Add(user[0].Id, user[0]);

            return(RegisterStatus.Success);
        }