Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindableGuildMember"/> class.
        /// </summary>
        /// <param name="model">The base <see cref="GuildMember"/> object.</param>
        /// <param name="guildId">The Guild for the member.</param>
        /// <param name="presence">The presence of the user.</param>
        public BindableGuildMember([NotNull] GuildMember model, string guildId, Presence presence = null) : base(model)
        {
            if (model == null)
            {
                return;
            }

            GuildId = guildId;

            if (presence != null)
            {
                Presence = presence;
            }
            else
            {
                Presence = new Presence()
                {
                    User    = model.User,
                    Status  = "offline",
                    GuildId = guildId,
                };
            }

            Messenger.Default.Register <GatewayPresenceUpdatedMessage>(this, m =>
            {
                DispatcherHelper.CheckBeginInvokeOnUi(() =>
                {
                    if (m.UserId == Model.User.Id)
                    {
                        Presence = m.Presence;
                    }
                });
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindableChannel"/> class.
        /// </summary>
        /// <param name="model">API Channel Model.</param>
        /// <param name="guildId">Id of Channel's guild.</param>
        /// <param name="states">List of VoiceStates for users in a voice channel.</param>
        public BindableChannel([NotNull] Channel model, [CanBeNull] IEnumerable<VoiceState> states = null) : base(model)
        {
            MessengerInstance.Register<GatewayUserGuildSettingsUpdatedMessage>(this, m =>
            {
                if ((m.Settings.GuildId ?? "DM") == GuildId)
                {
                    DispatcherHelper.CheckBeginInvokeOnUi(() =>
                    {
                        // Updated channel settings
                        ChannelOverride channelOverride = ChannelsService.GetChannelSettings(Model.Id);
                        if (channelOverride != null)
                        {
                            Muted = channelOverride.Muted;
                        }
                    });
                }
            });

            MessengerInstance.Register<SettingChangedMessage<bool>>(this, m =>
            {
                if (m.Key == SettingKeys.ShowNoPermssions)
                {
                    RaisePropertyChanged(nameof(Hidden));
                }
            });

            MessengerInstance.Register<SettingChangedMessage<CollapseOverride>>(this, m =>
            {
                if (m.Key == SettingKeys.CollapseOverride)
                {
                    RaisePropertyChanged(nameof(Hidden));
                }
            });

            MessengerInstance.Register<SpeakMessage>(this, e =>
            {
                if (e.EventData.UserId != null && ConnectedUsers.ContainsKey(e.EventData.UserId))
                {
                    DispatcherHelper.CheckBeginInvokeOnUi(() => { ConnectedUsers[e.EventData.UserId].Speaking = e.EventData.Speaking > 0; });
                }
            });

            MessengerInstance.Register<GatewayVoiceStateUpdateMessage>(this, m =>
            {
                DispatcherHelper.CheckBeginInvokeOnUi(() =>
                {
                    if (m.VoiceState.ChannelId == Model.Id)
                    {
                        if (ConnectedUsers.ContainsKey(m.VoiceState.UserId))
                        {
                            ConnectedUsers[m.VoiceState.UserId].Model = m.VoiceState;
                            ConnectedUsers[m.VoiceState.UserId].UpateProperties();
                        }
                        else
                        {
                            ConnectedUsers.Add(m.VoiceState.UserId, new BindableVoiceUser(m.VoiceState));
                        }
                    }
                    else if (ConnectedUsers.ContainsKey(m.VoiceState.UserId))
                    {
                        ConnectedUsers.Remove(m.VoiceState.UserId);
                    }
                });
            });

            if (states != null)
            {
                foreach (var state in states)
                {
                    if (state.ChannelId == Model.Id)
                    {
                        state.GuildId = GuildId;
                        ConnectedUsers.Add(state.UserId, new BindableVoiceUser(state));
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindableGuild"/> class.
        /// </summary>
        /// <param name="model">The base <see cref="Guild"/> object.</param>
        public BindableGuild([NotNull] Guild model) : base(model)
        {
            _channels = new ObservableCollection <BindableChannel>();

            MessengerInstance.Register <GatewayGuildUpdatedMessage>(this, m =>
            {
                if (m.Guild.Id == Model.Id)
                {
                    DispatcherHelper.CheckBeginInvokeOnUi(() =>
                    {
                        Model = m.Guild;
                        RaisePropertyChanged(nameof(DisplayText));
                        RaisePropertyChanged(nameof(HasIcon));
                        RaisePropertyChanged(nameof(IconUrl));
                    });
                }
            });

            MessengerInstance.Register <GatewayMessageRecievedMessage>(this, m =>
            {
                DispatcherHelper.CheckBeginInvokeOnUi(() =>
                {
                    RaisePropertyChanged(nameof(NotificationCount));
                    RaisePropertyChanged(nameof(IsUnread));
                    RaisePropertyChanged(nameof(ShowUnread));
                });
            });

            MessengerInstance.Register <GatewayMessageAckMessage>(this, m =>
            {
                DispatcherHelper.CheckBeginInvokeOnUi(() =>
                {
                    RaisePropertyChanged(nameof(NotificationCount));
                    RaisePropertyChanged(nameof(IsUnread));
                    RaisePropertyChanged(nameof(ShowUnread));
                });
            });

            MessengerInstance.Register <GatewayUserGuildSettingsUpdatedMessage>(this, m =>
            {
                if ((m.Settings.GuildId ?? "DM") == Model.Id)
                {
                    DispatcherHelper.CheckBeginInvokeOnUi(() =>
                    {
                        GuildSetting guildSetting = GuildsService.GetGuildSetting(Model.Id);
                        if (guildSetting != null)
                        {
                            IsMuted = guildSetting.Muted;
                        }
                    });
                }
            });

            MessengerInstance.Register <SettingChangedMessage <bool> >(this, m =>
            {
                if (m.Key == SettingKeys.ServerMuteIcons)
                {
                    RaisePropertyChanged(nameof(ShowMute));
                }
            });
        }