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

Commit f1a45e6

Browse files
authored
Merge pull request #590 from UWPCommunity/rewrite/main
Alpha update
2 parents 198223f + 57ed5b3 commit f1a45e6

File tree

21 files changed

+505
-32
lines changed

21 files changed

+505
-32
lines changed

src/API/Discord.API/Models/Json/Messages/JsonMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class JsonMessage
3030
public ulong? WebhookId { get; set; }
3131

3232
[JsonPropertyName("author")]
33-
public JsonUser? Author { get; set; }
33+
public JsonUser Author { get; set; }
3434

3535
[JsonPropertyName("call")]
3636
public JsonCall? Call { get; set; }

src/Quarrel.Client/Models/Messages/Interfaces/IMessage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Discord.API.Models.Enums.Messages;
44
using Quarrel.Client.Models.Base.Interfaces;
5+
using Quarrel.Client.Models.Users;
56
using System;
67

78
namespace Quarrel.Client.Models.Messages.Interfaces
@@ -42,5 +43,10 @@ internal interface IMessage : ISnowflakeItem
4243
/// Gets the timestamp the message was last edited.
4344
/// </summary>
4445
DateTimeOffset? EditedTimestamp { get; }
46+
47+
/// <summary>
48+
/// Gets the author of the message.
49+
/// </summary>
50+
User? Author { get; }
4551
}
4652
}

src/Quarrel.Client/Models/Messages/Message.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Discord.API.Models.Json.Messages;
55
using Quarrel.Client.Models.Base;
66
using Quarrel.Client.Models.Messages.Interfaces;
7+
using Quarrel.Client.Models.Users;
78
using System;
89

910
namespace Quarrel.Client.Models.Messages
@@ -22,7 +23,9 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :
2223
MentionsEveryone = jsonMessage.MentionsEveryone;
2324
Timestamp = jsonMessage.Timestamp ?? DateTimeOffset.MinValue;
2425
EditedTimestamp = jsonMessage.EditedTimestamp;
25-
Content = jsonMessage.Content ?? String.Empty;
26+
Content = jsonMessage.Content ?? string.Empty;
27+
28+
Author = context.GetOrAddUserInternal(jsonMessage.Author);
2629
}
2730

2831
/// <inheritdoc/>
@@ -45,5 +48,8 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :
4548

4649
/// <inheritdoc/>
4750
public DateTimeOffset? EditedTimestamp { get; private set; }
51+
52+
/// <inheritdoc/>
53+
public User Author { get; private set; }
4854
}
4955
}

src/Quarrel.Client/QuarrelClient.State.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ internal bool AddReadState(JsonReadState jsonReadState)
177177
return null;
178178
}
179179

180-
internal User? GetOrAddUserInternal(JsonUser jsonUser)
180+
internal User GetOrAddUserInternal(JsonUser jsonUser)
181181
{
182182
if(_userMap.TryGetValue(jsonUser.Id, out User user))
183183
{
184184
return user;
185185
}
186186

187+
// This null override should really be safe
187188
AddUser(jsonUser);
188-
return GetUserInternal(jsonUser.Id);
189+
return GetUserInternal(jsonUser.Id)!;
189190
}
190191

191192
internal bool AddUser(JsonUser jsonUser)

src/Quarrel.ViewModels/Bindables/Messages/BindableMessage.cs

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

33
using Microsoft.Toolkit.Mvvm.ComponentModel;
44
using Quarrel.Bindables.Abstract;
5+
using Quarrel.Bindables.Users;
56
using Quarrel.Client.Models.Messages;
67
using Quarrel.Services.Discord;
78
using Quarrel.Services.Dispatcher;
@@ -15,14 +16,23 @@ public partial class BindableMessage : SelectableItem
1516
{
1617
[ObservableProperty]
1718
private Message _message;
18-
19+
1920
/// <summary>
2021
/// Initializes a new instance of the <see cref="BindableMessage"/> class.
2122
/// </summary>
2223
internal BindableMessage(IDiscordService discordService, IDispatcherService dispatcherService, Message message) :
2324
base(discordService, dispatcherService)
2425
{
2526
_message = message;
27+
if (message.Author is not null)
28+
{
29+
Author = _discordService.GetUser(message.Author.Id);
30+
}
2631
}
32+
33+
/// <summary>
34+
/// Gets the author of the message as a bindable user.
35+
/// </summary>
36+
public BindableUser? Author { get; }
2737
}
2838
}

