protected SolidColorBrush GetBrush(ICharacter character) { if (Permissions != null && Permissions.IsModerator(character.Name)) { return((SolidColorBrush)Application.Current.FindResource("ModeratorBrush")); } if (characters != null && characters.IsOnList(character.Name, ListKind.NotInterested)) { return((SolidColorBrush)Application.Current.FindResource("NotAvailableBrush")); } var normalColorName = character.IsInteresting && ApplicationSettings.AllowOfInterestColoring ? "Contrast" : GetGenderName(character.Gender); if (!ApplicationSettings.AllowStatusDiscolor) { return((SolidColorBrush)TryGet(normalColorName, true)); } if (character.Status == StatusType.Crown || character.Status == StatusType.Online || character.Status == StatusType.Looking) { return((SolidColorBrush)TryGet(normalColorName, true)); } return((SolidColorBrush)Application.Current.FindResource("NotAvailableBrush")); }
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)); }
public void AddMessage( string message, string channelName, string poster, MessageType messageType = MessageType.Normal) { var sender = characters.Find(poster == Constants.Arguments.ThisCharacter ? cm.CurrentCharacter.Name : poster); var channel = cm.CurrentChannels.FirstByIdOrNull(channelName) ?? (ChannelModel)cm.CurrentPms.FirstByIdOrNull(channelName); if (channel == null) { return; // exception circumstance, swallow message } if (messageType == MessageType.Ad && characters.IsOnList(poster, ListKind.NotInterested, false)) { return; // don't want these clogging up our filter or.. anything really } Dispatcher.InvokeWithRetry(() => { var thisMessage = new MessageModel(sender, message, messageType); channel.AddMessage(thisMessage, characters.IsOfInterest(poster)); if (channel.Settings.LoggingEnabled && ApplicationSettings.AllowLogging) { // check if the user wants logging for this channel logger.LogMessage(channel.Title, channel.Id, thisMessage); } if (poster == Constants.Arguments.ThisCharacter) { return; } // don't push events for our own messages if (channel is GeneralChannelModel) { events.GetEvent <NewMessageEvent>() .Publish( new Dictionary <string, object> { { Constants.Arguments.Message, thisMessage }, { Constants.Arguments.Channel, channel } }); } else { events.GetEvent <NewPmEvent>().Publish(thisMessage); } }); }
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"); }
public bool IsAdmin(string name) => characters.IsOnList(name, ListKind.Moderator, false);
private void HandleNewChannelMessage(IDictionary <string, object> update) { var channel = update.Get <GeneralChannelModel>("channel"); var message = update.Get <IMessage>("message"); if (message == null || channel == null) { return; } if (message.Poster.NameEquals(cm.CurrentCharacter.Name)) { return; } var isFocusedAndSelected = (channel.IsSelected && WindowIsFocused); var cleanMessageText = HttpUtility.HtmlDecode(message.Message); var temp = new List <string>(channel.Settings.EnumerableTerms); temp.AddRange(ApplicationSettings.GlobalNotifyTermsList); if (ApplicationSettings.CheckForOwnName) { temp.Add(cm.CurrentCharacter.Name.ToLower()); } var checkAgainst = temp.Distinct(StringComparer.OrdinalIgnoreCase).Select(x => x.Trim()); // if any of these conditions hold true we have no reason to evaluate further if (characters.IsOnList(message.Poster.Name, ListKind.NotInterested) && message.Type == MessageType.Ad) { return; } var notifyLevel = message.Type == MessageType.Ad ? channel.Settings.AdNotifyLevel : channel.Settings.MessageNotifyLevel; // now we check to see if we should notify because of settings if (notifyLevel > (int)ChannelSettingsModel.NotifyLevel.NotificationOnly && !isFocusedAndSelected) { if (!channel.Settings.MessageNotifyOnlyForInteresting || IsOfInterest(message.Poster.Name)) { if (notifyLevel > (int)ChannelSettingsModel.NotifyLevel.NotificationAndToast) { ToastManager.PlaySound(); ToastManager.FlashWindow(); } toast.TargetCharacter = message.Poster; toast.Title = $"{(ApplicationSettings.ShowNamesInToasts ? message.Poster.Name : "A user")} #{channel.Title}"; toast.Content = ApplicationSettings.ShowMessagesInToasts ? cleanMessageText : "Has a new message"; toast.ShowNotifications(); toast.Navigator = new SimpleNavigator(chatState => { chatState.EventAggregator.GetEvent <RequestChangeTabEvent>().Publish(channel.Id); ShowWindow(); }); toast.TargetCharacter = message.Poster; if (ApplicationSettings.ShowAvatarsInToasts) { message.Poster.GetAvatar(); } } } #region Ding Word evaluation // We have something to check for // Tokenized List is the list of terms the message has // Check against is a combined set of terms that the user has identified as ding words // Is Matching String uses Check against to see if any terms are a match var wordList = checkAgainst as IList <string> ?? checkAgainst.ToList(); if (channel.Settings.NotifyIncludesCharacterNames) { // if the poster's name contains a ding word var match = wordList .Select(dingword => message.Poster.Name.FirstMatch(dingword)) .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1)); if (match != null) { var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs { Channel = channel, Context = match.Item2, TriggeredWord = match.Item1, IsNameMention = true }); events.NewUpdate(newUpdate); if (!isFocusedAndSelected) { channel.FlashTab(); } message.IsOfInterest = true; return; } } { // check the message content var match = wordList.Select(cleanMessageText.FirstMatch) .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1)); if (match == null) { return; } var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs { Channel = channel, Context = match.Item2, TriggeredWord = match.Item1, IsNameMention = false }); events.NewUpdate(newUpdate); if (!isFocusedAndSelected) { channel.FlashTab(); } message.IsOfInterest = true; } #endregion }
public void InappropriateListDoesNotCrash() { var result = characters.IsOnList("", ListKind.Banned, false); Assert.IsFalse(result); }