<commit_before>﻿using IrcClientCore;
using Microsoft.QueryStringDotNET;
using NotificationsExtensions;
using NotificationsExtensions.Toasts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Notifications;
using Windows.UI.Popups;
using Windows.UI.Text;
using Windows.UI.Xaml;
using WinIRC.Utils;

namespace WinIRC.Net
{
    public abstract class IrcUWPBase : Irc, IDisposable
    {
        internal StreamSocket streamSocket;
        internal DataReader reader;
        internal DataWriter writer;

        public String BackgroundTaskName {
            get
            {
                return "WinIRCBackgroundTask." + Server.Name;
            }
        }

        Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

        public string buffer;
        public string currentChannel;

        internal Connection ConnCheck;

        private readonly int MAX_MESSAGES = 1000;

        public bool IsBouncer { get; private set; }
        public new Action<IrcUWPBase> HandleDisconnect { get; set; }
        public ObservableCollection<Message> ircMessages { get; set; }

        public IrcUWPBase(WinIrcServer server) : base(server)
        {
            ConnCheck = new Connection();
            ConnCheck.ConnectionChanged += async (connected) =>
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ConnectionChanged(connected)
            );

            Mentions.CollectionChanged += Mentions_CollectionChanged;
        }

        private void Mentions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            var message = e.NewItems[0] as Message;

            var key = Config.PerChannelSetting(this.Server.Name, message.Channel, Config.AlwaysNotify);
            var ping = Config.GetBoolean(key, false);

            if (currentChannel != message.Channel || (App.Current as App).IncrementPings == true || MainPage.instance.currentServer == this.Server.Name || ping)
            {
                var toast = CreateMentionToast(message.Text, message.Channel, message.Text);
                toast.ExpirationTime = DateTime.Now.AddDays(2);
                ToastNotificationManager.CreateToastNotifier().Show(toast);
                (App.Current as App).NumberPings++;
            }
        }

        private void ConnectionChanged(bool connected)<commit_msg>Fix notification<commit_after>﻿using IrcClientCore;
using Microsoft.QueryStringDotNET;
using NotificationsExtensions;
using NotificationsExtensions.Toasts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Notifications;
using Windows.UI.Popups;
using Windows.UI.Text;
using Windows.UI.Xaml;
using WinIRC.Utils;

namespace WinIRC.Net
{
    public abstract class IrcUWPBase : Irc, IDisposable
    {
        internal StreamSocket streamSocket;
        internal DataReader reader;
        internal DataWriter writer;

        public String BackgroundTaskName {
            get
            {
                return "WinIRCBackgroundTask." + Server.Name;
            }
        }

        Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

        public string buffer;
        public string currentChannel;

        internal Connection ConnCheck;

        private readonly int MAX_MESSAGES = 1000;

        public bool IsBouncer { get; private set; }
        public new Action<IrcUWPBase> HandleDisconnect { get; set; }
        public ObservableCollection<Message> ircMessages { get; set; }

        public IrcUWPBase(WinIrcServer server) : base(server)
        {
            ConnCheck = new Connection();
            ConnCheck.ConnectionChanged += async (connected) =>
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ConnectionChanged(connected)
            );

            Mentions.CollectionChanged += Mentions_CollectionChanged;
        }

        private void Mentions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            var message = e.NewItems[0] as Message;

            var key = Config.PerChannelSetting(this.Server.Name, message.Channel, Config.AlwaysNotify);
            var ping = Config.GetBoolean(key, false);

            if (currentChannel != message.Channel || (App.Current as App).IncrementPings == true || MainPage.instance.currentServer == this.Server.Name || ping)
            {
                var toast = CreateMentionToast(message.User, message.Channel, message.Text);
                toast.ExpirationTime = DateTime.Now.AddDays(2);
                ToastNotificationManager.CreateToastNotifier().Show(toast);
                (App.Current as App).NumberPings++;
            }
        }

        private void ConnectionChanged(bool connected)
{'fraction_non_alphanumeric': 0.08195261001247105, 'fraction_numerical': 0.002137894174238375, 'mean_word_length': 2.9368863955119213, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7285540', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1400, 'n_words': 328}