Skip to content

Commit 9c13d60

Browse files
VisualMessages moved to ChatUI project to solve #15 Introduction of .NET 5 blocked from strict dependency of ChatLib from graphics (WPF) (#16)
1 parent 9ec4fc2 commit 9c13d60

File tree

3 files changed

+185
-176
lines changed

3 files changed

+185
-176
lines changed

src/ChatLib/Message.cs

Lines changed: 1 addition & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
using System.ComponentModel;
3333
using System.Runtime.CompilerServices;
3434
using System.Collections.ObjectModel;
35-
using System.Windows;
3635

3736
namespace MASES.S4I.ChatLib
3837
{
@@ -69,181 +68,7 @@ public enum MessageKindType : int
6968
VOID,
7069
}
7170

72-
/// <summary>
73-
/// Class to manage messages that shall be displayed
74-
/// note: this class could be moved in the UI project
75-
/// </summary>
76-
public class VisualMessage
77-
{
78-
internal Message Message { get; set; }
79-
internal ChatUser User { get; set; }
80-
81-
/// <summary>
82-
/// Alignement of the message in the chat
83-
/// </summary>
84-
public HorizontalAlignment Alignment { get; set; }
85-
86-
87-
/// <summary>
88-
/// Index of the message in the array
89-
/// </summary>
90-
public int Idx
91-
{
92-
get;
93-
internal set;
94-
}
95-
96-
/// <summary>
97-
/// Return the StringContent of the message
98-
/// </summary>
99-
public string StringContent
100-
{
101-
get
102-
{
103-
return Message.StringContent;
104-
}
105-
}
106-
107-
/// <summary>
108-
/// Name of the sender or sender id
109-
/// </summary>
110-
public string SenderName
111-
{
112-
get
113-
{
114-
if (User != null)
115-
return string.Format("{0} {1}", User.Name, User.LastName);
116-
else
117-
return Message.Sender.ToString();
118-
}
119-
}
120-
121-
/// <summary>
122-
/// return true if the message contains a file
123-
/// </summary>
124-
public bool HaveDownload
125-
{
126-
get
127-
{
128-
if (Message.Kind == MessageKindType.FILE ||
129-
Message.Kind == MessageKindType.IMAGE)
130-
return true;
131-
return false;
132-
}
133-
}
134-
135-
/// <summary>
136-
/// True if the message is encrypted
137-
/// </summary>
138-
public bool Encrypted
139-
{
140-
get
141-
{
142-
return Message.Destination != Guid.Empty;
143-
}
144-
}
145-
146-
/// <summary>
147-
/// encapsulate Message veerified property
148-
/// </summary>
149-
public bool Verified
150-
{
151-
get
152-
{
153-
return Message.Verified;
154-
}
155-
}
156-
157-
/// <summary>
158-
/// The file contained in the message
159-
/// </summary>
160-
public ChatFileContent File
161-
{
162-
get
163-
{
164-
try
165-
{
166-
switch (Message.Kind)
167-
{
168-
case MessageKindType.IMAGE:
169-
ChatImage ci = Message as ChatImage;
170-
return ci.ImageContent.RawFile;
171-
case MessageKindType.FILE:
172-
ChatFile cf = Message as ChatFile;
173-
return cf.FileContent;
174-
}
175-
}
176-
catch (Exception ex)
177-
{
178-
//TODO: add logging
179-
180-
}
181-
return null;
182-
}
183-
}
184-
185-
/// <summary>
186-
/// The name of the file contained in the message
187-
/// </summary>
188-
public string FileName
189-
{
190-
get
191-
{
192-
try
193-
{
194-
switch (Message.Kind)
195-
{
196-
case MessageKindType.IMAGE:
197-
ChatImage ci = Message as ChatImage;
198-
return ci.Name;
199-
case MessageKindType.FILE:
200-
ChatFile cf = Message as ChatFile;
201-
return cf.Name;
202-
}
203-
}
204-
catch (Exception ex)
205-
{
206-
//TODO: add logging
207-
208-
}
209-
return null;
210-
}
211-
}
212-
}
213-
214-
/// <summary>
215-
/// A class to manage the received messages
216-
/// implements <see cref="INotifyPropertyChanged"/> to be used in user interface
217-
/// Note: this class could be moved in the UI project
218-
/// </summary>
219-
public class ReceivedMessages : INotifyPropertyChanged
220-
{
221-
public ObservableCollection<VisualMessage> MessageList = new ObservableCollection<VisualMessage>();
222-
223-
/// <summary>
224-
/// Add a message to the exposed MessageList
225-
/// </summary>
226-
/// <param name="receivedMessage">the <see cref="Message"/> message to add</param>
227-
public void Add(Message receivedMessage, ChatUser cu, bool received)
228-
{
229-
HorizontalAlignment alignment = (received) ? HorizontalAlignment.Left : HorizontalAlignment.Right;
230-
MessageList.Add(new VisualMessage() { Message = receivedMessage, User = cu, Idx = MessageList.Count, Alignment = alignment });
231-
NotifyPropertyChanged("MessageList");
232-
}
233-
234-
/// <summary>
235-
/// The PropertyChangedEventHandler event
236-
/// </summary>
237-
public event PropertyChangedEventHandler PropertyChanged;
238-
239-
// This method is called by the Set accessor of each property.
240-
// The CallerMemberName attribute that is applied to the optional propertyName
241-
// parameter causes the property name of the caller to be substituted as an argument.
242-
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
243-
{
244-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
245-
}
246-
}
71+
24772

