private void UsersListOnline_ItemActivate(object sender, EventArgs e) { var receiver = usersListOnline.SelectedItems[0].Text; if (privMessagesStarted.Contains($"{receiver},authorize")) { ShowPrivMessage(receiver, privMessagesTest.FirstOrDefault(x => x.ConversationBetween.Contains(receiver)).TopicName); //PrivMessage.something = true; } else if (LoginForm.loginData[0] != receiver) { string topicName = $"{Guid.NewGuid().ToString()}/{receiver}"; //subuje kanał z nazwą użytkownika po czym wysyła wiadomość informującą klienta o połączeniu client.Subscribe(new string[] { $"{LoginForm.loginData[1]}/{receiver}" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); client.Publish($"{LoginForm.loginData[1]}/{receiver}", Encoding.UTF8.GetBytes($"{LoginForm.loginData[0]},{topicName},authorize"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); //unsubuje topic nasłuchowy klienta client.Unsubscribe(new string[] { $"{LoginForm.loginData[1]}/{receiver}" }); //otwiera okno z prywatnym chatem privMessagesStarted.Add($"{receiver},authorize"); var privMessage = new PrivMessage(receiver, topicName); privMessage.Show(); //selectedUser = new List<string>(new string[] { null, null }); } else { MessageBox.Show("Nie możesz chatować ze sobą, chyba że 'jest nas wielu' to okej ale nie tutaj", "Ni dy rydy", MessageBoxButtons.OK); } }
private void ShowPrivMessage(string user, string topicNameGenerated) { //privMessage.Show(); if (this.InvokeRequired) { this.Invoke(new Action <string, string>(ShowPrivMessage), user, topicNameGenerated); } else { //PrivMessage privMessageRecv = new PrivMessage(); //Application.Run(privMessage); var currentPrivMessage = privMessagesTest.FirstOrDefault(x => x.ConversationBetween.Contains(user)); if (currentPrivMessage != null) { currentPrivMessage.PrivMessage.Show(); } else { var privMessage = new PrivMessage(user, topicNameGenerated); privMessage.Show(); } } }