public static async Task Register(ChatsViewController thisView, string inputName, string inputEmail, string inputPassword) { bool done = false; AppData.auth.CreateUser(inputEmail, inputPassword, (user, error) => { if (error != null) { AlertShow.Alert(thisView, "Error", "This went wrong: " + error.UserInfo.Description); return; } UserProfileChangeRequest changeRequest = user.User.ProfileChangeRequest(); changeRequest.DisplayName = inputName; changeRequest.CommitChanges(async(profileError) => { if (profileError != null) { AlertShow.Alert(thisView, "Error", "Profile Error: " + profileError); return; } SetLocalUser.Set(new UserClass { Name = user.User.DisplayName, Email = user.User.Email, Uid = user.User.Uid }); object[] userKeys = { "name", "email", "uid" }; object[] userVals = { user.User.DisplayName, user.User.Email, user.User.Uid }; var userDict = NSDictionary.FromObjectsAndKeys(userVals, userKeys); AppData.UsersNode.GetChild(user.User.Uid).SetValue <NSDictionary>(userDict); foreach (ChatListClass any in AppData.currentLST) { if (any.ChatOwner.Uid == AppData.curUser.Uid) { SaveListOnCloud.Save(any); } } await thisView.ReloadData(); AlertShow.Alert(thisView, "Success", "You are now registered on Coder"); done = true; }); }); while (!done) { await Task.Delay(50); } }
public static async Task Read(ChatsViewController thisView) { ReadWriteDisk.ReadUser(); if (AppData.curUser == null) { AppData.curUser = new UserClass { Name = "Coder Dev Team", Email = "*****@*****.**", Uid = "defUid" }; PrepareInitialData.Prepare(); ReadWriteDisk.WriteData(); ReadWriteDisk.WriteUser(); } else { ReadWriteDisk.ReadData(); AppData.currentLST = AppData.offlineLST; } //color of profile button if offline thisView.SetLoginButton("Login", UIColor.Red); // read online chats if (AppData.auth.CurrentUser != null) { //color of profile button if online thisView.SetLoginButton("Hello " + AppData.auth.CurrentUser.DisplayName, UIColor.Cyan); //someone is logged in await ReadOnlineData.Read(); AppData.currentLST = CompareChatLists.Compare(AppData.onlineLST, AppData.offlineLST); ReadWriteDisk.WriteData(); foreach (ChatListClass any in AppData.currentLST) { if (any.ChatOwner.Uid == AppData.curUser.Uid) { SaveListOnCloud.Save(any); } } await ReadInvitations.Read(); //await FetchInvitations.Fetch(); //foreach (ChatListClass any in AppData.invitationsLST) // AppData.currentLST.Add(any); } }