Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ChatMessage.cs
1using System.Globalization;
2using System.Windows.Input;
6
8{
12 public enum MessageType
13 {
17 Sent,
18
22 Received
23 }
24
28 [CollectionName("ChatMessages")]
29 [TypeName(TypeNameSerialization.None)]
30 [Index("RemoteBareJid", "Created")]
31 [Index("RemoteBareJid", "RemoteObjectId")]
32 public class ChatMessage : IUniqueItem
33 {
34 private string? objectId = null;
35 private CaseInsensitiveString? remoteBareJid = null;
36 private DateTime created = DateTime.MinValue;
37 private DateTime updated = DateTime.MinValue;
38 private string? remoteObjectId = null;
39 private MessageType messageType = MessageType.Sent;
40 private string plainText = string.Empty;
41 private string markdown = string.Empty;
42 private string html = string.Empty;
43 private object? parsedXaml = null;
44
45 private IChatView? chatView;
46
50 public ChatMessage()
51 {
52 this.MessageType = MessageType.Received;
53 this.Updated = DateTime.MinValue;
54
55 this.XmppUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.Xmpp));
56 this.IotIdUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.IotId));
57 this.IotScUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.IotSc));
58 this.NeuroFeatureUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.NeuroFeature));
59 this.IotDiscoUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.IotDisco));
60 this.EDalerUriClicked = new Command(async Parameter => await this.ExecuteUriClicked(Parameter, UriScheme.EDaler));
61 this.HyperlinkClicked = new Command(async Parameter => await ExecuteHyperlinkClicked(Parameter));
62 }
63
65 public string UniqueName => this.ObjectId ?? string.Empty;
66
70 [ObjectId]
71 public string? ObjectId
72 {
73 get => this.objectId;
74 set => this.objectId = value;
75 }
76
81 {
82 get => this.remoteBareJid;
83 set => this.remoteBareJid = value;
84 }
85
89 public DateTime Created
90 {
91 get => this.created;
92 set => this.created = value;
93 }
94
98 [DefaultValueDateTimeMinValue]
99 public DateTime Updated
100 {
101 get => this.updated;
102 set => this.updated = value;
103 }
104
108 public string? RemoteObjectId
109 {
110 get => this.remoteObjectId;
111 set => this.remoteObjectId = value;
112 }
113
118 {
119 get => this.messageType;
120 set => this.messageType = value;
121 }
122
126 public string PlainText
127 {
128 get => this.plainText;
129 set => this.plainText = value;
130 }
131
135 public string Markdown
136 {
137 get => this.markdown;
138 set => this.markdown = value;
139 }
140
144 public string Html
145 {
146 get => this.html;
147 set
148 {
149 this.html = value;
150 this.parsedXaml = null;
151 }
152 }
153
157 public string StyleId => "Message" + this.messageType.ToString();
158
163 public async Task GenerateXaml(IChatView View)
164 {
165 this.chatView = View;
166
167 if (!string.IsNullOrEmpty(this.markdown))
168 {
169 this.parsedXaml = await this.markdown.MarkdownToParsedXaml();
170 if (this.parsedXaml is VerticalStackLayout Layout)
171 Layout.StyleId = this.StyleId;
172 }
173 else
174 {
175 VerticalStackLayout Layout = new()
176 {
177 StyleId = string.IsNullOrEmpty(this.html) && string.IsNullOrEmpty(this.plainText) ? string.Empty : this.StyleId
178 };
179
180 if (!string.IsNullOrEmpty(this.html))
181 {
182 Layout.Children.Add(new Label()
183 {
184 Text = this.html,
185 TextType = TextType.Html
186 });
187 }
188 else if (!string.IsNullOrEmpty(this.plainText))
189 {
190 Layout.Children.Add(new Label()
191 {
192 Text = this.plainText,
193 TextType = TextType.Text
194 });
195 }
196 this.parsedXaml = Layout;
197 }
198 }
199
203 public object? ParsedXaml => this.parsedXaml;
204
208 public Command XmppUriClicked { get; }
209
213 public Command IotIdUriClicked { get; }
214
218 public Command IotScUriClicked { get; }
219
223 public Command NeuroFeatureUriClicked { get; }
224
228 public Command IotDiscoUriClicked { get; }
229
233 public Command EDalerUriClicked { get; }
234
238 public Command HyperlinkClicked { get; }
239
240 private Task ExecuteUriClicked(object Parameter, UriScheme Scheme)
241 {
242 if (Parameter is string Uri && this.chatView is not null)
243 return this.chatView.ExecuteUriClicked(Uri, Scheme);
244 else
245 return Task.CompletedTask;
246 }
247
248 private static async Task ExecuteHyperlinkClicked(object Parameter)
249 {
250 if (Parameter is not string Url)
251 return;
252
253 await App.OpenUrlAsync(Url);
254 }
255
257 public override string ToString()
258 {
259 return this.created.ToString(CultureInfo.CurrentCulture);
260 }
261
262 }
263}
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static Task< bool > OpenUrlAsync(string Url)
Opens an URL in the application.
Definition: App.xaml.cs:919
async Task GenerateXaml(IChatView View)
Parses the XAML in the message.
Definition: ChatMessage.cs:163
Command HyperlinkClicked
Command executed when a hyperlink in rendered markdown has been clicked.
Definition: ChatMessage.cs:238
Command XmppUriClicked
Command executed when a multi-media-link with the xmpp URI scheme is clicked.
Definition: ChatMessage.cs:208
DateTime Created
When message was created
Definition: ChatMessage.cs:90
string? RemoteObjectId
Remote Objcet ID. If sent by the local user, value will be null or empty.
Definition: ChatMessage.cs:109
CaseInsensitiveString? RemoteBareJid
Remote Bare JID
Definition: ChatMessage.cs:81
Command IotDiscoUriClicked
Command executed when a multi-media-link with the iotdisco URI scheme is clicked.
Definition: ChatMessage.cs:228
Command IotIdUriClicked
Command executed when a multi-media-link with the iotid URI scheme is clicked.
Definition: ChatMessage.cs:213
string UniqueName
Unique name used to compare items.
Definition: ChatMessage.cs:65
DateTime Updated
When message was created
Definition: ChatMessage.cs:100
Command IotScUriClicked
Command executed when a multi-media-link with the iotsc URI scheme is clicked.
Definition: ChatMessage.cs:218
Command EDalerUriClicked
Command executed when a multi-media-link with the edaler URI scheme is clicked.
Definition: ChatMessage.cs:233
Command NeuroFeatureUriClicked
Command executed when a multi-media-link with the nfeat URI scheme is clicked.
Definition: ChatMessage.cs:223
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
Interfaces for views displaying markdown
Definition: IChatView.cs:43
Task ExecuteUriClicked(string Uri, UriScheme Scheme)
Called when a special Multi-media URI link has been clicked.
TypeNameSerialization
How the type name should be serialized.