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

Commit

Permalink
Added mark as read commands to BindableMessage and IBindableMessageCh…
Browse files Browse the repository at this point in the history
…annels
  • Loading branch information
Avid29 committed May 21, 2022
1 parent 67eab9a commit 51adea1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Abstract;
using Quarrel.Bindables.Channels.Interfaces;
Expand All @@ -26,6 +27,7 @@ internal BindablePrivateChannel(
PrivateChannel privateChannel) :
base(messenger, discordService, dispatcherService, privateChannel)
{
MarkAsReadCommand = new RelayCommand(() => _discordService.MarkRead(Id, MessageChannel.LastMessageId ?? 0));
}

/// <inheritdoc/>
Expand All @@ -37,6 +39,9 @@ internal BindablePrivateChannel(
/// <inheritdoc/>
public IMessageChannel MessageChannel => (IMessageChannel)Channel;

/// <inheritdoc/>
public RelayCommand MarkAsReadCommand { get; }

/// <summary>
/// Creates a new instance of a <see cref="BindablePrivateChannel"/> based on the type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Channels.Abstract;
using Quarrel.Bindables.Channels.Interfaces;
Expand All @@ -25,6 +26,7 @@ internal BindableTextChannel(
BindableCategoryChannel? parent = null) :
base(messenger, discordService, dispatcherService, channel, selfMember, parent)
{
MarkAsReadCommand = new RelayCommand(() => _discordService.MarkRead(MessageChannel.Id, MessageChannel.LastMessageId ?? 0));
}

/// <inheritdoc/>
Expand All @@ -39,6 +41,9 @@ internal BindableTextChannel(
/// <inheritdoc/>
public GuildTextChannel TextChannel => (GuildTextChannel)Channel;

/// <inheritdoc/>
public RelayCommand MarkAsReadCommand { get; }

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

using Microsoft.Toolkit.Mvvm.Input;
using Quarrel.Client.Models.Channels.Interfaces;

namespace Quarrel.Bindables.Channels.Interfaces
Expand All @@ -13,5 +14,10 @@ public interface IBindableMessageChannel : IBindableSelectableChannel
/// Gets the wrapped <see cref="IMessageChannel"/>.
/// </summary>
IMessageChannel MessageChannel { get; }

/// <summary>
/// Gets a command that marks the channel as read.
/// </summary>
RelayCommand MarkAsReadCommand { get; }
}
}
6 changes: 6 additions & 0 deletions src/Quarrel.ViewModels/Bindables/Messages/BindableMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal BindableMessage(
Attachments[i] = new BindableAttachment(messenger, discordService, dispatcherService, _message.Attachments[i]);
}

MarkLastReadCommand = new RelayCommand(() => _discordService.MarkRead(ChannelId, Id));
CopyIdCommand = new RelayCommand(() => _clipboardService.Copy($"{Id}"));
CopyLinkCommand = new RelayCommand(() => _clipboardService.Copy($"{message.MessageUri}"));
DeleteCommand = new RelayCommand(() => _discordService.DeleteMessage(ChannelId, Id));
Expand Down Expand Up @@ -169,6 +170,11 @@ _message.Type is MessageType.ApplicationCommand or MessageType.ContextMenuComman
// TODO: Properly handle deletable condition
public bool CanDelete => Message.IsOwn;

/// <summary>
/// Gets a command that marks the message as the last read message in the channel.
/// </summary>
public RelayCommand MarkLastReadCommand { get; }

/// <summary>
/// Gets a command that copies the message id to the clipboard.
/// </summary>
Expand Down

0 comments on commit 51adea1

Please sign in to comment.