src/Quarrel.ViewModels/Services/Localization/ILocalizationService.cs

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

3+
using System.Collections.Generic;
4+
35
namespace Quarrel.Services.Localization
46
{
57
/// <summary>
@@ -27,6 +29,8 @@ public interface ILocalizationService
2729
/// </summary>
2830
string CommaList(params string[] args);
2931

32+
public string LanguageOverride { get; set; }
33+
3034
/// <summary>
3135
/// Gets a value indicating whether or not the current language is written right to left.
3236
/// </summary>
@@ -36,5 +40,10 @@ public interface ILocalizationService
3640
/// Gets a value indicating whether or not the current language is the app's neutral language.
3741
/// </summary>
3842
bool IsNeutralLanguage { get; }
43+
44+
/// <summary>
45+
/// Gets the list of available languages.
46+
/// </summary>
47+
public IReadOnlyList<string> AvailableLanguages { get; }
3948
}
4049
}

src/Quarrel.ViewModels/ViewModels/SubPages/UserSettings/Pages/DisplayPageViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Quarrel.Services.Localization;
44
using Quarrel.Services.Storage;
55
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;
6+
using System.Collections.Generic;
67

78
namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
89
{
@@ -20,5 +21,16 @@ internal DisplayPageViewModel(ILocalizationService localizationService, IStorage
2021

2122
/// <inheritdoc/>
2223
public override string Title => _localizationService[ConnectionsResource];
24+
25+
/// <inheritdoc/>
26+
public override bool IsActive => true;
27+
28+
public string SelectedLanguage
29+
{
30+
get => _localizationService.LanguageOverride;
31+
set => _localizationService.LanguageOverride = value;
32+
}
33+
34+
public IReadOnlyList<string> LanguageOptions => _localizationService.AvailableLanguages;
2335
}
2436
}

src/Quarrel/App.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313
<!--Styles-->
1414
<ResourceDictionary Source="Styles/ButtonStyles.xaml"/>
15-
<ResourceDictionary Source="Styles/TextBoxStyles.xaml"/>
1615
<ResourceDictionary Source="Styles/ChannelItemStyles.xaml"/>
1716
<ResourceDictionary Source="Styles/GuildItemStyles.xaml"/>
17+
<ResourceDictionary Source="Styles/MessageItemStyles.xaml"/>
1818
<ResourceDictionary Source="Styles/MiscStyles.xaml"/>
19+
<ResourceDictionary Source="Styles/TextBoxStyles.xaml"/>
1920

2021
<!--Data Templates-->
2122
<dt:GuildTemplates/>

src/Quarrel/Controls/Message/MessageRenderer.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
d:DesignHeight="300"
1010
d:DesignWidth="400">
1111

12-
<RichTextBlock x:Name="textBlock"/>
12+
<RichTextBlock x:Name="textBlock"
13+
IsTextSelectionEnabled="False"
14+
TextWrapping="WrapWholeWords"/>
1315
</UserControl>

src/Quarrel/Controls/Message/MessageRenderer.xaml.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
using Windows.UI.Xaml.Media;
1414
using Windows.UI.Xaml.Media.Imaging;
1515

