Skip to content

Commit

Permalink
#942 完善消息页
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Jan 12, 2025
1 parent 7f83ada commit e9884f1
Showing 13 changed files with 555 additions and 107 deletions.
8 changes: 8 additions & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
@@ -139,9 +139,13 @@
<Compile Include="Controls\AttentionButton.xaml.cs">
<DependentUpon>AttentionButton.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\ChatMessages\ChatMessageTemplate.xaml.cs">
<DependentUpon>ChatMessageTemplate.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Common\PieControl.xaml.cs">
<DependentUpon>PieControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\DataTemplateSelectors\ChatMessageDataTemplateSelector.cs" />
<Compile Include="Controls\DataTemplateSelectors\UserDynamicItemV2DataTemplateSelector.cs" />
<Compile Include="Controls\Dynamic\DynamicItemV2Control.xaml.cs">
<DependentUpon>DynamicItemV2Control.xaml</DependentUpon>
@@ -1205,6 +1209,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\ChatMessages\ChatMessageTemplate.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\CommentControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
175 changes: 175 additions & 0 deletions src/BiliLite.UWP/Controls/ChatMessages/ChatMessageTemplate.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<ResourceDictionary
x:Class="BiliLite.Controls.ChatMessages.ChatMessageTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dataTemplateSelectors="using:BiliLite.Controls.DataTemplateSelectors"
xmlns:msg="using:BiliLite.Models.Common.Msg"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
<dataTemplateSelectors:ChatMessageDataTemplateSelector x:Key="ChatMessageDataTemplateSelector"
NotificationTemplate="{StaticResource ChatMessageNotification}"
ImageTemplate="{StaticResource ChatMessageImage}"
TextTemplate="{StaticResource ChatMessageText}"
OtherTemplate="{StaticResource ChatMessageOther}">
</dataTemplateSelectors:ChatMessageDataTemplateSelector>

<DataTemplate x:Key="ChatMessageText" x:DataType="msg:ChatMessage">
<Grid Margin="0 8">
<Grid Visibility="{Binding IsSelf,Converter={StaticResource display}}" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse Width="40" Height="40" Margin="10,0,10,0"
VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>

<!--消息气泡-->
<Border Background="{ThemeResource DefaultCardColor}"
Grid.Column="1"
CornerRadius="10" Padding="10" >
<StackPanel>
<TextBlock Text="{Binding TextContent.Content}" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</Grid>

<Grid Visibility="{Binding IsSelf}" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Ellipse Grid.Column="1" Width="40" Height="40" Margin="10,0,10,0"
VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>

<!--消息气泡-->
<Border Background="{ThemeResource DefaultCardColor}"
CornerRadius="10" Padding="10" >
<StackPanel HorizontalAlignment="Right">
<TextBlock Text="{Binding TextContent.Content}" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</Grid>
</Grid>
</DataTemplate>

<DataTemplate x:Key="ChatMessageImage" x:DataType="msg:ChatMessage">
<Grid Margin="0 8">
<Grid Visibility="{Binding IsSelf,Converter={StaticResource display}}" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse Width="40" Height="40" Margin="10,0,10,0"
VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>

<!--消息气泡-->
<Border Background="{ThemeResource DefaultCardColor}"
Grid.Column="1"
CornerRadius="10" Padding="10" >
<StackPanel>
<HyperlinkButton Padding="0"
Click="OpenImageBtn_OnClick">
<controls:ImageEx
IsCacheEnabled="True"
PlaceholderSource="ms-appx:///Assets/Thumbnails/Placeholde.png"
MaxHeight="150"
MaxWidth="300"
Source="{Binding ImageContent.Url}" ></controls:ImageEx>
</HyperlinkButton>
</StackPanel>
</Border>
</Grid>

<Grid Visibility="{Binding IsSelf}" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Ellipse Grid.Column="1" Width="40" Height="40" Margin="10,0,10,0"
VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>

