コード例 #1
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data, bool sameUser)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();
            newTableRow.Tag = data;

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();
            usernameTableCell.Name = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();
            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.Name.Replace("\n", "").Replace("\r", ""))
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");

            if(!sameUser)
                usernameParagraph.Inlines.Add(data.Username);

            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();
            messageParagraph.TextAlignment = TextAlignment.Left;

            if (!data.IsGroupMsg && data.IsSelf)
                messageParagraph.Foreground = Brushes.LightGray;

            bool isHighlight = data.IsGroupMsg && !data.IsSelf && data.Message.ToLower().Contains(tox.Name.ToLower());
            ProcessMessage(data, messageParagraph, false, isHighlight);

            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestampParagraph = new Paragraph();
            timestampParagraph.Foreground = Brushes.LightGray;
            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestampParagraph.Inlines.Add(data.Timestamp.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestampParagraph);

            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);
        }
コード例 #2
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data, EmojiProvider emojiProvider)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();
            usernameTableCell.Name = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();
            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.GetSelfName())
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");

            usernameParagraph.Inlines.Add(data.Username);
            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();
            messageParagraph.TextAlignment = TextAlignment.Left;

            ProcessMessage(data, messageParagraph, false, emojiProvider);

            //messageParagraph.Inlines.Add(fakeHyperlink);
            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestamParagraph = new Paragraph();
            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestamParagraph.Inlines.Add(DateTime.Now.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestamParagraph);
            timestamParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));
            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);
        }
