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

Commit 5ada12d

Browse files
authored
Merge pull request #587 from UWPCommunity/rewrite/main
Alpha release update
2 parents 4949ba4 + 6662de6 commit 5ada12d

32 files changed

+529
-31
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Quarrel.Client.Models.Users;
88
using Quarrel.Services.Discord;
99
using Quarrel.Services.Dispatcher;
10+
using Quarrel.Services.Localization;
1011
using System;
1112

1213
namespace Quarrel.Bindables.Channels.Abstract
@@ -84,19 +85,20 @@ private void AckUpdateRoot(object sender, EventArgs e)
8485
/// <summary>
8586
/// Creates a new instance of a <see cref="BindableChannel"/> based on the type.
8687
/// </summary>
87-
/// <param name="discordService">The discord service to pass to the <see cref="BindableItem"/>.</param>
88-
/// <param name="dispatcherService">The dispatcher service to pass to the <see cref="BindableItem"/>.</param>
88+
/// <param name="discordService">The <see cref="IDiscordService"/> to pass to the <see cref="BindableItem"/>.</param>
89+
/// <param name="localizationService">The <see cref="ILocalizationService"/> to pass to the <see cref="BindableItem"/>.</param>
90+
/// <param name="dispatcherService">The <see cref="IDispatcherService"/> to pass to the <see cref="BindableItem"/>.</param>
8991
/// <param name="channel">The channel to wrap.</param>
9092
/// <param name="member">The current user's guild member for the channel's guild. Null if not a guild channel.</param>
9193
/// <param name="parent">The parent category of the channel.</param>
92-
public static BindableChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IChannel channel, GuildMember? member = null, BindableCategoryChannel? parent = null)
94+
public static BindableChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IChannel channel, GuildMember? member = null, BindableCategoryChannel? parent = null)
9395
{
9496
if (member is null)
9597
{
9698
return channel switch
9799
{
98100
DirectChannel c => new BindableDirectChannel(discordService, dispatcherService, c),
99-
GroupChannel c => new BindableGroupChannel(discordService, dispatcherService, c),
101+
GroupChannel c => new BindableGroupChannel(discordService, localizationService, dispatcherService, c),
100102
_ => null
101103
};
102104
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Quarrel.Client.Models.Users;
99
using Quarrel.Services.Discord;
1010
using Quarrel.Services.Dispatcher;
11+
using Quarrel.Services.Localization;
1112

1213
namespace Quarrel.Bindables.Channels.Abstract
1314
{
@@ -57,14 +58,15 @@ internal BindableGuildChannel(IDiscordService discordService, IDispatcherService
5758
/// <summary>
5859
/// Creates a new <see cref="BindableGuildChannel"/> based on the type.
5960
/// </summary>
60-
/// <param name="discordService">The discord service to pass to the <see cref="BindableItem"/>.</param>
61-
/// <param name="dispatcherService">The dispatcher service to pass to the <see cref="BindableItem"/>.</param>
61+
/// <param name="discordService">The <see cref="IDiscordService"/> to pass to the <see cref="BindableItem"/>.</param>
62+
/// <param name="localizationService">The <see cref="ILocalizationService"/> to pass to the <see cref="BindableItem"/>.</param>
63+
/// <param name="dispatcherService">The <see cref="IDispatcherService"/> to pass to the <see cref="BindableItem"/>.</param>
6264
/// <param name="channel">The channel to wrap.</param>
6365
/// <param name="member">The current user's guild member for the channel's guild.</param>
6466
/// <param name="parent">The channel's parent category.</param>
65-
public static BindableGuildChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IGuildChannel channel, GuildMember member, BindableCategoryChannel? parent = null)
67+
public static BindableGuildChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IGuildChannel channel, GuildMember member, BindableCategoryChannel? parent = null)
6668
{
67-
return BindableChannel.Create(discordService, dispatcherService, channel, member, parent) as BindableGuildChannel;
69+
return BindableChannel.Create(discordService, localizationService, dispatcherService, channel, member, parent) as BindableGuildChannel;
6870
}
6971

7072
/// <inheritdoc/>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Quarrel.Client.Models.Channels.Interfaces;
66
using Quarrel.Services.Discord;
77
using Quarrel.Services.Dispatcher;
8+
using Quarrel.Services.Localization;
89

910
namespace Quarrel.Bindables.Channels.Abstract
1011
{
@@ -27,9 +28,9 @@ internal BindablePrivateChannel(IDiscordService discordService, IDispatcherServi
2728
/// <inheritdoc/>
2829
public IMessageChannel MessageChannel => (IMessageChannel)Channel;
2930

30-
public static BindablePrivateChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IPrivateChannel channel)
31+
public static BindablePrivateChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IPrivateChannel channel)
3132
{
32-
return BindableChannel.Create(discordService, dispatcherService, channel) as BindablePrivateChannel;
33+
return BindableChannel.Create(discordService, localizationService, dispatcherService, channel) as BindablePrivateChannel;
3334
}
3435
}
3536
}

