Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit 845c172

Browse files
authored
Merge pull request #601 from UWPCommunity/rewrite/main
Removed AnyCPU from Quarrel.Markdown
2 parents 03e6395 + de3c4f9 commit 845c172

29 files changed

+251
-118
lines changed

src/Libs/Quarrel.Markdown/Quarrel.Markdown.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
77
<ProjectGuid>{E4B6DFB8-B9B7-4EE7-9F86-AFDDC221FFB3}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>

src/Libs/Quarrel.Markdown/Rendering/MessageRenderer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Threading.Tasks;
8+
using Windows.Foundation;
79
using Windows.UI;
10+
using Windows.UI.Core;
811
using Windows.UI.Text;
912
using Windows.UI.Xaml;
1013
using Windows.UI.Xaml.Controls;
1114
using Windows.UI.Xaml.Documents;
1215
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Shapes;
1317

1418
namespace Quarrel.Markdown
1519
{
@@ -18,8 +22,6 @@ public sealed partial class MessageRenderer : Control
1822
{
1923
private const string RichBlockPartName = "RichBlock";
2024

21-
private const bool IsTextSelectable = false;
22-
2325
private RichTextBlock? _richBlock;
2426

2527
public MessageRenderer()
@@ -150,7 +152,6 @@ private void RenderMarkdown(IList<ASTRoot> tree)
150152
FontWeight = container.FontWeight,
151153
FontStretch = container.FontStretch,
152154
TextDecorations = container.TextDecorations,
153-
Style = InlineCodeStyle,
154155
};
155156
}
156157
break;
@@ -179,7 +180,6 @@ private void RenderMarkdown(IList<ASTRoot> tree)
179180
FontSize = container.FontSize,
180181
FontStretch = container.FontStretch,
181182
TextDecorations = container.TextDecorations,
182-
IsTextSelectionEnabled = IsTextSelectable,
183183
Text = roleMention.RoleID
184184
}
185185
};
@@ -210,7 +210,6 @@ private void RenderMarkdown(IList<ASTRoot> tree)
210210
FontSize = container.FontSize,
211211
FontStretch = container.FontStretch,
212212
TextDecorations = container.TextDecorations,
213-
IsTextSelectionEnabled = IsTextSelectable,
214213
Text = globalMention.Target,
215214
}
216215
};
@@ -231,7 +230,6 @@ private void RenderMarkdown(IList<ASTRoot> tree)
231230
FontSize = container.FontSize,
232231
FontStretch = container.FontStretch,
233232
TextDecorations = container.TextDecorations,
234-
IsTextSelectionEnabled = IsTextSelectable,
235233
Text = channel.ChannelID
236234
}
237235
};

src/Libs/Quarrel.Markdown/Themes/Generic.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Setter Property="Padding" Value="8,0,0,0"/>
1111
<Setter Property="BorderBrush" Value="DarkGray"/>
1212
<Setter Property="BorderThickness" Value="2,0,0,0"/>
13+
<Setter Property="IsTextSelectionEnabled" Value="False"/>
1314
<Setter Property="Template">
1415
<Setter.Value>
1516
<ControlTemplate TargetType="local:BlockQuoteElement">
@@ -100,6 +101,7 @@
100101

101102
<Style TargetType="local:TimestampElement">
102103
<Setter Property="Background" Value="DarkGray"/>
104+
<Setter Property="IsTextSelectionEnabled" Value="False"/>
103105
<Setter Property="Template">
104106
<Setter.Value>
105107
<ControlTemplate TargetType="local:TimestampElement">
@@ -127,6 +129,7 @@
127129

128130
<Style TargetType="local:EmojiElement">
129131
<Setter Property="Height" Value="22"/>
132+
<Setter Property="IsTextSelectionEnabled" Value="False"/>
130133
<Setter Property="Template">
131134
<Setter.Value>
132135
<ControlTemplate TargetType="local:EmojiElement">
@@ -142,6 +145,7 @@
142145

