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

Commit 628ec76

Browse files
authored
Merge pull request #604 from UWPCommunity/rewrite/main
Alpha release
2 parents 3f4b131 + 150267e commit 628ec76

38 files changed

+196
-60
lines changed

src/Quarrel.Client/QuarrelClient.Methods.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,24 @@ public IPrivateChannel[] GetPrivateChannels()
136136
}
137137
}
138138

139+
// Nullability is improperly accessed here
140+
#pragma warning disable CS8629
139141
Array.Resize(ref privateChannels, i);
140142
Array.Sort(privateChannels, Comparer<IPrivateChannel>.Create((item1, item2) =>
141143
{
142-
if (!item2.LastMessageId.HasValue) return -1;
143-
if (!item1.LastMessageId.HasValue) return 1;
144+
bool i1Null = !item1.LastMessageId.HasValue;
145+
bool i2Null = !item2.LastMessageId.HasValue;
146+
147+
if (i1Null && i2Null) return 0;
148+
if (i2Null) return -1;
149+
if (i1Null) return 1;
144150

145151
long compare = (long)item2.LastMessageId.Value - (long)item1.LastMessageId.Value;
146152
if (compare < 0) return -1;
147153
if (compare > 0) return 1;
148154
return 0;
149155
}));
156+
#pragma warning restore CS8629
150157

151158
return privateChannels;
152159
}

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

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

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

