Files
Chat/ChatController/ChatKlassen/Contact.cs

174 lines
5.0 KiB
C#
Raw Normal View History

2017-09-12 14:32:34 +02:00
using System;
using System.Collections.Generic;
2017-09-12 14:32:34 +02:00
using System.ComponentModel;
using System.Windows;
2017-09-12 14:32:34 +02:00
using System.Windows.Media;
using ChatController.Core;
using ChatController.LoginKlassen;
using ChatController.Utilities;
using Brush = System.Windows.Media.Brush;
2017-09-12 14:32:34 +02:00
namespace ChatController.ChatKlassen
{
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
private GroupLatestMessage _ReceivedMessage;
public GroupLatestMessage ReceivedMessage
2017-09-12 14:32:34 +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
}
}
public bool IsNewMessage { get; set; }
private Brush _Color;
2017-09-12 14:32:34 +02:00
public Brush Color
{
get => _Color;
2019-04-04 13:00:10 +02:00
2017-09-12 14:32:34 +02:00
set
{
_Color = value;
2019-04-04 13:00:10 +02:00
OnPropertyChanged(nameof(Color));
2017-09-12 14:32:34 +02:00
}
}
private bool _HasUnreadMessages;
public bool HasUnreadMessages
2017-09-12 14:32:34 +02:00
{
get => _HasUnreadMessages;
2017-09-12 14:32:34 +02:00
set
{
_HasUnreadMessages = value;
var userId = OwnChatCache.GetInstance().LoggedOnUserId;
var rmUserId = ReceivedMessage?.UserId;
var isOwnMessage = rmUserId.HasValue && rmUserId.Value.Equals(userId);
_Color = _HasUnreadMessages && !isOwnMessage ? new BrushConverter().ConvertFromString("#FF5A00") as SolidColorBrush : new SolidColorBrush(Colors.Gray);
2017-09-12 14:32:34 +02:00
OnPropertyChanged(nameof(HasUnreadMessages));
2019-04-04 13:00:10 +02:00
OnPropertyChanged(nameof(Color));
2017-09-12 14:32:34 +02:00
}
}
private ImageSource _Image;
public ImageSource Image
{
get => _Image;
set
{
2023-03-03 21:23:48 +01:00
if(Equals(_Image, value))
{
2023-03-03 21:23:48 +01:00
return;
}
2023-03-03 21:23:48 +01:00
_Image = value;
OnPropertyChanged(nameof(Image));
}
}
2017-09-12 14:32:34 +02:00
public DateTime TimeStamp { get; set; }
public int GroupId { get; }
public string UserIdManage { get; }
2017-09-12 14:32:34 +02:00
public bool IsChatMessageInputGridVisible { get; }
public Contact(string pName, GroupLatestMessage pLatestMessage, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount, bool isChatMessageInputGridVisible, string accentColorBrushString, string profilePicturePath, string key, Dictionary<long, string> userId2Uri)
2017-09-12 14:32:34 +02:00
{
Name = pName;
ReceivedMessage = pLatestMessage;
TimeStamp = pTimeStamp;
GroupId = pGroupId;
UserIdManage = pUserIdManage;
HasUnreadMessages = false;
IsChatMessageInputGridVisible = isChatMessageInputGridVisible;
Utils.DownloadUserProfilePicturesAsync(userId2Uri);
if (accentColorBrushString is null)
{
if(!(pUserIdManage is null))
{
accentColorBrushString = "3B7799";
}
else if(pOnlyEmployees && pUserCount > 2)
{
accentColorBrushString = "45993B";
}
else
{
accentColorBrushString = "000000";
}
}
AccentColorBrush = new BrushConverter().ConvertFromString($"#{accentColorBrushString}") as SolidColorBrush;
IsGroupChat = pUserCount > 2;
Utils.DownloadGroupProfilePictureAsync(profilePicturePath, key, delegate(ImageSource imageSource)
{
Image = imageSource;
});
}
public bool IsGroupChat { get; }
public override bool Equals(object obj)
{
2022-08-01 13:25:20 +02:00
return obj is Contact y && GroupId == y.GroupId;
}
public override int GetHashCode()
{
unchecked
2017-11-16 15:38:30 +01:00
{
var hashCode = Name?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ GroupId;
hashCode = (hashCode * 397) ^ (UserIdManage?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ IsChatMessageInputGridVisible.GetHashCode();
return hashCode;
2017-11-16 15:38:30 +01:00
}
2017-09-12 14:32:34 +02:00
}
public override string ToString()
{
return $"({GroupId}) {Name}";
}
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
}
}
public class ContactDependencyObject : DependencyObject
{
public Contact Contact { get; set; }
public ContactDependencyObject(Contact contact)
{
Contact = contact;
}
}
2017-09-12 14:32:34 +02:00
}