Fix topic uniqueness issue

This commit is contained in:
Alexander Horner
2022-12-06 20:14:45 +00:00
parent 6aa48fdd2f
commit 5a4dfc01b6
3 changed files with 38 additions and 20 deletions

View File

@@ -5,8 +5,11 @@ namespace ntfysh_client
{
public partial class SubscribeDialog : Form
{
public SubscribeDialog()
private readonly ListBox _notificationTopics;
public SubscribeDialog(ListBox notificationTopics)
{
_notificationTopics = notificationTopics;
InitializeComponent();
}
@@ -30,6 +33,11 @@ namespace ntfysh_client
return password.Text;
}
public string getUniqueString()
{
return $"{topicId.Text}@{serverUrl.Text}";
}
private void button1_Click(object sender, EventArgs e)
{
if (topicId.Text.Length < 1)
@@ -64,6 +72,14 @@ namespace ntfysh_client
return;
}
if (_notificationTopics.Items.Contains(getUniqueString()))
{
MessageBox.Show($"The specified topic '{topicId.Text}' on the server '{serverUrl.Text}' is already subscribed", "Topic already subscribed", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
username.Focus();
return;
}
DialogResult = DialogResult.OK;
}