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

Commit d4105b2

Browse files
committed
Added AuthorMember to BindableMessage
1 parent 4da93f7 commit d4105b2

File tree

11 files changed

+88
-18
lines changed

11 files changed

+88
-18
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Message : SnowflakeItem, IMessage
1717
internal Message(JsonMessage jsonMessage, QuarrelClient context) :
1818
base(context)
1919
{
20+
GuildId = jsonMessage.GuildId;
2021
Type = jsonMessage.Type;
2122
IsTextToSpeech = jsonMessage.IsTextToSpeech ?? false;
2223
IsPinned = jsonMessage.Pinned ?? false;
@@ -40,6 +41,8 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :
4041
}
4142
}
4243

44+
public ulong? GuildId{ get; private set; }
45+
4346
/// <inheritdoc/>
4447
public MessageType Type { get; private set; }
4548

src/Quarrel.Client/QuarrelClient.Methods.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public partial class QuarrelClient
4141
/// Gets messages in a channel.
4242
/// </summary>
4343
/// <param name="channelId">The channel's id.</param>
44-
public async Task<Message[]> GetMessagesAsync(ulong channelId)
44+
public async Task<Message[]> GetMessagesAsync(ulong channelId, ulong? guildId = null)
4545
{
4646
Guard.IsNotNull(_channelService, nameof(_channelService));
4747

@@ -51,6 +51,7 @@ public async Task<Message[]> GetMessagesAsync(ulong channelId)
5151
Message[] messages = new Message[jsonMessages.Length];
5252
for (int i = 0; i < messages.Length; i++)
5353
{
54+
jsonMessages[i].GuildId = jsonMessages[i].GuildId ?? guildId;
5455
messages[i] = new Message(jsonMessages[i], this);
5556
}
5657

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

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

33
using Quarrel.Bindables.Abstract;
4+
using Quarrel.Bindables.Channels.Interfaces;
45
using Quarrel.Client.Models.Channels;
56
using Quarrel.Client.Models.Channels.Abstract;
67
using Quarrel.Client.Models.Channels.Interfaces;
@@ -15,7 +16,7 @@ namespace Quarrel.Bindables.Channels.Abstract
1516
/// <summary>
1617
/// A wrapper of a <see cref="Client.Models.Channels.Abstract.Channel"/> that can be bound to the UI.
1718
/// </summary>
18-
public abstract partial class BindableChannel : SelectableItem
19+
public abstract partial class BindableChannel : SelectableItem, IBindableChannel
1920
{
2021
private Channel _channel;
2122

@@ -29,14 +30,10 @@ internal BindableChannel(IDiscordService discordService, IDispatcherService disp
2930
_channel.ItemUpdated += AckUpdateRoot;
3031
}
3132

32-
/// <summary>
33-
/// Gets the id of the channel.
34-
/// </summary>
33+
/// <inheritdoc/>
3534
public ulong Id => Channel.Id;
3635

37-
/// <summary>
38-
/// Gets the name of the channel as displayed.
39-
/// </summary>
36+
/// <inheritdoc/>
4037
public virtual string? Name => _channel.Name;
4138

4239
/// <summary>
@@ -65,6 +62,12 @@ private set
6562
}
6663
}
6764

65+
/// <inheritdoc/>
66+
public abstract ulong? GuildId { get; }
67+
68+
/// <inheritdoc/>
69+
public abstract bool IsAccessible { get; }
70+
6871
/// <summary>
6972
/// Invokes property changed for mutable properties when <see cref="Channel.ItemUpdated"/> is invoked.
7073
/// </summary>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ internal BindableGuildChannel(IDiscordService discordService, IDispatcherService
4040
ApplyOverrides(channel.PermissionOverwrites, selfMember);
4141
}
4242

43+
private GuildChannel GuildChannel => (GuildChannel)Channel;
44+
45+
/// <inheritdoc/>
46+
public override ulong? GuildId => GuildChannel.GuildId;
47+
4348
/// <summary>
4449
/// The category the channel belongs to.
4550
/// </summary>
@@ -50,11 +55,6 @@ internal BindableGuildChannel(IDiscordService discordService, IDispatcherService
5055
/// </summary>
5156
public Permissions Permissions { get; private set; }
5257

53-
/// <summary>
54-
/// Gets if the user has permission to open the channel.
55-
/// </summary>
56-
public abstract bool IsAccessible { get; }
57-
5858
/// <summary>
5959
/// Creates a new <see cref="BindableGuildChannel"/> based on the type.
6060
/// </summary>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ internal BindablePrivateChannel(IDiscordService discordService, IDispatcherServi
2323
}
2424