コード例 #3
0
        static void ProcessMessage(MessageData data, Paragraph messageParagraph, bool append, bool isBold)
        {
            List<string> urls = new List<string>();
            List<int> indices = new List<int>();
            string[] parts = data.Message.Split(' ');

            foreach (string part in parts)
            {
                if (Regex.IsMatch(part, @"(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&amp;%_\./-~-]*)?", RegexOptions.IgnoreCase)/*Regex.IsMatch(part, @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$")*/)
                    urls.Add(part);
            }

            if (urls.Count > 0)
            {
                foreach (string url in urls)
                {
                    indices.Add(data.Message.IndexOf(url));
                    data.Message = data.Message.Replace(url, "");
                }

                messageParagraph.AddMessage(data.Message, append, isBold);
                Inline inline = messageParagraph.Inlines.LastInline;

                for (int i = indices.Count; i-- > 0; )
                {
                    string url = urls[i];
                    int index = append ? indices[i] + 1 : indices[i];

                    Run run = new Run(url);
                    TextPointer pointer = new TextRange(inline.ContentStart, inline.ContentEnd).Text == "\n" ? inline.ContentEnd : inline.ContentStart;

                    Hyperlink link = new Hyperlink(run, pointer.GetPositionAtOffset(index));
                    link.IsEnabled = true;
                    link.Click += delegate(object sender, RoutedEventArgs args)
                    {
                        try { Process.Start(url); }
                        catch { }
                    };
                }
            }
            else
            {
                messageParagraph.AddMessage(data.Message, append, isBold);
            }
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: kstaruch/Toxy
        private void TextToSend_KeyDown(object sender, KeyEventArgs e)
        {
            string text = emojis.GetPlainText(TextToSend.Document);

            if (e.Key == Key.Enter)
            {
                if (Keyboard.IsKeyDown(Key.LeftShift))
                {
                    TextToSend.AppendText(Environment.NewLine);
                    TextToSend.CaretPosition = TextToSend.CaretPosition.GetLineStartPosition(1);
                    return;
                }

                if (e.IsRepeat)
                    return;

                if (string.IsNullOrEmpty(text))
                    return;

                var selectedChatNumber = this.ViewModel.SelectedChatNumber;
                if (tox.GetFriendConnectionStatus(selectedChatNumber) == 0 && this.ViewModel.IsFriendSelected)
                    return;

                if (text.StartsWith("/me "))
                {
                    //action
                    string action = text.Substring(4);
                    int messageid = -1;

                    if (this.ViewModel.IsFriendSelected)
                        messageid = tox.SendAction(selectedChatNumber, action);
                    else if (this.ViewModel.IsGroupSelected)
                        tox.SendGroupAction(selectedChatNumber, action);

                    MessageData data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", tox.GetSelfName(), action), IsAction = true };

                    if (this.ViewModel.IsFriendSelected)
                    {
                        if (convdic.ContainsKey(selectedChatNumber))
                        {
                            convdic[selectedChatNumber].AddNewMessageRow(tox, data, emojis);
                        }
                        else
                        {
                            FlowDocument document = GetNewFlowDocument();
                            convdic.Add(selectedChatNumber, document);
                            convdic[selectedChatNumber].AddNewMessageRow(tox, data, emojis);
                        }
                    }
                }
                else
                {
                    //regular message
                    string message = text;

                    int messageid = -1;

                    if (this.ViewModel.IsFriendSelected)
                        messageid = tox.SendMessage(selectedChatNumber, message);
                    else if (this.ViewModel.IsGroupSelected)
                        tox.SendGroupMessage(selectedChatNumber, message);

                    MessageData data = new MessageData() { Username = tox.GetSelfName(), Message = message };

                    if (this.ViewModel.IsFriendSelected)
                    {
                        if (convdic.ContainsKey(selectedChatNumber))
                        {
                            Run run = GetLastMessageRun(convdic[selectedChatNumber]);
                            if (run != null)
                            {
                                if (run.Text == data.Username)
                                    convdic[selectedChatNumber].AppendMessage(data, emojis);
                                else
                                    convdic[selectedChatNumber].AddNewMessageRow(tox, data, emojis);
                            }
                            else
                            {
                                convdic[selectedChatNumber].AddNewMessageRow(tox, data, emojis);
                            }
                        }
                        else
                        {
                            FlowDocument document = GetNewFlowDocument();
                            convdic.Add(selectedChatNumber, document);
                            convdic[selectedChatNumber].AddNewMessageRow(tox, data, emojis);
                        }
                    }
                }

                ScrollChatBox();

                TextToSend.Document.Blocks.Clear();// .Text = "";
                e.Handled = true;
            }
            else if (e.Key == Key.Tab && this.ViewModel.IsGroupSelected)
            {
                string[] names = tox.GetGroupNames(this.ViewModel.SelectedChatNumber);

                foreach (string name in names)
                {
                    if (!name.ToLower().StartsWith(text.ToLower()))
                        continue;

                    //TextToSend.Text = string.Format("{0}, ", name);
                    //TextToSend.SelectionStart = TextToSend.Text.Length;
                }

                e.Handled = true;
            }
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: kstaruch/Toxy
        private void tox_OnGroupMessage(int groupnumber, int friendgroupnumber, string message)
        {
            MessageData data = new MessageData() { Username = tox.GetGroupMemberName(groupnumber, friendgroupnumber), Message = message };

            if (groupdic.ContainsKey(groupnumber))
            {
                Run run = GetLastMessageRun(groupdic[groupnumber]);

                if (run != null)
                {
                    if (run.Text == data.Username)
                        groupdic[groupnumber].AppendMessage(data, emojis);
                    else
                        groupdic[groupnumber].AddNewMessageRow(tox, data, emojis);
                }
                else
                {
                    groupdic[groupnumber].AddNewMessageRow(tox, data, emojis);
                }
            }
            else
            {
                FlowDocument document = GetNewFlowDocument();
                groupdic.Add(groupnumber, document);
                groupdic[groupnumber].AddNewMessageRow(tox, data, emojis);
            }

            var group = this.ViewModel.GetGroupObjectByNumber(groupnumber);
            if (group != null)
            {
                if (!group.Selected)
                {
                    group.HasNewMessage = true;
                    group.NewMessageCount++;
                }
                else
                {
                    ScrollChatBox();
                }
            }
            if (this.ViewModel.MainToxyUser.ToxStatus != ToxUserStatus.BUSY)
                this.Flash();

            this.nIcon.Icon = newMessageNotifyIcon;
            this.ViewModel.HasNewMessage = true;
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: kstaruch/Toxy
        private void tox_OnGroupAction(int groupnumber, int friendgroupnumber, string action)
        {
            MessageData data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", tox.GetGroupMemberName(groupnumber, friendgroupnumber), action), IsAction = true };

            if (groupdic.ContainsKey(groupnumber))
            {
                groupdic[groupnumber].AddNewMessageRow(tox, data, emojis);
            }
            else
            {
                FlowDocument document = GetNewFlowDocument();
                groupdic.Add(groupnumber, document);
                groupdic[groupnumber].AddNewMessageRow(tox, data, emojis);
            }

            var group = this.ViewModel.GetGroupObjectByNumber(groupnumber);
            if (group != null)
            {
                if (!group.Selected)
                {
                    group.HasNewMessage = true;
                    group.NewMessageCount++;
                }
                else
                {
                    ScrollChatBox();
                }
            }
            if (this.ViewModel.MainToxyUser.ToxStatus != ToxUserStatus.BUSY)
                this.Flash();
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: kstaruch/Toxy
        private void tox_OnFriendMessage(int friendnumber, string message)
        {
            MessageData data = new MessageData() { Username = tox.GetName(friendnumber), Message = message };

            if (convdic.ContainsKey(friendnumber))
            {
                Run run = GetLastMessageRun(convdic[friendnumber]);

                if (run != null)
                {
                    if (run.Text == tox.GetName(friendnumber))
                        convdic[friendnumber].AppendMessage(data, emojis);
                    else
                        convdic[friendnumber].AddNewMessageRow(tox, data, emojis);
                }
                else
                {
                    convdic[friendnumber].AddNewMessageRow(tox, data, emojis);
                }
            }
            else
            {
                FlowDocument document = GetNewFlowDocument();
                convdic.Add(friendnumber, document);
                convdic[friendnumber].AddNewMessageRow(tox, data, emojis);
            }

            var friend = this.ViewModel.GetFriendObjectByNumber(friendnumber);
            if (friend != null)
            {
                if (!friend.Selected)
                {
                    friend.HasNewMessage = true;
                    friend.NewMessageCount++;
                }
                else
                {
                    ScrollChatBox();
                }
            }
            if (this.ViewModel.MainToxyUser.ToxStatus != ToxUserStatus.BUSY)
                this.Flash();

            this.nIcon.Icon = newMessageNotifyIcon;
            this.ViewModel.HasNewMessage = true;
        }
コード例 #8
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
 private void AddActionToView(int friendNumber, MessageData data)
 {
     if (convdic.ContainsKey(friendNumber))
     {
         convdic[friendNumber].AddNewMessageRow(tox, data, false);
     }
     else
     {
         FlowDocument document = FlowDocumentExtensions.CreateNewDocument();
         convdic.Add(friendNumber, document);
         convdic[friendNumber].AddNewMessageRow(tox, data, false);
     }
 }
コード例 #9
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data, bool sameUser)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();

            newTableRow.Tag = data;

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();

            usernameTableCell.Name    = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();

            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground    = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.GetSelfName())
            {
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");
            }

            if (!sameUser)
            {
                usernameParagraph.Inlines.Add(data.Username);
            }

            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();

            messageParagraph.TextAlignment = TextAlignment.Left;

            if (data.IsSelf)
            {
                messageParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));
            }

            ProcessMessage(data, messageParagraph, false);

            //messageParagraph.Inlines.Add(fakeHyperlink);
            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestamParagraph  = new Paragraph();

            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestamParagraph.Inlines.Add(DateTime.Now.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestamParagraph);
            timestamParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));
            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");

            MessageRows.Rows.Add(newTableRow);
        }
