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; } } }
/// <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"); // }); // } //} }
/// <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; } }