diff --git a/ntfysh_client/MainForm.Designer.cs b/ntfysh_client/MainForm.Designer.cs
index 0f9d1ad..909d5c3 100644
--- a/ntfysh_client/MainForm.Designer.cs
+++ b/ntfysh_client/MainForm.Designer.cs
@@ -101,12 +101,13 @@ namespace ntfysh_client
//
topicContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { sendNotificationMenuItem });
topicContextMenu.Name = "topicContextMenu";
- topicContextMenu.Size = new System.Drawing.Size(167, 26);
+ topicContextMenu.Size = new System.Drawing.Size(181, 48);
//
// sendNotificationMenuItem
//
+ sendNotificationMenuItem.Image = (System.Drawing.Image)resources.GetObject("sendNotificationMenuItem.Image");
sendNotificationMenuItem.Name = "sendNotificationMenuItem";
- sendNotificationMenuItem.Size = new System.Drawing.Size(166, 22);
+ sendNotificationMenuItem.Size = new System.Drawing.Size(180, 22);
sendNotificationMenuItem.Text = "Send Notification";
sendNotificationMenuItem.Click += SendNotificationMenuItem_Click;
//
@@ -162,7 +163,7 @@ namespace ntfysh_client
//
exitToolStripMenuItem1.Image = (System.Drawing.Image)resources.GetObject("exitToolStripMenuItem1.Image");
exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
- exitToolStripMenuItem1.Size = new System.Drawing.Size(116, 22);
+ exitToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
exitToolStripMenuItem1.Text = "Exit";
exitToolStripMenuItem1.Click += exitToolStripMenuItem1_Click;
//
@@ -170,7 +171,7 @@ namespace ntfysh_client
//
settingsToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("settingsToolStripMenuItem.Image");
settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
- settingsToolStripMenuItem.Size = new System.Drawing.Size(116, 22);
+ settingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
settingsToolStripMenuItem.Text = "Settings";
settingsToolStripMenuItem.Click += settingsToolStripMenuItem_Click;
//
diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs
index 8e8a8cc..036d4d2 100644
--- a/ntfysh_client/MainForm.cs
+++ b/ntfysh_client/MainForm.cs
@@ -426,15 +426,19 @@ namespace ntfysh_client
{
if (notificationTopics.SelectedItem != null && string.IsNullOrEmpty(notificationTopics.SelectedItem as string) == false)
{
- var dlg = new SendMessageForm();
- var r = dlg.ShowDialog(this);
- if (r == DialogResult.OK)
+ try
{
- var topicAndHost = notificationTopics.SelectedItem.ToString()?.Split("@");
- var topic = topicAndHost[0];
- var host = topicAndHost[1].Replace("wss", "https");
- var msg = dlg.Message;
- await _notificationListener.SendNotification(host, new NtfyEvent { Topic = topic, Title = dlg.Title, Message = msg });
+ SendMessageForm dlg = new SendMessageForm();
+ DialogResult r = dlg.ShowDialog(this);
+ if (r == DialogResult.OK)
+ {
+ string key = notificationTopics.SelectedItem.ToString();
+ await _notificationListener.SendNotification(key, dlg.Title, dlg.Message);
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
}
}
}
diff --git a/ntfysh_client/MainForm.resx b/ntfysh_client/MainForm.resx
index 41a6834..a810cf0 100644
--- a/ntfysh_client/MainForm.resx
+++ b/ntfysh_client/MainForm.resx
@@ -120,6 +120,26 @@
384, 17
+
+
+
+ iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+ YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAALtSURBVGhD7ZfPaxNBFMeTkqS9WDyotTHJvjdJ/VUpirQK
+ elFKa1pSK2lNapOrP8BDPRQEL7X+qFjEg2JBEERrEc2hh0jT6EHUo3+DPSi2tV6E4sGmREaSsHlM1iaZ
+ lVnJFz6X3TeZ98lLZhObrZZaaqnF0kHEcUR8rTjjtO+iIOIkImYtwiTtvxBEXBAsUJUF2n8hehEAmELE
+ UZXI9VSeiKZpYU3TmhUjbKqIM/z47Pb9J4BeNwHzRByRF1dt8XTWfubV26a2ENL7kjFHxBF9eY1L5KmL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A6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA69AAAOvQFH+5CtAAABQUlE
QVQ4T7WTTU4CQRCF5whG48KxnfoqMxfAcyjoDdz4cw1xLXoC2AgnULmPBuMST4B5pEigGeNGK+mkp1+/
V1Wva4riv8Ld79x9Eauf460BXAPjlNIu8GpmF1ruPo2zse7kvGUAV8AbMHL3D+DLzDp1XR9r7+4zYAi8
t4oAE12oquoA6JnZo/Za2gPdwEaqJOcXZrYjdTM7q+v6CHhQJZF5oDN3P9W32tkgyyT1DMwj2wB4Tikd
diff --git a/ntfysh_client/Notifications/NotificationListener.cs b/ntfysh_client/Notifications/NotificationListener.cs
index 5561f84..15dc3a0 100644
--- a/ntfysh_client/Notifications/NotificationListener.cs
+++ b/ntfysh_client/Notifications/NotificationListener.cs
@@ -352,10 +352,24 @@ namespace ntfysh_client.Notifications
SubscribedTopicsByUnique.Remove(topicUniqueString);
}
- public async Task SendNotification(string host, NtfyEvent message)
+ public async Task SendNotification(string key, string title, string message)
{
- var httpClient = new HttpClient();
- return await httpClient.PostAsJsonAsync(host, message);
+ if (SubscribedTopicsByUnique.TryGetValue(key, out SubscribedTopic topic))
+ {
+ HttpClient httpClient = new HttpClient();
+ PublishEvent notification = new PublishEvent();
+ notification.Title = title;
+ notification.Message = message;
+ notification.Topic = topic.TopicId;
+ if (!string.IsNullOrEmpty(topic.Username) || !string.IsNullOrEmpty(topic.Password))
+ {
+ string value = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{topic.Username}:{topic.Password}"));
+ httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", value);
+ }
+
+ HttpResponseMessage response = await httpClient.PostAsJsonAsync(topic.ServerUrl.Replace("wss://", "https://"), notification);
+ response.EnsureSuccessStatusCode();
+ }
}
}
}
diff --git a/ntfysh_client/Notifications/PublishEvent.cs b/ntfysh_client/Notifications/PublishEvent.cs
new file mode 100644
index 0000000..fac6c92
--- /dev/null
+++ b/ntfysh_client/Notifications/PublishEvent.cs
@@ -0,0 +1,50 @@
+using Newtonsoft.Json;
+using System.Text.Json.Nodes;
+
+namespace ntfysh_client.Notifications
+{
+ internal class PublishEvent
+ {
+ [JsonProperty("topic")]
+ public string Topic { get; set; } = null!;
+
+ [JsonProperty("message")]
+ public string? Message { get; set; } = null;
+
+ [JsonProperty("title")]
+ public string? Title { get; set; } = null;
+
+ [JsonProperty("tags")]
+ public string[] Tags { get; set; } = null!;
+
+ [JsonProperty("priority")]
+ public NotificationPriority? Priority { get; set; } = null;
+
+ [JsonProperty("actions")]
+ public JsonArray? Actions { get; set; } = null;
+
+ [JsonProperty("click")]
+ public string? Click { get; set; } = null;
+
+ [JsonProperty("attach")]
+ public string? Attach { get; set; } = null;
+
+ [JsonProperty("markdown")]
+ public bool? Markdown { get; set; } = null;
+
+ [JsonProperty("icon")]
+ public string? Icon { get; set; } = null;
+
+ [JsonProperty("filename")]
+ public string? Filename { get; set; } = null;
+
+ [JsonProperty("delay")]
+ public string? Delay { get; set; } = null;
+
+ [JsonProperty("email")]
+ public string? Email { get; set; } = null;
+
+ [JsonProperty("call")]
+ public string? Call { get; set; } = null;
+ }
+}
diff --git a/ntfysh_client/SendMessageForm.Designer.cs b/ntfysh_client/SendMessageForm.Designer.cs
index ba0294a..b6ed39e 100644
--- a/ntfysh_client/SendMessageForm.Designer.cs
+++ b/ntfysh_client/SendMessageForm.Designer.cs
@@ -92,7 +92,7 @@
MaximizeBox = false;
MinimizeBox = false;
Name = "SendMessageForm";
- Text = "SendMessageForm";
+ Text = "Send Message";
ResumeLayout(false);
PerformLayout();
}