143146
<Style TargetType="local:SpoilerElement">
144147
<Setter Property="Background" Value="Red"/>
148+
<Setter Property="IsTextSelectionEnabled" Value="False"/>
145149
<Setter Property="Template">
146150
<Setter.Value>
147151
<ControlTemplate TargetType="local:SpoilerElement">
@@ -172,6 +176,7 @@
172176
<Setter Property="Foreground" Value="{ThemeResource SystemColorControlAccentBrush}"/>
173177
<Setter Property="Padding" Value="0"/>
174178
<Setter Property="FontWeight" Value="SemiBold"/>
179+
<Setter Property="IsTextSelectionEnabled" Value="False"/>
175180
<Setter Property="Template">
176181
<Setter.Value>
177182
<ControlTemplate TargetType="local:UserMentionElement">
@@ -233,7 +238,7 @@
233238
<Rectangle x:Name="bg" Fill="{TemplateBinding Background}"
234239
RadiusX="2" RadiusY="2" Opacity=".2"
235240
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
236-
241+
237242
<TextBlock x:Name="ContentPresenter"
238243
Text="{TemplateBinding Content}"
239244
TextWrapping="Wrap"

src/Quarrel.Client/Models/Base/Interfaces/IUpdatableItem.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Quarrel.Client/Models/Channels/Abstract/Channel.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Quarrel.Client.Models.Channels.Abstract
1313
/// <summary>
1414
/// A base class for a channel managed by a <see cref="QuarrelClient"/>.
1515
/// </summary>
16-
public abstract class Channel : SnowflakeItem, IChannel, IUpdatableItem
16+
public abstract class Channel : SnowflakeItem, IChannel
1717
{
1818
internal Channel(JsonChannel restChannel, QuarrelClient context) :
1919
base(context)
@@ -28,15 +28,11 @@ internal Channel(JsonChannel restChannel, QuarrelClient context) :
2828

2929
/// <inheritdoc/>
3030
public ChannelType Type { get; private set; }
31-
32-
/// <inheritdoc/>
33-
public event EventHandler? ItemUpdated;
3431

3532
internal virtual void UpdateFromJsonChannel(JsonChannel jsonChannel)
3633
{
3734
Guard.IsEqualTo(Id, jsonChannel.Id, nameof(Id));
3835
PrivateUpdateFromJsonChannel(jsonChannel);
39-
InvokeUpdate();
4036
}
4137

4238
internal virtual void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel)
@@ -69,17 +65,5 @@ internal virtual JsonChannel ToJsonChannel()
6965
Type = Type,
7066
};
7167
}
72-
73-
/// <summary>
74-
/// Invokes item updated.
75-
/// </summary>
76-
protected void UpdateItem<T>(ref T field, T value)
77-
{
78-
field = value;
79-
InvokeUpdate();
80-
}
81-
82-
private void InvokeUpdate()
83-
=> ItemUpdated?.Invoke(this, EventArgs.Empty);
8468
}
8569
}

