private async Task <bool> AssertEntered(bool ForwardPresence) { if (!this.entered && !this.entering) { this.entering = true; try { UserPresenceEventArgs e; EnterRoomForm Form = null; Mouse.OverrideCursor = Cursors.Wait; if (string.IsNullOrEmpty(this.nickName)) { ServiceDiscoveryEventArgs e2 = await this.MucClient.GetMyNickNameAsync(this.roomId, this.domain); if (e2.Ok) { foreach (Identity Id in e2.Identities) { if (Id.Category == "conference" && Id.Type == "text") { this.nickName = Id.Name; this.OnUpdated(); break; } } } } if (string.IsNullOrEmpty(this.nickName)) { e = null; } else { e = await this.MucClient.EnterRoomAsync(this.roomId, this.domain, this.nickName, this.password); } while (!(e?.Ok ?? false)) { TaskCompletionSource <bool> InputReceived = new TaskCompletionSource <bool>(); if (Form is null) { Form = new EnterRoomForm(this.roomId, this.domain) { Owner = MainWindow.currentInstance }; Form.NickName.Text = this.nickName; Form.Password.Password = this.password; } MainWindow.MouseDefault(); MainWindow.UpdateGui(() => { bool?Result = Form.ShowDialog(); InputReceived.TrySetResult(Result.HasValue && Result.Value); }); if (!await InputReceived.Task) { this.entered = false; return(false); } Mouse.OverrideCursor = Cursors.Wait; e = await this.MucClient.EnterRoomAsync(this.roomId, this.domain, Form.NickName.Text, Form.Password.Password); if (!e.Ok) { MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to enter room." : e.ErrorText); } } if (!(Form is null)) { string Prefix = this.MucClient.Client.BareJID + "." + this.roomId + "@" + this.domain; bool Updated = false; if (this.nickName != Form.NickName.Text) { this.nickName = Form.NickName.Text; await RuntimeSettings.SetAsync(Prefix + ".Nick", this.nickName); Updated = true; } if (this.password != Form.Password.Password) { this.password = Form.Password.Password; await RuntimeSettings.SetAsync(Prefix + ".Pwd", this.password); Updated = true; } if (Updated) { this.OnUpdated(); } } if (ForwardPresence) { await this.Service.MucClient_OccupantPresence(this, e); } this.entered = true; } finally { this.entering = false; } } return(true); }
public override void Add() { EnterRoomForm Dialog = new EnterRoomForm(this.mucClient.ComponentAddress) { Owner = MainWindow.currentInstance }; bool?Result = Dialog.ShowDialog(); if (Result.HasValue && Result.Value) { string RoomId = Dialog.RoomID.Text; string Domain = Dialog.Domain.Text; string NickName = Dialog.NickName.Text; string Password = Dialog.Password.Password; string Prefix = this.mucClient.Client.BareJID + "." + RoomId + "@" + Domain; DataForm Form = null; this.mucClient.EnterRoom(RoomId, Domain, NickName, Password, async(sender, e) => { if (e.Ok) { if (e.HasStatus(MucStatus.Created)) { this.mucClient.GetRoomConfiguration(RoomId, Domain, (sender2, ConfigurationForm) => { Form = ConfigurationForm; if (!string.IsNullOrEmpty(Password)) { Field PasswordProtectionField = Form["muc#roomconfig_passwordprotectedroom"]; PasswordProtectionField?.SetValue("true"); Field PasswordField = Form["muc#roomconfig_roomsecret"]; PasswordField?.SetValue(Password); } MainWindow.currentInstance.ShowDataForm(ConfigurationForm); return(Task.CompletedTask); }, async(sender2, e2) => { if (e2.Ok) { await RuntimeSettings.SetAsync(Prefix + ".Nick", NickName); await RuntimeSettings.SetAsync(Prefix + ".Pwd", Password); Field NameField = Form["muc#roomconfig_roomname"]; string Name = NameField?.ValueString ?? RoomId; this.AddRoomNode(RoomId, Domain, NickName, Password, Name, true); } }, null); } else { await RuntimeSettings.SetAsync(Prefix + ".Nick", NickName); await RuntimeSettings.SetAsync(Prefix + ".Pwd", Password); this.AddRoomNode(RoomId, Domain, NickName, Password, string.Empty, true); await this.MucClient_OccupantPresence(this, e); } } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to add room." : e.ErrorText); } }, null); } }