<!--消息气泡-->
<Border Background="{ThemeResource DefaultCardColor}"
CornerRadius="10" Padding="10" >
<StackPanel HorizontalAlignment="Right">
<HyperlinkButton Padding="0"
Click="OpenImageBtn_OnClick">
<controls:ImageEx
IsCacheEnabled="True"
PlaceholderSource="ms-appx:///Assets/Thumbnails/Placeholde.png"
MaxHeight="150"
MaxWidth="300"
Source="{Binding ImageContent.Url}" ></controls:ImageEx>
</HyperlinkButton>
</StackPanel>
</Border>
</Grid>
</Grid>
</DataTemplate>

<DataTemplate x:Key="ChatMessageNotification" x:DataType="msg:ChatMessage">
<Grid Background="{ThemeResource DefaultCardColor}" Padding="16" CornerRadius="8" BorderThickness="1" BorderBrush="LightGray"
MaxWidth="480"
Margin="0 16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<!-- 标题 -->
<TextBlock x:Name="TitleText" Text="{Binding NotificationContent.Title}" FontSize="18" FontWeight="Bold" Grid.Row="0" Margin="0,0,0,8"/>

<!-- 详情文本 -->
<TextBlock x:Name="DetailText" Text="{Binding NotificationContent.Text}" FontSize="14" Grid.Row="1" Margin="0,0,0,16"
TextWrapping="Wrap"/>

<!-- 信息表格 -->
<ItemsControl x:Name="InfoItemsControl" Grid.Row="2" Margin="0,0,0,16" ItemsSource="{Binding NotificationContent.Modules}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" FontSize="14" Margin="0,0,8,4"/>
<TextBlock Text="{Binding Detail}" FontSize="14" Grid.Column="1" Margin="0,0,0,4"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<!-- 操作按钮 -->
<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Right">
<Button Content="{Binding NotificationContent.JumpText}" Visibility="{Binding NotificationContent.ShowJumpBtn}" Click="NotificationMsgAction_OnClick" />
<Button Content="{Binding NotificationContent.JumpText2}" Visibility="{Binding NotificationContent.ShowJumpBtn2}" Click="NotificationMsgAction_OnClick" />
<Button Content="{Binding NotificationContent.JumpText3}" Visibility="{Binding NotificationContent.ShowJumpBtn3}" Click="NotificationMsgAction_OnClick" />
</StackPanel>
</Grid>
</DataTemplate>

<DataTemplate x:Key="ChatMessageOther">
<Border BorderThickness="1" HorizontalAlignment="Stretch" BorderBrush="#C8E5E9EF" CornerRadius="4">
<StackPanel Margin="12">
<TextBlock TextWrapping="Wrap">暂不支持的消息格式</TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ResourceDictionary>
18 changes: 18 additions & 0 deletions src/BiliLite.UWP/Controls/ChatMessages/ChatMessageTemplate.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Windows.UI.Xaml;

