internal BindableVoiceChannel(
            IMessenger messenger,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            VoiceChannel channel,
            GuildMember selfMember,
            BindableCategoryChannel?parent = null) :
            base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, channel, selfMember, parent)
        {
            SelectionCommand  = new RelayCommand(Select);
            OpenChatCommand   = new RelayCommand(OpenChat);
            JoinCallCommand   = new RelayCommand(JoinCall);
            MarkAsReadCommand = new RelayCommand(MarkRead);

            VoiceMembers = new ObservableCollection <BindableVoiceState>(
                channel.GetVoiceStates()
                .Select(x => new BindableVoiceState(messenger, discordService, quarrelClient, dispatcherService, x)));

            _messenger.Register <MyVoiceStateUpdatedMessage>(this, (_, m) =>
            {
                IsConnected = m.VoiceState.Channel?.Id == Id;
            });
            _messenger.Register <VoiceStateAddedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        var state = new BindableVoiceState(
                            _messenger,
                            _discordService,
                            _quarrelClient,
                            _dispatcherService,
                            m.VoiceState);

                        VoiceMembers.Add(state);
                    });
                }
            });
            _messenger.Register <VoiceStateRemovedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        VoiceMembers.Remove(VoiceMembers.FirstOrDefault(x =>
                                                                        x.State.User?.Id == m.VoiceState.User?.Id));
                    });
                }
            });
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VoiceControllerViewModel"/> class.
        /// </summary>
        public VoiceControllerViewModel(IMessenger messenger, IDiscordService discordService, QuarrelClient quarrelClient, IDispatcherService dispatcherService)
        {
            _messenger         = messenger;
            _discordService    = discordService;
            _quarrelClient     = quarrelClient;
            _dispatcherService = dispatcherService;

            _messenger.Register <MyVoiceStateUpdatedMessage>(this, (_, m) =>
            {
                var state = new BindableVoiceState(
                    _messenger,
                    _discordService,
                    _quarrelClient,
                    _dispatcherService,
                    m.VoiceState);

                _dispatcherService.RunOnUIThread(() => VoiceState = state);
            });

            HangupCommand = new RelayCommand(Hangup);
        }