Exemplo n.º 1
0
        public static bool MeetsChatModelLists(
            this ICharacter character, GenericSearchSettingsModel search, ICharacterManager cm,
            GeneralChannelModel channel)
        {
            var name = character.Name;

            var map = new HashSet <KeyValuePair <ListKind, bool> >
            {
                new KeyValuePair <ListKind, bool>(ListKind.Ignored, search.ShowIgnored),
                new KeyValuePair <ListKind, bool>(ListKind.NotInterested, search.ShowNotInterested),
                new KeyValuePair <ListKind, bool>(ListKind.Moderator, search.ShowMods),
                new KeyValuePair <ListKind, bool>(ListKind.Friend, search.ShowFriends),
                new KeyValuePair <ListKind, bool>(ListKind.Bookmark, search.ShowBookmarks)
            };

            // weee thread-safe functions
            foreach (var pair in map.Where(pair => cm.IsOnList(name, pair.Key, false)))
            {
                return(pair.Value);
            }

            if (channel == null)
            {
                return(search.MeetsStatusFilter(character));
            }

            return(channel.CharacterManager.IsOnList(name, ListKind.Moderator, false)
                ? search.ShowMods
                : search.MeetsStatusFilter(character));
        }
Exemplo n.º 2
0
        public static bool MeetsFilters(
            this ICharacter character,
            GenderSettingsModel genders,
            GenericSearchSettingsModel search,
            ICharacterManager cm,
            GeneralChannelModel channel)
        {
            if (!character.NameContains(search.SearchString))
            {
                return(false);
            }

            return(genders.MeetsGenderFilter(character) &&
                   character.MeetsChatModelLists(search, cm, channel));
        }
Exemplo n.º 3
0
        public static bool MeetsFilters(
            this IMessage message,
            GenderSettingsModel genders,
            GenericSearchSettingsModel search,
            ICharacterManager cm,
            GeneralChannelModel channel)
        {
            if (!message.Poster.NameContains(search.SearchString) &&
                !message.Message.ContainsOrdinal(search.SearchString))
            {
                return(false);
            }

            return(genders.MeetsGenderFilter(message.Poster) &&
                   message.Poster.MeetsChatModelLists(search, cm, channel));
        }
Exemplo n.º 4
0
 public ShortcutManager(TextBox entry, GenericSearchSettingsModel model)
     : this(entry)
 {
     this.model = model;
 }
Exemplo n.º 5
0
 public ShortcutManager(TextBox entry, GenericSearchSettingsModel model)
     : this(entry)
 {
     this.model = model;
 }
Exemplo n.º 6
0
        public GeneralChannelViewModel(
            string name, IUnityContainer contain, IRegionManager regman, IEventAggregator events, IChatModel cm,
            ICharacterManager manager)
            : base(contain, regman, events, cm, manager)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = HelperConverter.EscapeSpaces(name);

                Container.RegisterType<object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, Model as GeneralChannelModel);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged += OnAdsChanged;
                Model.PropertyChanged += OnModelPropertyChanged;

                searchSettings = new GenericSearchSettingsModel();
                genderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                genderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFlood.Elapsed += (s, e) =>
                    {
                        isInCoolDownMessage = false;
                        messageFlood.Enabled = false;
                        OnPropertyChanged("CanPost");
                    };

                adFlood.Elapsed += (s, e) =>
                    {
                        isInCoolDownAd = false;
                        adFlood.Enabled = false;
                        OnPropertyChanged("CanPost");
                        OnPropertyChanged("CannotPost");
                        OnPropertyChanged("ShouldShowAutoPost");
                        if (autoPostAds)
                            SendAutoAd();
                    };

                update.Elapsed += (s, e) =>
                    {
                        if (!Model.IsSelected)
                            return;

                        if (CannotPost)
                            OnPropertyChanged("TimeLeft");

                        OnPropertyChanged("StatusString");
                    };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                update.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    cm.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                    {
                        OnPropertyChanged("ChannelSettings");
                        OnPropertyChanged("HasNotifyTerms");
                        if (!ChannelSettings.IsChangingSettings)
                        {
                            SettingsService.UpdateSettingsFile(
                                ChannelSettings, cm.CurrentCharacter.Name, Model.Title, Model.Id);
                        }
                    };

                PropertyChanged += OnPropertyChanged;

                Events.GetEvent<NewUpdateEvent>().Subscribe(UpdateChat);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }
Exemplo n.º 7
0
        public static bool MeetsFilters(
            this IMessage message,
            GenderSettingsModel genders,
            GenericSearchSettingsModel search,
            ICharacterManager cm,
            GeneralChannelModel channel)
        {
            if (!message.Poster.NameContains(search.SearchString)
                && !message.Message.ContainsOrdinal(search.SearchString))
                return false;

            return genders.MeetsGenderFilter(message.Poster)
                   && message.Poster.MeetsChatModelLists(search, cm, channel);
        }
Exemplo n.º 8
0
        public GeneralChannelViewModel(string name, IChatState chatState)
            : base(chatState)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = StringExtensions.EscapeSpaces(name);

                Container.RegisterType <object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, (GeneralChannelModel)Model);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged      += OnAdsChanged;
                Model.PropertyChanged            += OnModelPropertyChanged;

                SearchSettings = new GenericSearchSettingsModel();
                GenderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                GenderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownMessage       = false;
                    messageFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                };

                adFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownAd       = false;
                    adFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                    OnPropertyChanged("CannotPost");
                    OnPropertyChanged("ShouldShowAutoPost");
                    if (autoPostAds)
                    {
                        SendAutoAd();
                    }
                    else
                    {
                        autoPostCount = 0;
                    }
                };

                updateTimer.Elapsed += (s, e) =>
                {
                    if (!Model.IsSelected)
                    {
                        return;
                    }

                    if (CannotPost)
                    {
                        OnPropertyChanged("TimeLeft");
                        OnPropertyChanged("AutoTimeLeft");
                    }

                    OnPropertyChanged("StatusString");
                };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                updateTimer.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    ChatModel.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                {
                    OnPropertyChanged("ChannelSettings");
                    OnPropertyChanged("HasNotifyTerms");
                    if (!ChannelSettings.IsChangingSettings)
                    {
                        SettingsService.UpdateSettingsFile(
                            ChannelSettings, ChatModel.CurrentCharacter.Name, Model.Title, Model.Id);
                    }
                };

                PropertyChanged += OnPropertyChanged;

                updateSearch = DeferredAction.Create(() => messageManager.IsFiltering = isSearching);

                Events.GetEvent <NewUpdateEvent>().Subscribe(UpdateChat);

                LoggingSection = "general chan vm";

                if (!string.IsNullOrWhiteSpace(ChannelSettings.LastMessage))
                {
                    Message = ChannelSettings.LastMessage;
                    ChannelSettings.LastMessage = null;
                }
                SearchSettings.ShowOffline = true;

                Application.Current.Dispatcher.Invoke(
                    () => Application.Current.MainWindow.Deactivated += SetLastMessageMark);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }
Exemplo n.º 9
0
        public GeneralChannelViewModel(string name, IChatState chatState)
            : base(chatState)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = StringExtensions.EscapeSpaces(name);

                Container.RegisterType<object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, (GeneralChannelModel) Model);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged += OnAdsChanged;
                Model.PropertyChanged += OnModelPropertyChanged;

                SearchSettings = new GenericSearchSettingsModel();
                GenderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                GenderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownMessage = false;
                    messageFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                };

                adFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownAd = false;
                    adFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                    OnPropertyChanged("CannotPost");
                    OnPropertyChanged("ShouldShowAutoPost");
                    if (autoPostAds)
                        SendAutoAd();
                    else
                        autoPostCount = 0;
                };

                updateTimer.Elapsed += (s, e) =>
                {
                    if (!Model.IsSelected)
                        return;

                    if (CannotPost)
                    {
                        OnPropertyChanged("TimeLeft");
                        OnPropertyChanged("AutoTimeLeft");
                    }

                    OnPropertyChanged("StatusString");
                };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                updateTimer.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    ChatModel.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                {
                    OnPropertyChanged("ChannelSettings");
                    OnPropertyChanged("HasNotifyTerms");
                    if (!ChannelSettings.IsChangingSettings)
                    {
                        SettingsService.UpdateSettingsFile(
                            ChannelSettings, ChatModel.CurrentCharacter.Name, Model.Title, Model.Id);
                    }
                };

                PropertyChanged += OnPropertyChanged;

                updateSearch = DeferredAction.Create(() => messageManager.IsFiltering = isSearching);

                Events.GetEvent<NewUpdateEvent>().Subscribe(UpdateChat);

                LoggingSection = "general chan vm";

                if (!string.IsNullOrWhiteSpace(ChannelSettings.LastMessage))
                {
                    Message = ChannelSettings.LastMessage;
                    ChannelSettings.LastMessage = null;
                }
                SearchSettings.ShowOffline = true;

                Application.Current.Dispatcher.Invoke(
                    () => Application.Current.MainWindow.Deactivated += SetLastMessageMark);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }