Esempio n. 1
0
        internal DirectChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, settings, context)
        {
            Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients));

            RecipientId = restChannel.Recipients[0].Id;
        }
        internal MyAccountPageViewModel(
            ILocalizationService localizationService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IStorageService storageService,
            IClipboardService clipboardService) :
            base(localizationService, discordService, storageService)
        {
            _quarrelClient    = quarrelClient;
            _clipboardService = clipboardService;

            _isLoggedIn = false;
            _userId     = null;

            SelfUser?user = _quarrelClient.Self.CurrentUser;


            if (user is not null)
            {
                _isLoggedIn = true;
                _userId     = user.Id;

                Email         = new DraftValue <string?>(user.Email);
                Username      = new DraftValue <string?>(user.Username);
                Discriminator = new DraftValue <int>(user.Discriminator);
                AboutMe       = new DraftValue <string?>(user.Bio);

                RegisterDraftValues(AboutMe);
            }

            CopyIdCommand = new RelayCommand(CopyId);
        }
        internal BindableGuildChannel(
            IMessenger messenger,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            GuildChannel channel,
            GuildMember selfMember,
            BindableCategoryChannel?parent = null) :
            base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, channel)
        {
            CategoryChannel = parent;

            if (CategoryChannel is null)
            {
                Permissions = new Permissions();
                var roles = selfMember.GetRoles();
                foreach (var role in roles)
                {
                    Permissions += role.Permissions;
                }
            }
            else
            {
                Permissions = CategoryChannel.Permissions;
            }

            Guard.IsNotNull(channel.PermissionOverwrites, nameof(channel.PermissionOverwrites));
            ApplyOverrides(channel.PermissionOverwrites, selfMember);
        }
Esempio n. 4
0
 internal Channel(JsonChannel restChannel, QuarrelClient context) :
     base(context)
 {
     Id   = restChannel.Id;
     Name = restChannel.Name;
     Type = restChannel.Type;
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GuildsViewModel"/> class.
        /// </summary>
        public GuildsViewModel(
            ILoggingService loggingService,
            IMessenger messenger,
            ILocalizationService localizationService,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService)
        {
            _loggingService      = loggingService;
            _messenger           = messenger;
            _localizationService = localizationService;
            _clipboardService    = clipboardService;
            _discordService      = discordService;
            _quarrelClient       = quarrelClient;
            _dispatcherService   = dispatcherService;

            Source  = new ObservableCollection <IBindableGuildListItem>();
            _guilds = new ConcurrentDictionary <ulong, BindableGuild>();

            OpenGuildSettingsCommand = new RelayCommand(OpenGuildSettings);

            _messenger.Register <UserLoggedInMessage>(this, (_, _) => LoadGuilds());
            _messenger.Register <SelectGuildMessage <ulong> >(this, (_, m) => SelectGuildById(m.Guild));
            _messenger.Register <SelectGuildMessage <IBindableSelectableGuildItem> >(this, (_, m) => SelectedGuild = m.Guild);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindableVoiceState"/> class.
        /// </summary>
        internal BindableVoiceState(
            IMessenger messenger,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            VoiceState state) :
            base(messenger, discordService, quarrelClient, dispatcherService)
        {
            _state = state;

            JoinStreamCommand = new RelayCommand(JoinStream);

            _messenger.Register <VoiceStateUpdatedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.User.Id == State.User.Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        OnPropertyChanged(nameof(State));
                        OnPropertyChanged(nameof(CanJoin));
                    });
                }
            });
            _messenger.Register <StreamCreatedMessage>(this, (_, m) =>
            {
                if (m.StreamKey.EndsWith(State.User.Id.ToString()))
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        IsWatching = true;
                    });
                }
            });
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessagesViewModel"/> class.
        /// </summary>
        public MessagesViewModel(
            IMessenger messenger,
            IDiscordService discordService,
            IDispatcherService dispatcherService,
            IClipboardService clipboardService,
            QuarrelClient quarrelClient)
        {
            _messenger         = messenger;
            _discordService    = discordService;
            _dispatcherService = dispatcherService;
            _clipboardService  = clipboardService;
            _quarrelClient     = quarrelClient;
            _semaphore         = new SemaphoreSlim(1, 1);

            Source    = new ObservableRangeCollection <BindableMessage>();
            IsLoading = false;

            _messenger.Register <ChannelSelectedMessage <IBindableSelectableChannel> >(this, (_, m) => SelectedChannel = m.Channel);
            _messenger.Register <MessageCreatedMessage>(this, (_, m) =>
            {
                if (SelectedChannel?.Id != m.Message.ChannelId)
                {
                    return;
                }
                _dispatcherService.RunOnUIThread(() => AppendMessage(m.Message));
            });
            _messenger.Register <MessageDeletedMessage>(this, (_, m) =>
            {
                if (SelectedChannel?.Id != m.ChannelId)
                {
                    return;
                }
                _dispatcherService.RunOnUIThread(() => RemoveMessage(m.MessageId));
            });
        }
Esempio n. 8
0
        /// <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));
        }
Esempio n. 9
0
 internal GuildFolder(JsonGuildFolder jsonGuildFolder, QuarrelClient context) :
     base(context)
 {
     Id       = jsonGuildFolder.Id;
     Name     = jsonGuildFolder.Name;
     Color    = jsonGuildFolder.Color;
     GuildIds = jsonGuildFolder.GuildIds;
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectableItem"/> class.
 /// </summary>
 public SelectableItem(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
 }
Esempio n. 11
0
 internal BindableAttachment(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     Attachment attachment) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     _attachment = attachment;
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindableSelfUser"/> class.
 /// </summary>
 internal BindableSelfUser(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     SelfUser selfUser) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     _selfUser = selfUser;
 }
Esempio n. 13
0
        internal PrivateChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, context)
        {
            LastMessageId = restChannel.LastMessageId;
            RTCRegion     = restChannel.RTCRegion;

            IsMuted = settings?.Muted ?? false;

            _users = new HashSet <ulong>();
        }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindableGuildMember"/> class.
 /// </summary>
 internal BindableGuildMember(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     GuildMember guildMember) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     _guildMember = guildMember;
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindableUser"/> class.
 /// </summary>
 internal BindableUser(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     User user) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     _user = user;
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new isntance of the <see cref="BindableHomeItem"/> class.
 /// </summary>
 public BindableHomeItem(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     ILocalizationService localizationService) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     _localizationService = localizationService;
 }
Esempio n. 17
0
        internal GroupChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, settings, context)
        {
            Guard.IsNotNull(restChannel.OwnerId, nameof(restChannel.OwnerId));
            Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients));

            OwnerId = restChannel.OwnerId.Value;

            Recipients = restChannel.Recipients.Select(x => new User(x, context)).ToArray();
            Icon       = restChannel.Icon;
        }
Esempio n. 18
0
 internal Attachment(JsonAttachment jsonAttachment, QuarrelClient context) :
     base(context)
 {
     Id       = jsonAttachment.Id;
     Filename = jsonAttachment.Filename;
     Size     = jsonAttachment.Size;
     Url      = jsonAttachment.Url;
     ProxyUrl = jsonAttachment.ProxyUrl;
     Height   = jsonAttachment.Height;
     Width    = jsonAttachment.Width;
 }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindableItem"/> class.
 /// </summary>
 public BindableItem(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService)
 {
     _messenger         = messenger;
     _discordService    = discordService;
     _quarrelClient     = quarrelClient;
     _dispatcherService = dispatcherService;
 }
Esempio n. 20
0
 internal BindableChannelGroup(
     IMessenger messenger,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     BindableCategoryChannel?key) :
     base(messenger, discordService, quarrelClient, dispatcherService)
 {
     Key      = key;
     Children = new ObservableCollection <BindableChannel>();
 }
 internal BindableCategoryChannel(
     IMessenger messenger,
     IClipboardService clipboardService,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     CategoryChannel channel,
     GuildMember selfMember) :
     base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, channel, selfMember)
 {
 }
Esempio n. 22
0
 internal Role(JsonRole jsonRole, QuarrelClient context) :
     base(context)
 {
     Id            = jsonRole.Id;
     Name          = jsonRole.Name;
     Position      = jsonRole.Position;
     Icon          = jsonRole.Icon;
     Permissions   = (Permission)jsonRole.Permissions;
     IsHoisted     = jsonRole.Hoist;
     IsManaged     = jsonRole.Managed;
     IsMentionable = jsonRole.Mentionable;
 }
Esempio n. 23
0
        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));
                    });
                }
            });
        }