コード例 #10
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private void tox_OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e)
        {
            MessageData data;
            if (e.MessageType == ToxMessageType.Message)
                data = new MessageData() { Username = getFriendName(e.FriendNumber), Message = e.Message, Timestamp = DateTime.Now };
            else
                data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", getFriendName(e.FriendNumber), e.Message), IsAction = true, Timestamp = DateTime.Now };

            Dispatcher.BeginInvoke(((Action)(() =>
            {
                AddMessageToView(e.FriendNumber, data);

                var friend = ViewModel.GetFriendObjectByNumber(e.FriendNumber);
                if (friend != null)
                {
                    MessageAlertIncrement(friend);

                    if (friend.Selected)
                        ScrollChatBox();
                }
                if (ViewModel.MainToxyUser.ToxStatus != ToxStatus.Busy)
                    this.Flash();

                nIcon.Icon = newMessageNotifyIcon;
                ViewModel.HasNewMessage = true;
            })));

            if (config.EnableChatLogging)
                dbConnection.InsertAsync(new ToxMessage() { PublicKey = tox.GetFriendPublicKey(e.FriendNumber).GetString(), Message = data.Message, Timestamp = DateTime.Now, IsAction = false, Name = data.Username, ProfilePublicKey = tox.Id.PublicKey.GetString() });
        }
