コード例 #1
0
        private void SentButton_Click(object sender, RoutedEventArgs e)
        {
            UserControlMessageSent userControlMessageSent = new UserControlMessageSent();

            userControlMessageSent.changeText(messageTextBox.Text);
            userControlMessageSent.HorizontalAlignment = HorizontalAlignment.Right;
            if (selectedId != null && !selectedStatus)
            {
                MessageEvent @event = new MessageEvent("Send", "chat", selectedId, DateTime.Now, -1, messageTextBox.Text);
                ConnectToServer.SendRequest(@event);
            }
            //ConnectToServer.SendRequest($"send chat {selectedId} {DateTime.Now.ToShortTimeString()} {messageTextBox.Text}");
            else
            {
                MessageEvent @event = new MessageEvent("Send", "group", selectedId, DateTime.Now, -1, messageTextBox.Text);
                ConnectToServer.SendRequest(@event);
            }
            //ConnectToServer.SendRequest($"send group {selectedId} {DateTime.Now.ToShortTimeString()} {messageTextBox.Text}");
            userControlMessageSent.timeSent.Text = DateTime.Now.ToShortTimeString().ToString();
            messagePlace.Children.Add(userControlMessageSent);
            messageTextBox.Clear();
            scrollViewerMess.ScrollToBottom();
        }
コード例 #2
0
 public void senderMessage(List <userMessages> mess, bool totalFlag)
 {
     if (mess.Count > 1)
     {
         for (int i = 0; i < mess.Count; i++)
         {
             if (mess[i].senderId == userId)
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageSent userControlMessageSent = new UserControlMessageSent();
                     userControlMessageSent.changeText(mess[i].content);
                     userControlMessageSent.Id = mess[i].messageId;
                     userControlMessageSent.HorizontalAlignment = HorizontalAlignment.Right;
                     userControlMessageSent.timeSent.Text       = mess[i].createAt.ToString();
                     messagePlace.Children.Add(userControlMessageSent);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[i].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[i].content;
                     userControlMessageReceived.Id = mess[i].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
         }
     }
     else
     {
         if (totalFlag)
         {
             if (mess[0].recipientGroupId == Convert.ToInt32(selectedId))
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[0].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[0].content;
                     userControlMessageReceived.Id = mess[0].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     foreach (ListViewItem lvi in this.listViewI)
                     {
                         if (lvi.Name == $"id{mess[0].recipientGroupId}")
                         {
                             ListViewItem listViewItem = (ListViewItem)listViewI[listViewI.IndexOf(lvi)];
                             if ((bool)listViewItem.Tag)
                             {
                                 Border border     = (Border)listViewItem.FindName("messageBorderCount");
                                 TextBlock block   = (TextBlock)listViewItem.FindName("messageCount");
                                 border.Visibility = Visibility.Visible;
                                 block.Text        = Convert.ToString(Convert.ToInt32(block.Text) + 1);
                                 messageTextBox.Focus();
                             }
                         }
                     }
                 }));
             }
         }
         else
         {
             if (mess[0].recipientChatId == Convert.ToInt32(selectedId))
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[0].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[0].content;
                     userControlMessageReceived.Id = mess[0].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     messageTextBox.Focus();
                     scrollViewerMess.ScrollToBottom();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     foreach (ListViewItem lvi in this.listViewI)
                     {
                         if (lvi.Name == $"id{mess[0].recipientChatId}")
                         {
                             ListViewItem listViewItem = (ListViewItem)listViewI[listViewI.IndexOf(lvi)];
                             if (!(bool)listViewItem.Tag)
                             {
                                 Border border     = (Border)listViewItem.FindName("messageBorderCount");
                                 TextBlock block   = (TextBlock)listViewItem.FindName("messageCount");
                                 border.Visibility = Visibility.Visible;
                                 block.Text        = Convert.ToString(Convert.ToInt32(block.Text) + 1);
                                 messageTextBox.Focus();
                             }
                         }
                     }
                 }));
             }
         }
     }
 }