Ejemplo n.º 1
0
 /// <summary>
 /// Gửi bản tin thách đấu lên club
 /// </summary>
 /// <param name="SenderID"></param>
 /// <param name="TargetID"></param>
 /// <param name="content"></param>
 /// <param name="startTimer"></param>
 /// <param name="EndTime"></param>
 public static void ChallengeClub(long SenderID, long TargetClubID, string content, long startTimer, long EndTime)
 {
     if (!SeqIDsClubTarget.ContainsKey(TargetClubID))
     {
         QHMessage msg       = new QHMessage((ushort)PingPongMsg.MSG_INVITE_CHALLENGE_REQ);
         var       Challenge = new ChallengeInfo();
         Challenge.SenderID   = SenderID;
         Challenge.TargetType = 1;
         Challenge.TargetID   = TargetClubID;
         Challenge.Content    = content;
         Challenge.StartTime  = startTimer;
         Challenge.EndTime    = EndTime;
         Challenge.SeqID      = SeqIDs.Count + 1;
         msg.SetAt((byte)MsgInviteChallengeReqArg.SenderID, new QHNumber(SenderID));
         msg.SetAt((byte)MsgInviteChallengeReqArg.TargetType, new QHNumber(1));
         msg.SetAt((byte)MsgInviteChallengeReqArg.TargetID, new QHNumber(TargetClubID));
         msg.SetAt((byte)MsgInviteChallengeReqArg.Content, new QHString(content));
         msg.SetAt((byte)MsgInviteChallengeReqArg.StartTime, new QHNumber(startTimer));
         msg.SetAt((byte)MsgInviteChallengeReqArg.EndTime, new QHNumber(EndTime));
         msg.SetAt((byte)MsgInviteChallengeReqArg.SeqID, new QHNumber(SeqIDs.Count + 1));
         if (!SeqIDs.ContainsKey(SeqIDs.Count + 1))
         {
             SeqIDs.Add(SeqIDs.Count + 1, Challenge);
         }
         Services.Service.Instiance().SendMessage(msg);
     }
     else
     {
         UserDialogs.Instance.Toast("Đang đợi duyệt từ Admin hoặc đợi 15 phút để tiếp tục gửi thách đấu");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Lọc ack cho từ ứng dụng
        /// </summary>
        /// <param name="msg"></param>
        public void AcceptAck(QHMessage msg)
        {
            App app = Application.Current as App;

            if (myAccept == 1)
            {
                if (myAccJoinClub != null)
                {
                    Services.Service.Instiance().ClubModel.MyClub.Numbers.Add(myAccJoinClub.IdNumberID);
                    Services.Service.Instiance().ClubModel.MyClub.Requests.Remove(myAccJoinClub.IdNumberID);
                    Services.Service.Instiance().ClubModel.MyClub.ReloadReative();
                    app.ListAccInClub.Remove(myAccJoinClub);
                    ListRequest.Remove(myAccJoinClub);
                    myAccJoinClub = null;
                    NotifiDialog.Initiance().DialogAccept();
                }
            }
            else
            {
                if (myAccJoinClub != null)
                {
                    Services.Service.Instiance().ClubModel.MyClub.Requests.Remove(myAccJoinClub.IdNumberID);
                    //Services.Service.Instiance().ClubModel.MyClub.ReloadReative();
                    app.ListAccInClub.Remove(myAccJoinClub);
                    ListRequest.Remove(myAccJoinClub);
                    myAccJoinClub = null;
                }
            }
        }
Ejemplo n.º 3
0
 public void SendAddInfoPingPong(InfPpAccount Pp)
 {
     QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_PROFILE_INFO_REQ);
     //if (Pp != null)
     //{
     //    if(Pp)
     //}
 }
Ejemplo n.º 4
0
        /// <summary>
        /// gửi bản tin trả lời thách đấu từ admin hoặc cá nhân
        /// </summary>
        /// <param name="NumberID"></param>
        /// <param name="ChallengeID"></param>
        public static void AcceptOrCancelChall(long ChallengeID, long Accept)
        {
            QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_INVITE_CHALLENGE_CNF);

            msg.SetAt((byte)MsgInviteChallengeCnfArg.ChallengeID, new QHNumber(ChallengeID));
            msg.SetAt((byte)MsgInviteChallengeCnfArg.Accept, new QHNumber(Accept));
            Services.Service.Instiance().SendMessage(msg);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// gửi bản tin xóa lời mời thách đấu với ngườu khác
        /// </summary>
        /// <param name="NumberID">Number của người chủ lời mời</param>
        /// <param name="ChallengeID">ID của lời mời thách đấu</param>
        public static void CancelChallenge(long NumberID, long ChallengeID)
        {
            QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_CANCEL_CHALLENGE_REQ);

            msg.SetAt((byte)MsgCancelChallengeReqArg.NumberID, new QHNumber(NumberID));
            msg.SetAt((byte)MsgCancelChallengeReqArg.ChallengeID, new QHNumber(ChallengeID));
            Services.Service.Instiance().SendMessage(msg);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// lấy danh sách các thách đấu của người dùng
        /// </summary>
        /// <param name="NumberID"></param>
        public static void SetGetChallenge(long NumberID, long ClubID)
        {
            QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_LIST_CHALLENGES_REQ);

            msg.SetAt((byte)MsgListChallengeReqArg.NumberID, new QHNumber(NumberID));
            if (ClubID > 0)
            {
                msg.SetAt((byte)MsgListChallengeReqArg.ClubID, new QHNumber(ClubID));
            }
            Services.Service.Instiance().SendMessage(msg);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// thực hiện login vào hệ thống
        /// </summary>
        /// <param name="PhoneNumber"></param>
        /// <param name="PassWord"></param>
        public void loginExe(string PhoneNumber, string PassWord)
        {
            QHMessage msg = new QHMessage((ushort)Chat.ChatMessage.MSG_LOGIN_REQ);

            msg.SetAt((byte)Chat.MsgLoginReqArg.PhoneNumber, new QHString(PhoneNumber));
            msg.SetAt((byte)Chat.MsgLoginReqArg.MD5Password, new QHString(MD5.MD5.GetMd5String(PassWord)));
            msg.SetAt((byte)Chat.MsgLoginReqArg.DeviceID, CrossDeviceInfo.Current.Id);
            if (!Services.Service.Instiance().SendMessage(msg))
            {
                NotifiDialog.Initiance().DialogErrorInternter();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Thực hiện đăng kí tài khoản lên server
        /// </summary>
        /// <param name="PhoneNumber"></param>
        /// <param name="PassWord"></param>
        /// <param name="FullName"></param>
        public void Register(string PhoneNumber, string FullName, string PassWord)
        {
            this.PhoneNumber = PhoneNumber;
            this.PassWord    = PassWord;
            this.FullName    = FullName;
            QHMessage msg = new QHMessage((ushort)Chat.ChatMessage.MSG_REGISTER_REQ);

            msg.SetAt((byte)Chat.MsgRegisterReqArg.PhoneNumber, new QHString(PhoneNumber));
            msg.SetAt((byte)Chat.MsgRegisterReqArg.MD5Password, new QHString(MD5.MD5.GetMd5String(PassWord)));
            msg.SetAt((byte)Chat.MsgRegisterReqArg.FullName, FullName);
            Services.Service.Instiance().SendMessage(msg);
        }
        /// <summary>
        /// Gửi Bản tin đăng bài cá nhân lên Server
        /// </summary>
        public async void SendContentPost()
        {
            // Kiểm tra xem có homepageInfo chưa?
            if (Services.Service.Instiance().NewsSiteVM.homePageInfo == null)
            {
                UserDialogs.Instance.Toast("Không xác định được trang cá nhân");
                return;
            }
            var  idhome = Services.Service.Instiance().NewsSiteVM.homePageInfo.homePageId;
            bool isPost = true;

            account = Helper.Instance().MyAccount;
            //thêm nội dung cho content
            var list = new List <string>();

            // Lấy ảnh của bài đăng
            if (images.Count > 0)
            {
                isPost = await postMuiltiImage();
            }
            QHVector Image_Id = new QHVector();
            var      imagesID = new List <long>();

            if (!isPost)
            {
                for (int i = 0; i < images.Count; i++)
                {
                    list.Add(images[i].UriImage);
                    Image_Id.SetAt(i, new QHNumber(images[i].Image_Id));
                    imagesID.Add(images[i].Image_Id);
                }
            }
            QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_HOMEPAGE_ADD_CONTENT_REQ);

            json = new ContentFormat {
                Text = personalPost.content, Images_Id = list
            };
            string output = JsonConvert.SerializeObject(json);

            //kiểm tra account
            if (Helper.Instance().CheckLogin())
            {
                account = Helper.Instance().MyAccount;
                msg.SetAt((byte)MsgHomePageAddContentReq.SenderID, new QHNumber(account.Number_Id));
                msg.SetAt((byte)MsgHomePageAddContentReq.HomePageID, new QHNumber(Services.Service.Instiance().NewsSiteVM.homePageInfo.homePageId));
                msg.SetAt((byte)MsgHomePageAddContentReq.Content, new QHString(output));
                msg.SetAt((byte)MsgHomePageAddContentReq.ImagesID, Image_Id);
                Services.Service.Instiance().SendMessage(msg);
                Debug.WriteLine("MSG_HOMEPAGE_ADD_CONTENT_REQ: " + msg.JSONString());
            }
        }
        /// <summary>
        /// Bản tin đăng bài từ Server trả về
        /// </summary>
        /// <param name="msg"></param>
        public void UpdateContent(QHMessage msg)
        {
            long errorCode  = 0;
            long contentId  = 0;
            long homePageId = 0;
            long CreateDate = 0;

            msg.TryGetAt((byte)MsgHomePageAddContentAck.Error, ref errorCode);
            if (errorCode == 0)
            {
                if (msg.TryGetAt((byte)MsgHomePageAddContentAck.ContentID, ref contentId))
                {
                }
                if (msg.TryGetAt((byte)MsgHomePageAddContentAck.HomePageID, ref homePageId))
                {
                }
                var contentInfo = new ContentInfo();
                contentInfo.Accounts = Helper.Instance().MyAccount;
                if (msg.TryGetAt((byte)MsgHomePageAddContentAck.CreateDate, ref CreateDate))
                {
                    contentInfo.Detail.Created = CreateDate;
                }
                contentInfo.Detail.Id      = contentId;
                contentInfo.Detail.Content = JsonConvert.SerializeObject(json);
                // Thêm vào cached content để lần sau lấy ra dùng
                if (!Helper.Instance().ListContent.ContainsKey(contentId))
                {
                    lock (Helper.Instance().ListContent)
                    {
                        Helper.Instance().ListContent.Add(contentId, contentInfo);
                    }
                }

                else
                {
                    Helper.Instance().ListContent[contentId] = contentInfo;
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    Services.Service.Instiance().NewsSiteVM.ListNews.Insert(0, Helper.Instance().ListContent[contentId]);
                });
            }
            else
            {
                Debug.WriteLine("Error code: " + msg.JSONString());
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gửi like và unlike Reply
        /// </summary>
        /// <param name="isLike"></param>
        /// <param name="reply"></param>
        public static void SendLike(bool isLike, ref ReplyComments reply)
        {
            if (Helper.Instance().ListReplyComment.ContainsKey(reply.Id))
            {
                Helper.Instance().ListReplyComment[reply.Id] = reply;
            }
            else
            {
                Helper.Instance().ListReplyComment.Add(reply.Id, reply);
            }
            QHMessage msg;

            //like reply
            if (isLike)
            {
                msg = new QHMessage((ushort)PingPongMsg.MSG_LIKE_REQ);
            }
            //unlike reply
            else
            {
                msg = new QHMessage((ushort)PingPongMsg.MSG_UNLIKE_REQ);
            }
            if (reply != null)
            {
                var id = Helper.Instance().MyAccount.Number_Id;
                if (id > 0)
                {
                    msg.SetAt((byte)MsgLikeReqArg.NumberID, new QHNumber(id));
                }
                else
                {
                    return;
                }
                if (reply.Id > 0)
                {
                    msg.SetAt((byte)MsgLikeReqArg.ReplyID, new QHNumber(reply.Id));
                }
                else
                {
                    return;
                }
                Services.Service.Instiance().Like = Services.StatueLike.Reply;
                Services.Service.Instiance().SendMessage(msg);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Gửi Like và unlike Comment
 /// </summary>
 /// <param name="isLike"></param>
 /// <param name="comment"></param>
 public static void SendLike(bool isLike, ref CommentInfor comment)
 {
     if (comment != null)
     {
         if (Helper.Instance().ListComment.ContainsKey(comment.Comment.Id))
         {
             Helper.Instance().ListComment[comment.Comment.Id] = comment;
         }
         else
         {
             Helper.Instance().ListComment.Add(comment.Comment.Id, comment);
         }
         QHMessage msg;
         if (isLike)
         {
             msg = new QHMessage((ushort)PingPongMsg.MSG_LIKE_REQ);
         }
         else
         {
             msg = new QHMessage((ushort)PingPongMsg.MSG_UNLIKE_REQ);
         }
         var Id = Helper.Instance().MyAccount.Number_Id;
         //thêm id của người like vào trong club
         if (Id > 0)
         {
             msg.SetAt((byte)MsgLikeReqArg.NumberID, new QHNumber(Id));
         }
         else
         {
             return;
         }
         //thêm id của comment vào trong club
         if (comment.Comment.Id > 0)
         {
             msg.SetAt((byte)MsgLikeReqArg.CommentID, new QHNumber(comment.Comment.Id));
         }
         else
         {
             return;
         }
         Service.Instiance().Like = StatueLike.Comment;
         Service.Instiance().SendMessage(msg);
     }
 }
Ejemplo n.º 13
0
        public void RegisterProcess(QHMessage msg)
        {
            Chat.RegisterErrorCode ErrorCode = (Chat.RegisterErrorCode)(msg.GetAt((byte)Chat.MsgRegisterAckArg.ErrorCode) as QHNumber).value;
            switch (ErrorCode)
            {
            case Chat.RegisterErrorCode.SUCCESS:
            {
                UserDialogs.Instance.Toast("Bạn đã đăng ký thành công tài khoản");
                // Nếu đăng ký thành công thì gửi bản tin Login lên Server luôn
                if (!PhoneNumber.Equals("") && !PassWord.Equals(""))
                {
                    QHMessage msgLogin = new QHMessage((ushort)Chat.ChatMessage.MSG_LOGIN_REQ);
                    msgLogin.SetAt((byte)Chat.MsgLoginReqArg.PhoneNumber, new QHString(PhoneNumber));
                    msgLogin.SetAt((byte)Chat.MsgLoginReqArg.MD5Password, new QHString(MD5.MD5.GetMd5String(PassWord)));
                    msgLogin.SetAt((byte)Chat.MsgLoginReqArg.DeviceID, CrossDeviceInfo.Current.Id);
                    if (!Services.Service.Instiance().SendMessage(msgLogin))
                    {
                        NotifiDialog.Initiance().DialogErrorInternter();
                    }
                }
                else
                {
                    NotifiDialog.Initiance().DialogErrorNumber();
                }
                break;
            }

            case Chat.RegisterErrorCode.ERR_PHONE_IN_USED:
            {
                Device.BeginInvokeOnMainThread(() =>
                    {
                        NotifiDialog.Initiance().DialogExistPhoneNumber();
                    });
                break;
            }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Like Content Ack
        /// </summary>
        /// <param name="msg"></param>
        public static void LikeContentAck(QHMessage msg)
        {
            var error = (LikeError)(msg.GetAt((byte)MsgLikeAckArg.Error) as QHNumber).value;

            switch (error)
            {
            case LikeError.SUCCESS:
                //Debug.WriteLine("Thành công");
                long ContentID = 0;
                long CommentID = 0;
                long ReplyID   = 0;
                if (msg.TryGetAt((byte)MsgLikeAckArg.ContentID, ref ContentID))
                {
                    if (msg.TryGetAt((byte)MsgLikeAckArg.CommentID, ref CommentID))
                    {
                        if (msg.TryGetAt((byte)MsgLikeAckArg.ReplyID, ref ReplyID))
                        {
                        }
                    }
                }
                //Like Reply
                if (ReplyID > 0)
                {
                    if (Helper.Instance().ListReplyComment.ContainsKey(ReplyID))
                    {
                        var id = Helper.Instance().MyAccount.Number_Id;

                        if (id > 0)
                        {
                            if (Helper.Instance().ListReplyComment[ReplyID].Likes.IndexOf(id) < 0)
                            {
                                Helper.Instance().ListReplyComment[ReplyID].Likes.Add(id);
                                Helper.Instance().ListReplyComment[ReplyID].Owner = id;
                                Helper.Instance().ListReplyComment[ReplyID].Reset();
                            }
                        }
                    }
                    return;
                }
                //Like Comment
                if (CommentID > 0)
                {
                    if (Helper.Instance().ListComment.ContainsKey(CommentID))
                    {
                        var id   = Helper.Instance().MyAccount.Number_Id;
                        var item = Helper.Instance().ListComment[CommentID];
                        if (id > 0)
                        {
                            item.NumberId = id;
                            if (item.likes.IndexOf(id) < 0)
                            {
                                item.likes.Add(id);
                                item.Reset();
                            }
                        }
                    }
                    return;
                }
                //Like Content
                if (ContentID > 0)
                {
                    if (Helper.Instance().ListContent.ContainsKey(ContentID))
                    {
                        var item = Helper.Instance().ListContent[ContentID];
                        var like = (new LikeContent
                        {
                            Content_Id = ContentID,
                            Owner = Helper.Instance().MyAccount.Number_Id
                        });
                        item.LikeContent.Owner = Helper.Instance().MyAccount.Number_Id;
                        if (!item.LikeContent.LikeContent.ContainsKey("" + item.LikeContent.Owner))
                        {
                            item.LikeContent.LikeContent.Add("" + item.LikeContent.Owner, like);
                            item.LikeContent.Reset();
                        }
                    }
                    return;
                }
                break;

            case LikeError.ERR_PERMISSION_DENIED:
                Debug.WriteLine("");
                break;

            case LikeError.ERR_NOT_EXIST_REPLY:
                break;

            case LikeError.ERR_NOT_EXIST_CONTENT:
                break;

            case LikeError.ERR_NOT_EXIST_COMMENT:
                break;
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Gửi Like và UnLike Content
 /// </summary>
 /// <param name="isLike"></param>
 /// <param name="content"></param>
 public static void SendLike(bool isLike, ref ContentInfo content)
 {
     // kiểm tra tồn tại của content và cập nhật lại like cho content
     if (!Helper.Instance().ListContent.ContainsKey(content.Detail.Id))
     {
         lock (Helper.Instance().ListContent)
         {
             Helper.Instance().ListContent.Add(content.Detail.Id, content);
         }
     }
     else
     {
         Helper.Instance().ListContent[content.Detail.Id] = content;
     }
     //Like
     if (isLike)
     {
         QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_LIKE_REQ);
         if (Helper.Instance().MyAccount != null)
         {
             msg.SetAt((byte)MsgLikeReqArg.NumberID, new QHNumber(Helper.Instance().MyAccount.Number_Id));
         }
         else
         {
             return;
         }
         if (content != null && content.Detail.Id > 0)
         {
             msg.SetAt((byte)MsgLikeReqArg.ContentID, new QHNumber(content.Detail.Id));
         }
         else
         {
             return;
         }
         Service.Instiance().Like = StatueLike.Content;
         if (!Service.Instiance().SendMessage(msg))
         {
         }
     }
     //unlike
     else
     {
         QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_UNLIKE_REQ);
         if (Helper.Instance().MyAccount != null)
         {
             msg.SetAt((byte)MsgLikeReqArg.NumberID, new QHNumber(Helper.Instance().MyAccount.Number_Id));
         }
         else
         {
             return;
         }
         if (content != null && content.Detail.Id > 0)
         {
             msg.SetAt((byte)MsgLikeReqArg.ContentID, new QHNumber(content.Detail.Id));
         }
         else
         {
             return;
         }
         Service.Instiance().Like = StatueLike.Content;
         Service.Instiance().SendMessage(msg);
     }
 }
Ejemplo n.º 16
0
        public static void OnReciveAckChall(QHMessage msg)
        {
            long Error       = 0; // QHNumber
            long ChallengeID = 0; // QHNumber(ID của lời mời)
            long SeqID       = 0; // QHNumber(ID tự sinh do client gửi lên trong MsgInviteChallengeReqArg)
            long RemainTime  = 0; // QHNumber (Thời gian đếm ngược tính bằng giây khi có thể gửi lời mời thách đấu tiếp theo)

            if (msg.TryGetAt((byte)MsgInviteChallengeAckArg.Error, ref Error))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeAckArg.ChallengeID, ref ChallengeID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeAckArg.SeqID, ref SeqID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeAckArg.RemainTime, ref RemainTime))
            {
            }
            var ChallengeError = (InviteChallengeError)Error;

            switch (ChallengeError)
            {
            case InviteChallengeError.SUCCESS:
                if (SeqIDs.ContainsKey(SeqID))
                {
                    var Chall = SeqIDs[SeqID];
                    //thực hiện thách đấu với cá nhân
                    if (Chall.TargetType == 0)
                    {
                        if (Helpers.Helper.Instance().ListAcclocal.ContainsKey(Chall.TargetID))
                        {
                            Helpers.Helper.Instance().ListAcclocal[Chall.TargetID].Challenge = "pingpong_invi.png";
                            NotifiDialog.Initiance().DialogChallengePer(Helpers.Helper.Instance().ListAcclocal[Chall.TargetID].fullname);
                            if (!SeqIDsAccTarget.ContainsKey(Chall.TargetID))
                            {
                                SeqIDsAccTarget.Add(Chall.TargetID, SeqID);
                                ListAccRecive.Add(Chall.TargetID, Chall);
                            }
                        }
                    }
                    //thực hiện thách đấu với club
                    else
                    {
                        if (Helpers.Helper.Instance().ListClub.ContainsKey(Chall.TargetID))
                        {
                            Helpers.Helper.Instance().ListClub[Chall.TargetID].Challenge = "pingpong_invi.png";
                            NotifiDialog.Initiance().DialogChallengeClub(Helpers.Helper.Instance().ListClub[Chall.TargetID].ClubName);
                            if (!SeqIDsClubTarget.ContainsKey(Chall.TargetID))
                            {
                                SeqIDsClubTarget.Add(Chall.TargetID, SeqID);
                                ListClubRecive.Add(Chall.TargetID, Chall);
                            }
                        }
                    }
                    AppChat.Helpers.Helper.Instiance().UpdateProfileFinish?.Invoke();
                }
                break;

            case InviteChallengeError.ERR_TOO_FREQUENTLY:
                break;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Indicator cho các cá  nhân và club
 /// </summary>
 /// <param name="msg"></param>
 public void OnReciveChallengeInd(QHMessage msg)
 {
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Unlike Content Ack
        /// </summary>
        /// <param name="msg"></param>
        public static void UnlikeContentAck(QHMessage msg)
        {
            long error = -1;

            if (msg.TryGetAt((byte)MsgUnlikeAckArg.Error, ref error))
            {
                switch ((UnlikeError)error)
                {
                case UnlikeError.SUCCESS:
                    long NumberID  = 0;
                    long ContentID = 0;
                    long CommentID = 0;
                    long ReplyID   = 0;
                    if (msg.TryGetAt((byte)MsgUnlikeAckArg.ContentID, ref ContentID))
                    {
                        if (msg.TryGetAt((byte)MsgUnlikeAckArg.CommentID, ref CommentID))
                        {
                            if (msg.TryGetAt((byte)MsgUnlikeAckArg.ReplyID, ref ReplyID))
                            {
                            }
                        }
                    }
                    //unlike Reply
                    if (ReplyID > 0)
                    {
                        if (Helper.Instance().ListReplyComment.ContainsKey(ReplyID))
                        {
                            var item = Helper.Instance().ListReplyComment[ReplyID];
                            if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                            {
                                if (item.Likes.IndexOf(NumberID) >= 0)
                                {
                                    item.Likes.Remove(NumberID);
                                    item.Owner = NumberID;
                                    item.Reset();
                                }
                            }
                        }
                        return;
                    }
                    //unlike Comment
                    if (CommentID > 0)
                    {
                        if (Helper.Instance().ListComment.ContainsKey(CommentID))
                        {
                            var item = Helper.Instance().ListComment[CommentID];
                            if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                            {
                                if (item.likes.IndexOf(NumberID) >= 0)
                                {
                                    item.likes.Remove(NumberID);
                                    item.Reset();
                                }
                            }
                        }
                        return;
                    }
                    //unlike Content
                    if (ContentID > 0)
                    {
                        if (Helper.Instance().ListContent.ContainsKey(ContentID))
                        {
                            var item = Helper.Instance().ListContent[ContentID];

                            if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                            {
                                //tìm kiếm và xóa danh sách item like trong danh sách like
                                if (item.LikeContent.LikeContent.ContainsKey("" + NumberID))
                                {
                                    item.LikeContent.LikeContent.Remove("" + NumberID);
                                    item.LikeContent.Reset();
                                }
                            }
                        }
                        return;
                    }
                    break;

                case UnlikeError.ERR_PERMISSION_DENIED:
                    break;

                case UnlikeError.ERR_NOT_EXIST_REPLY:
                    break;

                case UnlikeError.ERR_NOT_EXIST_CONTENT:
                    break;

                case UnlikeError.ERR_NOT_EXIST_COMMENT:
                    break;
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// UnLike Indicator trong content, comment, reply
        /// </summary>
        /// <param name="msg"></param>
        public static void UnLikeInd(QHMessage msg)
        {
            long NumberID  = 0;
            long ContentID = 0;
            long CommentID = 0;
            long ReplyID   = 0;

            if (msg.TryGetAt((byte)MsgUnlikeAckArg.ContentID, ref ContentID))
            {
                if (msg.TryGetAt((byte)MsgUnlikeAckArg.CommentID, ref CommentID))
                {
                    if (msg.TryGetAt((byte)MsgUnlikeAckArg.ReplyID, ref ReplyID))
                    {
                    }
                }
            }
            //Reply
            if (ReplyID > 0)
            {
                if (Helper.Instance().ListReplyComment.ContainsKey(ReplyID))
                {
                    var item = Helper.Instance().ListReplyComment[ReplyID];
                    if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                    {
                        if (item.Likes.IndexOf(NumberID) > 0)
                        {
                            item.Likes.Remove(NumberID);
                            item.Owner = NumberID;
                            item.Reset();
                        }
                    }
                }
                return;
            }
            //Comment
            if (CommentID > 0)
            {
                if (Helper.Instance().ListComment.ContainsKey(CommentID))
                {
                    var item = Helper.Instance().ListComment[CommentID];
                    if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                    {
                        if (item.likes.IndexOf(NumberID) > 0)
                        {
                            item.likes.Remove(NumberID);
                            item.Reset();
                        }
                    }
                }
                return;
            }
            //Content
            if (ContentID > 0)
            {
                if (Helper.Instance().ListContent.ContainsKey(ContentID))
                {
                    var item = Helper.Instance().ListContent[ContentID];

                    if (msg.TryGetAt((byte)MsgUnlikeAckArg.NumberID, ref NumberID))
                    {
                        //tìm kiếm và xóa danh sách item like trong danh sách like
                        if (item.LikeContent.LikeContent.ContainsKey("" + NumberID))
                        {
                            item.LikeContent.LikeContent.Remove("" + NumberID);
                            item.LikeContent.Reset();
                        }
                    }
                }
                return;
            }
        }
Ejemplo n.º 20
0
        public void SendAccept(AccJoinClub accJoinClub, int accept)
        {
            QHMessage msg = new QHMessage((ushort)PingPongMsg.MSG_CLUB_JOIN_ACCEPT_REQ);

            if (accJoinClub != null)
            {
                //id của người được chấp nhận
                if (accJoinClub.IdNumberID > 0)
                {
                    msg.SetAt((byte)MsgClubJoinAcceptReqArg.NumberID, new QHNumber(accJoinClub.IdNumberID));
                }
                else
                {
                    return;
                }
                //tên của người được chấp nhận
                if (!accJoinClub.FullName.Equals(""))
                {
                    msg.SetAt((byte)MsgClubJoinAcceptReqArg.FullName, new QHString(accJoinClub.FullName));
                }
                else
                {
                    return;
                }
                //avatar của người được chấp nhận
                if (!accJoinClub.Avatar.Equals(""))
                {
                    msg.SetAt((byte)MsgClubJoinAcceptReqArg.Avatar, new QHString(accJoinClub.Avatar));
                }
                else
                {
                    return;
                }
                //id của club chấp nhận
                if (accJoinClub.ClubID > 0)
                {
                    msg.SetAt((byte)MsgClubJoinAcceptReqArg.ClubID, new QHNumber(accJoinClub.ClubID));
                }
                else
                {
                    return;
                }
                //cover của club chấp nhận yêu cầu
                if (!accJoinClub.ClubCover.Equals(""))
                {
                    msg.SetAt((byte)MsgClubJoinAcceptReqArg.ClubCover, new QHString(accJoinClub.ClubCover));
                }
                else
                {
                    return;
                }
                msg.SetAt((byte)MsgClubJoinAcceptReqArg.AcceptTime, new QHString(DateTime.Now.ToLongDateString()));
                msg.SetAt((byte)MsgClubJoinAcceptReqArg.Accept, new QHNumber(accept));
                if (!Services.Service.Instiance().SendMessage(msg))
                {
                    NotifiDialog.Initiance().DialogErrorInternter();
                }
                else
                {
                    myAccJoinClub = accJoinClub;
                    myAccept      = accept;
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Bản tin Indicator khi người dùng nhận được
        /// </summary>
        /// <param name="msg"></param>
        public void ClubJoinAck(QHMessage msg)
        {
            int  sampleId = 0;
            long Accept   = -1;
            long NumberID = 0;
            long ClubId   = 0;

            if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.Accept, ref Accept))
            {
                if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.ClubID, ref ClubId))
                {
                }
                if (Accept == 1)
                {
                    if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.NumberID, ref NumberID))
                    {
                        Services.Service.Instiance().ClubModel.MyClub.Numbers.Add(NumberID);
                        Services.Service.Instiance().ClubModel.MyClub.Requests.Remove(NumberID);
                        Services.Service.Instiance().ClubModel.MyClub.ReloadReative();
                    }
                    string Title    = "AppBongBan";
                    string nameclub = "";
                    string notifi   = "";
                    if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.ClubName, ref nameclub))
                    {
                        notifi = nameclub;
                    }
                    if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.FullName, ref nameclub))
                    {
                        notifi += " đã chấp nhận tham gia của " + nameclub;
                    }
                    // Thay đổi Icon trong ListClub
                    foreach (var club in Helper.Instance().ListClub)
                    {
                        if (club.Value.ClubID == ClubId)
                        {
                            club.Value.Relation = 0;
                        }
                    }
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DependencyService.Get <ILocalNotificationService>().LocalNotification(Title, notifi, sampleId, 0);
                    });
                }
                else if (Accept == 0)
                {
                    if (msg.TryGetAt((byte)MsgClubJoinAcceptIndArg.NumberID, ref NumberID))
                    {
                        Services.Service.Instiance().ClubModel.MyClub.Requests.Remove(NumberID);
                        Services.Service.Instiance().ClubModel.MyClub.ReloadReative();
                    }
                    // Thay đổi Icon trong ListClub
                    foreach (var club in Helper.Instance().ListClub)
                    {
                        if (club.Value.ClubID == ClubId)
                        {
                            club.Value.Relation = -1;
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// nhận indicator thách đấu từ server trả về
        /// </summary>
        /// <param name="msg"></param>
        public async void OnReciveChallengeInd(QHMessage msg)
        {
            long   SenderID    = 0;  // QHNumber
            long   TargetType  = 0;  // QHNumber{ 0 : Player, 1:Club }
            long   TargetID    = 0;  // QHNumber ID of TargetType
            string Content     = ""; // QHString (Nội dung text hoặc json của Challenges)
            long   StartTime   = 0;  // QHNumber Thời gian thách đấu bắt đầu
            long   EndTime     = 0;  // QHNumber Thời gian thách đấu kết thúc
            long   ChallengeID = 0;  // QHNumber ID của lời mời thách đấu

            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.SenderID, ref SenderID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.TargetType, ref TargetType))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.TargetID, ref TargetID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.Content, ref Content))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.StartTime, ref StartTime))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.EndTime, ref EndTime))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeIndArg.ChallengeID, ref ChallengeID))
            {
            }
            var Chall = new ChallengeInfo();

            Chall.SenderID    = SenderID;
            Chall.TargetType  = TargetType;
            Chall.TargetID    = TargetID;
            Chall.Content     = Content;
            Chall.StartTime   = StartTime;
            Chall.EndTime     = EndTime;
            Chall.ChallengeID = ChallengeID;
            Accountlocal AccLocal = new Accountlocal();

            if (Helper.Instance().ListAcclocal.ContainsKey(SenderID))
            {
                AccLocal = Helpers.Helper.Instance().ListAcclocal[SenderID];
            }
            else
            {
                var accounOwner = await Helper.Instance().CheckExistAccount(SenderID);

                if (accounOwner != null)
                {
                    var acccount = new Accountlocal();
                    acccount.Challenge        = "pingpong.png";
                    acccount.Blade            = "Cốt A - Hãng A";
                    acccount.Facebat          = "Mặt A - Hãng A";
                    acccount.Level            = "Hạng A";
                    acccount.AccepLevel       = "Đã Duyệt";
                    acccount.AddFriend        = Helper.Instance().IsFriendImg(accounOwner.Number_Id);
                    acccount.TextStatusFriend = Helper.Instance().IsFriend(accounOwner.Number_Id);
                    acccount.TextAcceptFriend = Helper.Instance().TextAcceptFriend;
                    acccount.Number_Id        = accounOwner.Number_Id;
                    acccount.fullname         = accounOwner.fullname;
                    acccount.Avatar_Uri       = accounOwner.Avatar_Uri;
                    Helper.Instance().ListAcclocal.Add(SenderID, acccount);
                    AccLocal = acccount;
                }
            }
            // Thách đấu cá nhân
            if (TargetType == 0)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", AccLocal.fullname + " đã gửi lời mời thách đấu đến bạn", (int)Helpers.Notifi.Challenge, 0);
                });
                Chall.Acc = AccLocal;
                if (!ChallengeAction.ListSendAcc.ContainsKey(SenderID))
                {
                    ChallengeAction.ListSendAcc.Add(SenderID, Chall);
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    ListChallengesPer.Add(Chall);
                    count += ListChallengesPer.Count;
                    notify = count.ToString();
                    //  Helper.Instance().challengeNotify?.Invoke();
                });
            }
            // Thách đấu Club
            else
            {
                var club = await Helper.Instance().CheckExistClub(TargetID);

                Chall.Clubs = club;
                Chall.Acc   = AccLocal;
                Device.BeginInvokeOnMainThread(() =>
                {
                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", AccLocal.fullname + " đã gửi lời mời thách đấu đến " + club.ClubName, (int)Helpers.Notifi.Challenge, 0);
                });
                if (!ChallengeAction.ListSendClub.ContainsKey(SenderID))
                {
                    ChallengeAction.ListSendClub.Add(SenderID, Chall);
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    ListChallengesClub.Add(Chall);
                    count += ListChallengesClub.Count;
                    notify = count.ToString();
                });
            }

            // Thông báo để thêm vào chuông cho người dùng biết
            Helper.Instance().CountChallengeNotifi++;
            //Helper.Instance().challengeNotify?.Invoke();
            AppChat.Helpers.Helper.Instiance().NotifiAction?.Invoke();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Nhận danh sách các thách đấu từ server trả về liên quan đến người dùng và quản lý Club
        /// </summary>
        /// <param name="msg"></param>
        public async void OnReciveListChallenge(QHMessage msg)
        {
            long    Error            = 0;             // QHNumber
            QHTable ClubChallenges   = new QHTable(); // QHTable{ChallengeID(0):QHNumber, SenderID(1):QHNumber, TargetID(2):QHNumber, Content(3):QHString, CreateTime(4):QHNumber,StartTime(5):QHNumber,EndTime(6):QHNumber}
            QHTable PlayerChallenges = new QHTable(); // QHTable{ChallengeID(0):QHNumber, SenderID(1):QHNumber, TargetID(2):QHNumber, Content(3):QHString, CreateTime(4):QHNumber,StartTime(5):QHNumber,EndTime(6):QHNumber}

            if (msg.TryGetAt((byte)MsgListChallengeAckArg.Error, ref Error))
            {
            }
            if (msg.TryGetAt((byte)MsgListChallengeAckArg.ClubChallenges, ref ClubChallenges))
            {
            }
            if (msg.TryGetAt((byte)MsgListChallengeAckArg.PlayerChallenges, ref PlayerChallenges))
            {
            }
            var acc = Helper.Instance().MyAccount;

            //Debug.WriteLine("row: "+ ClubChallenges.GetRowCount());
            //Debug.WriteLine("row: " + PlayerChallenges.GetRowCount());
            if (Error == 0)
            {
                var rowCount   = ClubChallenges.GetRowCount();
                var columCount = ClubChallenges.GetColumnCount();
                //danh sách các thách đấu mà admin nhận được hoặc từ các
                for (int i = 0; i < rowCount; i++)
                {
                    long   ChallengeID = 0;
                    long   SenderID    = 0;
                    long   TargetID    = 0;
                    string Content     = "";
                    long   CreateTime  = 0;
                    long   StartTime   = 0;
                    long   EndTime     = 0;

                    if (ClubChallenges.TryGetAt(i, 0, ref ChallengeID))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 1, ref SenderID))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 2, ref TargetID))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 3, ref Content))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 4, ref CreateTime))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 5, ref StartTime))
                    {
                    }
                    if (ClubChallenges.TryGetAt(i, 6, ref EndTime))
                    {
                    }

                    var Chall = new ChallengeInfo();
                    Chall.ChallengeID = ChallengeID;
                    Chall.SenderID    = SenderID;
                    Chall.TargetID    = TargetID;
                    Chall.Content     = Content;
                    Chall.CreateTime  = CreateTime;
                    Chall.StartTime   = StartTime;
                    Chall.EndTime     = EndTime;
                    if (!Helper.Instance().ListClub.TryGetValue(TargetID, out Club clubContent))
                    {
                        clubContent = new Club()
                        {
                            ClubID = TargetID
                        };
                        Helper.Instance().ListClub.Add(TargetID, clubContent);
                    }

                    var club = Helper.Instance().ListClub[TargetID];
                    //  Lấy thông tin club
                    Helper.Instance().CheckExistClubAsync(TargetID);
                    Chall.Clubs = club;
                    if (acc.Number_Id == SenderID)
                    {
                        if (!ChallengeAction.ListClubRecive.ContainsKey(TargetID))
                        {
                            ChallengeAction.ListClubRecive.Add(TargetID, Chall);
                        }
                    }
                    else
                    {
                        if (!ChallengeAction.ListSendClub.ContainsKey(SenderID))
                        {
                            ChallengeAction.ListSendClub.Add(SenderID, Chall);
                            if (Helpers.Helper.Instance().ListAcclocal.ContainsKey(SenderID))
                            {
                                var AccLocal = Helpers.Helper.Instance().ListAcclocal[SenderID];
                                Chall.Acc = AccLocal;
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    ListChallengesClub.Add(Chall);
                                    // Cập nhật lại số lượng thông báo cho chuông
                                    Helper.Instance().CountChallengeNotifi++;
                                    count += ListChallengesClub.Count;
                                    notify = count.ToString();
                                    // Thông báo để thêm vào chuông cho người dùng biết
                                    // Helper.Instance().challengeNotify?.Invoke();
                                    AppChat.Helpers.Helper.Instiance().NotifiAction?.Invoke();
                                });
                            }
                            else
                            {
                                var accounOwner = await Helpers.Helper.Instance().CheckExistAccount(SenderID);

                                if (accounOwner != null)
                                {
                                    var acccount = new Accountlocal();
                                    acccount.Challenge        = "pingpong.png";
                                    acccount.Blade            = "Cốt A - Hãng A";
                                    acccount.Facebat          = "Mặt A - Hãng A";
                                    acccount.Level            = "Hạng A";
                                    acccount.AccepLevel       = "Đã Duyệt";
                                    acccount.AddFriend        = Helper.Instance().IsFriendImg(accounOwner.Number_Id);
                                    acccount.TextStatusFriend = Helper.Instance().IsFriend(accounOwner.Number_Id);
                                    acccount.TextAcceptFriend = Helper.Instance().TextAcceptFriend;
                                    acccount.Number_Id        = accounOwner.Number_Id;
                                    acccount.fullname         = accounOwner.fullname;
                                    acccount.Avatar_Uri       = accounOwner.Avatar_Uri;
                                    Chall.Acc = acccount;
                                    Helpers.Helper.Instance().ListAcclocal.Add(acccount.Number_Id, acccount);
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        ListChallengesClub.Add(Chall);
                                        // Cập nhật lại số lượng thông báo cho chuông
                                        Helper.Instance().CountChallengeNotifi++;
                                        count += ListChallengesClub.Count;
                                        notify = count.ToString();
                                        // Thông báo để thêm vào chuông cho người dùng biết
                                        // Helper.Instance().challengeNotify?.Invoke();
                                        AppChat.Helpers.Helper.Instiance().NotifiAction?.Invoke();
                                    });
                                }
                            }
                        }
                    }
                }
                //danh sách các thách đấu mà người dùng gửi lên hoặc người dùng nhận được
                for (int i = 0; i < PlayerChallenges.GetRowCount(); i++)
                {
                    //Debug.WriteLine("Colum: " + PlayerChallenges.GetColumnCount());
                    long   ChallengeID = 0;
                    long   SenderID    = 0;
                    long   TargetID    = 0;
                    string Content     = "";
                    long   CreateTime  = 0;
                    long   StartTime   = 0;
                    long   EndTime     = 0;

                    if (PlayerChallenges.TryGetAt(i, 0, ref ChallengeID))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 1, ref SenderID))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 2, ref TargetID))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 3, ref Content))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 4, ref CreateTime))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 5, ref StartTime))
                    {
                    }
                    if (PlayerChallenges.TryGetAt(i, 6, ref EndTime))
                    {
                    }

                    var Chall = new ChallengeInfo();
                    Chall.ChallengeID = ChallengeID;
                    Chall.SenderID    = SenderID;
                    Chall.TargetID    = TargetID;
                    Chall.Content     = Content;
                    Chall.CreateTime  = CreateTime;
                    Chall.StartTime   = StartTime;
                    Chall.EndTime     = EndTime;

                    //var club = await Helpers.Helper.Instance().CheckExistClub(TargetID);
                    //Chall.Clubs = club;
                    if (acc == null)
                    {
                        return;
                    }
                    if (acc.Number_Id == SenderID)
                    {
                        Debug.WriteLine("Tra ve true");
                        Debug.WriteLine("Number_Id: " + acc.Number_Id);
                        Debug.WriteLine("SenderID: " + SenderID);
                        if (!ChallengeAction.ListAccRecive.ContainsKey(TargetID))
                        {
                            ChallengeAction.ListAccRecive.Add(TargetID, Chall);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Tra ve false");
                        if (!ChallengeAction.ListSendAcc.ContainsKey(SenderID))
                        {
                            ChallengeAction.ListSendAcc.Add(SenderID, Chall);
                            if (Helper.Instance().ListAcclocal.ContainsKey(SenderID))
                            {
                                var AccLocal = Helper.Instance().ListAcclocal[SenderID];
                                Chall.Acc = AccLocal;
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    ListChallengesPer.Add(Chall);
                                    // Cập nhật lại số lượng thông báo cho chuông
                                    Helper.Instance().CountChallengeNotifi++;
                                    count += ListChallengesPer.Count;
                                    notify = count.ToString();
                                    // Thông báo để thêm vào chuông cho người dùng biết
                                    // Helper.Instance().challengeNotify?.Invoke();
                                    AppChat.Helpers.Helper.Instiance().NotifiAction?.Invoke();
                                });
                            }
                            else
                            {
                                var accounOwner = await Helper.Instance().CheckExistAccount(SenderID);

                                if (accounOwner != null)
                                {
                                    var acccount = new Accountlocal();
                                    acccount.Challenge        = "pingpong.png";
                                    acccount.Blade            = "Cốt A - Hãng A";
                                    acccount.Facebat          = "Mặt A - Hãng A";
                                    acccount.Level            = "Hạng A";
                                    acccount.AccepLevel       = "Đã Duyệt";
                                    acccount.AddFriend        = Helper.Instance().IsFriendImg(accounOwner.Number_Id);
                                    acccount.TextStatusFriend = Helper.Instance().IsFriend(accounOwner.Number_Id);
                                    acccount.TextAcceptFriend = Helper.Instance().TextAcceptFriend;
                                    acccount.Number_Id        = accounOwner.Number_Id;
                                    acccount.fullname         = accounOwner.fullname;
                                    Debug.WriteLine("Name: " + accounOwner.fullname);
                                    Debug.WriteLine("Avatar: " + accounOwner.Avatar_Uri);
                                    acccount.Avatar_Uri = accounOwner.Avatar_Uri;
                                    Chall.Acc           = acccount;

                                    Helper.Instance().ListAcclocal.Add(acccount.Number_Id, acccount);
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        ListChallengesPer.Add(Chall);
                                        count += ListChallengesPer.Count;
                                        notify = count.ToString();
                                        // Cập nhật lại số lượng thông báo cho chuông
                                        Helper.Instance().CountChallengeNotifi++;
                                        // Thông báo để thêm vào chuông cho người dùng biết
                                        //Helper.Instance().challengeNotify?.Invoke();
                                        AppChat.Helpers.Helper.Instiance().NotifiAction?.Invoke();
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Xử lý bản tin login từ hệ thóng trả vế
        /// </summary>
        /// <param name="msg"></param>
        public void LoginAckProcess(QHMessage msg)
        {
            //try
            //{
            Chat.LoginErrorCode login_error = (Chat.LoginErrorCode)(msg.GetAt((byte)Chat.MsgLoginAckArg.ErrorCode) as QHNumber).value;
            switch (login_error)
            {
            case Chat.LoginErrorCode.SUCCESS:

                if (!Helper.Instance().CheckLogin())
                {
                    Helper.Instance().MyAccount = new Accounts();
                }
                long   sessionId = 0;
                string phone     = "";
                string fullname  = "";
                string email     = "";
                long   numberId  = 0;
                string avarta    = "";
                string address   = "";
                long   birthday  = 0;
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.SessionID, ref sessionId))
                {
                    App.SessionID = sessionId;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.PhoneNumber, ref phone))
                {
                    Helper.Instance().MyAccount.Phone = phone;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.FullName, ref fullname))
                {
                    Helper.Instance().MyAccount.fullname = fullname;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.Email, ref email))
                {
                    Helper.Instance().MyAccount.Email = email;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.NumberID, ref numberId))
                {
                    Helper.Instance().MyAccount.Number_Id = (uint)numberId;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.AvatarURI, ref avarta))
                {
                    Helper.Instance().MyAccount.Avatar_Uri = avarta;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.Address, ref address))
                {
                    Helper.Instance().MyAccount.Address = address;
                }
                if (msg.TryGetAt((byte)Chat.MsgLoginAckArg.BirthDay, ref birthday))
                {
                    Helper.Instance().MyAccount.Birthday = birthday;
                }
                //Kiểm tra filename
                Helper.Instance().ConvertPingPongToChat();
                Helper.Instance().MyAccount.Last_Time_Sync_Contact = 0;
                //  Services.Service.Instiance().Namefile = Helper.Instance().MyAccount.Number_Id.ToString();
                AppChat.Helpers.Helper.Instiance().nameDataBase = Helper.Instance().AccountChat.NumberId.ToString();
                //   AppChat.Helpers.Helper.Instiance().database.InsertOrReAccount(account);
                AppChat.Helpers.Helper.Instiance().database.InsertOrReAccount(Helper.Instance().AccountChat);
                // Thay layout ảnh đại diện
                HomePage.avartaChange();
                if (AppChat.Helpers.Helper.Instiance().database != null)
                {
                    if (Helper.Instance().MyAccount.Avatar_Uri.Equals("") || Helper.Instance().MyAccount.Avatar_Uri == null)
                    {
                        Helper.Instance().MyAccount.Avatar_Uri = "account.png";
                    }
                    if (Page != null)
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            Xamarin.Forms.DependencyService.Get <AppChat.Dependency.ILocalCache>().SetData(CrossDeviceInfo.Current.Id, Helper.Instance().AccountChat);
                            //   MessagingCenter.Send<App>((App)Xamarin.Forms.Application.Current, "Login");
                            Helper.Instance().GetContactGroupChat = true;
                            MessagingCenter.Send <App>((App)Xamarin.Forms.Application.Current, "Login1");
                            await Page.Navigation.PopToRootAsync();
                        });
                    }
                }
                Debug.WriteLine("LoginJson: " + msg.JSONString());
                break;

            case Chat.LoginErrorCode.ERR_PHONE_NOT_EXIST:
            {
                // Login in fale thì xoa file
                Xamarin.Forms.DependencyService.Get <ILocalCache>().RemoveData <Accounts>(CrossDeviceInfo.Current.Id);
                if (Page != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                        {
                            Page.DisplayAlert("Thông báo", "Số điện thoại không tồn tại", "Ok");
                        });
                }
                break;
            }

            case Chat.LoginErrorCode.ERR_PASSWORD_MISMATCH:
            {
                Xamarin.Forms.DependencyService.Get <ILocalCache>().RemoveData <Accounts>(CrossDeviceInfo.Current.Id);
                if (Page != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                        {
                            Page.DisplayAlert("Thông báo", "Mật khẩu không đúng", "Ok");
                        });
                }
                break;
            }

            case Chat.LoginErrorCode.ERR_USERNAME_NOT_EXIST:
            {
                Xamarin.Forms.DependencyService.Get <ILocalCache>().RemoveData <Accounts>(CrossDeviceInfo.Current.Id);
                if (Page != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                        {
                            Page.DisplayAlert("Thông báo", "Tài khoản đăng nhập không đúng", "Ok");
                        });
                }
                break;
            }
            }
            //}
            //catch (Exception ex)
            //{
            //    if (Page != null)
            //    {
            //        Device.BeginInvokeOnMainThread(() =>
            //        {
            //            Page.DisplayAlert("Lỗi Login", ex.Message, "Ok");
            //        });
            //    }
            //}
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Nhận bản tin trả lời thách đấu từ server trả về cho người nhận được
        /// </summary>
        /// <param name="msg"></param>
        public async void OnReciveCancelChallengeInd(QHMessage msg)
        {
            long   SenderID    = 0;  // QHNumber
            long   TargetType  = 0;  // QHNumber{ 0 : Player, 1:Club }
            long   TargetID    = 0;  // QHNumber ID of TargetType
            string Content     = ""; // QHString (Nội dung text hoặc json của Challenges)
            long   StartTime   = 0;  // QHNumber Thời gian thách đấu bắt đầu
            long   EndTime     = 0;  // QHNumber Thời gian thách đấu kết thúc
            long   ChallengeID = 0;  // QHNumber ID của lời mời thách đấu
            long   Accept      = 0;

            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.SenderID, ref SenderID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.TargetType, ref TargetType))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.TargetID, ref TargetID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.Content, ref Content))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.StartTime, ref StartTime))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.EndTime, ref EndTime))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.ChallengeID, ref ChallengeID))
            {
            }
            if (msg.TryGetAt((byte)MsgInviteChallengeCnfIndArg.Accept, ref Accept))
            {
            }
            if (Accept == 0)
            {
                if (TargetType == 0)
                {
                    if (ChallengeAction.ListAccRecive.ContainsKey(TargetID))
                    {
                        ListChallAcc.Remove(ChallengeAction.ListAccRecive[TargetID]);
                        ChallengeAction.ListAccRecive.Remove(TargetID);
                        ChallengeAction.SeqIDsAccTarget.Remove(TargetID);
                        if (Helpers.Helper.Instance().ListAcclocal.ContainsKey(TargetID))
                        {
                            Helpers.Helper.Instance().ListAcclocal[TargetID].Challenge = "pingpong.png";
                        }
                    }
                }
                else
                {
                    if (ChallengeAction.ListClubRecive.ContainsKey(TargetID))
                    {
                        ListChallAcc.Remove(ChallengeAction.ListClubRecive[TargetID]);
                        ChallengeAction.ListClubRecive.Remove(TargetID);
                        ChallengeAction.SeqIDsClubTarget.Remove(TargetID);
                        if (Helpers.Helper.Instance().ListClub.ContainsKey(TargetID))
                        {
                            Helpers.Helper.Instance().ListClub[TargetID].Challenge = "pingpong.png";
                        }
                    }
                }
            }
            else
            {
                if (TargetType == 0)
                {
                    if (ChallengeAction.ListAccRecive.ContainsKey(TargetID))
                    {
                        ChallengeAction.ListAccRecive.Remove(TargetID);
                        ChallengeAction.SeqIDsAccTarget.Remove(TargetID);
                        if (Helpers.Helper.Instance().ListAcclocal.ContainsKey(TargetID))
                        {
                            Helpers.Helper.Instance().ListAcclocal[TargetID].Challenge = "pingpong.png";
                        }
                    }
                    // Yêu cầu Server trả về fullName để hiển thị thông báo
                    var accTarget = await Helpers.Helper.Instance().CheckExistAccount(TargetID);

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", accTarget.fullname + " đã chấp nhận mời thách đấu của bạn", (int)Helpers.Notifi.Challenge, 0);
                    });
                }
                else
                {
                    if (ChallengeAction.ListClubRecive.ContainsKey(TargetID))
                    {
                        ChallengeAction.ListClubRecive.Remove(TargetID);
                        ChallengeAction.SeqIDsClubTarget.Remove(TargetID);
                        if (Helpers.Helper.Instance().ListClub.ContainsKey(TargetID))
                        {
                            Helpers.Helper.Instance().ListClub[TargetID].Challenge = "pingpong.png";
                        }
                    }
                    var club = await Helpers.Helper.Instance().CheckExistClub(TargetID);

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", "Câu lạc bộ " + club.ClubName + " đã chấp nhận mời thách đấu của bạn", (int)Helpers.Notifi.Challenge, 0);
                    });
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Like indicator
        /// </summary>
        /// <param name="msg"></param>
        public async static void LikeInd(QHMessage msg)
        {
            long   NumberId  = 0;
            string FullName  = "";
            string avatar    = "";
            long   ContentID = 0;
            long   CommentID = 0;
            long   ReplyID   = 0;
            long   OwnerID   = 0;

            if (msg.TryGetAt((byte)MsgLikeIndArg.FullName, ref FullName))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.OwnerID, ref OwnerID))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.NumberID, ref NumberId))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.ContentID, ref ContentID))
            {
                if (msg.TryGetAt((byte)MsgLikeIndArg.CommentID, ref CommentID))
                {
                    if (msg.TryGetAt((byte)MsgLikeIndArg.ReplyID, ref ReplyID))
                    {
                    }
                }
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.CommentID, ref CommentID))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.ReplyID, ref ReplyID))
            {
            }
            //LikeReply
            if (ReplyID > 0)
            {
                if (Helper.Instance().ListReplyComment.ContainsKey(ReplyID))
                {
                    var item = Helper.Instance().ListReplyComment[ReplyID];
                    item.Owner = Helper.Instance().MyAccount.Number_Id;
                    if (item.Likes.IndexOf(NumberId) < 0)
                    {
                        item.Likes.Add(NumberId);
                        item.Reset();
                    }
                    if (Helper.IdNews == CommentID && Helper.IndexPage == Helpers.IsDetailNews.Reply)
                    {
                    }
                    else
                    {
                        if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của bạn", (int)Helpers.Notifi.LikeReply, 0);
                            });
                        }
                        else
                        {
                            var acc = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (acc.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của " + acc.fullname, (int)Helpers.Notifi.LikeReply, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của bạn", (int)Helpers.Notifi.LikeReply, 0);
                        });
                    }
                    else
                    {
                        var acc = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (acc.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của " + acc.fullname, (int)Helpers.Notifi.LikeReply, 0);
                            });
                        }
                    }
                }

                return;
            }
            //LikeComment
            if (CommentID > 0)
            {
                if (Helper.Instance().ListComment.ContainsKey(CommentID))
                {
                    var item = Helper.Instance().ListComment[CommentID];
                    if (item.likes.IndexOf(NumberId) < 0)
                    {
                        item.likes.Add(NumberId);
                        item.Reset();
                    }
                    if (Helper.IdNews == ContentID && Helper.IndexPage == Helpers.IsDetailNews.Comment)
                    {
                    }
                    //nếú chưa có trong danh sách comment
                    else
                    {
                        if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bình luận của bạn", (int)Helpers.Notifi.LikeComment, 0);
                            });
                        }
                        else
                        {
                            var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (accounOwner != null && accounOwner.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của" + accounOwner.fullname, (int)Helpers.Notifi.LikeComment, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bình luận của bạn", (int)Helpers.Notifi.LikeComment, 0);
                        });
                    }
                    else
                    {
                        var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (accounOwner != null && accounOwner.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của" + accounOwner.fullname, (int)Helpers.Notifi.LikeComment, 0);
                            });
                        }
                    }
                }
                return;
            }
            //LikeContent
            if (ContentID > 0)
            {
                if (Helper.Instance().ListContent.ContainsKey(ContentID))
                {
                    var item = Helper.Instance().ListContent[ContentID];
                    var Like = new LikeContent {
                        Content_Id = ContentID, Owner = NumberId
                    };
                    if (!item.LikeContent.LikeContent.ContainsKey("" + NumberId))
                    {
                        item.LikeContent.LikeContent.Add("" + NumberId, Like);
                        item.LikeContent.Reset();
                    }

                    if (Helper.IdNews == ContentID && Helper.IndexPage == Helpers.IsDetailNews.Content)
                    {
                    }
                    //Nếu người dùng chưa vào giao diện chi tiết content
                    else
                    {
                        var id = Helper.Instance().MyAccount.Number_Id;
                        if (id == OwnerID)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của bạn", (int)Notifi.LikeContent, 0);
                            });
                        }

                        else
                        {
                            var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (accounOwner != null && accounOwner.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của " + accounOwner.fullname, (int)Notifi.LikeContent, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    var id = Helper.Instance().MyAccount.Number_Id;
                    if (id == OwnerID)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của bạn", (int)Notifi.LikeContent, 0);
                        });
                    }

                    else
                    {
                        var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (accounOwner != null && accounOwner.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của " + accounOwner.fullname, (int)Notifi.LikeContent, 0);
                            });
                        }
                    }
                }
                return;
            }
        }