Files
Chat/ChatController/ChatKlassen/Contact.cs
LynJet 410945af20 Massennachricht hinzugefügt
Optik an die vom Android- und Webclient angepasst
Asynchrone Methoden verbessert
2022-07-11 16:01:14 +02:00

194 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using ChatController.Core;
using ChatController.LoginKlassen;
using ChatController.Utilities;
using Brush = System.Windows.Media.Brush;
namespace ChatController.ChatKlassen
{
public class Contact : INotifyPropertyChanged
{
public string Name { get; }
private GroupLatestMessage _ReceivedMessage;
public GroupLatestMessage ReceivedMessage
{
get => _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;
var userId = OwnChatCache.GetInstance().LoggedOnUserId;
var rmUserId = ReceivedMessage?.UserId;
var isOwnMessage = rmUserId.HasValue && rmUserId.Value.Equals(userId);
if (_HasUnreadMessages && !isOwnMessage)
{
_Color = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
}
else
{
_Color = new SolidColorBrush(Colors.Gray);
}
OnPropertyChanged(nameof(HasUnreadMessages));
OnPropertyChanged(nameof(Color));
}
}
private ImageSource _Image;
public ImageSource Image
{
get => _Image;
set
{
if(!Equals(_Image, value))
{
_Image = value;
OnPropertyChanged(nameof(Image));
}
}
}
public DateTime TimeStamp { get; set; }
public int GroupId { get; }
public string UserIdManage { get; }
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)
{
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)
{
if(obj is Contact y)
{
if(ReferenceEquals(this, y))
{
return true;
}
if(GetType() != y.GetType())
{
return false;
}
return Name == y.Name &&
IsNewMessage == y.IsNewMessage &&
TimeStamp.Equals(y.TimeStamp) &&
GroupId == y.GroupId &&
UserIdManage == y.UserIdManage &&
IsChatMessageInputGridVisible == y.IsChatMessageInputGridVisible;
}
return false;
}
public override int GetHashCode()
{
unchecked
{
var hashCode = Name != null ? Name.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ GroupId;
hashCode = (hashCode * 397) ^ (UserIdManage != null ? UserIdManage.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ IsChatMessageInputGridVisible.GetHashCode();
return hashCode;
}
}
public SolidColorBrush AccentColorBrush { get; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class ContactDependencyObject : DependencyObject
{
public Contact Contact { get; set; }
public ContactDependencyObject(Contact contact)
{
Contact = contact;
}
}
}