src/Quarrel.Client/Models/Channels/GuildTextChannel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ internal GuildTextChannel(JsonChannel restChannel, ulong? guildId, QuarrelClient
4646
public ulong? LastMessageId
4747
{
4848
get => _lastMessageId;
49-
internal set => UpdateItem(ref _lastMessageId, value);
49+
internal set => _lastMessageId = value;
5050
}
5151

5252
/// <inheritdoc/>
5353
public ulong? LastReadMessageId
5454
{
5555
get => _lastReadMessageId;
56-
internal set => UpdateItem(ref _lastReadMessageId, value);
56+
internal set => _lastReadMessageId = value;
5757
}
5858

5959
/// <inheritdoc/>

src/Quarrel.ViewModels/Bindables/Abstract/BindableItem.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Quarrel © 2022
22

33
using Microsoft.Toolkit.Mvvm.ComponentModel;
4+
using Microsoft.Toolkit.Mvvm.Messaging;
45
using Quarrel.Services.Discord;
56
using Quarrel.Services.Dispatcher;
67

@@ -11,6 +12,11 @@ namespace Quarrel.Bindables.Abstract
1112
/// </summary>
1213
public abstract class BindableItem : ObservableObject
1314
{
15+
/// <summary>
16+
/// Gets the <see cref="IMessenger"/> for the <see cref="BindableItem"/>.
17+
/// </summary>
18+
protected readonly IMessenger _messenger;
19+
1420
/// <summary>
1521
/// Gets the <see cref="IDiscordService"/> for the <see cref="BindableItem"/>.
1622
/// </summary>
@@ -24,8 +30,12 @@ public abstract class BindableItem : ObservableObject
2430
/// <summary>
2531
/// Initializes a new instance of the <see cref="BindableItem"/> class.
2632
/// </summary>
27-
public BindableItem(IDiscordService discordService, IDispatcherService dispatcherService)
33+
public BindableItem(
34+
IMessenger messenger,
35+
IDiscordService discordService,
36+
IDispatcherService dispatcherService)
2837
{
38+
_messenger = messenger;
2939
_discordService = discordService;
3040
_dispatcherService = dispatcherService;
3141
}

src/Quarrel.ViewModels/Bindables/Abstract/SelectableItem.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Quarrel © 2022
22

3+
using Microsoft.Toolkit.Mvvm.Messaging;
34
using Quarrel.Bindables.Interfaces;
45
using Quarrel.Services.Discord;
56
using Quarrel.Services.Dispatcher;
@@ -16,8 +17,11 @@ public abstract class SelectableItem : BindableItem, ISelectableItem
1617
/// <summary>
1718
/// Initializes a new instance of the <see cref="SelectableItem"/> class.
1819
/// </summary>
19-
public SelectableItem(IDiscordService discordService, IDispatcherService dispatcherService) :
20-
base(discordService, dispatcherService)
20+
public SelectableItem(
21+
IMessenger messenger,
22+
IDiscordService discordService,
23+
IDispatcherService dispatcherService) :
24+
base(messenger, discordService, dispatcherService)
2125
{
2226

2327
}

src/Quarrel.ViewModels/Bindables/Channels/Abstract/BindableChannel.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Quarrel © 2022
22

3+
using Microsoft.Toolkit.Mvvm.Messaging;
34
using Quarrel.Bindables.Abstract;
45
using Quarrel.Bindables.Channels.Interfaces;
56
using Quarrel.Client.Models.Channels;
67
using Quarrel.Client.Models.Channels.Abstract;
78
using Quarrel.Client.Models.Channels.Interfaces;
89
using Quarrel.Client.Models.Users;
10+
using Quarrel.Messages.Discord;
911
using Quarrel.Services.Discord;
1012
using Quarrel.Services.Dispatcher;
1113
using Quarrel.Services.Localization;
@@ -23,11 +25,22 @@ public abstract partial class BindableChannel : SelectableItem, IBindableChannel
2325
/// <summary>
2426
/// Initializes a new instance of the <see cref="BindableChannel"/> class.
2527
/// </summary>
26-
internal BindableChannel(IDiscordService discordService, IDispatcherService dispatcherService, Channel channel) :
27-
base(discordService, dispatcherService)
28+
internal BindableChannel(
29+
IMessenger messenger,
30+
IDiscordService discordService,
31+
IDispatcherService dispatcherService,
32+
Channel channel) :
33+
base(messenger, discordService, dispatcherService)
2834
{
2935
_channel = channel;
30-
_channel.ItemUpdated += AckUpdateRoot;
36+
37+
messenger.Register<ChannelUpdatedMessage>(this, (_, e) =>
38+
{
39+
if (Id == e.Channel.Id)
40+
{
41+
Channel = e.Channel;
42+
}
43+
});
3144
}
3245

3346
/// <inheritdoc/>
@@ -49,16 +62,8 @@ public Channel Channel
4962
get => _channel;
5063
private set
5164
{
52-
if (_channel is not null)
53-
{
54-
_channel.ItemUpdated -= AckUpdateRoot;
55-
}
56-
57-
if (SetProperty(ref _channel, value))
58-
{
59-
OnPropertyChanged(nameof(Name));
60-
_channel.ItemUpdated += AckUpdateRoot;
61-
}
65+
SetProperty(ref _channel, value);
66+
AckUpdateRoot();
6267
}
6368
}
6469

@@ -77,7 +82,7 @@ protected virtual void AckUpdate()
7782
OnPropertyChanged(nameof(Name));
7883
}
7984

