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

Commit

Permalink
Merge pull request #604 from UWPCommunity/rewrite/main
Browse files Browse the repository at this point in the history
Alpha release
  • Loading branch information
Avid29 authored May 8, 2022
2 parents 3f4b131 + 150267e commit 628ec76
Show file tree
Hide file tree
Showing 38 changed files with 196 additions and 60 deletions.
11 changes: 9 additions & 2 deletions src/Quarrel.Client/QuarrelClient.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,24 @@ public IPrivateChannel[] GetPrivateChannels()
}
}

// Nullability is improperly accessed here
#pragma warning disable CS8629
Array.Resize(ref privateChannels, i);
Array.Sort(privateChannels, Comparer<IPrivateChannel>.Create((item1, item2) =>
{
if (!item2.LastMessageId.HasValue) return -1;
if (!item1.LastMessageId.HasValue) return 1;
bool i1Null = !item1.LastMessageId.HasValue;
bool i2Null = !item2.LastMessageId.HasValue;
if (i1Null && i2Null) return 0;
if (i2Null) return -1;
if (i1Null) return 1;
long compare = (long)item2.LastMessageId.Value - (long)item1.LastMessageId.Value;
if (compare < 0) return -1;
if (compare > 0) return 1;
return 0;
}));
#pragma warning restore CS8629

return privateChannels;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Quarrel © 2022

