Ejemplo n.º 1
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            ChatFilter filter = null;

            if (parameter is int id)
            {
                var response = await ProtoService.SendAsync(new GetChatFilter(id));

                if (response is ChatFilter result)
                {
                    Id     = id;
                    Filter = result;
                    filter = result;
                }
                else
                {
                    // TODO
                }
            }
            else
            {
                Id     = null;
                Filter = null;
                filter = new ChatFilter();
                filter.PinnedChatIds   = new List <long>();
                filter.IncludedChatIds = new List <long>();
                filter.ExcludedChatIds = new List <long>();
            }

            if (filter == null)
            {
                return;
            }

            if (state != null && state.TryGet("included_chat_id", out long includedChatId))
            {
                filter.IncludedChatIds.Add(includedChatId);
            }

            _pinnedChatIds = filter.PinnedChatIds ?? new List <long>();

            _iconPicked = !string.IsNullOrEmpty(filter.IconName);

            Title = filter.Title;
            Icon  = Icons.ParseFilter(filter);

            Include.Clear();
            Exclude.Clear();

            if (filter.IncludeContacts)
            {
                Include.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.IncludeContacts
                });
            }
            if (filter.IncludeNonContacts)
            {
                Include.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.IncludeNonContacts
                });
            }
            if (filter.IncludeGroups)
            {
                Include.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.IncludeGroups
                });
            }
            if (filter.IncludeChannels)
            {
                Include.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.IncludeChannels
                });
            }
            if (filter.IncludeBots)
            {
                Include.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.IncludeBots
                });
            }

            if (filter.ExcludeMuted)
            {
                Exclude.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.ExcludeMuted
                });
            }
            if (filter.ExcludeRead)
            {
                Exclude.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.ExcludeRead
                });
            }
            if (filter.ExcludeArchived)
            {
                Exclude.Add(new FilterFlag {
                    Flag = ChatListFilterFlags.ExcludeArchived
                });
            }

            foreach (var chatId in filter.PinnedChatIds.Union(filter.IncludedChatIds))
            {
                var chat = CacheService.GetChat(chatId);
                if (chat == null)
                {
                    continue;
                }

                Include.Add(new FilterChat {
                    Chat = chat
                });
            }

            foreach (var chatId in filter.ExcludedChatIds)
            {
                var chat = CacheService.GetChat(chatId);
                if (chat == null)
                {
                    continue;
                }

                Exclude.Add(new FilterChat {
                    Chat = chat
                });
            }

            UpdateIcon();
        }