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

Alpha release update #587

Merged
merged 7 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Quarrel.Client.Models.Users;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;
using System;

namespace Quarrel.Bindables.Channels.Abstract
Expand Down Expand Up @@ -84,19 +85,20 @@ private void AckUpdateRoot(object sender, EventArgs e)
/// <summary>
/// Creates a new instance of a <see cref="BindableChannel"/> based on the type.
/// </summary>
/// <param name="discordService">The discord service to pass to the <see cref="BindableItem"/>.</param>
/// <param name="dispatcherService">The dispatcher service to pass to the <see cref="BindableItem"/>.</param>
/// <param name="discordService">The <see cref="IDiscordService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="localizationService">The <see cref="ILocalizationService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="dispatcherService">The <see cref="IDispatcherService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="channel">The channel to wrap.</param>
/// <param name="member">The current user's guild member for the channel's guild. Null if not a guild channel.</param>
/// <param name="parent">The parent category of the channel.</param>
public static BindableChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IChannel channel, GuildMember? member = null, BindableCategoryChannel? parent = null)
public static BindableChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IChannel channel, GuildMember? member = null, BindableCategoryChannel? parent = null)
{
if (member is null)
{
return channel switch
{
DirectChannel c => new BindableDirectChannel(discordService, dispatcherService, c),
GroupChannel c => new BindableGroupChannel(discordService, dispatcherService, c),
GroupChannel c => new BindableGroupChannel(discordService, localizationService, dispatcherService, c),
_ => null
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Quarrel.Client.Models.Users;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;

namespace Quarrel.Bindables.Channels.Abstract
{
Expand Down Expand Up @@ -57,14 +58,15 @@ internal BindableGuildChannel(IDiscordService discordService, IDispatcherService
/// <summary>
/// Creates a new <see cref="BindableGuildChannel"/> based on the type.
/// </summary>
/// <param name="discordService">The discord service to pass to the <see cref="BindableItem"/>.</param>
/// <param name="dispatcherService">The dispatcher service to pass to the <see cref="BindableItem"/>.</param>
/// <param name="discordService">The <see cref="IDiscordService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="localizationService">The <see cref="ILocalizationService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="dispatcherService">The <see cref="IDispatcherService"/> to pass to the <see cref="BindableItem"/>.</param>
/// <param name="channel">The channel to wrap.</param>
/// <param name="member">The current user's guild member for the channel's guild.</param>
/// <param name="parent">The channel's parent category.</param>
public static BindableGuildChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IGuildChannel channel, GuildMember member, BindableCategoryChannel? parent = null)
public static BindableGuildChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IGuildChannel channel, GuildMember member, BindableCategoryChannel? parent = null)
{
return BindableChannel.Create(discordService, dispatcherService, channel, member, parent) as BindableGuildChannel;
return BindableChannel.Create(discordService, localizationService, dispatcherService, channel, member, parent) as BindableGuildChannel;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Quarrel.Client.Models.Channels.Interfaces;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;

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

public static BindablePrivateChannel? Create(IDiscordService discordService, IDispatcherService dispatcherService, IPrivateChannel channel)
public static BindablePrivateChannel? Create(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, IPrivateChannel channel)
{
return BindableChannel.Create(discordService, dispatcherService, channel) as BindablePrivateChannel;
return BindableChannel.Create(discordService, localizationService, dispatcherService, channel) as BindablePrivateChannel;
}
}
}
23 changes: 18 additions & 5 deletions src/Quarrel.ViewModels/Bindables/Channels/BindableGroupChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Quarrel.Client.Models.Channels.Interfaces;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;
using System.Linq;

namespace Quarrel.Bindables.Channels
{
Expand All @@ -16,9 +18,13 @@ namespace Quarrel.Bindables.Channels
/// </summary>
public class BindableGroupChannel : BindablePrivateChannel, IBindableMessageChannel
{
internal BindableGroupChannel(IDiscordService discordService, IDispatcherService dispatcherService, GroupChannel groupChannel) :
private ILocalizationService _localizationService;

internal BindableGroupChannel(IDiscordService discordService, ILocalizationService localizationService, IDispatcherService dispatcherService, GroupChannel groupChannel) :
base(discordService, dispatcherService, groupChannel)
{
_localizationService = localizationService;

Guard.IsNotNull(groupChannel.Recipients);
Recipients = new BindableUser[groupChannel.Recipients.Length];
int i = 0;
Expand All @@ -32,17 +38,24 @@ internal BindableGroupChannel(IDiscordService discordService, IDispatcherService
}

/// <inheritdoc/>
public IGroupChannel DirectChannel => (IGroupChannel)Channel;
public IGroupChannel GroupChannel => (IGroupChannel)Channel;

// TODO: Formatted names
/// <inheritdoc/>
public override string? Name => Channel.Name;
public override string? Name => Channel.Name ?? _localizationService.CommaList(Recipients.Select(x => x.User.Username).ToArray());

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

/// <summary>
/// Gets the recipients of the group channel as a <see cref="BindableUser"/> array.
/// </summary>
public BindableUser[] Recipients { get; }

/// <summary>
/// Gets the number of members in the group channel.
/// </summary>
public int MemberCount => Recipients.Length + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async Task<BindableMessage[]> GetChannelMessagesAsync(IBindableMessageCha
category = categories[nestedChannel.CategoryId.Value];
}

channel = BindableGuildChannel.Create(this, _dispatcherService, nestedChannel, member, category);
channel = BindableGuildChannel.Create(this, _localizationService, _dispatcherService, nestedChannel, member, category);

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

if (channels[i] is IBindableSelectableChannel selectableChannel &&
selectableChannel.Id == home.SelectedChannelId)
Expand Down
5 changes: 4 additions & 1 deletion src/Quarrel.ViewModels/Services/Discord/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Quarrel.Services.Analytics.Enums;
using Quarrel.Services.Analytics.Models;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;
using Quarrel.Services.Storage.Accounts.Models;
using System;
using System.Threading.Tasks;
Expand All @@ -24,15 +25,17 @@ public partial class DiscordService : IDiscordService
{
private readonly QuarrelClient _quarrelClient;
private readonly IAnalyticsService _analyticsService;
private readonly ILocalizationService _localizationService;
private readonly IDispatcherService _dispatcherService;
private readonly IMessenger _messenger;

/// <summary>
/// Initializes a new instance of the <see cref="DiscordService"/> class.
/// </summary>
public DiscordService(IAnalyticsService analyticsService, IDispatcherService dispatcherService, IMessenger messenger)
public DiscordService(IAnalyticsService analyticsService, ILocalizationService localizationService, IDispatcherService dispatcherService, IMessenger messenger)
{
_analyticsService = analyticsService;
_localizationService = localizationService;
_dispatcherService = dispatcherService;
_messenger = messenger;
_quarrelClient = new QuarrelClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface ILocalizationService
/// <returns>Localized <see langword="string"/> if valid, otherwise returns an empty <see langword="string"/>.</returns>
string this[string key, params object[] args] { get; }

/// <summary>
/// Gets a list of items as as a string with and.
/// </summary>
string CommaList(params string[] args);

/// <summary>
/// Gets a value indicating whether or not the current language is written right to left.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Quarrel.ViewModels/ViewModels/CurrentUserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Users;
using Quarrel.Messages;
using Quarrel.Messages.Navigation.SubPages;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.ViewModels.SubPages.Settings;

namespace Quarrel.ViewModels
{
Expand Down Expand Up @@ -46,6 +48,7 @@ public CurrentUserViewModel(IMessenger messenger, IDiscordService discordService
[ICommand]
public void NavigateToSettings()
{
_messenger.Send(new NavigateToSubPageMessage(typeof(UserSettingsPageViewModel)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Quarrel.Services.Localization;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract
{
public abstract class UserSettingsSubPageViewModel : ObservableObject
{
protected readonly ILocalizationService _localizationService;

public UserSettingsSubPageViewModel(ILocalizationService localizationService)
{
_localizationService = localizationService;
}

public abstract string Glyph { get; }

public abstract string Title { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class BehaviorPageViewModel : UserSettingsSubPageViewModel
{
private const string BehaviorResource = "UserSettings/Behavior";

public BehaviorPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[BehaviorResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class ConnectionsPageViewModel : UserSettingsSubPageViewModel
{
private const string ConnectionsResource = "UserSettings/Connections";

public ConnectionsPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[ConnectionsResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class DisplayPageViewModel : UserSettingsSubPageViewModel
{
private const string ConnectionsResource = "UserSettings/Display";

public DisplayPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[ConnectionsResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class MyAccountPageViewModel : UserSettingsSubPageViewModel
{
private const string MyAccountResource = "UserSettings/MyAccount";

public MyAccountPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[MyAccountResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class NotificationsPageViewModel : UserSettingsSubPageViewModel
{
private const string NotificationsResource = "UserSettings/Notifications";

public NotificationsPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[NotificationsResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class PrivacyPageViewModel : UserSettingsSubPageViewModel
{
private const string PrivacyResource = "UserSettings/Privacy";

public PrivacyPageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

public override string Glyph => "";

public override string Title => _localizationService[PrivacyResource];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Quarrel © 2022

using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.UserSettings.Pages.Abstract;

namespace Quarrel.ViewModels.SubPages.UserSettings.Pages
{
public class VoicePageViewModel : UserSettingsSubPageViewModel
{
private const string VoiceResource = "UserSettings/Voice";

public VoicePageViewModel(ILocalizationService localizationService) :
base(localizationService)
{
}

/// <inheritdoc/>
public override string Glyph => "";

/// <inheritdoc/>
public override string Title => _localizationService[VoiceResource];
}
}
Loading