49+
/// <inheritdoc/>
50+
public ChannelType Type => Channel.Type;
51+
4852
/// <inheritdoc/>
4953
public virtual string? Name => _channel.Name;
5054

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ internal BindableTextChannel(
3535

3636
/// <inheritdoc/>
3737
public IMessageChannel MessageChannel => (IMessageChannel)Channel;
38+
39+
/// <inheritdoc/>
40+
public GuildTextChannel TextChannel => (GuildTextChannel)Channel;
3841

3942
/// <inheritdoc/>
4043
protected override void AckUpdate()

src/Quarrel.ViewModels/Bindables/Channels/Interfaces/IBindableChannel.cs

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

3+
using Discord.API.Models.Enums.Channels;
34
using Quarrel.Client.Models.Channels.Interfaces;
45

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

18+
/// <summary>
19+
/// Gets the channel type.
20+
/// </summary>
21+
public ChannelType Type { get; }
22+
1723
/// <summary>
1824
/// Gets the id of the guild the channel belongs to, or null if a DM.
1925
/// </summary>

src/Quarrel.ViewModels/Services/Analytics/Enums/LoggedEvent.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public enum LoggedEvent
2121
/// </summary>
2222
[StringValue("Message Sent")]
2323
MessageSent,
24+
25+
/// <summary>
26+
/// Opened a channel.
27+
/// </summary>
28+
[StringValue("Guild Opened")]
29+
GuildOpened,
30+
31+
/// <summary>
32+
/// Opened a channel.
33+
/// </summary>
34+
[StringValue("Channel Opened")]
35+
ChannelOpened,
2436
#endregion
2537

2638
#region Login

src/Quarrel.ViewModels/ViewModels/Panels/ChannelsViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
using Quarrel.Bindables.Channels.Interfaces;
77
using Quarrel.Bindables.Guilds.Interfaces;
88
using Quarrel.Messages.Navigation;
9+
using Quarrel.Services.Analytics;
10+
using Quarrel.Services.Analytics.Enums;
911
using Quarrel.Services.Discord;
12+
using System;
1013
using System.Collections.Generic;
1114

1215
namespace Quarrel.ViewModels.Panels
@@ -16,6 +19,7 @@ namespace Quarrel.ViewModels.Panels
1619
/// </summary>
1720
public partial class ChannelsViewModel : ObservableRecipient
1821
{
22+
private readonly IAnalyticsService _analyticsService;
1923
private readonly IMessenger _messenger;
2024
private readonly IDiscordService _discordService;
2125

@@ -27,8 +31,9 @@ public partial class ChannelsViewModel : ObservableRecipient
2731
/// <summary>
2832
/// Initializes a new instance of the <see cref="ChannelsViewModel"/> class.
2933
/// </summary>
30-
public ChannelsViewModel(IMessenger messenger, IDiscordService discordService)
34+
public ChannelsViewModel(IAnalyticsService analyticsService, IMessenger messenger, IDiscordService discordService)
3135
{
36+
_analyticsService = analyticsService;
3237
_messenger = messenger;
3338
_discordService = discordService;
3439

@@ -55,6 +60,10 @@ public IBindableSelectableChannel? SelectedChannel
5560
{
5661
value.IsSelected = true;
5762
_currentGuild.SelectedChannelId = value.Id;
63+
64+
_analyticsService.Log(LoggedEvent.ChannelOpened,
65+
("Type", $"{_selectedChannel.Type}"));
66+
5867
_messenger.Send(new NavigateToChannelMessage<IBindableSelectableChannel>(value));
5968
}
6069
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Quarrel © 2022
2+
3+
using Microsoft.Toolkit.Mvvm.ComponentModel;
4+
using Microsoft.Toolkit.Mvvm.Messaging;
5+
using Quarrel.Bindables.Channels.Interfaces;
6+
using Quarrel.Messages.Navigation;
7+
using Quarrel.Services.Analytics;
8+
using Quarrel.Services.Discord;
9+
10+
namespace Quarrel.ViewModels.Panels
11+
{
12+
public class CommandBarViewModel : ObservableRecipient
13+
{
14+
private readonly IAnalyticsService _analyticsService;
15+
private readonly IMessenger _messenger;
16+
private readonly IDiscordService _discordService;
17+
18+
private IBindableSelectableChannel? _selectedChannel;
19+
20+
public CommandBarViewModel(IAnalyticsService analyticsService, IMessenger messenger, IDiscordService discordService)
21+
{
22+
_analyticsService = analyticsService;
23+
_messenger = messenger;
24+
_discordService = discordService;
25+
26+
_messenger.Register<NavigateToChannelMessage<IBindableSelectableChannel>>(this, (_, m) => SelectedChannel = m.Channel);
27+
}
28+
29+
public IBindableSelectableChannel? SelectedChannel
30+
{
31+
get => _selectedChannel;
32+
set => SetProperty(ref _selectedChannel, value);
33+
}
34+
}
35+
}

src/Quarrel.ViewModels/ViewModels/Panels/GuildsViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Quarrel.Bindables.Guilds.Interfaces;
77
using Quarrel.Messages;
88
using Quarrel.Messages.Navigation;
9+
using Quarrel.Services.Analytics;
10+
using Quarrel.Services.Analytics.Enums;
911
using Quarrel.Services.Discord;
1012
using Quarrel.Services.Dispatcher;
1113
using Quarrel.Services.Localization;
@@ -19,6 +21,7 @@ namespace Quarrel.ViewModels
1921
/// </summary>
2022
public partial class GuildsViewModel : ObservableRecipient
2123
{
24+
private readonly IAnalyticsService _analyticsService;
2225
private readonly IMessenger _messenger;
2326
private readonly ILocalizationService _localizationService;
2427
private readonly IDiscordService _discordService;
@@ -30,8 +33,9 @@ public partial class GuildsViewModel : ObservableRecipient
3033
/// <summary>
3134
/// Initializes a new instance of the <see cref="GuildsViewModel"/> class.
3235
/// </summary>
33-
public GuildsViewModel(IMessenger messenger, ILocalizationService localizationService, IDiscordService discordService, IDispatcherService dispatcherService)
36+
public GuildsViewModel(IAnalyticsService analyticsService, IMessenger messenger, ILocalizationService localizationService, IDiscordService discordService, IDispatcherService dispatcherService)
3437
{
38+
_analyticsService = analyticsService;
3539
_messenger = messenger;
3640
_localizationService = localizationService;
3741
_discordService = discordService;
@@ -58,6 +62,7 @@ public IBindableSelectableGuildItem? SelectedGuild
5862
if (SetProperty(ref _selectedGuild, value) && value is not null)
5963
{
6064
value.IsSelected = true;
65+
_analyticsService.Log(LoggedEvent.GuildOpened);
6166
_messenger.Send(new NavigateToGuildMessage<IBindableSelectableGuildItem>(value));
6267
}
6368
}

src/Quarrel.ViewModels/ViewModels/Panels/MessageBoxViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Quarrel.Messages.Navigation;
88
using Quarrel.Services.Discord;
99
using Quarrel.Services.Dispatcher;
10-
using System.Collections.Generic;
1110

1211
namespace Quarrel.ViewModels.Panels
1312
{

src/Quarrel.ViewModels/ViewModels/Panels/MessagesViewModel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
using Quarrel.Messages.Navigation;
1111
using Quarrel.Services.Discord;
1212
using Quarrel.Services.Dispatcher;
13-
using System.Collections.Generic;
1413
using System.Collections.ObjectModel;
15-
using System.Linq;
1614

1715
namespace Quarrel.ViewModels.Panels
1816
{
@@ -96,10 +94,13 @@ private void LoadInitialMessages(IBindableMessageChannel? channel)
9694
// Load messages
9795
var messages = await _discordService.GetChannelMessagesAsync(channel);
9896
BindableMessage[] bindableMessages = new BindableMessage[messages.Length];
99-
bindableMessages[0] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length-1]);
100-
for (int i = 1; i < messages.Length; i++)
97+
if (bindableMessages.Length > 0)
10198
{
102-
bindableMessages[i] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length-1-i], messages[messages.Length-i]);
99+
bindableMessages[0] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length - 1]);
100+
for (int i = 1; i < messages.Length; i++)
101+
{
102+
bindableMessages[i] = new BindableMessage(_messenger, _discordService, _dispatcherService, messages[messages.Length - 1 - i], messages[messages.Length - i]);
103+
}
103104
}
104105

105106
// Add messages to the UI and mark loading as finished

0 commit comments

Comments
 (0)