/// <summary> /// Initializes a new instance of the <see cref="BindableChannel"/> class. /// </summary> internal BindableChannel( IMessenger messenger, IClipboardService clipboardService, IDiscordService discordService, QuarrelClient quarrelClient, IDispatcherService dispatcherService, Channel channel) : base(messenger, discordService, quarrelClient, dispatcherService) { _clipboardService = clipboardService; _channel = channel; _messenger.Register <ChannelUpdatedMessage>(this, (_, m) => { if (Id == m.Channel.Id) { Channel = m.Channel; } }); _messenger.Register <MessageMarkedReadMessage>(this, (_, m) => { if (m.ChannelId != Channel.Id) { return; } AckUpdateRoot(); }); CopyIdCommand = new RelayCommand(() => _clipboardService.Copy($"{Id}")); CopyLinkCommand = new RelayCommand(() => _clipboardService.Copy(Channel.Url)); }
/// <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); } }); }