24873
/// <summary>
24974
/// A class to manage the contact list

src/ChatUI/ChatUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Generator>MSBuild:Compile</Generator>
7272
<SubType>Designer</SubType>
7373
</ApplicationDefinition>
74+
<Compile Include="VisualMessages.cs" />
7475
<Page Include="ConfigurationWindow.xaml">
7576
<SubType>Designer</SubType>
7677
<Generator>MSBuild:Compile</Generator>

src/ChatUI/VisualMessages.cs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
using MASES.S4I.ChatLib;
2+
using System;
3+
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
5+
using System.Runtime.CompilerServices;
6+
using System.Windows;
7+
8+
namespace MASES.S4I.ChatUI
9+
{
10+
/// <summary>
11+
/// Class to manage messages that shall be displayed
12+
/// </summary>
13+
public class VisualMessage
14+
{
15+
internal Message Message { get; set; }
16+
internal ChatUser User { get; set; }
17+
18+
/// <summary>
19+
/// Alignement of the message in the chat
20+
/// </summary>
21+
public HorizontalAlignment Alignment { get; set; }
22+
23+
24+
/// <summary>
25+
/// Index of the message in the array
26+
/// </summary>
27+
public int Idx
28+
{
29+
get;
30+
internal set;
31+
}
32+
33+
/// <summary>
34+
/// Return the StringContent of the message
35+
/// </summary>
36+
public string StringContent
37+
{
38+
get
39+
{
40+
return Message.StringContent;
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Name of the sender or sender id
46+
/// </summary>
47+
public string SenderName
48+
{
49+
get
50+
{
51+
if (User != null)
52+
return string.Format("{0} {1}", User.Name, User.LastName);
53+
else
54+
return Message.Sender.ToString();
55+
}
56+
}
57+
58+
/// <summary>
59+
/// return true if the message contains a file
60+
/// </summary>
61+
public bool HaveDownload
62+
{
63+
get
64+
{
65+
if (Message.Kind == MessageKindType.FILE ||
66+
Message.Kind == MessageKindType.IMAGE)
67+
return true;
68+
return false;
69+
}
70+
}
71+
72+
/// <summary>
73+
/// True if the message is encrypted
74+
/// </summary>
75+
public bool Encrypted
76+
{
77+
get
78+
{
79+
return Message.Destination != Guid.Empty;
80+
}
81+
}
82+
83+
/// <summary>
84+
/// encapsulate Message veerified property
85+
/// </summary>
86+
public bool Verified
87+
{
88+
get
89+
{
90+
return Message.Verified;
91+
}
92+
}
93+
94+
/// <summary>
95+
/// The file contained in the message
96+
/// </summary>
97+
public ChatFileContent File
98+
{
99+
get
100+
{
101+
try
102+
{
103+
switch (Message.Kind)
104+
{
105+
case MessageKindType.IMAGE:
106+
ChatImage ci = Message as ChatImage;
107+
return ci.ImageContent.RawFile;
108+
case MessageKindType.FILE:
109+
ChatFile cf = Message as ChatFile;
110+
return cf.FileContent;
111+
}
112+
}
113+
catch (Exception ex)
114+
{
115+
//TODO: add logging
116+
117+
}
118+
return null;
119+
}
120+
}
121+
122+
/// <summary>
123+
/// The name of the file contained in the message
124+
/// </summary>
125+
public string FileName
126+
{
127+
get
128+
{
129+
try
130+
{
131+
switch (Message.Kind)
132+
{
133+
case MessageKindType.IMAGE:
134+
ChatImage ci = Message as ChatImage;
135+
return ci.Name;
136+
case MessageKindType.FILE:
137+
ChatFile cf = Message as ChatFile;
138+
return cf.Name;
139+
}
140+
}
141+
catch (Exception ex)
142+
{
143+
//TODO: add logging
144+
145+
}
146+
return null;
147+
}
148+
}
149+
}
150+
151+
/// <summary>
152+
/// A class to manage the received messages
153+
/// implements <see cref="INotifyPropertyChanged"/> to be used in user interface
154+
/// </summary>
155+
public class ReceivedMessages : INotifyPropertyChanged
156+
{
157+
public ObservableCollection<VisualMessage> MessageList = new ObservableCollection<VisualMessage>();
158+
159+
/// <summary>
160+
/// Add a message to the exposed MessageList
161+
/// </summary>
162+
/// <param name="receivedMessage">the <see cref="Message"/> message to add</param>
163+
public void Add(Message receivedMessage, ChatUser cu, bool received)
164+
{
165+
HorizontalAlignment alignment = (received) ? HorizontalAlignment.Left : HorizontalAlignment.Right;
166+
MessageList.Add(new VisualMessage() { Message = receivedMessage, User = cu, Idx = MessageList.Count, Alignment = alignment });
167+
NotifyPropertyChanged("MessageList");
168+
}
169+
170+
/// <summary>
171+
/// The PropertyChangedEventHandler event
172+
/// </summary>
173+
public event PropertyChangedEventHandler PropertyChanged;
174+
175+
// This method is called by the Set accessor of each property.
176+
// The CallerMemberName attribute that is applied to the optional propertyName
177+
// parameter causes the property name of the caller to be substituted as an argument.
178+
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
179+
{
180+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)