Beispiel #1
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            //if (mode == NavigationMode.New)
            //{
            //    _dialogs = null;
            //}

            //var response = await ProtoService.SendAsync(new GetChats(new ChatListMain(), long.MaxValue, 0, int.MaxValue));
            var response = await ProtoService.GetChatListAsync(new ChatListMain(), 0, 200);

            if (response is Telegram.Td.Api.Chats chats)
            {
                var list = ProtoService.GetChats(chats.ChatIds);
                Items.Clear();

                if (_searchType == SearchChatsType.Post || _searchType == SearchChatsType.All)
                {
                    var myId = CacheService.Options.MyId;
                    var self = list.FirstOrDefault(x => x.Type is ChatTypePrivate privata && privata.UserId == myId);
                    if (self == null)
                    {
                        self = await ProtoService.SendAsync(new CreatePrivateChat(myId, false)) as Chat;
                    }

                    if (self != null)
                    {
                        list.Remove(self);
                        list.Insert(0, self);
                    }
                }

                foreach (var chat in list)
                {
                    if (_searchType == SearchChatsType.BasicAndSupergroups)
                    {
                        if (chat.Type is ChatTypeBasicGroup basic)
                        {
                            var basicGroup = ProtoService.GetBasicGroup(basic.BasicGroupId);
                            if (basicGroup == null)
                            {
                                continue;
                            }

                            if (basicGroup.CanInviteUsers())
                            {
                                Items.Add(chat);
                            }
                        }
                        else if (chat.Type is ChatTypeSupergroup super)
                        {
                            var supergroup = ProtoService.GetSupergroup(super.SupergroupId);
                            if (supergroup == null)
                            {
                                continue;
                            }

                            if (supergroup.CanInviteUsers())
                            {
                                Items.Add(chat);
                            }
                        }
                    }
                    else if (_searchType == SearchChatsType.PrivateAndGroups)
                    {
                        if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeBasicGroup || chat.Type is ChatTypeSupergroup supergroup && !supergroup.IsChannel)
                        {
                            Items.Add(chat);
                        }
                    }
                    else if (_searchType == SearchChatsType.Private)
                    {
                        if (chat.Type is ChatTypePrivate)
                        {
                            Items.Add(chat);
                        }
                    }
                    else if (_searchType == SearchChatsType.Post)
                    {
                        if (CacheService.CanPostMessages(chat))
                        {
                            Items.Add(chat);
                        }
                    }
                    else
                    {
                        Items.Add(chat);
                    }
                }

                var pre = PreSelectedItems;
                if (pre == null)
                {
                    return;
                }

                var items         = Items;
                var selectedItems = SelectedItems;

                foreach (var id in pre)
                {
                    var chat = CacheService.GetChat(id);
                    if (chat == null)
                    {
                        chat = await ProtoService.SendAsync(new GetChat(id)) as Chat;
                    }

                    if (chat == null)
                    {
                        continue;
                    }

                    selectedItems.Add(chat);

                    var index = items.IndexOf(chat);
                    if (index > -1)
                    {
                        if (index > 0)
                        {
                            items.Remove(chat);
                            items.Insert(1, chat);
                        }
                    }
                    else if (items.Count > 0)
                    {
                        items.Insert(1, chat);
                    }
                }

                if (PreSelectedItems.Count > 0 && SelectionMode == ListViewSelectionMode.Multiple)
                {
                    RaisePropertyChanged(nameof(PreSelectedItems));
                }
            }
        }
Beispiel #2
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            //if (mode == NavigationMode.New)
            //{
            //    _dialogs = null;
            //}

            var response = await ProtoService.SendAsync(new GetChats(new ChatListMain(), long.MaxValue, 0, int.MaxValue));

            if (response is Telegram.Td.Api.Chats chats)
            {
                var list = ProtoService.GetChats(chats.ChatIds);
                Items.Clear();

                if (_searchType != SearchChatsType.BasicAndSupergroups)
                {
                    var myId = CacheService.Options.MyId;
                    var self = list.FirstOrDefault(x => x.Type is ChatTypePrivate privata && privata.UserId == myId);
                    if (self == null)
                    {
                        self = await ProtoService.SendAsync(new CreatePrivateChat(myId, false)) as Chat;
                    }

                    if (self != null)
                    {
                        list.Remove(self);
                        list.Insert(0, self);
                    }
                }

                foreach (var chat in list)
                {
                    if (_searchType == SearchChatsType.BasicAndSupergroups)
                    {
                        if (chat.Type is ChatTypeBasicGroup basic)
                        {
                            var basicGroup = ProtoService.GetBasicGroup(basic.BasicGroupId);
                            if (basicGroup == null)
                            {
                                continue;
                            }

                            if (basicGroup.CanInviteUsers())
                            {
                                Items.Add(chat);
                            }
                        }
                        else if (chat.Type is ChatTypeSupergroup super)
                        {
                            var supergroup = ProtoService.GetSupergroup(super.SupergroupId);
                            if (supergroup == null)
                            {
                                continue;
                            }

                            if (supergroup.CanInviteUsers())
                            {
                                Items.Add(chat);
                            }
                        }
                    }
                    else
                    {
                        if (CacheService.CanPostMessages(chat))
                        {
                            Items.Add(chat);
                        }
                    }
                }
            }
        }