Ejemplo n.º 1
0
        public void QuickJoinChannel(string id, string name)
        {
            name = HttpUtility.HtmlDecode(name);

            var type = (id == name) ? ChannelType.Public : ChannelType.Private;

            if (cm.CurrentChannels.FirstByIdOrNull(id) != null)
            {
                return;
            }

            Log((id != name && !string.IsNullOrEmpty(name))
                ? $"Quick Joining {type} Channel {id} \"{name}\""
                : $"Quick Joining {type} Channel {id}");

            var temp = new GeneralChannelModel(id, name, type);

            Dispatcher.Invoke(() =>
            {
                cm.AllChannels.Add(temp);
                cm.CurrentChannels.Add(temp);
            });

            container.Resolve <GeneralChannelViewModel>(new ParameterOverride("name", id));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public void AddChannel(ChannelType type, string id, string name)
        {
            Log((id != name && !string.IsNullOrEmpty(name))
                ? $"Making {type} Channel {id} \"{name}\""
                : $"Making {type} Channel {id}");

            if (type == ChannelType.PrivateMessage)
            {
                var character = characters.Find(id);

                character.GetAvatar(); // make sure we have their picture

                // model doesn't have a reference to PrivateMessage channels, build it manually
                var temp = new PmChannelModel(character);
                container.RegisterInstance(temp.Id, temp);
                container.Resolve <PmChannelViewModel>(new ParameterOverride("name", temp.Id));

                Dispatcher.Invoke(() => cm.CurrentPms.Add(temp));
                // then add it to the model's data

                ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs);
                SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
            }
            else
            {
                GeneralChannelModel temp;
                if (type == ChannelType.Utility)
                {
                    // our model won't have a reference to home, so we build it manually
                    temp = new GeneralChannelModel(id, ChannelType.Utility);
                    container.RegisterInstance(id, temp);
                    container.Resolve <HomeChannelViewModel>(new ParameterOverride("name", id));
                }
                else
                {
                    // our model should have a reference to other channels though
                    temp = cm.AllChannels.FirstOrDefault(param => param.Id == id);

                    if (temp == null)
                    {
                        temp = new GeneralChannelModel(id, name,
                                                       id == name ? ChannelType.Public : ChannelType.Private);
                        Dispatcher.Invoke(() => cm.AllChannels.Add(temp));
                    }

                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));

                    container.Resolve <GeneralChannelViewModel>(new ParameterOverride("name", id));

                    ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs);
                    SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
                }

                if (!cm.CurrentChannels.Contains(temp))
                {
                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));
                }
            }
        }
Ejemplo n.º 4
0
        public ChannelManagementViewModel(IEventAggregator eventagg, GeneralChannelModel model)
        {
            this.model = model;
            description = this.model.Description;
            events = eventagg;
            this.model.PropertyChanged += UpdateDescription;

            modeTypes = new[] {"Ads", "chat", "both"};
        }
Ejemplo n.º 5
0
        public ChannelManagementViewModel(IEventAggregator eventagg, GeneralChannelModel model)
        {
            this.model  = model;
            description = this.model.Description;
            events      = eventagg;
            this.model.PropertyChanged += UpdateDescription;

            modeTypes = new[] { "Ads", "chat", "both" };
        }
