Files
Chat/ChatController/ChatKlassen/Contact.cs
Lyndon 3fbf8afe0d Anzeige von neuen Nachrichten und die Ladegeschwindigkeit von Konversationen verbessert
Aufgrund der Benutzung von Threads anstelle von Timern hat das Aufrufen der einzelnen Konversationen ca. 2 Sekunden gedauert.
Die Synchronisationsdatei enthält, ob die letzte Nachrichte bereits gelesen wurde, sodass man,
wenn man den Chat beendet bevor man eine neue Nachricht gelesen hat, diese nach dem erneuten Öffnen immer noch als neu angezeigt wird.

- Dateinamen verbessert
- Diverse Verbesserungen des Codes
2019-05-14 13:37:20 +02:00

120 lines
3.4 KiB
C#

using System;
using System.ComponentModel;
using System.Windows.Media;
using static System.String;
namespace ChatController.ChatKlassen
{
public class Contact
{
public string Name { get; }
private string _ReceivedMessage;
public string ReceivedMessage
{
get
{
if (!IsNullOrEmpty(_ReceivedMessage) && _ReceivedMessage.Length > 25)
{
return _ReceivedMessage.Substring(0, 25) + "...";
}
return _ReceivedMessage;
}
set
{
_ReceivedMessage = value;
OnPropertyChanged(nameof(ReceivedMessage));
}
}
public bool IsNewMessage { get; set; }
private Brush _color;
public Brush Color
{
get => _color;
set
{
_color = value;
OnPropertyChanged(nameof(Color));
}
}
private bool _HasUnreadMessages;
public bool HasUnreadMessages
{
get => _HasUnreadMessages;
set
{
_HasUnreadMessages = value;
if (_HasUnreadMessages)
{
_color = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
}
else
{
_color = new SolidColorBrush(Colors.Gray);
}
OnPropertyChanged(nameof(HasUnreadMessages));
OnPropertyChanged(nameof(Color));
}
}
private Brush _ContactChatColor;
public Brush ContactChatColor
{
get => _ContactChatColor;
set
{
_ContactChatColor = value;
OnPropertyChanged(nameof(ContactChatColor));
}
}
public ImageSource Image { get; }
public DateTime TimeStamp { get; set; }
public int GroupId { get; set; }
public int UserOid { get; set; }
public string UserIdManage { get; set; }
public Contact(string pName, ImageSource pImage, string pLastMessageText, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount)
{
Name = pName;
ReceivedMessage = pLastMessageText;
Image = pImage;
TimeStamp = pTimeStamp;
GroupId = pGroupId;
UserIdManage = pUserIdManage;
HasUnreadMessages = false;
if (UserIdManage != null)
{
_ContactChatColor = new BrushConverter().ConvertFromString("#3B7799") as SolidColorBrush;
}
else if (pOnlyEmployees && pUserCount > 2)
{
_ContactChatColor = new BrushConverter().ConvertFromString("#45993B") as SolidColorBrush;
}
else
{
_ContactChatColor = new BrushConverter().ConvertFromString("#000000") as SolidColorBrush;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}