/// <summary>
 /// Adds a filter to the list of exclusions
 /// </summary>
 /// <param name="filter">The filter to add</param>
 /// <returns></returns>
 public CoverletSettings WithFilter(string filter)
 {
     Exclude.Add(filter);
     return(this);
 }
Exemple #2
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();
        }
Exemple #3
0
        public bool Parse(JToken tkn)
        {
            var o = tkn as JObject;

            if (o == null)
            {
                return(false);
            }

            try
            {
                if (o["name"] != null)
                {
                    Name = o["name"].ToString();
                }
                if (o["description"] != null)
                {
                    Description = o["description"].ToString();
                }
                if (o["waitMode"] != null)
                {
                    var m = new BlockWaitMode();
                    if (m.Parse(o["waitMode"]))
                    {
                        WaitMode = m;
                    }
                    else
                    {
                        WaitMode = new BlockWaitMode
                        {
                            WaitMin = 1,
                            WaitMax = 60,
                            Mode    = "random"
                        }
                    };
                }

                if (o["exclude"] != null)
                {
                    if (Exclude == null)
                    {
                        Exclude = new List <BlockLockRef>();
                    }

                    var ar = o["exclude"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var item    = ar[i];
                            var itemObj = new BlockLockRef();
                            if (itemObj.Parse(item))
                            {
                                Exclude.Add(itemObj);
                            }
                        }
                    }
                }

                if (o["locked"] != null)
                {
                    var lockTkn = o["locked"];
                    if (lockTkn != null)
                    {
                        if (lockTkn.Type == JTokenType.String)
                        {
                            var lockV = lockTkn.ToString();
                            if (!string.IsNullOrEmpty(lockV))
                            {
                                Locked = lockV.Equals("true", StringComparison.OrdinalIgnoreCase);
                            }
                            else
                            {
                                Locked = false;
                            }
                        }
                        else if (lockTkn.Type == JTokenType.Boolean)
                        {
                            Locked = (bool)lockTkn;
                        }
                        else if (lockTkn.Type == JTokenType.Integer)
                        {
                            Locked = (int)lockTkn == 1;
                        }
                    }
                }

                if (o["occupation"] != null)
                {
                    var locRef = new BlockLockRef();
                    if (locRef.Parse(o["occupation"]))
                    {
                        Occupation = locRef;
                    }
                }

                if (o["sidePlus"] != null)
                {
                    var arPlus = o["sidePlus"] as JArray;
                    if (arPlus != null)
                    {
                        foreach (var e in arPlus)
                        {
                            if (e == null)
                            {
                                continue;
                            }
                            if (_sidePlusNames.Contains(e.ToString()))
                            {
                                continue;
                            }
                            _sidePlusNames.Add(e.ToString());
                        }
                    }
                }

                if (o["sideMinus"] != null)
                {
                    var arMinus = o["sideMinus"] as JArray;
                    if (arMinus != null)
                    {
                        foreach (var e in arMinus)
                        {
                            if (e == null)
                            {
                                continue;
                            }
                            if (_sideMinusNames.Contains(e.ToString()))
                            {
                                continue;
                            }
                            _sideMinusNames.Add(e.ToString());
                        }
                    }
                }

                if (o["plusEvents"] != null)
                {
                    var evList = new BlockEvents(Ctx);
                    if (evList.Parse(o["plusEvents"]))
                    {
                        PlusEvents = evList;
                    }
                    else
                    {
                        PlusEvents = null;
                    }
                }

                if (o["minusEvents"] != null)
                {
                    var evList = new BlockEvents(Ctx);
                    if (evList.Parse(o["minusEvents"]))
                    {
                        MinusEvents = evList;
                    }
                    else
                    {
                        MinusEvents = null;
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }