Example #1
0
        private bool TryGetAutocomplete(string text, string query, out IAutocompleteCollection autocomplete)
        {
            if (Emoji.ContainsSingleEmoji(text) && ViewModel.ComposerHeader?.EditingMessage == null)
            {
                autocomplete = new SearchStickersCollection(ViewModel.ProtoService, ViewModel.Settings, text.Trim());
                return(true);
            }
            else if (SearchByUsername(query, out string username, out int index))
            {
                var chat = ViewModel.Chat;
                if (chat == null)
                {
                    autocomplete = null;
                    return(false);
                }

                var members = true;
                if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeSecret || chat.Type is ChatTypeSupergroup supergroup && supergroup.IsChannel)
                {
                    members = false;
                }

                autocomplete = new UsernameCollection(ViewModel.ProtoService, ViewModel.Chat.Id, username, index == 0, members);
                return(true);
            }
Example #2
0
        private bool TryGetAutocomplete(string text, string query, out IAutocompleteCollection autocomplete)
        {
            if (Emoji.ContainsSingleEmoji(text) && ViewModel.ComposerHeader?.EditingMessage == null)
            {
                var chat = ViewModel.Chat;
                if (chat?.Permissions.CanSendOtherMessages == false)
                {
                    autocomplete = null;
                    return(false);
                }

                if (ViewModel.CacheService.TryGetSupergroup(chat, out Supergroup supergroup))
                {
                    if (supergroup.Status is ChatMemberStatusRestricted restricted && !restricted.Permissions.CanSendOtherMessages)
                    {
                        autocomplete = null;
                        return(false);
                    }
                }

                autocomplete = new SearchStickersCollection(ViewModel.ProtoService, ViewModel.Settings, text.Trim());
                return(true);
            }
            else if (SearchByUsername(query, out string username, out int index))
            {
                var chat = ViewModel.Chat;
                if (chat == null)
                {
                    autocomplete = null;
                    return(false);
                }

                var members = true;
                if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeSecret || chat.Type is ChatTypeSupergroup supergroup && supergroup.IsChannel)
                {
                    members = false;
                }

                autocomplete = new UsernameCollection(ViewModel.ProtoService, ViewModel.Chat.Id, ViewModel.ThreadId, username, index == 0, members);
                return(true);
            }
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint phase)
        {
            return(AsyncInfo.Run(async token =>
            {
                if (phase == 0)
                {
                    var response = await _protoService.SendAsync(new SearchInstalledStickerSets(_masks, _query, 100));
                    if (response is StickerSets sets)
                    {
                        foreach (var item in sets.Sets.Select(x => new StickerSetViewModel(_protoService, _aggregator, x)))
                        {
                            Add(item);
                        }

                        //AddRange(sets.Sets.Select(x => new StickerSetViewModel(_protoService, _aggregator, x)));
                    }
                }
                else if (phase == 1 && _query.Length > 1)
                {
                    if (Emoji.ContainsSingleEmoji(_query))
                    {
                        var response = await _protoService.SendAsync(new GetStickers(_query, 100));
                        if (response is Stickers stickers && stickers.StickersValue.Count > 0)
                        {
                            Add(new StickerSetViewModel(_protoService, _aggregator,
                                                        new StickerSetInfo(0, _query, "emoji", null, false, false, false, false, false, false, stickers.StickersValue.Count, stickers.StickersValue),
                                                        new StickerSet(0, _query, "emoji", null, false, false, false, false, false, false, stickers.StickersValue, new Emojis[0])));
                        }
                    }
                    else
                    {
                        var emojis = await _protoService.SendAsync(new SearchEmojis(_query, false, new[] { _inputLanguage })) as Emojis;
                        if (emojis != null)
                        {
                            for (int i = 0; i < Math.Min(10, emojis.EmojisValue.Count); i++)
                            {
                                var response = await _protoService.SendAsync(new GetStickers(emojis.EmojisValue[i], 100));
                                if (response is Stickers stickers && stickers.StickersValue.Count > 0)
                                {
                                    Add(new StickerSetViewModel(_protoService, _aggregator,
                                                                new StickerSetInfo(0, emojis.EmojisValue[i], "emoji", null, false, false, false, false, false, false, stickers.StickersValue.Count, stickers.StickersValue),
                                                                new StickerSet(0, emojis.EmojisValue[i], "emoji", null, false, false, false, false, false, false, stickers.StickersValue, new Emojis[0])));
                                }
                            }
                        }
                    }
                }
                else if (phase == 2)
                {
                    var response = await _protoService.SendAsync(new SearchStickerSets(_query));
                    if (response is StickerSets sets)
                    {
                        foreach (var item in sets.Sets.Select(x => new StickerSetViewModel(_protoService, _aggregator, x, x.Covers)))
                        {
                            Add(item);
                        }

                        //AddRange(sets.Sets.Select(x => new StickerSetViewModel(_protoService, _aggregator, x)));
                    }
                }

                return new LoadMoreItemsResult();
            }));
        }
Example #4
0
        private async void OnSelectionChanged(object sender, RoutedEventArgs e)
        {
            Document.GetText(TextGetOptions.NoHidden, out string text);

            // This needs to run before text empty check as it cleans up
            // some stuff it inline bot isn't found
            if (SearchInlineBotResults(text, out string inlineQuery))
            {
                ViewModel.Autocomplete = null;
                ViewModel.StickerPack  = null;

                ViewModel.GetInlineBotResults(inlineQuery);
                return;
            }

            if (string.IsNullOrEmpty(text) || Document.Selection.Length != 0)
            {
                ViewModel.StickerPack  = null;
                ViewModel.Autocomplete = null;
                return;
            }

            if (Emoji.ContainsSingleEmoji(text) && ViewModel.ComposerHeader?.EditingMessage == null)
            {
                ViewModel.Autocomplete     = null;
                ViewModel.CurrentInlineBot = null;
                ViewModel.InlineBotResults = null;
                InlinePlaceholderText      = string.Empty;

                ViewModel.StickerPack = new SearchStickersCollection(ViewModel.ProtoService, ViewModel.Settings, text.Trim());
                return;
            }

            var query = text.Substring(0, Math.Min(Document.Selection.EndPosition, text.Length));

            if (TryGetAutocomplete(text, query, out var autocomplete))
            {
                ViewModel.StickerPack      = null;
                ViewModel.CurrentInlineBot = null;
                ViewModel.InlineBotResults = null;
                InlinePlaceholderText      = string.Empty;

                ViewModel.Autocomplete = autocomplete;
            }
            else
            {
                ViewModel.StickerPack  = null;
                ViewModel.Autocomplete = null;

                if (SearchByInlineBot(query, out string username, out int index) && await ViewModel.ResolveInlineBotAsync(username))
                {
                    if (SearchInlineBotResults(text, out query))
                    {
                        ViewModel.StickerPack  = null;
                        ViewModel.Autocomplete = null;

                        ViewModel.GetInlineBotResults(query);
                        return;
                    }
                }

                ViewModel.StickerPack      = null;
                ViewModel.CurrentInlineBot = null;
                ViewModel.InlineBotResults = null;
                InlinePlaceholderText      = string.Empty;
            }
        }