コード例 #11
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private void tox_OnGroupMessage(object sender, ToxEventArgs.GroupMessageEventArgs e)
        {
            Dispatcher.BeginInvoke(((Action)(() =>
            {
                var group = ViewModel.GetGroupObjectByNumber(e.GroupNumber);
                if (group == null)
                    return;

                var peer = group.PeerList.GetPeerByPublicKey(tox.GetGroupPeerPublicKey(e.GroupNumber, e.PeerNumber));
                if (peer != null && peer.Ignored)
                    return;

                MessageData data = new MessageData() { Username = tox.GetGroupMemberName(e.GroupNumber, e.PeerNumber), Message = e.Message, Timestamp = DateTime.Now, IsGroupMsg = true, IsSelf = tox.PeerNumberIsOurs(e.GroupNumber, e.PeerNumber) };

                if (groupdic.ContainsKey(e.GroupNumber))
                {
                    var run = groupdic[e.GroupNumber].GetLastMessageRun();

                    if (run != null)
                    {
                        if (((MessageData)run.Tag).Username == data.Username)
                            groupdic[e.GroupNumber].AddNewMessageRow(tox, data, true);
                        else
                            groupdic[e.GroupNumber].AddNewMessageRow(tox, data, false);
                    }
                    else
                    {
                        groupdic[e.GroupNumber].AddNewMessageRow(tox, data, false);
                    }
                }
                else
                {
                    FlowDocument document = FlowDocumentExtensions.CreateNewDocument();
                    groupdic.Add(e.GroupNumber, document);
                    groupdic[e.GroupNumber].AddNewMessageRow(tox, data, false);
                }

                MessageAlertIncrement(group);

                if (group.Selected)
                    ScrollChatBox();

                if (ViewModel.MainToxyUser.ToxStatus != ToxStatus.Busy)
                    this.Flash();

                nIcon.Icon = newMessageNotifyIcon;
                ViewModel.HasNewMessage = true;
            })));
        }