namespace BiliLite.Controls.ChatMessages
{
public partial class ChatMessageTemplate : ResourceDictionary
{
private void NotificationMsgAction_OnClick(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}

private void OpenImageBtn_OnClick(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;
using BiliLite.Models.Common.Msg;

namespace BiliLite.Controls.DataTemplateSelectors
{
public class ChatMessageDataTemplateSelector : DataTemplateSelector
{
private static readonly Dictionary<ChatMsgType, Func<ChatMessageDataTemplateSelector, ChatMessage, DataTemplate>> _chatMsgTypeTemplateSelectFuncs;

static ChatMessageDataTemplateSelector()
{
_chatMsgTypeTemplateSelectFuncs =
new Dictionary<ChatMsgType, Func<ChatMessageDataTemplateSelector,
ChatMessage, DataTemplate>>()
{
{ ChatMsgType.Text, (selector, chatMessage) => selector.TextTemplate },
{ ChatMsgType.Image, (selector, chatMessage) => selector.ImageTemplate },
{ ChatMsgType.CustomEmote, (selector, chatMessage) => selector.ImageTemplate },
{ ChatMsgType.Notification, (selector, chatMessage) => selector.NotificationTemplate },
};
}

public DataTemplate TextTemplate { get; set; }

public DataTemplate ImageTemplate { get; set; }

public DataTemplate NotificationTemplate { get; set; }

public DataTemplate OtherTemplate { get; set; }

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
var chatMessage = item as ChatMessage;
var success = _chatMsgTypeTemplateSelectFuncs.TryGetValue(chatMessage.MsgType, out var selectFunc);
return success ? selectFunc(this, chatMessage) : OtherTemplate;
}
}
}
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Extensions/MapperExtensions.cs
Original file line number Diff line number Diff line change
@@ -208,6 +208,9 @@ public static IServiceCollection AddMapper(this IServiceCollection services)
.ForMember(dest => dest.Type,
opt => opt.MapFrom(src =>
src.SessionType))
.ForMember(dest => dest.Time,
opt => opt.MapFrom(src =>
src.SessionTs))
.ForMember(dest => dest.FromUserId,
opt => opt.MapFrom(src =>
src.LastMsg.SenderUid));
@@ -217,6 +220,9 @@ public static IServiceCollection AddMapper(this IServiceCollection services)
.ForMember(dest => dest.UserId,
opt => opt.MapFrom(src =>
src.SenderUid))
.ForMember(dest => dest.ChatMessageId,
opt => opt.MapFrom(src =>
src.MsgSeqno))
.ForMember(dest => dest.ContentStr,
opt => opt.MapFrom(src =>
src.Content));
23 changes: 21 additions & 2 deletions src/BiliLite.UWP/Models/Common/Msg/ChatMessage.cs
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ public class ChatMessage
private string m_contentStr;
private IChatMsgContent m_chatMsgContent;

public string ChatMessageId { get; set; }

public string ContentStr
{
get => m_contentStr;
@@ -27,6 +29,21 @@ public string ContentStr
DisplayText = msgContent.Content;
break;
}
case ChatMsgType.Image:
case ChatMsgType.CustomEmote:
{
var msgContent = JsonConvert.DeserializeObject<ImageChatMessageContent>(m_contentStr);
m_chatMsgContent = msgContent;
DisplayText = "[图片]";
break;
}
case ChatMsgType.Notification:
{
var msgContent = JsonConvert.DeserializeObject<NotificationChatMessageContent>(m_contentStr);
m_chatMsgContent = msgContent;
DisplayText = msgContent.Title;
break;
}
default:
{
var msgContent = new TextChatMessageContent()
@@ -50,6 +67,10 @@ public string ContentStr

public TextChatMessageContent TextContent => m_chatMsgContent as TextChatMessageContent;

public NotificationChatMessageContent NotificationContent => m_chatMsgContent as NotificationChatMessageContent;

public ImageChatMessageContent ImageContent => m_chatMsgContent as ImageChatMessageContent;

public string UserId { get; set; }

public string Face { get; set; }
@@ -58,8 +79,6 @@ public string ContentStr

public bool IsSelf { get; set; }

public int IsSelfColumn => IsSelf ? 1 : 0;

public ChatMsgType MsgType { get; set; }

public string DisplayText { get; set; }
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ public class NotificationChatMessageContent : IChatMsgContent
[JsonProperty("jump_text")]
public string JumpText { get; set; }

public bool ShowJumpBtn => !string.IsNullOrEmpty(JumpText);

/// <summary>
/// 按钮1跳转链接。若按钮1不存在则为空。
/// </summary>
@@ -42,6 +44,8 @@ public class NotificationChatMessageContent : IChatMsgContent
[JsonProperty("jump_text_2")]
public string JumpText2 { get; set; }

public bool ShowJumpBtn2 => !string.IsNullOrEmpty(JumpText2);

/// <summary>
/// 按钮2跳转链接。若按钮2不存在则为空。
/// </summary>
@@ -54,6 +58,8 @@ public class NotificationChatMessageContent : IChatMsgContent
[JsonProperty("jump_text_3")]
public string JumpText3 { get; set; }

public bool ShowJumpBtn3 => !string.IsNullOrEmpty(JumpText3);

/// <summary>
/// 按钮3跳转链接。若按钮3不存在则为空。
/// </summary>
Loading

0 comments on commit e9884f1

Please sign in to comment.