Ejemplo n.º 6
0
        protected override void Dispose(bool isManaged)
        {
            if (!isManaged)
            {
                model.PropertyChanged -= UpdateDescription;
                events = null;
                model  = null;
            }

            base.Dispose(isManaged);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        private void ChannelListCommand(IDictionary <string, object> command, bool isPublic)
        {
            var arr = (JsonArray)command[Constants.Arguments.MultipleChannels];

            lock (chatStateLocker)
            {
                foreach (IDictionary <string, object> channel in arr)
                {
                    var    name  = channel.Get(Constants.Arguments.Name);
                    string title = null;
                    if (!isPublic)
                    {
                        title = HttpUtility.HtmlDecode(channel.Get(Constants.Arguments.Title));
                    }

                    var mode = ChannelMode.Both;
                    if (isPublic)
                    {
                        mode = channel.Get(Constants.Arguments.Mode).ToEnum <ChannelMode>();
                    }

                    var number = (long)channel[Constants.Arguments.MultipleCharacters];
                    if (number < 0)
                    {
                        number = 0;
                    }

                    var model = new GeneralChannelModel(name, isPublic ? ChannelType.Public : ChannelType.Private,
                                                        (int)number, mode)
                    {
                        Title = isPublic ? name : title
                    };

                    Dispatcher.Invoke(() =>
                    {
                        var current = ChatModel.AllChannels.FirstByIdOrNull(name);
                        if (current == null)
                        {
                            ChatModel.AllChannels.Add(model);
                            return;
                        }

                        current.Mode      = mode;
                        current.UserCount = (int)number;
                    });
                }
            }
        }
Ejemplo n.º 9
0
            public ChannelCommandTests()
            {
                channelModel = new GeneralChannelModel(ChannelName, ChannelType.Public);

                chatModel.SetupGet(x => x.AllChannels)
                .Returns(new ObservableCollection <GeneralChannelModel> {
                    channelModel
                });

                chatModel.SetupGet(x => x.CurrentChannels)
                .Returns(new ObservableCollection <GeneralChannelModel> {
                    channelModel
                });

                chatModel.Setup(x => x.FindChannel(ChannelName, null)).Returns(channelModel);
            }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        public static string RelationshipToUser(this ICharacter character, ICharacterManager cm,
                                                GeneralChannelModel channel)
        {
            foreach (var pair in GeneralExtensions.ListKindSet.Where(pair => cm.IsOnList(character.Name, pair.Key)))
            {
                return(pair.Value);
            }

            if (channel != null && channel.CharacterManager.IsOnList(character.Name, ListKind.Moderator))
            {
                return("d");
            }

            string result;

            return(GeneralExtensions.SortDictionary.TryGetValue(character.Status, out result)
                ? result
                : "f");
        }
Ejemplo n.º 12
0
        public UsersTabViewModel(
            IChatModel cm, IUnityContainer contain, IRegionManager regman, IEventAggregator eventagg,
            ICharacterManager manager)
            : base(contain, regman, eventagg, cm, manager)
        {
            Container.RegisterType<object, UsersTabView>(UsersTabView);
            genderSettings = new GenderSettingsModel();

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

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

            ChatModel.SelectedChannelChanged += (s, e) =>
                {
                    currentChan = null;
                    OnPropertyChanged("SortContentString");
                    OnPropertyChanged("SortedUsers");
                };

            Events.GetEvent<NewUpdateEvent>().Subscribe(
                args =>
                    {
                        var thisNotification = args as CharacterUpdateModel;
                        if (thisNotification == null)
                            return;

                        if (thisNotification.Arguments is CharacterUpdateModel.PromoteDemoteEventArgs)
                            OnPropertyChanged("HasPermissions");

                        else if (thisNotification.Arguments is CharacterUpdateModel.JoinLeaveEventArgs
                                 || thisNotification.Arguments is CharacterUpdateModel.ListChangedEventArgs)
                            OnPropertyChanged("SortedUsers");
                    });
        }
Ejemplo n.º 13
0
        private void ChannelListCommand(IDictionary<string, object> command, bool isPublic)
        {
            var arr = (JsonArray) command[Constants.Arguments.MultipleChannels];
            lock (ChatModel.AllChannels)
            {
                foreach (IDictionary<string, object> channel in arr)
                {
                    var name = channel.Get(Constants.Arguments.Name);
                    string title = null;
                    if (!isPublic)
                        title = HttpUtility.HtmlDecode(channel.Get(Constants.Arguments.Title));

                    var mode = ChannelMode.Both;
                    if (isPublic)
                        mode = channel.Get(Constants.Arguments.Mode).ToEnum<ChannelMode>();

                    var number = (long) channel[Constants.Arguments.MultipleCharacters];
                    if (number < 0)
                        number = 0;

                    var model = new GeneralChannelModel(name, isPublic ? ChannelType.Public : ChannelType.Private,
                        (int) number, mode)
                    {
                        Title = isPublic ? name : title
                    };

                    Dispatcher.Invoke(() =>
                    {
                        var current = ChatModel.AllChannels.FirstByIdOrNull(name);
                        if (current == null)
                        {
                            ChatModel.AllChannels.Add(model);
                            return;
                        }

                        current.Mode = mode;
                        current.UserCount = (int) number;
                    });
                }
            }
        }
Ejemplo n.º 14
0
        public void AddChannel(ChannelType type, string id, string name)
        {
            if (type == ChannelType.PrivateMessage)
            {
                var character = characterManager.Find(id);

                character.GetAvatar(); // make sure we have their picture

                // model doesn't have a reference to PrivateMessage channels, build it manually
                var temp = new PmChannelModel(character);
                container.RegisterInstance(temp.Id, temp);
                container.Resolve<PmChannelViewModel>(new ParameterOverride("name", temp.Id));

                Dispatcher.Invoke((Action) (() => model.CurrentPms.Add(temp)));
                // then add it to the model's data

                ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs);
                SettingsService.SaveApplicationSettingsToXml(model.CurrentCharacter.Name);
            }
            else
            {
                GeneralChannelModel temp;
                if (type == ChannelType.Utility)
                {
                    // our model won't have a reference to home, so we build it manually
                    temp = new GeneralChannelModel(id, ChannelType.Utility);
                    container.RegisterInstance(id, temp);
                    container.Resolve<UtilityChannelViewModel>(new ParameterOverride("name", id));
                }
                else
                {
                    // our model should have a reference to other channels though
                    temp = model.AllChannels.FirstOrDefault(param => param.Id == id)
                           ?? new GeneralChannelModel(id, ChannelType.InviteOnly) {Title = name};

                    Dispatcher.Invoke((Action) (() => model.CurrentChannels.Add(temp)));

                    container.Resolve<GeneralChannelViewModel>(new ParameterOverride("name", id));

                    ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs);
                    SettingsService.SaveApplicationSettingsToXml(model.CurrentCharacter.Name);
                }

                if (!model.CurrentChannels.Contains(temp))
                    Dispatcher.Invoke((Action) (() => model.CurrentChannels.Add(temp)));
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        protected override void Dispose(bool isManaged)
        {
            if (!isManaged)
            {
                model.PropertyChanged -= UpdateDescription;
                events = null;
                model = null;
            }

            base.Dispose(isManaged);
        }
Ejemplo n.º 17
0
        public void AddChannel(ChannelType type, string id, string name)
        {
            Log((id != name && !string.IsNullOrEmpty(name))
                ? $"Making {type} Channel {id} \"{name}\""
                : $"Making {type} Channel {id}");

            if (type == ChannelType.PrivateMessage)
            {
                var character = characters.Find(id);

                character.GetAvatar(); // make sure we have their picture

                // model doesn't have a reference to PrivateMessage channels, build it manually
                var temp = new PmChannelModel(character);
                container.RegisterInstance(temp.Id, temp);
                container.Resolve<PmChannelViewModel>(new ParameterOverride("name", temp.Id));

                Dispatcher.Invoke(() => cm.CurrentPms.Add(temp));
                // then add it to the model's data

                ApplicationSettings.RecentCharacters.BacklogWithUpdate(id, MaxRecentTabs);
                SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
            }
            else
            {
                GeneralChannelModel temp;
                if (type == ChannelType.Utility)
                {
                    // our model won't have a reference to home, so we build it manually
                    temp = new GeneralChannelModel(id, ChannelType.Utility);
                    container.RegisterInstance(id, temp);
                    container.Resolve<HomeChannelViewModel>(new ParameterOverride("name", id));
                }
                else
                {
                    // our model should have a reference to other channels though
                    temp = cm.AllChannels.FirstOrDefault(param => param.Id == id);

                    if (temp == null)
                    {
                        temp = new GeneralChannelModel(id, name,
                            id == name ? ChannelType.Public : ChannelType.Private);
                        Dispatcher.Invoke(() => cm.AllChannels.Add(temp));
                    }

                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));

                    container.Resolve<GeneralChannelViewModel>(new ParameterOverride("name", id));

                    ApplicationSettings.RecentChannels.BacklogWithUpdate(id, MaxRecentTabs);
                    SettingsService.SaveApplicationSettingsToXml(cm.CurrentCharacter.Name);
                }

                if (!cm.CurrentChannels.Contains(temp))
                    Dispatcher.Invoke(() => cm.CurrentChannels.Add(temp));
            }
        }
Ejemplo n.º 18
0
        public void QuickJoinChannel(string id, string name)
        {
            name = HttpUtility.HtmlDecode(name);

            var type = (id == name) ? ChannelType.Public : ChannelType.Private;

            if (cm.CurrentChannels.FirstByIdOrNull(id) != null)
                return;

            Log((id != name && !string.IsNullOrEmpty(name))
                ? $"Quick Joining {type} Channel {id} \"{name}\""
                : $"Quick Joining {type} Channel {id}");

            var temp = new GeneralChannelModel(id, name, type);
            Dispatcher.Invoke(() =>
            {
                cm.AllChannels.Add(temp);
                cm.CurrentChannels.Add(temp);
            });

            container.Resolve<GeneralChannelViewModel>(new ParameterOverride("name", id));
        }