16-
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
17-
1816
namespace Quarrel.Controls.Message
1917
{
2018
public sealed partial class MessageRenderer : UserControl
2119
{
20+
private const bool IsTextSelectable = false;
21+
private const bool IsCodeSelectable = true;
22+
2223
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
23-
"Text",
24+
nameof(Text),
2425
typeof(string),
2526
typeof(MessageRenderer),
2627
new PropertyMetadata(null, OnTextChanged)
@@ -30,7 +31,6 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE
3031
{
3132
var messageRenderer = (MessageRenderer)d;
3233
messageRenderer.textBlock.Blocks.Clear();
33-
var parser = new Parser();
3434
var tree = Parser.ParseAST((string)e.NewValue, true, false);
3535
var modTree = AdjustTree(tree);
3636
Parse(modTree, messageRenderer.textBlock.Blocks);
@@ -83,6 +83,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
8383
FontSize = container.FontSize,
8484
FontStretch = container.FontStretch,
8585
TextDecorations = container.TextDecorations,
86+
IsTextSelectionEnabled = IsCodeSelectable,
8687
Blocks = { codeParagraph }
8788
}
8889
};
@@ -106,7 +107,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
106107
FontSize = container.FontSize,
107108
FontStretch = container.FontStretch,
108109
TextDecorations = container.TextDecorations,
109-
IsTextSelectionEnabled = true,
110+
IsTextSelectionEnabled = IsCodeSelectable,
110111
Text = codeBlock.Content
111112
}
112113
};
@@ -225,11 +226,11 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
225226
}
226227
}
227228
break;
228-
case S u:
229+
case S s:
229230
{
230231
var inline = new Span() { TextDecorations = TextDecorations.Strikethrough };
231232
inlineCollection.Add(inline);
232-
foreach (AST child in u.Children.Reverse())
233+
foreach (AST child in s.Children.Reverse())
233234
{
234235
stack.Push((child, inline.Inlines));
235236
}
@@ -250,15 +251,14 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
250251
FontSize = container.FontSize,
251252
FontStretch = container.FontStretch,
252253
TextDecorations = container.TextDecorations,
253-
IsTextSelectionEnabled = true,
254+
IsTextSelectionEnabled = IsCodeSelectable,
254255
Text = inlineCode.Content
255256
}
256257
};
257258
}
258259
break;
259260
case Timestamp timeStamp:
260261
{
261-
262262
InlineUIContainer container = new InlineUIContainer();
263263
inlineCollection.Add(container);
264264
container.Child = new Border()
@@ -271,7 +271,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
271271
FontSize = container.FontSize,
272272
FontStretch = container.FontStretch,
273273
TextDecorations = container.TextDecorations,
274-
IsTextSelectionEnabled = true,
274+
IsTextSelectionEnabled = IsTextSelectable,
275275
Text = timeStamp.Format switch
276276
{
277277
"F" or "" => timeStamp.Time.ToString("F"),
@@ -300,7 +300,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
300300
FontSize = container.FontSize,
301301
FontStretch = container.FontStretch,
302302
TextDecorations = container.TextDecorations,
303-
IsTextSelectionEnabled = true,
303+
IsTextSelectionEnabled = IsTextSelectable,
304304
Text = roleMention.RoleID
305305
}
306306
};
@@ -320,7 +320,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
320320
FontSize = container.FontSize,
321321
FontStretch = container.FontStretch,
322322
TextDecorations = container.TextDecorations,
323-
IsTextSelectionEnabled = true,
323+
IsTextSelectionEnabled = IsTextSelectable,
324324
Text = mention.UserID
325325
}
326326
};
@@ -340,7 +340,7 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
340340
FontSize = container.FontSize,
341341
FontStretch = container.FontStretch,
342342
TextDecorations = container.TextDecorations,
343-
IsTextSelectionEnabled = true,
343+
IsTextSelectionEnabled = IsTextSelectable,
344344
Text = channel.ChannelID
345345
}
346346
};
@@ -362,7 +362,8 @@ private static void Parse(IList<ASTRoot> tree, BlockCollection blocks)
362362
FontSize = container.FontSize,
363363
FontStretch = container.FontStretch,
364364
TextDecorations = container.TextDecorations,
365-
Blocks = { codeParagraph }
365+
IsTextSelectionEnabled = IsTextSelectable,
366+
Blocks = { codeParagraph },
366367
}
367368
};
368369
foreach (AST child in spoiler.Children.Reverse())

0 commit comments

Comments
 (0)