- Links in Nachrichten klickbar
- Profilbilder werden in Gruppenchats (mehr als 2 Teilnehmer) angezeigt - Profilbilder werden im Cache gespeichert - Verbesserungen am Code
This commit is contained in:
@@ -72,6 +72,8 @@
|
||||
<Compile Include="Converter\BoolToVisibilityConverter.cs" />
|
||||
<Compile Include="Converter\StringEmptyToVisibilityConverter.cs" />
|
||||
<Compile Include="Converter\StringToBoolConverter.cs" />
|
||||
<Compile Include="Converter\UserProfilePictureVisibilityConverter.cs" />
|
||||
<Compile Include="Core\BindableTextBlock.cs" />
|
||||
<Compile Include="Core\OwnChatCache.cs" />
|
||||
<Compile Include="Data\LookupResult.cs" />
|
||||
<Compile Include="Data\OwnChatApi.cs" />
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using ChatController.Core;
|
||||
using ChatController.HauptKlassen;
|
||||
using ChatController.Utilities;
|
||||
using static System.Windows.HorizontalAlignment;
|
||||
using Application = System.Windows.Application;
|
||||
using HorizontalAlignment = System.Windows.HorizontalAlignment;
|
||||
|
||||
namespace ChatController.ChatKlassen
|
||||
{
|
||||
@@ -22,55 +24,74 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
public bool IsSeparator { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
public long SenderId { get; }
|
||||
|
||||
// Separator
|
||||
public ChatMessage(DateTime sendTime)
|
||||
private ObservableCollection<Inline> _MessageInlines;
|
||||
|
||||
public ObservableCollection<Inline> MessageInlines
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
IsSeparator = true;
|
||||
SendTime = sendTime;
|
||||
|
||||
MessageType = ChatMessageType.Separator;
|
||||
get => _MessageInlines;
|
||||
set
|
||||
{
|
||||
if(false == (_MessageInlines?.Equals(value) ?? false))
|
||||
{
|
||||
_MessageInlines = value;
|
||||
OnPropertyChanged(nameof(MessageInlines));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Chat-Ansicht
|
||||
public ChatMessage(string username, string message, DateTime sendtime, bool isme, long groupId, long fileSize, long messageId)
|
||||
public ChatMessage(long groupId, long messageId, string userName, string messageText, DateTime sendTime, bool isOwnMessage, long fileSize, string filePath,
|
||||
string originalImage, string imageName, string thumbnailPath, ImageSource logo, ChatMessageType chatMessageType, long senderId)
|
||||
{
|
||||
MessageId = messageId;
|
||||
|
||||
Id = Guid.NewGuid();
|
||||
Username = username;
|
||||
UserMessage = message;
|
||||
SendTime = sendtime;
|
||||
IsMyMessage = isme;
|
||||
|
||||
SenderId = senderId;
|
||||
|
||||
MessageType = chatMessageType;
|
||||
|
||||
MessageId = messageId;
|
||||
GroupId = groupId;
|
||||
Username = userName;
|
||||
|
||||
MessageType = IsHyperlink(message) ? ChatMessageType.Hyperlink : ChatMessageType.Message;
|
||||
UserMessage = messageText;
|
||||
if(!string.IsNullOrEmpty(messageText))
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MessageInlines = Utils.ConvertLinksToHyperlinks(messageText);
|
||||
});
|
||||
}
|
||||
|
||||
// Image-Ansicht
|
||||
public ChatMessage(string username, string message, DateTime sendtime, bool isme, string filePath, string originalImage, string imageName, long groupId, long fileSize, long messageId)
|
||||
{
|
||||
PicturePlaceholderHeight = Utils.GetHeightFromThumbnailUri(filePath);
|
||||
PictureSource = Utils.GetPicturePlaceholder();
|
||||
|
||||
MessageId = messageId;
|
||||
|
||||
Id = Guid.NewGuid();
|
||||
Username = username;
|
||||
UserMessage = message;
|
||||
SendTime = sendtime;
|
||||
|
||||
IsMyMessage = isme;
|
||||
SendTime = sendTime;
|
||||
IsMyMessage = isOwnMessage;
|
||||
|
||||
OriginalImage = originalImage;
|
||||
OriginalImageName = imageName;
|
||||
|
||||
GroupId = groupId;
|
||||
if(MessageId == 0 && MessageType == ChatMessageType.Image && logo != null)
|
||||
{
|
||||
PictureSource = logo;
|
||||
PicturePlaceholderHeight = (int) logo.Height;
|
||||
}
|
||||
|
||||
MessageType = ChatMessageType.Image;
|
||||
FilePath = filePath;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(thumbnailPath))
|
||||
{
|
||||
ThumbnailPlaceholderHeight = Utils.GetHeightFromThumbnailUri(thumbnailPath);
|
||||
Thumbnail = Utils.GetPicturePlaceholder();
|
||||
|
||||
Utils.DownloadImageAsync(thumbnailPath, $"group-{groupId}", CacheCategory.Thumbnail, imageSource =>
|
||||
{
|
||||
Thumbnail = imageSource;
|
||||
});
|
||||
}
|
||||
|
||||
if(MessageType == ChatMessageType.Image && !string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
PicturePlaceholderHeight = Utils.GetHeightFromThumbnailUri(filePath);
|
||||
PictureSource = Utils.GetPicturePlaceholder();
|
||||
|
||||
Utils.DownloadImageAsync(filePath, $"group-{groupId}", CacheCategory.Thumbnail, imageSource =>
|
||||
{
|
||||
@@ -78,52 +99,7 @@ namespace ChatController.ChatKlassen
|
||||
});
|
||||
}
|
||||
|
||||
//Dokumenten-Ansicht
|
||||
public ChatMessage(string username, string message, DateTime sendtime, string thumbnailPath, bool isme, string filePath, long groupId, long fileSize, long messageId)
|
||||
{
|
||||
ThumbnailPlaceholderHeight = Utils.GetHeightFromThumbnailUri(thumbnailPath);
|
||||
Thumbnail = Utils.GetPicturePlaceholder();
|
||||
|
||||
MessageId = messageId;
|
||||
|
||||
Id = Guid.NewGuid();
|
||||
Username = username;
|
||||
UserMessage = message;
|
||||
SendTime = sendtime;
|
||||
IsMyMessage = isme;
|
||||
|
||||
FilePath = filePath;
|
||||
|
||||
Utils.DownloadImageAsync(thumbnailPath, $"group-{groupId}", CacheCategory.Thumbnail, imageSource =>
|
||||
{
|
||||
Thumbnail = imageSource;
|
||||
});
|
||||
|
||||
GroupId = groupId;
|
||||
|
||||
MessageType = ChatMessageType.Document;
|
||||
}
|
||||
|
||||
// Mit Logo
|
||||
public ChatMessage(string username, string message, DateTime sendtime, bool isme, ImageSource logo, string originalImage, string imageName, long groupId, long fileSize, long messageId)
|
||||
{
|
||||
MessageId = messageId;
|
||||
|
||||
Id = Guid.NewGuid();
|
||||
Username = username;
|
||||
UserMessage = message;
|
||||
SendTime = sendtime;
|
||||
|
||||
IsMyMessage = isme;
|
||||
|
||||
OriginalImage = originalImage;
|
||||
OriginalImageName = imageName;
|
||||
|
||||
GroupId = groupId;
|
||||
|
||||
MessageType = ChatMessageType.Image;
|
||||
|
||||
PictureSource = logo;
|
||||
IsSeparator = MessageType == ChatMessageType.Separator;
|
||||
}
|
||||
|
||||
public ChatMessageType MessageType { get; }
|
||||
@@ -157,47 +133,6 @@ namespace ChatController.ChatKlassen
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Regex _UrlRegex = new Regex(@"(?#Protocol)^(http(?:s?)\:(\/\/|\\\\)|(w){3}(2|3)?\.{1})(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?");
|
||||
|
||||
public static bool IsHyperlink(string word)
|
||||
{
|
||||
if(word == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (word.IndexOfAny(@":.\/".ToCharArray()) != -1)
|
||||
{
|
||||
if (_UrlRegex.IsMatch(word))
|
||||
{
|
||||
var uri = new Uri(word, UriKind.RelativeOrAbsolute);
|
||||
|
||||
if (!uri.IsAbsoluteUri)
|
||||
{
|
||||
uri = new Uri(@"http://" + word, UriKind.Absolute);
|
||||
}
|
||||
|
||||
if (uri.IsAbsoluteUri)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsMyMessage { get; set; }
|
||||
|
||||
public string Username { get; }
|
||||
@@ -224,16 +159,6 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
public string OriginalImageName { get; }
|
||||
|
||||
public Visibility ChatVisibility => MessageType == ChatMessageType.Message ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public Visibility HyperlinkVisibility => MessageType == ChatMessageType.Hyperlink ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public Visibility PictureVisibility => MessageType == ChatMessageType.Image ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public Visibility PicturePlaceHolderVisibility => MessageType == ChatMessageType.DefaultImage ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public Visibility DokumentVisibility => MessageType == ChatMessageType.Document ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
private ImageSource _PictureSource;
|
||||
public ImageSource PictureSource
|
||||
{
|
||||
@@ -262,7 +187,7 @@ namespace ChatController.ChatKlassen
|
||||
}
|
||||
}
|
||||
|
||||
public object FilePath { get; }
|
||||
public string FilePath { get; }
|
||||
|
||||
public long GroupId { get; }
|
||||
|
||||
@@ -270,28 +195,7 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
public Guid Id { get; }
|
||||
|
||||
public Uri UserMessageAsUri
|
||||
{
|
||||
get
|
||||
{
|
||||
if(IsHyperlink(UserMessage))
|
||||
{
|
||||
Debug.WriteLine($"Link: {UserMessage}");
|
||||
|
||||
if(!UserMessage.Contains("http"))
|
||||
{
|
||||
return new Uri("http://" + UserMessage);
|
||||
}
|
||||
|
||||
if(UserMessage.Contains("https") || UserMessage.Contains("http"))
|
||||
{
|
||||
return new Uri(UserMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public ImageSource ProfilePicture => OwnChatCache.GetInstance().GetUserProfilePictureFromCache(SenderId)?.ProfilePicture;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
@@ -308,7 +212,7 @@ namespace ChatController.ChatKlassen
|
||||
return SendTime == message.SendTime;
|
||||
}
|
||||
|
||||
return MessageId.Equals(message.MessageId);
|
||||
return Id.Equals(message.Id) && MessageId.Equals(message.MessageId);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Media;
|
||||
using ChatController.LoginKlassen;
|
||||
@@ -82,7 +83,7 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
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)
|
||||
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;
|
||||
@@ -111,12 +112,18 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
AccentColorBrush = new BrushConverter().ConvertFromString($"#{accentColorBrushString}") as SolidColorBrush;
|
||||
|
||||
IsGroupChat = pUserCount > 2;
|
||||
|
||||
Utils.DownloadUserProfilePictures(userId2Uri);
|
||||
|
||||
Utils.DownloadProfilePictureAsync(profilePicturePath, key, delegate(ImageSource imageSource)
|
||||
{
|
||||
Image = imageSource;
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsGroupChat { get; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if(obj is Contact y)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:converter="clr-namespace:ChatController.Converter"
|
||||
xmlns:chatKlassen="clr-namespace:ChatController.ChatKlassen"
|
||||
xmlns:core="clr-namespace:ChatController.Core"
|
||||
xmlns:chatController="clr-namespace:ChatController"
|
||||
mc:Ignorable="d" x:Name="ChatControlling"
|
||||
d:DesignHeight="300" d:DesignWidth="600"
|
||||
Loaded="ChatMainControl_OnLoaded"
|
||||
@@ -13,10 +15,10 @@
|
||||
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converter:StringEmptyToVisibilityConverter x:Key="StringEmptyToVisibilityConverter" />
|
||||
<converter:StringToBoolConverter x:Key="StringToBoolConverter" />
|
||||
<converter:UserProfilePictureVisibilityConverter x:Key="UserProfilePictureVisibilityConverter" />
|
||||
|
||||
<SolidColorBrush x:Key="DarkBackColor" Color="#FFA9B8C2" />
|
||||
<SolidColorBrush x:Key="LightBackColor" Color="#E8EFF4" />
|
||||
<SolidColorBrush x:Key="ButtonForeground" Color="#ff5e00" />
|
||||
|
||||
<Style x:Key="MainNavigationScrollViewer" TargetType="{x:Type ScrollViewer}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="True"/>
|
||||
@@ -175,6 +177,7 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Gruppensuche und Gruppenliste aktualisieren -->
|
||||
<Grid Grid.Column="0" Grid.Row="0" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
@@ -192,7 +195,9 @@
|
||||
|
||||
<TextBox Grid.Column="0" x:Name="Suche" Height="22" HorizontalAlignment="Stretch" Margin="5" TabIndex="0" Template="{DynamicResource SearchTextBoxTemplate}" BorderThickness="0,0,0,0" TextChanged="Suche_OnTextChanged" />
|
||||
</Grid>
|
||||
<!-- /Gruppensuche und Gruppenliste aktualisieren -->
|
||||
|
||||
<!-- Kontaktliste -->
|
||||
<Grid Grid.Column="0" Grid.Row="1" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
@@ -205,6 +210,7 @@
|
||||
ItemContainerStyle="{StaticResource ContactListBoxItemStyle}" SelectionChanged="Clientlist_OnSelectionChanged" Style="{StaticResource ContactListStyle}">
|
||||
</ListView>
|
||||
</Grid>
|
||||
<!-- /Kontaktliste -->
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Column="1" Grid.Row="0" x:Name="GridRechts">
|
||||
@@ -301,45 +307,36 @@
|
||||
<Border>
|
||||
<Grid HorizontalAlignment="Stretch" Background="Transparent" MaxWidth="500">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Separator Grid.Column="0" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}" VerticalContentAlignment="Center" />
|
||||
<Label Content="{Binding SeparatorTimeString}" HorizontalAlignment="Center" Grid.Column="1" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}"></Label>
|
||||
<Separator Grid.Column="2" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}" />
|
||||
|
||||
<DockPanel Grid.Column="0" Grid.ColumnSpan="3" MinHeight="15" Margin="5" LastChildFill="True"
|
||||
Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<StackPanel DockPanel.Dock="Bottom" Visibility="{Binding ChatVisibility}">
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding UserMessage}" MinWidth="0" MaxWidth="{Binding MessageMaxWidth}" TextWrapping="Wrap" FontSize="14"/>
|
||||
<Ellipse Grid.Column="0"
|
||||
Margin="2,5,2,2" VerticalAlignment="Top" Width="32" Height="32" RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Ellipse.Fill>
|
||||
<ImageBrush ImageSource="{Binding Path=ProfilePicture, UpdateSourceTrigger=PropertyChanged}" Stretch="UniformToFill" RenderOptions.BitmapScalingMode="HighQuality" />
|
||||
</Ellipse.Fill>
|
||||
<Ellipse.Visibility>
|
||||
<MultiBinding Converter="{StaticResource UserProfilePictureVisibilityConverter}">
|
||||
<Binding Path="IsMyMessage" UpdateSourceTrigger="PropertyChanged" />
|
||||
<Binding Path="CurrentContact.IsGroupChat" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type chatController:ChatMainControl}}" UpdateSourceTrigger="PropertyChanged" />
|
||||
</MultiBinding>
|
||||
</Ellipse.Visibility>
|
||||
</Ellipse>
|
||||
|
||||
<Separator Grid.Column="0" Grid.ColumnSpan="2" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}" VerticalContentAlignment="Center" />
|
||||
<Label Content="{Binding SeparatorTimeString}" HorizontalAlignment="Center" Grid.Column="2" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}" />
|
||||
<Separator Grid.Column="3" Grid.ColumnSpan="2" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}" />
|
||||
|
||||
<DockPanel Grid.Column="1" Grid.ColumnSpan="3" MinHeight="15" Margin="5" LastChildFill="True" Visibility="{Binding IsSeparator, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Vertical">
|
||||
<Image ToolTip="Dokument öffnen" Height="{Binding ThumbnailPlaceholderHeight, UpdateSourceTrigger=PropertyChanged}" Width="150" Source="{Binding Path=Thumbnail, UpdateSourceTrigger=PropertyChanged}" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
<Image MaxWidth="300" Height="{Binding PicturePlaceholderHeight, UpdateSourceTrigger=PropertyChanged}" Source="{Binding Path=PictureSource, UpdateSourceTrigger=PropertyChanged}" x:Name="imgChatMessage" Stretch="UniformToFill" />
|
||||
<core:BindableTextBlock VerticalAlignment="Center" InlineList="{Binding MessageInlines, UpdateSourceTrigger=PropertyChanged}" MinWidth="0" MaxWidth="{Binding MessageMaxWidth}" TextWrapping="Wrap" FontSize="14" />
|
||||
</StackPanel>
|
||||
<StackPanel DockPanel.Dock="Bottom" Visibility="{Binding HyperlinkVisibility}" >
|
||||
<TextBlock>
|
||||
<Hyperlink NavigateUri="{Binding UserMessageAsUri}" RequestNavigate="Hyperlink_OnRequestNavigate" >
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding UserMessage}" MinWidth="0" MaxWidth="{Binding MessageMaxWidth}" TextWrapping="Wrap" FontSize="14"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
<DockPanel DockPanel.Dock="Bottom" Visibility="{Binding PictureVisibility}" >
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Image MaxWidth="300" Height="{Binding PicturePlaceholderHeight, UpdateSourceTrigger=PropertyChanged}" Source="{Binding PictureSource, UpdateSourceTrigger=PropertyChanged}" x:Name="imgChatMessage" Stretch="UniformToFill"/>
|
||||
<TextBlock Text="{Binding UserMessage}" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="14"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
<DockPanel DockPanel.Dock="Bottom" Visibility="{Binding PicturePlaceHolderVisibility}" >
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Image Source="pack://application:,,,/ChatController;component/Ressourcen/ClipboardDisabled.png" Stretch="None" />
|
||||
<TextBlock Text="{Binding UserMessage}" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="14" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
<DockPanel DockPanel.Dock="Bottom" Visibility="{Binding DokumentVisibility}" >
|
||||
<StackPanel Orientation="Vertical">
|
||||
<!-- Platzhalter mit Höhe 100 -->
|
||||
<Image ToolTip="Dokument öffnen" Height="{Binding ThumbnailPlaceholderHeight, UpdateSourceTrigger=PropertyChanged}" Width="150" Source="{Binding Path=Thumbnail}" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
<TextBlock Margin="2,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding UserMessage}" FontSize="14"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
<StackPanel DockPanel.Dock="Left" Margin="0,0,0,0">
|
||||
<TextBlock Text="{Binding UserTimeStringLeft}" MaxWidth="{Binding TimeStringMaxWidth}" FontSize="11" HorizontalAlignment="Left" TextAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Foreground}" />
|
||||
</StackPanel>
|
||||
@@ -347,6 +344,19 @@
|
||||
<TextBlock Text="{Binding UserTimeStringRight}" MaxWidth="{Binding TimeStringMaxWidth}" FontSize="11" HorizontalAlignment="Right" TextAlignment="Right" VerticalAlignment="Center" Foreground="{Binding Foreground}" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
<Ellipse Grid.Column="4"
|
||||
Margin="2,5,2,2" VerticalAlignment="Top" Width="32" Height="32" RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<Ellipse.Fill>
|
||||
<ImageBrush ImageSource="{Binding Path=ProfilePicture, UpdateSourceTrigger=PropertyChanged}" Stretch="UniformToFill" RenderOptions.BitmapScalingMode="HighQuality" />
|
||||
</Ellipse.Fill>
|
||||
<Ellipse.Visibility>
|
||||
<MultiBinding Converter="{StaticResource UserProfilePictureVisibilityConverter}" ConverterParameter="reverse">
|
||||
<Binding Path="IsMyMessage" UpdateSourceTrigger="PropertyChanged" />
|
||||
<Binding Path="CurrentContact.IsGroupChat" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type chatController:ChatMainControl}}" UpdateSourceTrigger="PropertyChanged" />
|
||||
</MultiBinding>
|
||||
</Ellipse.Visibility>
|
||||
</Ellipse>
|
||||
</Grid>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
@@ -429,14 +439,35 @@
|
||||
Click="EmojiButton_OnClick">
|
||||
<Image Width="24" Height="24" Source='pack://application:,,,/ChatController;component/Ressourcen/glucklicher.png' RenderOptions.BitmapScalingMode="HighQuality" HorizontalAlignment="Center" />
|
||||
</Button>
|
||||
<Button x:Name="SendButton" Height="25" Content="Senden" Padding="5,2" Margin="3" Grid.Column="3" VerticalAlignment="Bottom"
|
||||
Click="SendButton_OnClick" Background="{DynamicResource ButtonForeground}" IsEnabled="{Binding ElementName=Chatbox, Path=Text, Converter={StaticResource StringToBoolConverter}}">
|
||||
<Button.Resources>
|
||||
<Style TargetType="{x:Type Border}">
|
||||
<Setter Property="CornerRadius" Value="3"/>
|
||||
<Setter Property="Padding" Value="1" />
|
||||
<Button x:Name="SendButton" Height="25" Content="Senden" Margin="3" Grid.Column="3" VerticalAlignment="Bottom"
|
||||
Click="SendButton_OnClick" IsEnabled="{Binding ElementName=Chatbox, Path=Text, Converter={StaticResource StringToBoolConverter}}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="BorderBrush" Value="#ff5e00" />
|
||||
<Setter Property="Background" Value="#ff5e00" />
|
||||
<Setter Property="Foreground" Value="White"></Setter>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border x:Name="Border" Background="#ff5300" CornerRadius="5" Padding="5,2">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#ff9999" TargetName="Border" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="#ff3a00" TargetName="Border" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Background" Value="LightGray" TargetName="Border" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -484,21 +484,21 @@ namespace ChatController
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if(item.PictureSource == null && item.FilePath == null)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,8 +506,8 @@ namespace ChatController
|
||||
{
|
||||
//Schalte speichern unter Aus
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//prüfe ob was in dem Speicher vorhanden ist //Einfügen
|
||||
@@ -516,40 +516,40 @@ namespace ChatController
|
||||
if(dataObject != null && dataObject.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
var contextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if(dataObject != null && dataObject.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
var contextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if(dataObject != null && dataObject.GetDataPresent(DataFormats.Bitmap))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
var contextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// Prüfe, ob Dokumentation erlaubt
|
||||
if(CurrentContact.UserIdManage == null && ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if(ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
var contextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
contextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
if(ChatListBox.ContextMenu.Items.Count == 0)
|
||||
@@ -563,13 +563,13 @@ namespace ChatController
|
||||
{
|
||||
if(CurrentContact != null)
|
||||
{
|
||||
var fileToOpen = Chat.OpenFile();
|
||||
var pathToOriginalImage = Chat.OpenFile();
|
||||
|
||||
if(fileToOpen != null)
|
||||
if(pathToOriginalImage != null)
|
||||
{
|
||||
var filePath = FileUtils.ScaleImage(fileToOpen, Path.GetExtension(fileToOpen.ToUpperInvariant()), Chat.ChatDaten.MaxUploadSize);
|
||||
var pathToScaledImage = FileUtils.ScaleImage(pathToOriginalImage, Path.GetExtension(pathToOriginalImage.ToUpperInvariant()), Chat.ChatDaten.MaxUploadSize);
|
||||
|
||||
var isFileSizeTooLarge = FileUtils.CheckFileSize(filePath, Chat.ChatDaten.MaxUploadSize);
|
||||
var isFileSizeTooLarge = FileUtils.CheckFileSize(pathToScaledImage, Chat.ChatDaten.MaxUploadSize);
|
||||
|
||||
if(isFileSizeTooLarge)
|
||||
{
|
||||
@@ -577,9 +577,9 @@ namespace ChatController
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filePath))
|
||||
if (!string.IsNullOrWhiteSpace(pathToScaledImage))
|
||||
{
|
||||
_ChatMessages.AddRangeIfElementsNotIn(Chat.AddNewFile(filePath, fileToOpen, CurrentContact.GroupId, GetFirstMessage()));
|
||||
_ChatMessages.AddRangeIfElementsNotIn(Chat.AddNewFile(pathToScaledImage, pathToOriginalImage, CurrentContact.GroupId, GetFirstMessage()));
|
||||
|
||||
ChatMessages.MoveCurrentToLast();
|
||||
|
||||
@@ -587,11 +587,11 @@ namespace ChatController
|
||||
|
||||
ChatListBox.ScrollIntoView(currentChatMessage);
|
||||
|
||||
Chat.SendFileToContact(CurrentContact, filePath,fileToOpen);
|
||||
Chat.SendFileToContact(CurrentContact, pathToScaledImage,pathToOriginalImage);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filePath) && !filePath.Equals(fileToOpen) && File.Exists(filePath))
|
||||
if (!string.IsNullOrWhiteSpace(pathToScaledImage) && !pathToScaledImage.Equals(pathToOriginalImage) && File.Exists(pathToScaledImage))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
File.Delete(pathToScaledImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -606,8 +606,10 @@ namespace ChatController
|
||||
{
|
||||
if(CurrentContact != null && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
_ChatMessages.AddRangeIfElementsNotIn(Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId, GetFirstMessage()));
|
||||
var messages2Add = Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId, GetFirstMessage());
|
||||
|
||||
_ChatMessages.AddRangeIfElementsNotIn(messages2Add);
|
||||
OnPropertyChanged(nameof(ChatMessages));
|
||||
ChatMessages.MoveCurrentToLast();
|
||||
|
||||
ChatListBox.ScrollIntoView(ChatMessages.CurrentItem);
|
||||
@@ -753,7 +755,6 @@ namespace ChatController
|
||||
{
|
||||
foreach (var newContact in updatedContacts)
|
||||
{
|
||||
|
||||
if (contact.GroupId == newContact.GroupId)
|
||||
{
|
||||
// ReceivedMessage kann null sein!
|
||||
@@ -871,6 +872,17 @@ namespace ChatController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(selectedMessage.OriginalImage))
|
||||
{
|
||||
var uri = new Uri(selectedMessage.OriginalImage);
|
||||
|
||||
if(uri.IsFile)
|
||||
{
|
||||
var bitmapImage = new BitmapImage(uri);
|
||||
bitmapImage.Freeze();
|
||||
Chat.ShowPictureWindow(bitmapImage, "Test");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
StartWaitingImmediately();
|
||||
|
||||
Chat.ShowPicture(selectedMessage.OriginalImage, CurrentContact.GroupId, (imageSource, windowTitle) =>
|
||||
@@ -963,12 +975,6 @@ namespace ChatController
|
||||
});
|
||||
}
|
||||
|
||||
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void ButtonReloadGruppen_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DoSynchro();
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ChatController.Converter
|
||||
{
|
||||
public class UserProfilePictureVisibilityConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(values != null && values.Length == 2 && values[0] is bool isMyMessage && values[1] is bool isGroupChat)
|
||||
{
|
||||
if(parameter is string test && test == "reverse")
|
||||
{
|
||||
return isMyMessage && isGroupChat ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return !isMyMessage && isGroupChat ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
ChatController/Core/BindableTextBlock.cs
Normal file
31
ChatController/Core/BindableTextBlock.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace ChatController.Core
|
||||
{
|
||||
public class BindableTextBlock : TextBlock
|
||||
{
|
||||
public ObservableCollection<Inline> InlineList
|
||||
{
|
||||
get => (ObservableCollection<Inline>) GetValue(InlineListProperty);
|
||||
set => SetValue(InlineListProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged));
|
||||
|
||||
public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if(e.NewValue == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var textBlock = (BindableTextBlock)sender;
|
||||
|
||||
textBlock.Inlines.Clear();
|
||||
textBlock.Inlines.AddRange((ObservableCollection<Inline>) e.NewValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ namespace ChatController.Core
|
||||
// Key-> "group-127" oder "user-938"
|
||||
private Dictionary<string, ImageSourceCacheStorage> _ImageSourceCache = new Dictionary<string, ImageSourceCacheStorage>();
|
||||
|
||||
private Dictionary<long, ProfilePictureObject> _UserProfilePictures = new Dictionary<long, ProfilePictureObject>();
|
||||
|
||||
private static OwnChatCache _Instance;
|
||||
|
||||
private OwnChatCache() { }
|
||||
@@ -96,6 +98,41 @@ namespace ChatController.Core
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUserProfilePictureToCache(ImageSource imageSource, long userId, string uri)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
if(!_UserProfilePictures.ContainsKey(userId))
|
||||
{
|
||||
_UserProfilePictures.Add(userId, new ProfilePictureObject(userId, uri, imageSource));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ProfilePictureObject GetUserProfilePictureFromCache(long userId)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
return _UserProfilePictures.ContainsKey(userId) ? _UserProfilePictures[userId] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfilePictureObject
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
|
||||
public string Uri { get; set; }
|
||||
|
||||
public ImageSource ProfilePicture { get; set; }
|
||||
|
||||
public ProfilePictureObject(long userId, string uri, ImageSource profilePicture)
|
||||
{
|
||||
UserId = userId;
|
||||
Uri = uri;
|
||||
ProfilePicture = profilePicture;
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageSourceCacheStorage
|
||||
|
||||
@@ -3,7 +3,6 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
@@ -21,7 +20,6 @@ using System.Windows.Data;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using ChatController.Core;
|
||||
using ChatController.Extensions;
|
||||
using ChatController.LoginKlassen;
|
||||
@@ -45,7 +43,7 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
private readonly List<Contact> _Contacts = new List<Contact>();
|
||||
|
||||
public ChatDatenUebergabe ChatDaten { get; set; }
|
||||
public static ChatDatenUebergabe ChatDaten { get; set; }
|
||||
|
||||
private UserMessages _UserMessages;
|
||||
private UserMessages _AdditionalUserMessages;
|
||||
@@ -146,9 +144,6 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
client.ExecuteAsync(request, response =>
|
||||
{
|
||||
// TODO: Entfernen
|
||||
Debug.WriteLine(response.Content);
|
||||
|
||||
_UserMessages = JsonConvert.DeserializeObject<UserMessages>(response.Content);
|
||||
|
||||
if (_UserMessages.Response.HasMorePages)
|
||||
@@ -297,12 +292,9 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
client.ExecuteAsync(request, response =>
|
||||
{
|
||||
// TODO: Entfernen
|
||||
Debug.WriteLine(response.Content);
|
||||
|
||||
var messageCounter = JsonConvert.DeserializeObject<MessageCounter>(response.Content);
|
||||
|
||||
callback?.Invoke(messageCounter.MessageCount);
|
||||
callback?.Invoke(messageCounter?.MessageCount ?? 0);
|
||||
});
|
||||
}
|
||||
catch(Exception exception)
|
||||
@@ -357,25 +349,12 @@ namespace ChatController.HauptKlassen
|
||||
{
|
||||
var result = new List<ChatMessage>();
|
||||
|
||||
if(previousMessage != null)
|
||||
{
|
||||
result.Add(previousMessage);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var username = string.Empty;
|
||||
|
||||
var user = ChatDaten.LoggedInUser.Response.User;
|
||||
|
||||
if(user != null)
|
||||
{
|
||||
username = $"{user.Firstname} {user.Lastname}";
|
||||
}
|
||||
|
||||
var time = DateTime.Now;
|
||||
|
||||
result.Add(new ChatMessage(username, pMessage, time, true, pGroupId, 0, 0));
|
||||
var chatMessage = new ChatMessage(pGroupId, 0, ChatDaten.LoggedInUser.Response.User.UserName, pMessage, time, true, 0, null, null, null, null, null, ChatMessageType.Message, ChatDaten.LoggedInUser.Response.User.Oid);
|
||||
result.Add(chatMessage);
|
||||
|
||||
return AddSeparators(result);
|
||||
}
|
||||
@@ -526,35 +505,31 @@ namespace ChatController.HauptKlassen
|
||||
}
|
||||
}
|
||||
|
||||
public List<ChatMessage> AddNewFile(string pFile, string pOriginalFilePath, long pGroupId, ChatMessage previousMessage)
|
||||
public List<ChatMessage> AddNewFile(string pathToFile, string originalFilePath, long groupId, ChatMessage previousMessage)
|
||||
{
|
||||
var result = new List<ChatMessage>();
|
||||
|
||||
if (previousMessage != null)
|
||||
{
|
||||
result.Add(previousMessage);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(pFile) || string.IsNullOrEmpty(pOriginalFilePath))
|
||||
if (string.IsNullOrEmpty(pathToFile) || string.IsNullOrEmpty(originalFilePath))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var message = _UserMessages.Response.Messages.Last();
|
||||
var latestMessage = _UserMessages.Response.Messages.Last();
|
||||
|
||||
var sendTime = DateTime.Now;
|
||||
|
||||
if (Constants.ImageFileExtensions.Contains(Path.GetExtension(pFile).ToUpperInvariant()))
|
||||
if (Constants.ImageFileExtensions.Contains(Path.GetExtension(pathToFile).ToUpperInvariant()))
|
||||
{
|
||||
byte[] file;
|
||||
using (Stream reader = File.OpenRead(pFile))
|
||||
using (Stream reader = File.OpenRead(pathToFile))
|
||||
{
|
||||
file = Utils.ReadFully(reader);
|
||||
}
|
||||
|
||||
var memoryStream = new MemoryStream(file);
|
||||
using(var memoryStream = new MemoryStream(file))
|
||||
{
|
||||
var image = Image.FromStream(memoryStream);
|
||||
|
||||
using (var bitmap = new Bitmap(image))
|
||||
@@ -587,20 +562,18 @@ namespace ChatController.HauptKlassen
|
||||
bitmapImage.EndInit();
|
||||
bitmapImage.Freeze();
|
||||
|
||||
var filename = Path.GetFileName(pOriginalFilePath).ToLower();
|
||||
|
||||
filename = filename.Replace(".bmp", ".jpg");
|
||||
|
||||
result.Add(new ChatMessage(message.User_Name, filename, sendTime, true, bitmapImage, pFile, filename, pGroupId, file.LongLength, message.Id));
|
||||
var chatMessage = new ChatMessage(groupId, 0, ChatDaten.LoggedInUser.Response.User.UserName, Path.GetFileName(pathToFile), sendTime, true, memoryStream.Length, null, pathToFile, Path.GetFileName(pathToFile), null, bitmapImage, ChatMessageType.Image, ChatDaten.LoggedInUser.Response.User.Oid);
|
||||
result.Add(chatMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memoryStream.Dispose();
|
||||
memoryStream.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFile), sendTime, message.Smaller_Image, true, pFile, pGroupId, 0, message.Id));
|
||||
var linkToThumbnail = $"{ChatDaten.ServerUrl}/document.png";
|
||||
|
||||
var chatMessage = new ChatMessage(groupId, 0, ChatDaten.LoggedInUser.Response.User.UserName, Path.GetFileName(pathToFile), sendTime, true, 0, pathToFile, null, null, linkToThumbnail, null, ChatMessageType.Document, ChatDaten.LoggedInUser.Response.User.Oid);
|
||||
result.Add(chatMessage);
|
||||
}
|
||||
|
||||
return AddSeparators(result);
|
||||
@@ -613,11 +586,11 @@ namespace ChatController.HauptKlassen
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ChatMessage> AddMediumContextDerNachrichtView(byte[] pFile, string pFileName, long pGroupId, ChatMessage previousMessage)
|
||||
public List<ChatMessage> AddFileToMessage(byte[] file, string fileName, long groupId, ChatMessage previousMessage)
|
||||
{
|
||||
var result = new List<ChatMessage>();
|
||||
|
||||
if (string.IsNullOrEmpty(pFileName))
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -631,10 +604,10 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
var sendtime = DateTime.Now;
|
||||
|
||||
if (Constants.ImageFileExtensions.Contains(Path.GetExtension(pFileName).ToUpperInvariant()))
|
||||
if (Constants.ImageFileExtensions.Contains(Path.GetExtension(fileName).ToUpperInvariant()))
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
var memoryStream = new MemoryStream(pFile);
|
||||
var memoryStream = new MemoryStream(file);
|
||||
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.StreamSource = memoryStream;
|
||||
@@ -644,11 +617,16 @@ namespace ChatController.HauptKlassen
|
||||
memoryStream.Close();
|
||||
ImageSource logo = bitmapImage;
|
||||
|
||||
result.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, true, logo, pFileName, Path.GetFileName(pFileName), pGroupId, memoryStream.Length, message.Id));
|
||||
// Mit Logo
|
||||
var chatMessage = new ChatMessage(groupId, 0, ChatDaten.LoggedInUser.Response.User.UserName, Path.GetFileName(fileName), sendtime, true, memoryStream.Length, null, fileName, Path.GetFileName(fileName), null, logo, ChatMessageType.Image, ChatDaten.LoggedInUser.Response.User.Oid);
|
||||
|
||||
result.Add(chatMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, message.Smaller_Image, true, pFileName, pGroupId, 0, message.Id));
|
||||
// Dokument
|
||||
var chatMessage = new ChatMessage(groupId, 0, ChatDaten.LoggedInUser.Response.User.UserName, Path.GetFileName(fileName), sendtime, true, 0, fileName, null, null, message.Smaller_Image, null, ChatMessageType.Document, ChatDaten.LoggedInUser.Response.User.Oid);
|
||||
result.Add(chatMessage);
|
||||
}
|
||||
|
||||
return AddSeparators(result);
|
||||
@@ -847,7 +825,7 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
var mediaFile = File.ReadAllBytes(fileList[0]);
|
||||
|
||||
pChatMainControl.AddMessages(AddMediumContextDerNachrichtView(mediaFile, fileName, pGroupOid, pChatMainControl.GetFirstMessage()));
|
||||
pChatMainControl.AddMessages(AddFileToMessage(mediaFile, fileName, pGroupOid, pChatMainControl.GetFirstMessage()));
|
||||
|
||||
CollectionViewSource.GetDefaultView(pChatMainControl.ChatListBox.ItemsSource).Refresh();
|
||||
|
||||
@@ -886,7 +864,7 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
Image image = bitmap;
|
||||
|
||||
pChatMainControl.AddMessages(AddMediumContextDerNachrichtView(Utils.ImageToByteArray(image), imageName, pGroupOid, pChatMainControl.GetFirstMessage()));
|
||||
pChatMainControl.AddMessages(AddFileToMessage(Utils.ImageToByteArray(image), imageName, pGroupOid, pChatMainControl.GetFirstMessage()));
|
||||
|
||||
CollectionViewSource.GetDefaultView(pChatMainControl.ChatListBox.ItemsSource).Refresh();
|
||||
|
||||
@@ -1095,6 +1073,8 @@ namespace ChatController.HauptKlassen
|
||||
|
||||
var key = $"group-{groupInput.Oid}";
|
||||
|
||||
|
||||
|
||||
contacts.Add(new Contact(
|
||||
groupInput.Name,
|
||||
groupInput.LastMessage,
|
||||
@@ -1106,7 +1086,7 @@ namespace ChatController.HauptKlassen
|
||||
groupInput.CanWrite,
|
||||
groupInput.AccentColor,
|
||||
groupInput.Avatar,
|
||||
key));
|
||||
key, groupInput.Users.ToDictionary(user => user.Oid, user => user.Picture)));
|
||||
|
||||
if(pShouldUpdateLastTimeStamp)
|
||||
{
|
||||
@@ -1129,11 +1109,6 @@ namespace ChatController.HauptKlassen
|
||||
{
|
||||
var result = new List<ChatMessage>();
|
||||
|
||||
if(previousMessage != null)
|
||||
{
|
||||
result.Add(previousMessage);
|
||||
}
|
||||
|
||||
foreach (var message in pMessages)
|
||||
{
|
||||
var time = DateTime.Parse(message.Timestamp.Date);
|
||||
@@ -1145,16 +1120,16 @@ namespace ChatController.HauptKlassen
|
||||
if (!string.IsNullOrEmpty(message.File))
|
||||
{
|
||||
var message2Add = Constants.ImageFileExtensions.Contains(Path.GetExtension(message.File).ToUpperInvariant()) ? //SmallerImage ist null
|
||||
new ChatMessage(message.User_Name, messageText, formattedTime, isLoggedInUsersMessage, message.Smaller_Image, message.File, message.Original_Filename, message.GroupId, message.FileSize, message.Id) :
|
||||
new ChatMessage(message.User_Name, messageText, formattedTime, message.Smaller_Image, isLoggedInUsersMessage, message.File, message.GroupId, message.FileSize, message.Id);
|
||||
new ChatMessage(message.GroupId, message.Id, message.User_Name, messageText, formattedTime, isLoggedInUsersMessage, message.FileSize, message.Smaller_Image, message.File, message.Original_Filename, null, null, ChatMessageType.Image, message.UserId) :
|
||||
new ChatMessage(message.GroupId, message.Id, message.User_Name, messageText, formattedTime, isLoggedInUsersMessage, 0, message.File, null, null, message.Smaller_Image, null, ChatMessageType.Document, message.UserId);
|
||||
|
||||
result.AddIfNotIn(message2Add);
|
||||
}
|
||||
else
|
||||
{
|
||||
var message2Add2 = new ChatMessage(message.User_Name, message.Text, formattedTime, isLoggedInUsersMessage, message.GroupId, message.FileSize, message.Id);
|
||||
var chatMessage = new ChatMessage(message.GroupId, message.Id, message.User_Name, message.Text, formattedTime, isLoggedInUsersMessage, message.FileSize, null, null, null, null, null, ChatMessageType.Message, message.UserId);
|
||||
|
||||
result.AddIfNotIn(message2Add2);
|
||||
result.AddIfNotIn(chatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1174,7 +1149,7 @@ namespace ChatController.HauptKlassen
|
||||
{
|
||||
if(message.SendTime.Date != previousMessage.SendTime.Date)
|
||||
{
|
||||
var separatorMessage = new ChatMessage(null, null, message.SendTime.Date, false, 0, 0, -1) { IsSeparator = true };
|
||||
var separatorMessage = new ChatMessage(0, -1, null, null, message.SendTime.Date, false, 0, null, null, null, null, null, ChatMessageType.Separator, 0);
|
||||
|
||||
separators.Add(separatorMessage);
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.Background>
|
||||
<ImageBrush>
|
||||
@@ -48,12 +51,30 @@
|
||||
<PasswordBox FontSize="15" x:Name="PasswordBox" Grid.Column="1" Grid.Row="3" Margin="3" VerticalContentAlignment="Center" />
|
||||
|
||||
<Button FontSize="15" Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="5" VerticalContentAlignment="Center" Click="AnmeldenButton_OnClick" Content="Anmelden" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" Width="100" Height="40" Background="#ff5e00" HorizontalContentAlignment="Center" >
|
||||
<Button.Resources>
|
||||
<Style TargetType="{x:Type Border}">
|
||||
<Setter Property="CornerRadius" Value="5"/>
|
||||
<Setter Property="Padding" Value="1" />
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="BorderBrush" Value="#ff5e00" />
|
||||
<Setter Property="Background" Value="#ff5e00" />
|
||||
<Setter Property="Foreground" Value="White"></Setter>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border x:Name="Border" Background="#ff5300" CornerRadius="5" Padding="1">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#ff9999" TargetName="Border" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="#ff3a00" TargetName="Border" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Resources>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -92,10 +92,20 @@ namespace ChatController
|
||||
LeseDateiFallsVorhanden();
|
||||
|
||||
#if DEBUG
|
||||
//_Kundennummer = "4368658436";
|
||||
//_ChatCode = "ZMCKb-BckTt";
|
||||
//_Benutzername = "muellerp";
|
||||
//Password = "F5aTk9Co47JFJCWB2Z7Y";
|
||||
|
||||
//_Kundennummer = "9988776655";
|
||||
//_ChatCode = "K2UPV-qrirb";
|
||||
//_Benutzername = "lyndon";
|
||||
//Password = "lyndon2travemünde";
|
||||
|
||||
_Kundennummer = "4368658436";
|
||||
_ChatCode = "ZMCKb-BckTt";
|
||||
_Benutzername = "muellerp";
|
||||
Password = "F5aTk9Co47JFJCWB2Z7Y";
|
||||
_ChatCode = "B7x0b-FhhJA";
|
||||
_Benutzername = "jettenl";
|
||||
Password = "n8-yR+3Q=6nX#";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -53,5 +53,25 @@ namespace ChatController.LoginKlassen
|
||||
public bool IsEmployee { get; set; }
|
||||
|
||||
public string Token { get; set; }
|
||||
|
||||
public string UserName
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = string.Empty;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Firstname))
|
||||
{
|
||||
result = $"{Firstname} ";
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Lastname))
|
||||
{
|
||||
result += Lastname;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
@@ -7,7 +9,9 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
@@ -38,9 +42,16 @@ namespace ChatController.Utilities
|
||||
return;
|
||||
}
|
||||
|
||||
var url = pathToProfilePicture;
|
||||
DownloadImage(pathToProfilePicture, imageSource =>
|
||||
{
|
||||
cache.AddProfilePictureToCache(key, imageSource, pathToProfilePicture);
|
||||
callback?.Invoke(imageSource);
|
||||
});
|
||||
}
|
||||
|
||||
var client = new RestClient(url);
|
||||
private static void DownloadImage(string uri, Action<ImageSource> callback)
|
||||
{
|
||||
var client = new RestClient(uri);
|
||||
var request = new RestRequest
|
||||
{
|
||||
ResponseWriter = stream =>
|
||||
@@ -58,8 +69,6 @@ namespace ChatController.Utilities
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze();
|
||||
|
||||
cache.AddProfilePictureToCache(key, bitmap, pathToProfilePicture);
|
||||
|
||||
callback?.Invoke(bitmap);
|
||||
}
|
||||
};
|
||||
@@ -70,6 +79,33 @@ namespace ChatController.Utilities
|
||||
client.ExecuteAsync(request, response => { /*Das übernimmt der ResponseWriter von oben*/ });
|
||||
}
|
||||
|
||||
public static void DownloadUserProfilePictures(Dictionary<long, string> userId2Uris)
|
||||
{
|
||||
var cache = OwnChatCache.GetInstance();
|
||||
|
||||
foreach(var id2Uri in userId2Uris)
|
||||
{
|
||||
var userProfilePicture = cache.GetUserProfilePictureFromCache(id2Uri.Key);
|
||||
|
||||
if(userProfilePicture == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = id2Uri.Value;
|
||||
|
||||
DownloadImage(uri, profilePicture =>
|
||||
{
|
||||
cache.AddUserProfilePictureToCache(profilePicture, id2Uri.Key, uri);
|
||||
});
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DownloadImageAsync(string uri, string key, CacheCategory cacheCategory, Action<ImageSource> callback)
|
||||
{
|
||||
if(string.IsNullOrEmpty(uri))
|
||||
@@ -88,35 +124,11 @@ namespace ChatController.Utilities
|
||||
return;
|
||||
}
|
||||
|
||||
var url = uri;
|
||||
var client = new RestClient(url);
|
||||
var request = new RestRequest
|
||||
DownloadImage(uri, imageSource =>
|
||||
{
|
||||
ResponseWriter = stream =>
|
||||
{
|
||||
var bitmap = new BitmapImage();
|
||||
|
||||
var localStream = new MemoryStream();
|
||||
|
||||
stream.CopyTo(localStream);
|
||||
|
||||
localStream.Position = 0;
|
||||
|
||||
bitmap.BeginInit();
|
||||
bitmap.StreamSource = localStream;
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze();
|
||||
|
||||
cache.AddImageToCache(key, bitmap, cacheCategory, uri);
|
||||
|
||||
callback?.Invoke(bitmap);
|
||||
}
|
||||
};
|
||||
|
||||
request.AddHeader(Constants.Token, AuthToken);
|
||||
request.AddHeader(Constants.CustomerId, Tenant);
|
||||
|
||||
client.ExecuteAsync(request, response => { });
|
||||
cache.AddImageToCache(key, imageSource, cacheCategory, uri);
|
||||
callback?.Invoke(imageSource);
|
||||
});
|
||||
}
|
||||
|
||||
private static ImageSource GetDefaultImageSource(bool pIsGroup, bool pIsEmployee)
|
||||
@@ -438,5 +450,82 @@ namespace ChatController.Utilities
|
||||
|
||||
return 100;
|
||||
}
|
||||
|
||||
private static readonly Regex _UrlRegex = new Regex(@"(?#Protocol)(http(?:s?)\:(\/\/|\\\\)|(w){3}(2|3)?\.{1})(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static ObservableCollection<Inline> ConvertLinksToHyperlinks(string messageText)
|
||||
{
|
||||
var result = new ObservableCollection<Inline>();
|
||||
|
||||
if(messageText == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var guidString = Guid.NewGuid().ToString();
|
||||
var replacementString = Guid.NewGuid().ToString();
|
||||
|
||||
var matches = _UrlRegex.Matches(messageText);
|
||||
|
||||
var index2Link = new Dictionary<int, Hyperlink>();
|
||||
|
||||
for(var i = 0; i < matches.Count; i++)
|
||||
{
|
||||
var link = matches[i].Value;
|
||||
|
||||
if(!link.Contains("http"))
|
||||
{
|
||||
link = $"http://{link}";
|
||||
}
|
||||
|
||||
var hyperlink = new Hyperlink(new Run(link))
|
||||
{
|
||||
NavigateUri = new Uri(link, UriKind.Absolute)
|
||||
};
|
||||
|
||||
hyperlink.RequestNavigate += (s, e) =>
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
index2Link[i] = hyperlink;
|
||||
}
|
||||
|
||||
var splitMessage = _UrlRegex.Replace(messageText, replacementString + guidString).Split(new[] {guidString}, StringSplitOptions.None);
|
||||
|
||||
var linkIndex = 0;
|
||||
foreach(var text in splitMessage)
|
||||
{
|
||||
if(text.Equals(replacementString))
|
||||
{
|
||||
result.Add(index2Link[linkIndex]);
|
||||
linkIndex++;
|
||||
}
|
||||
else if(text.StartsWith(replacementString) || text.EndsWith(replacementString))
|
||||
{
|
||||
var splitLine = text.Split(new[] { replacementString }, StringSplitOptions.None);
|
||||
|
||||
foreach(var partLine in splitLine)
|
||||
{
|
||||
if(string.Empty.Equals(partLine))
|
||||
{
|
||||
result.Add(index2Link[linkIndex]);
|
||||
linkIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new Run(partLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new Run(text));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user