public static void NewCharacterUpdate(this IEventAggregator events, ICharacter character, CharacterUpdateEventArgs e) => events.NewUpdate(new CharacterUpdateModel(character, e));
public static void NewChannelUpdate(this IEventAggregator events, ChannelModel channel, ChannelUpdateEventArgs e) => events.NewUpdate(new ChannelUpdateModel(channel, e));
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 }