80-
private void AckUpdateRoot(object sender, EventArgs e)
85+
private void AckUpdateRoot()
8186
{
8287
_dispatcherService.RunOnUIThread(() =>
8388
{
@@ -94,23 +99,30 @@ private void AckUpdateRoot(object sender, EventArgs e)
9499
/// <param name="channel">The channel to wrap.</param>
95100
/// <param name="member">The current user's guild member for the channel's guild. Null if not a guild channel.</param>
96101
/// <param name="parent">The parent category of the channel.</param>
97-
public static BindableChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IChannel channel, GuildMember? member = null, BindableCategoryChannel? parent = null)
102+
public static BindableChannel? Create(
103+
IMessenger messenger,
104+
IDiscordService discordService,
105+
ILocalizationService localizationService,
106+
IDispatcherService dispatcherService,
107+
IChannel channel,
108+
GuildMember? member = null,
109+
BindableCategoryChannel? parent = null)
98110
{
99111
if (member is null)
100112
{
101113
return channel switch
102114
{
103-
DirectChannel c => new BindableDirectChannel(discordService, dispatcherService, c),
104-
GroupChannel c => new BindableGroupChannel(discordService, localizationService, dispatcherService, c),
115+
DirectChannel c => new BindableDirectChannel(messenger, discordService, dispatcherService, c),
116+
GroupChannel c => new BindableGroupChannel(messenger, discordService, localizationService, dispatcherService, c),
105117
_ => null
106118
};
107119
}
108120

109121
return channel switch
110122
{
111-
GuildTextChannel c => new BindableTextChannel(discordService, dispatcherService, c, member, parent),
112-
VoiceChannel c => new BindableVoiceChannel(discordService, dispatcherService, c, member, parent),
113-
CategoryChannel c => new BindableCategoryChannel(discordService, dispatcherService, c, member),
123+
GuildTextChannel c => new BindableTextChannel(messenger, discordService, dispatcherService, c, member, parent),
124+
VoiceChannel c => new BindableVoiceChannel(messenger, discordService, dispatcherService, c, member, parent),
125+
CategoryChannel c => new BindableCategoryChannel(messenger, discordService, dispatcherService, c, member),
114126
_ => null
115127
};
116128
}

src/Quarrel.ViewModels/Bindables/Channels/Abstract/BindableGuildChannel.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Quarrel © 2022
22

33
using CommunityToolkit.Diagnostics;
4+
using Microsoft.Toolkit.Mvvm.Messaging;
45
using Quarrel.Bindables.Abstract;
56
using Quarrel.Client.Models.Channels.Abstract;
67
using Quarrel.Client.Models.Channels.Interfaces;
@@ -17,8 +18,14 @@ namespace Quarrel.Bindables.Channels.Abstract
1718
/// </summary>
1819
public abstract class BindableGuildChannel : BindableChannel
1920
{
20-
internal BindableGuildChannel(IDiscordService discordService, IDispatcherService dispatcherService, GuildChannel channel, GuildMember selfMember, BindableCategoryChannel? parent = null) :
21-
base(discordService, dispatcherService, channel)
21+
internal BindableGuildChannel(
22+
IMessenger messenger,
23+
IDiscordService discordService,
24+
IDispatcherService dispatcherService,
25+
GuildChannel channel,
26+
GuildMember selfMember,
27+
BindableCategoryChannel? parent = null) :
28+
base(messenger, discordService, dispatcherService, channel)
2229
{
2330
CategoryChannel = parent;
2431

@@ -64,9 +71,16 @@ internal BindableGuildChannel(IDiscordService discordService, IDispatcherService
6471
/// <param name="channel">The channel to wrap.</param>
6572
/// <param name="member">The current user's guild member for the channel's guild.</param>
6673
/// <param name="parent">The channel's parent category.</param>
67-
public static BindableGuildChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IGuildChannel channel, GuildMember member, BindableCategoryChannel? parent = null)
74+
public static BindableGuildChannel? Create(
75+
IMessenger messenger,
76+
IDiscordService discordService,
77+
ILocalizationService localizationService,
78+
IDispatcherService dispatcherService,
79+
IGuildChannel channel,
80+
GuildMember member,
81+
BindableCategoryChannel? parent = null)
6882
{
69-
return BindableChannel.Create(discordService, localizationService, dispatcherService, channel, member, parent) as BindableGuildChannel;
83+
return BindableChannel.Create(messenger, discordService, localizationService, dispatcherService, channel, member, parent) as BindableGuildChannel;
7084
}
7185

7286
/// <inheritdoc/>

0 commit comments

Comments
 (0)