コード例 #12
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private void TextToSend_KeyDown(object sender, KeyEventArgs e)
        {
            var text = TextToSend.Text;

            if (e.Key == Key.Enter)
            {
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    return;

                if (e.IsRepeat)
                    return;

                if (string.IsNullOrEmpty(text))
                    return;

                var selectedChatNumber = ViewModel.SelectedChatNumber;
                if (!tox.IsFriendOnline(selectedChatNumber) && ViewModel.IsFriendSelected)
                {
                    var friendOnlineTip = (string) FindResource("Local_NotOnlineTip");
                    var data = new MessageData
                    {
                        Username = getSelfName(),
                        Message = friendOnlineTip,
                        Id = 0, IsSelf = true, Timestamp = DateTime.Now
                    };
                    AddMessageToView(selectedChatNumber, data);

                    return;
                }

                if (text.StartsWith("/me "))
                {
                    //action
                    string action = text.Substring(4);
                    int messageid = -1;

                    if (ViewModel.IsFriendSelected)
                        messageid = tox.SendMessage(selectedChatNumber, action, ToxMessageType.Action);
                    else if (ViewModel.IsGroupSelected)
                        tox.SendGroupAction(selectedChatNumber, action);

                    MessageData data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", getSelfName(), action), IsAction = true, Id = messageid, IsSelf = true, IsGroupMsg = ViewModel.IsGroupSelected, Timestamp = DateTime.Now };

                    if (ViewModel.IsFriendSelected)
                    {
                        AddActionToView(selectedChatNumber, data);

                        if (config.EnableChatLogging)
                            dbConnection.InsertAsync(new ToxMessage() { PublicKey = tox.GetFriendPublicKey(selectedChatNumber).GetString(), Message = data.Message, Timestamp = DateTime.Now, IsAction = true, Name = data.Username, ProfilePublicKey = tox.Id.PublicKey.GetString() });
                    }
                }
                else
                {
                    //regular message
                    foreach (string message in text.WordWrap(ToxConstants.MaxMessageLength))
                    {
                        int messageid = -1;

                        if (ViewModel.IsFriendSelected)
                            messageid = tox.SendMessage(selectedChatNumber, message, ToxMessageType.Message);
                        else if (ViewModel.IsGroupSelected)
                            tox.SendGroupMessage(selectedChatNumber, message);

                        MessageData data = new MessageData() { Username = getSelfName(), Message = message, Id = messageid, IsSelf = true, IsGroupMsg = ViewModel.IsGroupSelected, Timestamp = DateTime.Now };

                        if (ViewModel.IsFriendSelected)
                        {
                            AddMessageToView(selectedChatNumber, data);

                            if (config.EnableChatLogging)
                                dbConnection.InsertAsync(new ToxMessage() { PublicKey = tox.GetFriendPublicKey(selectedChatNumber).GetString(), Message = data.Message, Timestamp = DateTime.Now, IsAction = false, Name = data.Username, ProfilePublicKey = tox.Id.PublicKey.GetString() });
                        }
                    }
                }

                ScrollChatBox();

                TextToSend.Text = string.Empty;
                e.Handled = true;
            }
            else if (e.Key == Key.Tab && ViewModel.IsGroupSelected)
            {
                string[] names = tox.GetGroupNames(ViewModel.SelectedChatNumber);

                foreach (string name in names)
                {
                    string lastPart = text.Split(' ').Last();
                    if (!name.ToLower().StartsWith(lastPart.ToLower()))
                        continue;

                    if (text.Split(' ').Length > 1)
                    {
                        if (text.Last() != ' ')
                        {
                            TextToSend.Text = string.Format("{0}{1} ", text.Substring(0, text.Length - lastPart.Length), name);
                            TextToSend.SelectionStart = TextToSend.Text.Length;
                        }
                    }
                    else
                    {
                        TextToSend.Text = string.Format("{0}, ", name);
                        TextToSend.SelectionStart = TextToSend.Text.Length;
                    }
                }

                e.Handled = true;
            }
        }
コード例 #13
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private void tox_OnGroupAction(object sender, ToxEventArgs.GroupActionEventArgs e)
        {
            Dispatcher.BeginInvoke(((Action)(() =>
            {
                var group = ViewModel.GetGroupObjectByNumber(e.GroupNumber);
                if (group == null)
                    return;

                var peer = group.PeerList.GetPeerByPublicKey(tox.GetGroupPeerPublicKey(e.GroupNumber, e.PeerNumber));
                if (peer != null && peer.Ignored)
                    return;

                MessageData data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", tox.GetGroupMemberName(e.GroupNumber, e.PeerNumber), e.Action), IsAction = true, Timestamp = DateTime.Now, IsGroupMsg = true, IsSelf = tox.PeerNumberIsOurs(e.GroupNumber, e.PeerNumber) };

                if (groupdic.ContainsKey(e.GroupNumber))
                {
                    groupdic[e.GroupNumber].AddNewMessageRow(tox, data, false);
                }
                else
                {
                    FlowDocument document = FlowDocumentExtensions.CreateNewDocument();
                    groupdic.Add(e.GroupNumber, document);
                    groupdic[e.GroupNumber].AddNewMessageRow(tox, data, false);
                }

                MessageAlertIncrement(group);

                if (group.Selected)
                    ScrollChatBox();

                if (ViewModel.MainToxyUser.ToxStatus != ToxStatus.Busy)
                    this.Flash();
            })));
        }