2525
/// <inheritdoc/>
26-
public bool IsAccessible => true;
26+
public override ulong? GuildId => null;
27+
28+
/// <inheritdoc/>
29+
public override bool IsAccessible => true;
2730

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal BindableTextChannel(IDiscordService discordService, IDispatcherService
2828

2929
/// <inheritdoc/>
3030
public IMessageChannel MessageChannel => (IMessageChannel)Channel;
31-
31+
3232
/// <inheritdoc/>
3333
protected override void AckUpdate()
3434
{

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ public interface IBindableChannel
1313
/// Gets the id of the channel.
1414
/// </summary>
1515
public ulong Id { get; }
16-
16+
17+
/// <summary>
18+
/// Gets the id of the guild the channel belongs to, or null if a DM.
19+
/// </summary>
20+
public ulong? GuildId { get; }
21+
22+
/// <summary>
23+
/// Gets the name of the channel as displayed.
24+
/// </summary>
25+
public string? Name { get; }
26+
1727
/// <summary>
1828
/// Gets if the user has permission to open the channel.
1929
/// </summary>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ internal BindableMessage(IDiscordService discordService, IDispatcherService disp
3333
{
3434
Users.Add(user.Id, _discordService.GetUser(user.Id));
3535
}
36+
37+
if (message.GuildId.HasValue)
38+
{
39+
AuthorMember = _discordService.GetGuildMember(message.Author.Id, message.GuildId.Value);
40+
}
3641
}
3742

3843
/// <summary>
3944
/// Gets the author of the message as a bindable user.
4045
/// </summary>
4146
public BindableUser? Author { get; }
4247

48+
public BindableGuildMember? AuthorMember { get; }
49+
4350
public Dictionary<ulong, BindableUser?> Users { get; }
4451
}
4552
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Quarrel © 2022
2+
3+
using Quarrel.Bindables.Abstract;
4+
using Quarrel.Client.Models.Users;
5+
using Quarrel.Services.Discord;
6+
using Quarrel.Services.Dispatcher;
7+
8+
namespace Quarrel.Bindables.Users
9+
{
10+
public class BindableGuildMember : BindableItem
11+
{
12+
private GuildMember _guildMember;
13+
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="BindableGuildMember"/> class.
16+
/// </summary>
17+
internal BindableGuildMember(IDiscordService discordService, IDispatcherService dispatcherService, GuildMember guildMember) :
18+
base(discordService, dispatcherService)
19+
{
20+
_guildMember = guildMember;
21+
}
22+
23+
public GuildMember GuildMember
24+
{
25+
get => _guildMember;
26+
set => SetProperty(ref _guildMember, value);
27+
}
28+
}
29+
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public BindableGuildFolder[] GetMyGuildFolders()
7070

7171
return folders;
7272
}
73-
73+
7474
/// <inheritdoc/>
7575
public async Task<BindableMessage[]> GetChannelMessagesAsync(IBindableMessageChannel channel)
7676
{
77-
var rawMessages = await _quarrelClient.GetMessagesAsync(channel.Id);
77+
var rawMessages = await _quarrelClient.GetMessagesAsync(channel.Id, channel.GuildId);
7878
Guard.IsNotNull(rawMessages, nameof(rawMessages));
7979
BindableMessage[] messages = new BindableMessage[rawMessages.Length];
8080
for (int i = 0; i < messages.Length; i++)
@@ -169,5 +169,17 @@ public async Task<BindableMessage[]> GetChannelMessagesAsync(IBindableMessageCha
169169

170170
return channels;
171171
}
172+
173+
/// <inheritdoc/>
174+
public BindableGuildMember? GetGuildMember(ulong userId, ulong guildId)
175+
{
176+
var member = _quarrelClient.GetGuildMember(userId, guildId);
177+
if (member is not null)
178+
{
179+
return new BindableGuildMember(this, _dispatcherService, member);
180+
}
181+
182+
return null;
183+
}
172184
}
173185
}

0 commit comments

Comments
 (0)