using Discord.API.Models.Enums.Channels;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Abstract;
using Quarrel.Bindables.Channels.Interfaces;
Expand Down Expand Up @@ -45,6 +46,9 @@ internal BindableChannel(
/// <inheritdoc/>
public ulong Id => Channel.Id;

/// <inheritdoc/>
public ChannelType Type => Channel.Type;

/// <inheritdoc/>
public virtual string? Name => _channel.Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ internal BindableTextChannel(

/// <inheritdoc/>
public IMessageChannel MessageChannel => (IMessageChannel)Channel;

/// <inheritdoc/>
public GuildTextChannel TextChannel => (GuildTextChannel)Channel;

/// <inheritdoc/>
protected override void AckUpdate()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Quarrel © 2022

using Discord.API.Models.Enums.Channels;
using Quarrel.Client.Models.Channels.Interfaces;

namespace Quarrel.Bindables.Channels.Interfaces
Expand All @@ -14,6 +15,11 @@ public interface IBindableChannel
/// </summary>
public ulong Id { get; }

/// <summary>
/// Gets the channel type.
/// </summary>
public ChannelType Type { get; }

/// <summary>
/// Gets the id of the guild the channel belongs to, or null if a DM.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Quarrel.ViewModels/Services/Analytics/Enums/LoggedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public enum LoggedEvent
/// </summary>
[StringValue("Message Sent")]
MessageSent,

/// <summary>
/// Opened a channel.
/// </summary>
[StringValue("Guild Opened")]
GuildOpened,

/// <summary>
/// Opened a channel.
/// </summary>
[StringValue("Channel Opened")]
ChannelOpened,
#endregion

#region Login
Expand Down
11 changes: 10 additions & 1 deletion src/Quarrel.ViewModels/ViewModels/Panels/ChannelsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
using Quarrel.Bindables.Channels.Interfaces;
using Quarrel.Bindables.Guilds.Interfaces;
using Quarrel.Messages.Navigation;
using Quarrel.Services.Analytics;
using Quarrel.Services.Analytics.Enums;
using Quarrel.Services.Discord;
using System;
using System.Collections.Generic;

namespace Quarrel.ViewModels.Panels
Expand All @@ -16,6 +19,7 @@ namespace Quarrel.ViewModels.Panels
/// </summary>
public partial class ChannelsViewModel : ObservableRecipient
{
private readonly IAnalyticsService _analyticsService;
private readonly IMessenger _messenger;
private readonly IDiscordService _discordService;

Expand All @@ -27,8 +31,9 @@ public partial class ChannelsViewModel : ObservableRecipient
/// <summary>
/// Initializes a new instance of the <see cref="ChannelsViewModel"/> class.
/// </summary>
public ChannelsViewModel(IMessenger messenger, IDiscordService discordService)
public ChannelsViewModel(IAnalyticsService analyticsService, IMessenger messenger, IDiscordService discordService)
{
_analyticsService = analyticsService;
_messenger = messenger;
_discordService = discordService;

Expand All @@ -55,6 +60,10 @@ public IBindableSelectableChannel? SelectedChannel
{
value.IsSelected = true;
_currentGuild.SelectedChannelId = value.Id;

_analyticsService.Log(LoggedEvent.ChannelOpened,
("Type", $"{_selectedChannel.Type}"));

_messenger.Send(new NavigateToChannelMessage<IBindableSelectableChannel>(value));
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/Quarrel.ViewModels/ViewModels/Panels/CommandBarViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Channels.Interfaces;
using Quarrel.Messages.Navigation;
using Quarrel.Services.Analytics;
using Quarrel.Services.Discord;

namespace Quarrel.ViewModels.Panels
{
public class CommandBarViewModel : ObservableRecipient
{
private readonly IAnalyticsService _analyticsService;
private readonly IMessenger _messenger;
private readonly IDiscordService _discordService;

private IBindableSelectableChannel? _selectedChannel;

public CommandBarViewModel(IAnalyticsService analyticsService, IMessenger messenger, IDiscordService discordService)
{
_analyticsService = analyticsService;
_messenger = messenger;
_discordService = discordService;

_messenger.Register<NavigateToChannelMessage<IBindableSelectableChannel>>(this, (_, m) => SelectedChannel = m.Channel);
}

public IBindableSelectableChannel? SelectedChannel
{
get => _selectedChannel;
set => SetProperty(ref _selectedChannel, value);
}
}
}
7 changes: 6 additions & 1 deletion src/Quarrel.ViewModels/ViewModels/Panels/GuildsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Quarrel.Bindables.Guilds.Interfaces;
using Quarrel.Messages;
using Quarrel.Messages.Navigation;
using Quarrel.Services.Analytics;
using Quarrel.Services.Analytics.Enums;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;
Expand All @@ -19,6 +21,7 @@ namespace Quarrel.ViewModels
/// </summary>
public partial class GuildsViewModel : ObservableRecipient
{
private readonly IAnalyticsService _analyticsService;
private readonly IMessenger _messenger;
private readonly ILocalizationService _localizationService;
private readonly IDiscordService _discordService;
Expand All @@ -30,8 +33,9 @@ public partial class GuildsViewModel : ObservableRecipient
/// <summary>
/// Initializes a new instance of the <see cref="GuildsViewModel"/> class.
/// </summary>
public GuildsViewModel(IMessenger messenger, ILocalizationService localizationService, IDiscordService discordService, IDispatcherService dispatcherService)
public GuildsViewModel(IAnalyticsService analyticsService, IMessenger messenger, ILocalizationService localizationService, IDiscordService discordService, IDispatcherService dispatcherService)
{
_analyticsService = analyticsService;
_messenger = messenger;
_localizationService = localizationService;
_discordService = discordService;
Expand All @@ -58,6 +62,7 @@ public IBindableSelectableGuildItem? SelectedGuild
if (SetProperty(ref _selectedGuild, value) && value is not null)
{
value.IsSelected = true;
_analyticsService.Log(LoggedEvent.GuildOpened);
_messenger.Send(new NavigateToGuildMessage<IBindableSelectableGuildItem>(value));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Quarrel.Messages.Navigation;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using System.Collections.Generic;

namespace Quarrel.ViewModels.Panels
{
Expand Down
11 changes: 6 additions & 5 deletions src/Quarrel.ViewModels/ViewModels/Panels/MessagesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
using Quarrel.Messages.Navigation;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Quarrel.ViewModels.Panels
{
Expand Down Expand Up @@ -96,10 +94,13 @@ private void LoadInitialMessages(IBindableMessageChannel? channel)
// Load messages
var messages = await _discordService.GetChannelMessagesAsync(channel);
BindableMessage[] bindableMessages = new BindableMessage[messages.Length];
bindableMessages[0] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length-1]);
for (int i = 1; i < messages.Length; i++)
if (bindableMessages.Length > 0)
{
bindableMessages[i] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length-1-i], messages[messages.Length-i]);
bindableMessages[0] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length - 1]);
for (int i = 1; i < messages.Length; i++)
{
bindableMessages[i] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length - 1 - i], messages[messages.Length - i]);
}
}
// Add messages to the UI and mark loading as finished
Expand Down
1 change: 1 addition & 0 deletions src/Quarrel/App.Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private IServiceProvider ConfigureServices()
services.AddTransient<LoginPageViewModel>();
services.AddSingleton<GuildsViewModel>();
services.AddSingleton<ChannelsViewModel>();
services.AddSingleton<CommandBarViewModel>();
services.AddSingleton<MessagesViewModel>();
services.AddSingleton<MessageBoxViewModel>();
services.AddSingleton<CurrentUserViewModel>();
Expand Down
2 changes: 1 addition & 1 deletion src/Quarrel/Attached/TextHelpers/CharacterCasing.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Quarrel © 2022

using Quarrel.Converters;
using Quarrel.Converters.Common.Text;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down
34 changes: 32 additions & 2 deletions src/Quarrel/Controls/Shell/QuarrelCommandBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:qc="using:Quarrel.Controls"
xmlns:bchannel="using:Quarrel.Bindables.Channels"
xmlns:cselector="using:Quarrel.Selectors.Channels"
xmlns:vconvert="using:Quarrel.Converters.Common.Visible"
mc:Ignorable="d"
Background="Transparent"
d:DesignHeight="56"
Expand All @@ -19,12 +22,35 @@
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Transparent"/>
</Style>

<DataTemplate x:Key="TextChannelHeaderTemplate" x:DataType="bchannel:BindableTextChannel">
<StackPanel Padding="8,4" VerticalAlignment="Center">
<TextBlock Text="{x:Bind Name, Mode=OneWay}" FontSize="18"/>
<TextBlock Text="{x:Bind TextChannel.Topic, Mode=OneWay}"
Visibility="{x:Bind vconvert:VisibleWhenNotNullConverter.Convert(TextChannel.Topic), Mode=OneWay}"
Opacity=".7" FontSize="12"/>
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="DirectChannelHeaderTemplate" x:DataType="bchannel:BindableDirectChannel">
<TextBlock Text="{x:Bind Name, Mode=OneWay}" FontSize="18" Padding="8,4"/>
</DataTemplate>

<DataTemplate x:Key="GroupChannelHeaderTemplate" x:DataType="bchannel:BindableGroupChannel">
<TextBlock Text="{x:Bind Name, Mode=OneWay}" FontSize="18" Padding="8,4"/>
</DataTemplate>

<cselector:ChannelTemplateSelector x:Key="ChannelHeaderTemplateSelector"
TextChannelTemplate="{StaticResource TextChannelHeaderTemplate}"
DirectChannelTemplate="{StaticResource DirectChannelHeaderTemplate}"
GroupChannelTemplate="{StaticResource GroupChannelHeaderTemplate}"/>
</UserControl.Resources>

<Grid Height="48">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="72"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<!--Hamburger button-->
Expand All @@ -34,8 +60,12 @@
Click="HamburgerClicked">
<FontIcon Glyph="&#xE700;" FontSize="16"/>
</Button>

<ContentControl Content="{x:Bind ViewModel.SelectedChannel, Mode=OneWay}"
ContentTemplateSelector="{StaticResource ChannelHeaderTemplateSelector}"
Grid.Column="1" HorizontalAlignment="Left" VerticalContentAlignment="Center"/>

<StackPanel Grid.Column="1"
<StackPanel Grid.Column="2"
Orientation="Horizontal"
HorizontalAlignment="Right">
<Button x:Uid="CommandBar/NewWindowBTN"
Expand Down
4 changes: 2 additions & 2 deletions src/Quarrel/Controls/Shell/QuarrelCommandBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public sealed partial class QuarrelCommandBar : UserControl
public QuarrelCommandBar()
{
this.InitializeComponent();
DataContext = App.Current.Services.GetRequiredService<ChannelsViewModel>();
DataContext = App.Current.Services.GetRequiredService<CommandBarViewModel>();

_messenger = App.Current.Services.GetRequiredService<IMessenger>();
_windowService = App.Current.Services.GetRequiredService<IWindowService>();
}

public ChannelsViewModel ViewModel => (ChannelsViewModel)DataContext;
public CommandBarViewModel ViewModel => (CommandBarViewModel)DataContext;

public bool ShowHamburgerButton
{
Expand Down
4 changes: 2 additions & 2 deletions src/Quarrel/Controls/Shell/Shell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Guilds;
using Quarrel.Bindables.Guilds.Interfaces;
using Quarrel.Messages;
using Quarrel.Messages.Navigation;
using Quarrel.Messages.Panel;
Expand All @@ -24,7 +24,7 @@ public Shell()
_messenger = App.Current.Services.GetRequiredService<IMessenger>();
_dispatcherService = App.Current.Services.GetRequiredService<IDispatcherService>();

_messenger.Register<NavigateToGuildMessage<BindableGuild>>(this, (_,_) => _messenger.Send(new TogglePanelMessage(PanelSide.Left, PanelState.Open)));
_messenger.Register<NavigateToGuildMessage<IBindableSelectableGuildItem>>(this, (_,_) => _messenger.Send(new TogglePanelMessage(PanelSide.Left, PanelState.Open)));
_messenger.Register<TogglePanelMessage>(this, (_, e) =>
{
_dispatcherService.RunOnUIThread(() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Quarrel © 2022

namespace Quarrel.Converters
namespace Quarrel.Converters.Common.Boolean
{
public sealed class EqualityConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Quarrel © 2022

namespace Quarrel.Converters
namespace Quarrel.Converters.Common.Boolean
{
public sealed class InverseBoolConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Controls;

namespace Quarrel.Converters
namespace Quarrel.Converters.Common.Text
{
/// <summary>
/// A converter that changes the casing of a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Quarrel.Services.Localization;
using System;

namespace Quarrel.Converters.Time
namespace Quarrel.Converters.Common.Time
{
public class SmartTimeFormatConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Windows.UI.Xaml;

namespace Quarrel.Converters
namespace Quarrel.Converters.Common.Visible
{
/// <summary>
/// A converter that returns an inverted <see cref="Visibility"/> value for the input <see langword="bool"/> value.
Expand Down
Loading

0 comments on commit 628ec76

Please sign in to comment.