コード例 #14
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private async void initDatabase()
        {
            dbConnection = new SQLiteAsyncConnection(dbFilename);
            await dbConnection.CreateTableAsync<ToxMessage>().ContinueWith((r) => { Console.WriteLine("Created ToxMessage table"); });

            if (config.EnableChatLogging)
            {
                await dbConnection.Table<ToxMessage>().ToListAsync().ContinueWith((task) =>
                {
                    foreach (ToxMessage msg in task.Result)
                    {
                        if (string.IsNullOrEmpty(msg.ProfilePublicKey) || msg.ProfilePublicKey != tox.Id.PublicKey.GetString())
                            continue;

                        int friendNumber = GetFriendByPublicKey(msg.PublicKey);
                        if (friendNumber == -1)
                            continue;

                        Dispatcher.BeginInvoke(((Action)(() =>
                        {
                            var messageData = new MessageData() { Username = msg.Name, Message = msg.Message, IsAction = msg.IsAction, IsSelf = msg.IsSelf, Timestamp = msg.Timestamp };

                            if (!msg.IsAction)
                                AddMessageToView(friendNumber, messageData);
                            else
                                AddActionToView(friendNumber, messageData);
                        })));
                    }
                });
            }
        }
コード例 #15
0
        static void ProcessMessage(MessageData data, Paragraph messageParagraph, bool append)
        {
            List <string> urls    = new List <string>();
            List <int>    indices = new List <int>();

            string[] parts = data.Message.Split(' ');

            foreach (string part in parts)
            {
                if (Regex.IsMatch(part, @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$"))
                {
                    urls.Add(part);
                }
            }

            if (urls.Count > 0)
            {
                foreach (string url in urls)
                {
                    indices.Add(data.Message.IndexOf(url));
                    data.Message = data.Message.Replace(url, "");
                }

                if (!append)
                {
                    messageParagraph.Inlines.Add(data.Message);
                }
                else
                {
                    messageParagraph.Inlines.Add("\n" + data.Message);
                }

                Inline inline = messageParagraph.Inlines.LastInline;

                for (int i = indices.Count; i-- > 0;)
                {
                    string url   = urls[i];
                    int    index = append ? indices[i] + 1 : indices[i];

                    Run         run     = new Run(url);
                    TextPointer pointer = new TextRange(inline.ContentStart, inline.ContentEnd).Text == "\n" ? inline.ContentEnd : inline.ContentStart;

                    Hyperlink link = new Hyperlink(run, pointer.GetPositionAtOffset(index));
                    link.IsEnabled = true;
                    link.Click    += delegate(object sender, RoutedEventArgs args)
                    {
                        try { Process.Start(url); }
                        catch
                        {
                            try { Process.Start("http://" + url); }
                            catch { }
                        }
                    };
                }
            }
            else
            {
                if (!append)
                {
                    messageParagraph.Inlines.Add(data.Message);
                }
                else
                {
                    messageParagraph.Inlines.Add("\n" + data.Message);
                }
            }
        }
コード例 #16
0
        static void ProcessMessage(MessageData data, Paragraph messageParagraph, bool append, EmojiProvider emojiProvider)
        {
            List<string> urls = new List<string>();
            List<int> indices = new List<int>();
            string[] parts = data.Message.Split(' ');

            foreach (string part in parts)
            {
                if (Regex.IsMatch(part, @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$"))
                    urls.Add(part);
            }

            if (urls.Count > 0)
            {
                foreach (string url in urls)
                {
                    indices.Add(data.Message.IndexOf(url));
                    data.Message = data.Message.Replace(url, "");
                }

                if (!append)
                    messageParagraph.Inlines.Add(data.Message);
                else
                    messageParagraph.Inlines.Add("\n" + data.Message);

                Inline inline = messageParagraph.Inlines.LastInline;

                for (int i = indices.Count; i-- > 0; )
                {
                    string url = urls[i];
                    int index = append ? indices[i] + 1 : indices[i];

                    Run run = new Run(url);
                    TextPointer pointer = new TextRange(inline.ContentStart, inline.ContentEnd).Text == "\n" ? inline.ContentEnd : inline.ContentStart;

                    Hyperlink link = new Hyperlink(run, pointer.GetPositionAtOffset(index));
                    link.IsEnabled = true;
                    link.Click += delegate(object sender, RoutedEventArgs args)
                    {
                        try { Process.Start(url); }
                        catch
                        {
                            try { Process.Start("http://" + url); }
                            catch { }
                        }
                    };
                }
            }
            else
            {
                if (!append)
                    messageParagraph.Inlines.Add(data.Message);
                else
                    messageParagraph.Inlines.Add("\n" + data.Message);

                emojiProvider.ParseText(messageParagraph);
            }
        }
コード例 #17
0
ファイル: MainWindow.xaml.cs プロジェクト: kstaruch/Toxy
        private void tox_OnFriendAction(int friendnumber, string action)
        {
            MessageData data = new MessageData() { Username = "******", Message = string.Format("{0} {1}", tox.GetName(friendnumber), action), IsAction = true };

            if (convdic.ContainsKey(friendnumber))
            {
                convdic[friendnumber].AddNewMessageRow(tox, data, emojis);
            }
            else
            {
                FlowDocument document = GetNewFlowDocument();
                convdic.Add(friendnumber, document);
                convdic[friendnumber].AddNewMessageRow(tox, data, emojis);
            }

            var friend = this.ViewModel.GetFriendObjectByNumber(friendnumber);
            if (friend != null)
            {
                if (!friend.Selected)
                {
                    friend.HasNewMessage = true;
                    friend.NewMessageCount++;
                }
                else
                {
                    ScrollChatBox();
                }
            }
            if (this.ViewModel.MainToxyUser.ToxStatus != ToxUserStatus.BUSY)
                this.Flash();

            this.nIcon.Icon = newMessageNotifyIcon;
            this.ViewModel.HasNewMessage = true;
        }
コード例 #18
0
 public static void AppendMessage(this FlowDocument doc, MessageData data, EmojiProvider emojiProvider)
 {
     TableRow tableRow = doc.FindChildren<TableRow>().Last();
     Paragraph para = (Paragraph)tableRow.FindChildren<TableCell>().ElementAt(1).Blocks.LastBlock;
     Paragraph timestampParagraph = (Paragraph)tableRow.FindChildren<TableCell>().Last().Blocks.LastBlock;
     timestampParagraph.Inlines.Add(Environment.NewLine + DateTime.Now.ToShortTimeString());
     ProcessMessage(data, para, true, emojiProvider);
 }
コード例 #19
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        private void AddMessageToView(int friendNumber, MessageData data)
        {
            if (convdic.ContainsKey(friendNumber))
            {
                var run = convdic[friendNumber].GetLastMessageRun();

                if (run != null && run.Tag.GetType() == typeof(MessageData))
                {
                    if (((MessageData)run.Tag).Username == data.Username)
                        convdic[friendNumber].AddNewMessageRow(tox, data, true);
                    else
                        convdic[friendNumber].AddNewMessageRow(tox, data, false);
                }
                else
                {
                    convdic[friendNumber].AddNewMessageRow(tox, data, false);
                }
            }
            else
            {
                FlowDocument document = FlowDocumentExtensions.CreateNewDocument();
                convdic.Add(friendNumber, document);
                convdic[friendNumber].AddNewMessageRow(tox, data, false);
            }
        }