/// <inheritdoc/> public async Task <Message[]> GetChannelMessagesAsync(IBindableMessageChannel channel, ulong?beforeId = null) { var rawMessages = await _quarrelClient.Messages.GetMessagesAsync(channel.Id, channel.GuildId, beforeId); Guard.IsNotNull(rawMessages, nameof(rawMessages)); return(rawMessages); }
/// <summary> /// Initializes a new instance of the <see cref="BindableMessage"/> class. /// </summary> internal BindableMessage( IMessenger messenger, IDiscordService discordService, QuarrelClient quarrelClient, IDispatcherService dispatcherService, IClipboardService clipboardService, IBindableMessageChannel channel, Message message, Message?previousMessage = null) : base(messenger, discordService, quarrelClient, dispatcherService) { _clipboardService = clipboardService; _message = message; _previousMessage = previousMessage; Channel = channel; Users = new Dictionary <ulong, BindableUser?>(); if (message.Author is not null) { var user = _quarrelClient.Users.GetUser(message.Author.Id); Author = user != null ? new BindableUser(_messenger, _discordService, _quarrelClient, _dispatcherService, user) : null; Users.Add(message.Author.Id, Author); if (message.GuildId.HasValue) { AuthorMember = GetGuildMember(message.Author.Id, message.GuildId.Value); } } foreach (var user in _message.Mentions) { if (!Users.ContainsKey(user.Id)) { var mentionedUser = _quarrelClient.Users.GetUser(user.Id); Users.Add(user.Id, mentionedUser != null ? new BindableUser(_messenger, _discordService, _quarrelClient, _dispatcherService, mentionedUser) : null); } } Attachments = new BindableAttachment[_message.Attachments.Length]; for (int i = 0; i < Attachments.Length; i++) { Attachments[i] = new BindableAttachment(messenger, discordService, quarrelClient, 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)); _messenger.Register <MessageUpdatedMessage>(this, (_, e) => { if (Id == e.Message.Id) { _dispatcherService.RunOnUIThread(() => Message = e.Message); } }); _messenger.Register <MessageDeletedMessage>(this, (_, e) => { if (Id == e.MessageId) { _dispatcherService.RunOnUIThread(() => IsDeleted = true); } }); }