Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NotificationMessage.cs
1using System;
3
5{
12 {
17 {
18 this.Priority = NotificationPriority.High;
19 this.TimeToLive = 0; // Default TTL (4 weeks)
20 }
21
25 public bool SuppressNotification { get; set; }
26
32 public string Title { get; set; }
33
37 public string Body { get; set; }
38
44 public string ClickAction { get; set; }
45
49 public NotificationPriority Priority { get; set; }
50
54 public int TimeToLive { get; set; }
55
60 public virtual Dictionary<string, object> GetNotificationObject()
61 {
62 if (this.SuppressNotification)
63 return new Dictionary<string, object>();
64
65 Dictionary<string, object> Result = new Dictionary<string, object>();
66
67 if (!string.IsNullOrEmpty(this.Title))
68 Result["title"] = this.Title;
69
70 if (!string.IsNullOrEmpty(this.Body))
71 Result["body"] = this.Body;
72
73 return Result;
74 }
75
80 public virtual void ExportProperties(Dictionary<string, object> Message)
81 {
82 Dictionary<string, object> Notification = this.GetNotificationObject();
83 if (Notification.Count > 0)
84 Message["notification"] = Notification;
85 }
86
93 public virtual bool TrySetProperty(string Name, object Value)
94 {
95 switch (Name)
96 {
97 case "title":
98 if (Value is string Title)
99 {
100 this.Title = Title;
101 return true;
102 }
103 break;
104
105 case "body":
106 if (Value is string Body)
107 {
108 this.Body = Body;
109 return true;
110 }
111 break;
112
113 case "click_action":
114 if (Value is string ClickAction)
115 {
116 this.ClickAction = ClickAction;
117 return true;
118 }
119 break;
120
121 case "priority":
122 switch (Value)
123 {
124 case string s when Enum.TryParse(s, out NotificationPriority PriorityA):
125 this.Priority = PriorityA;
126 return true;
127 case int i when Enum.TryParse(i.ToString(), out NotificationPriority PriorityB):
128 this.Priority = PriorityB;
129 return true;
130 }
131
132 break;
133
134 case "time_to_live":
135 if (Value is int TimeToLive)
136 {
137 this.TimeToLive = TimeToLive;
138 return true;
139 }
140 break;
141
142 case "android":
143 case "apns":
144 case "webpush":
145 return true; // Ignore by default.
146 }
147
148 return false;
149 }
150
151 }
152}
bool SuppressNotification
If the visual notification part should be suppressed (data-only/background).
NotificationMessage()
Base class for Notification messages
virtual bool TrySetProperty(string Name, object Value)
Tries to set a property value.
virtual Dictionary< string, object > GetNotificationObject()
Gets the notification object for a push notification.
string ClickAction
The action associated with a user click on the notification.
int TimeToLive
This parameter specifies how long (in seconds) the message should be kept in FCM storage if the devic...
virtual void ExportProperties(Dictionary< string, object > Message)
Prepares the object to send to Firebase.
NotificationPriority Priority
Sets the priority of the message. Valid values are "normal" and "high."
NotificationPriority
Notification priority