2017-09-12 14:32:34 +02:00
|
|
|
|
using System;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
using System.ComponentModel;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using System.Drawing;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
using System.Windows.Media;
|
2019-09-03 15:15:12 +02:00
|
|
|
|
using ChatController.LoginKlassen;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using Brush = System.Windows.Media.Brush;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
namespace ChatController.ChatKlassen
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public class Contact : INotifyPropertyChanged
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2019-04-04 13:00:10 +02:00
|
|
|
|
public string Name { get; }
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2019-09-03 15:15:12 +02:00
|
|
|
|
private GroupLatestMessage _ReceivedMessage;
|
|
|
|
|
|
public GroupLatestMessage ReceivedMessage
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2019-09-03 15:15:12 +02:00
|
|
|
|
get => _ReceivedMessage;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2019-04-04 13:00:10 +02:00
|
|
|
|
_ReceivedMessage = value;
|
|
|
|
|
|
OnPropertyChanged(nameof(ReceivedMessage));
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
public bool IsNewMessage { get; set; }
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private Brush _Color;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
public Brush Color
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
get => _Color;
|
2019-04-04 13:00:10 +02:00
|
|
|
|
|
2017-09-12 14:32:34 +02:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
_Color = value;
|
2019-04-04 13:00:10 +02:00
|
|
|
|
OnPropertyChanged(nameof(Color));
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
private bool _HasUnreadMessages;
|
|
|
|
|
|
public bool HasUnreadMessages
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2019-05-14 13:37:20 +02:00
|
|
|
|
get => _HasUnreadMessages;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2019-05-14 13:37:20 +02:00
|
|
|
|
_HasUnreadMessages = value;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
if (_HasUnreadMessages)
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
_Color = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
2019-05-14 13:37:20 +02:00
|
|
|
|
else
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
_Color = new SolidColorBrush(Colors.Gray);
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
OnPropertyChanged(nameof(HasUnreadMessages));
|
2019-04-04 13:00:10 +02:00
|
|
|
|
OnPropertyChanged(nameof(Color));
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 13:00:10 +02:00
|
|
|
|
public ImageSource Image { get; }
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
2017-09-12 14:32:34 +02:00
|
|
|
|
public DateTime TimeStamp { get; set; }
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
public int GroupId { get; set; }
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
public int UserOid { get; set; }
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
2019-05-14 13:37:20 +02:00
|
|
|
|
public string UserIdManage { get; set; }
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public bool IsChatMessageInputGridVisible { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public Bitmap ProfilePicture { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public Contact(string pName, GroupLatestMessage pLatestMessage, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount, bool isChatMessageInputGridVisible, string accentColorBrushString, Bitmap profilePicture, ImageSource image)
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
Name = pName;
|
|
|
|
|
|
ReceivedMessage = pLatestMessage;
|
|
|
|
|
|
TimeStamp = pTimeStamp;
|
|
|
|
|
|
GroupId = pGroupId;
|
|
|
|
|
|
UserIdManage = pUserIdManage;
|
2019-05-14 13:37:20 +02:00
|
|
|
|
HasUnreadMessages = false;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
|
|
|
|
|
ProfilePicture = profilePicture;
|
|
|
|
|
|
|
|
|
|
|
|
IsChatMessageInputGridVisible = isChatMessageInputGridVisible;
|
|
|
|
|
|
|
|
|
|
|
|
AccentColorBrush = new BrushConverter().ConvertFromString($"#{accentColorBrushString}") as SolidColorBrush ?? new SolidColorBrush(Colors.Black);
|
|
|
|
|
|
|
|
|
|
|
|
Image = image;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private sealed class ContactEqualityComparer : IEqualityComparer<Contact>
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Equals(Contact x, Contact y)
|
2017-11-16 15:38:30 +01:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if(ReferenceEquals(x, y))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(x is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(y is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(x.GetType() != y.GetType())
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return x.Name == y.Name &&
|
|
|
|
|
|
x.IsNewMessage == y.IsNewMessage &&
|
|
|
|
|
|
Equals(x.ProfilePicture, y.ProfilePicture) &&
|
|
|
|
|
|
x.TimeStamp.Equals(y.TimeStamp) &&
|
|
|
|
|
|
x.GroupId == y.GroupId &&
|
|
|
|
|
|
x.UserOid == y.UserOid &&
|
|
|
|
|
|
x.UserIdManage == y.UserIdManage &&
|
|
|
|
|
|
x.IsChatMessageInputGridVisible == y.IsChatMessageInputGridVisible;
|
2017-11-16 15:38:30 +01:00
|
|
|
|
}
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
|
|
|
|
|
public int GetHashCode(Contact obj)
|
2017-11-16 15:38:30 +01:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
unchecked
|
|
|
|
|
|
{
|
|
|
|
|
|
var hashCode = obj.Name != null ? obj.Name.GetHashCode() : 0;
|
|
|
|
|
|
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ obj.IsNewMessage.GetHashCode();
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ (obj.ProfilePicture != null ? obj.ProfilePicture.GetHashCode() : 0);
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ obj.TimeStamp.GetHashCode();
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ obj.GroupId;
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ obj.UserOid;
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ (obj.UserIdManage != null ? obj.UserIdManage.GetHashCode() : 0);
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ obj.IsChatMessageInputGridVisible.GetHashCode();
|
|
|
|
|
|
|
|
|
|
|
|
return hashCode;
|
|
|
|
|
|
}
|
2017-11-16 15:38:30 +01:00
|
|
|
|
}
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public SolidColorBrush AccentColorBrush { get; }
|
|
|
|
|
|
|
2017-09-12 14:32:34 +02:00
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName)
|
|
|
|
|
|
{
|
|
|
|
|
|
var handler = PropertyChanged;
|
2019-04-04 13:00:10 +02:00
|
|
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|