4using System.Windows.Controls;
5using System.Windows.Documents;
6using System.Windows.Markup;
7using System.Windows.Media;
12using System.Threading.Tasks;
17 public enum ChatItemType
29 private readonly ChatItemType type;
30 private readonly DateTime timestamp;
31 private bool lastIsTable;
32 private readonly
string threadId;
34 private string fromStr;
35 private DateTime lastUpdated;
36 private string message;
37 private object formattedMessage;
38 private StringBuilder building =
null;
39 private DateTime timer = DateTime.MinValue;
57 this.timestamp = this.lastUpdated =
Timestamp;
60 this.fromStr = GetShortFrom(
From);
73 Result.formattedMessage =
new TextBlock()
75 TextWrapping = TextWrapping.Wrap,
80 if (Result.formattedMessage is DependencyObject Root)
81 Result.AddEventHandlers(Root);
83 Result.lastIsTable =
false;
87 await Result.ParseMarkdown(Markdown);
90 Result.lastIsTable = E is Content.Markdown.Model.BlockElements.Table;
96 internal bool LastIsTable => this.lastIsTable;
100 if (this.building is
null)
102 this.building =
new StringBuilder(this.message);
104 if (!this.message.EndsWith(
"\n"))
105 this.building.Append(Environment.NewLine);
110 this.building.Append(Environment.NewLine);
112 if (this.timer > DateTime.MinValue)
115 this.timer = DateTime.MinValue;
118 this.timer =
MainWindow.Scheduler.Add(DateTime.Now.AddSeconds(1),
this.Refresh,
new object[] { ChatListView, MainWindow });
121 private async
void Refresh(
object P)
125 if (this.timer > DateTime.MinValue)
127 WPF.MainWindow.Scheduler?.Remove(this.timer);
128 this.timer = DateTime.MinValue;
131 object[] P2 = (
object[])P;
132 ListView ChatListView = (ListView)P2[0];
134 string s = this.building.ToString();
135 this.building =
null;
139 MainWindow.UpdateGui(() => this.Refresh2(ChatListView, s, Markdown));
147 private async Task Refresh2(ListView ChatListView,
string s,
MarkdownDocument Markdown)
151 await this.Update(s, Markdown);
153 ChatListView.Items.Refresh();
154 ChatListView.ScrollIntoView(
this);
166 if (!(Markdown is
null))
168 string XAML = await Markdown.GenerateXAML(
ChatView.GetXamlSettings());
169 this.formattedMessage = XamlReader.Parse(XAML);
171 if (this.formattedMessage is DependencyObject Root)
172 this.AddEventHandlers(Root);
175 this.formattedMessage = this.
Message;
179 this.formattedMessage = this.
Message;
183 private void AddEventHandlers(DependencyObject Element)
185 int i, c = VisualTreeHelper.GetChildrenCount(Element);
186 DependencyObject Child;
188 if (Element is TextBlock TextBlock)
190 foreach (Inline Inline
in TextBlock.Inlines)
192 if (Inline is Hyperlink Hyperlink)
193 Hyperlink.Click += this.Hyperlink_Click;
197 for (i = 0; i < c; i++)
199 Child = VisualTreeHelper.GetChild(Element, i);
200 this.AddEventHandlers(Child);
204 private void Hyperlink_Click(
object Sender, RoutedEventArgs e)
206 if (!(e.Source is Hyperlink Link))
209 string Uri = Link.NavigateUri.ToString();
210 System.Diagnostics.Process.Start(Uri);
216 this.lastUpdated = DateTime.Now;
218 return this.ParseMarkdown(Markdown);
234 public ChatItemType
Type => this.type;
245 this.fromStr = GetShortFrom(value);
259 internal static string GetShortFrom(
string From)
261 int i =
From.IndexOfAny(Content.CommonTypes.CRLF);
264 StringBuilder sb =
new StringBuilder();
267 foreach (
string Row
in From.Split(Content.CommonTypes.CRLF, StringSplitOptions.RemoveEmptyEntries))
274 sb.Append(GetShortFrom(Row));
277 return sb.ToString();
284 i =
From.IndexOf(
'/');
288 return From.Substring(i + 1);
299 int i = this.from?.IndexOf(
'/') ?? -1;
303 return this.from.Substring(i + 1);
314 if (this.type == ChatItemType.Received ||
this.type == ChatItemType.Event)
315 return this.timestamp.ToLongTimeString();
328 if (this.type == ChatItemType.Transmitted)
329 return this.timestamp.ToLongTimeString();
Represents one item in a chat.
ChatItemType Type
Chat item type.
string From
Who sent the message.
DateTime Timestamp
Timestamp of item.
object FormattedMessage
Formatted Message
DateTime LastUpdated
Timestamp when item was last updated.
string FromStr
Nick-name of sender.
string Sent
Time of day of transmission, as a string.
string Received
Time of day of reception, as a string.
string FromResource
Resource-name of who sent the message.
Interaction logic for ChatView.xaml
Interaction logic for xaml
Abstract base class for selectable colorable item.
Color BackgroundColor
Background color
Color ForegroundColor
Foreground color
Contains a markdown document. This markdown document class supports original markdown,...
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Abstract base class for all markdown elements.
Contains settings that the XAML export uses to customize XAML output.
int ParagraphMarginTop
Top margin for paragraphs.
int ParagraphMarginLeft
Left margin for paragraphs.
int ParagraphMarginBottom
Bottom margin for paragraphs.
int ParagraphMarginRight
Right margin for paragraphs.
Class representing an event.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.