Esempio n. 24
0
        internal SelfUser(JsonUser restUser, QuarrelClient context) :
            base(restUser, context)
        {
            Guard.IsNotNull(restUser.PurchasedFlags, nameof(restUser.PurchasedFlags));

            Email          = restUser.Email;
            Phone          = restUser.Phone;
            Verified       = restUser.Verified;
            MfaEnabled     = restUser.MfaEnabled;
            NSFWAllowed    = restUser.NSFWAllowed;
            PurchasedFlags = restUser.PurchasedFlags.Value;
            Locale         = restUser.Locale;
        }
Esempio n. 25
0
 /// <summary>
 /// Creates a new <see cref="BindableGuildChannel"/> based on the type.
 /// </summary>
 /// <param name="messenger">The <see cref="IMessenger"/> to pass to the <see cref="BindableItem"/>.</param>
 /// <param name="clipboardService">The <see cref="IClipboardService"/> to pass to the <see cref="BindableItem"/>.</param>
 /// <param name="discordService">The <see cref="IDiscordService"/> to pass to the <see cref="BindableItem"/>.</param>
 /// <param name="localizationService">The <see cref="ILocalizationService"/> to pass to the <see cref="BindableItem"/>.</param>
 /// <param name="dispatcherService">The <see cref="IDispatcherService"/> to pass to the <see cref="BindableItem"/>.</param>
 /// <param name="channel">The channel to wrap.</param>
 /// <param name="member">The current user's guild member for the channel's guild.</param>
 /// <param name="parent">The channel's parent category.</param>
 public static BindableGuildChannel?Create(
     IMessenger messenger,
     IClipboardService clipboardService,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     ILocalizationService localizationService,
     IDispatcherService dispatcherService,
     IGuildChannel channel,
     GuildMember member,
     BindableCategoryChannel?parent = null)
 {
     return(BindableChannel.Create(messenger, clipboardService, discordService, quarrelClient, localizationService, dispatcherService, channel, member, parent) as BindableGuildChannel);
 }
        internal BindableDirectChannel(
            IMessenger messenger,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            DirectChannel directChannel) :
            base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, directChannel)
        {
            var user = _quarrelClient.Users.GetUser(DirectChannel.RecipientId);

            Guard.IsNotNull(user);
            Recipient = new BindableUser(_messenger, _discordService, _quarrelClient, _dispatcherService, user);
        }
Esempio n. 27
0
 internal BindableTextChannel(
     IMessenger messenger,
     IClipboardService clipboardService,
     IDiscordService discordService,
     QuarrelClient quarrelClient,
     IDispatcherService dispatcherService,
     GuildTextChannel channel,
     GuildMember selfMember,
     BindableCategoryChannel?parent = null) :
     base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, channel, selfMember, parent)
 {
     SelectionCommand  = new RelayCommand(Select);
     MarkAsReadCommand = new RelayCommand(MarkRead);
 }
Esempio n. 28
0
        internal GuildChannel(JsonChannel restChannel, ulong?guildId, QuarrelClient context) :
            base(restChannel, context)
        {
            guildId = restChannel.GuildId ?? guildId;
            Guard.IsNotNull(restChannel.Position, nameof(restChannel.Position));
            Guard.IsNotNull(guildId, nameof(guildId));

            Position = restChannel.Position.Value;
            GuildId  = guildId.Value;

            if (restChannel.PermissionOverwrites is not null)
            {
                PermissionOverwrites = CreateOverwrites(restChannel.PermissionOverwrites);
            }
        }
Esempio n. 29
0
 internal User(JsonUser restUser, QuarrelClient context) :
     base(context)
 {
     Id            = restUser.Id;
     Username      = restUser.Username;
     Discriminator = int.Parse(restUser.Discriminator);
     Avatar        = restUser.Avatar;
     Bio           = restUser.Bio;
     Banner        = restUser.Banner;
     BannerColor   = restUser.BannerColor;
     AccentColor   = restUser.AccentColor;
     Bot           = restUser.Bot;
     Flags         = restUser.Flags;
     PublicFlags   = restUser.PublicFlags;
 }
Esempio n. 30
0
        internal BindableGuild(
            IMessenger messenger,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            IClipboardService clipboardService,
            ILocalizationService localizationService,
            Guild guild) :
            base(messenger, discordService, quarrelClient, dispatcherService)
        {
            _clipboardService    = clipboardService;
            _localizationService = localizationService;

            _guild = guild;
        }