src/Quarrel.ViewModels/Bindables/Channels/BindableGroupChannel.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Quarrel.Client.Models.Channels.Interfaces;
99
using Quarrel.Services.Discord;
1010
using Quarrel.Services.Dispatcher;
11+
using Quarrel.Services.Localization;
12+
using System.Linq;
1113

1214
namespace Quarrel.Bindables.Channels
1315
{
@@ -16,9 +18,13 @@ namespace Quarrel.Bindables.Channels
1618
/// </summary>
1719
public class BindableGroupChannel : BindablePrivateChannel, IBindableMessageChannel
1820
{
19-
internal BindableGroupChannel(IDiscordService discordService, IDispatcherService dispatcherService, GroupChannel groupChannel) :
21+
private ILocalizationService _localizationService;
22+
23+
internal BindableGroupChannel(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, GroupChannel groupChannel) :
2024
base(discordService, dispatcherService, groupChannel)
2125
{
26+
_localizationService = localizationService;
27+
2228
Guard.IsNotNull(groupChannel.Recipients);
2329
Recipients = new BindableUser[groupChannel.Recipients.Length];
2430
int i = 0;
@@ -32,17 +38,24 @@ internal BindableGroupChannel(IDiscordService discordService, IDispatcherService
3238
}
3339

3440
/// <inheritdoc/>
35-
public IGroupChannel DirectChannel => (IGroupChannel)Channel;
41+
public IGroupChannel GroupChannel => (IGroupChannel)Channel;
3642

37-
// TODO: Formatted names
3843
/// <inheritdoc/>
39-
public override string? Name => Channel.Name;
44+
public override string? Name => Channel.Name ?? _localizationService.CommaList(Recipients.Select(x => x.User.Username).ToArray());
4045

41-
public string IconUrl => $"https://cdn.discordapp.com/channel-icons/{Channel.Id}/{DirectChannel.Icon}.png";
46+
/// <summary>
47+
/// Gets the icon url of the group channel.
48+
/// </summary>
49+
public string? IconUrl => GroupChannel.Icon is null ? null : $"https://cdn.discordapp.com/channel-icons/{Channel.Id}/{GroupChannel.Icon}.png";
4250

4351
/// <summary>
4452
/// Gets the recipients of the group channel as a <see cref="BindableUser"/> array.
4553
/// </summary>
4654
public BindableUser[] Recipients { get; }
55+
56+
/// <summary>
57+
/// Gets the number of members in the group channel.
58+
/// </summary>
59+
public int MemberCount => Recipients.Length + 1;
4760
}
4861
}

src/Quarrel.ViewModels/Services/Discord/DiscordService.Methods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public async Task<BindableMessage[]> GetChannelMessagesAsync(IBindableMessageCha
134134
category = categories[nestedChannel.CategoryId.Value];
135135
}
136136

137-
channel = BindableGuildChannel.Create(this, _dispatcherService, nestedChannel, member, category);
137+
channel = BindableGuildChannel.Create(this, _localizationService, _dispatcherService, nestedChannel, member, category);
138138

139139
if (channel is not null && (channel.Channel.Id == guild.SelectedChannelId || (selectedChannel is null && channel.IsAccessible)) &&
140140
channel is IBindableSelectableChannel messageChannel)
@@ -156,7 +156,7 @@ public async Task<BindableMessage[]> GetChannelMessagesAsync(IBindableMessageCha
156156
int i = 0;
157157
foreach (var channel in rawChannels)
158158
{
159-
channels[i] = BindablePrivateChannel.Create(this, _dispatcherService, channel);
159+
channels[i] = BindablePrivateChannel.Create(this, _localizationService, _dispatcherService, channel);
160160

161161
if (channels[i] is IBindableSelectableChannel selectableChannel &&
162162
selectableChannel.Id == home.SelectedChannelId)

src/Quarrel.ViewModels/Services/Discord/DiscordService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Quarrel.Services.Analytics.Enums;
1212
using Quarrel.Services.Analytics.Models;
1313
using Quarrel.Services.Dispatcher;
14+
using Quarrel.Services.Localization;
1415
using Quarrel.Services.Storage.Accounts.Models;
1516
using System;
1617
using System.Threading.Tasks;
@@ -24,15 +25,17 @@ public partial class DiscordService : IDiscordService
2425
{
2526
private readonly QuarrelClient _quarrelClient;
2627
private readonly IAnalyticsService _analyticsService;
28+
private readonly ILocalizationService _localizationService;
2729
private readonly IDispatcherService _dispatcherService;
2830
private readonly IMessenger _messenger;
2931

3032
/// <summary>
3133
/// Initializes a new instance of the <see cref="DiscordService"/> class.
3234
/// </summary>
33-
public DiscordService(IAnalyticsService analyticsService, IDispatcherService dispatcherService, IMessenger messenger)
35+
public DiscordService(IAnalyticsService analyticsService, ILocalizationService localizationService, IDispatcherService dispatcherService, IMessenger messenger)
3436
{
3537
_analyticsService = analyticsService;
38+
_localizationService = localizationService;
3639
_dispatcherService = dispatcherService;
3740
_messenger = messenger;
3841
_quarrelClient = new QuarrelClient();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public interface ILocalizationService
2222
/// <returns>Localized <see langword="string"/> if valid, otherwise returns an empty <see langword="string"/>.</returns>
2323
string this[string key, params object[] args] { get; }
2424

25+
/// <summary>
26+
/// Gets a list of items as as a string with and.
27+
/// </summary>
28+
string CommaList(params string[] args);
29+
2530
/// <summary>
2631
/// Gets a value indicating whether or not the current language is written right to left.
2732
/// </summary>

src/Quarrel.ViewModels/ViewModels/CurrentUserViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
using Microsoft.Toolkit.Mvvm.Messaging;
66
using Quarrel.Bindables.Users;
77
using Quarrel.Messages;
8+
using Quarrel.Messages.Navigation.SubPages;
89
using Quarrel.Services.Discord;
910
using Quarrel.Services.Dispatcher;
11+
using Quarrel.ViewModels.SubPages.Settings;
1012

1113
namespace Quarrel.ViewModels
1214
{
@@ -46,6 +48,7 @@ public CurrentUserViewModel(IMessenger messenger, IDiscordService discordService
4648
[ICommand]
4749
public void NavigateToSettings()
4850
{
51+
_messenger.Send(new NavigateToSubPageMessage(typeof(UserSettingsPageViewModel)));
4952
}
5053
}
5154
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Quarrel © 2022
2+
3+
using Microsoft.Toolkit.Mvvm.ComponentModel;
4+
using Quarrel.Services.Localization;
5+
6+
namespace Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract
7+
{
8+
public abstract class UserSettingsSubPageViewModel : ObservableObject
9+
{
10+
protected readonly ILocalizationService _localizationService;
11+
12+
public UserSettingsSubPageViewModel(ILocalizationService localizationService)
13+
{
14+
_localizationService = localizationService;
15+
}
16+
17+
public abstract string Glyph { get; }
18+
19+
public abstract string Title { get; }
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Quarrel © 2022
2+
3+
using Quarrel.Services.Localization;
4+
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;
5+
6+
namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
7+
{
8+
public class BehaviorPageViewModel : UserSettingsSubPageViewModel
9+
{
10+
private const string BehaviorResource = "UserSettings/Behavior";
11+
12+
public BehaviorPageViewModel(ILocalizationService localizationService) :
13+
base(localizationService)
14+
{
15+
}
16+
17+
/// <inheritdoc/>
18+
public override string Glyph => "";
19+
20+
/// <inheritdoc/>
21+
public override string Title => _localizationService[BehaviorResource];
22+
}
23+
}

0 commit comments

Comments
 (0)