コード例 #1
0
ファイル: ChatWindow.xaml.cs プロジェクト: AregPapyan/ChatHub
        private async void CallingAPIs()
        {
            string currentPath             = Environment.CurrentDirectory + "\\token.txt";
            string accesstoken             = File.ReadAllText(currentPath);
            var    accessTokenDeserialised = JsonConvert.DeserializeObject <AuthServerResponse>(accesstoken);

            MessageClient messageClient = new MessageClient(AccessToken);

            AllUnreadMessages = await messageClient.GetAllUnreadMessages();

            MessageToFrom messageNotif = new MessageToFrom();

            messageNotif.To = Username;

            for (int i = 0; i < Contacts.Count(); i++)
            {
                if (Contacts[i] != null)
                {
                    messageNotif.From = Contacts[i].Username;
                    var unreadMessages = await messageClient.UnreadMessages(messageNotif);

                    if (unreadMessages != null && unreadMessages.Count() != 0)
                    {
                        ContactsList.Items[i] = Contacts[i].Username + " (" + unreadMessages.Count() + ")";
                    }
                    if (unreadMessages.Count() == 0)
                    {
                        ContactsList.Items[i] = Contacts[i].Username;
                    }
                }
            }
        }
コード例 #2
0
        private async void CallingAPIs()
        {
            MessageClient messageClient = new MessageClient(AccessToken);

            MessageToFrom messageNotif = new MessageToFrom
            {
                To = Username
            };

            for (int i = 0; i < Contacts.Count(); i++)
            {
                if (Contacts[i] != null)
                {
                    messageNotif.From = Contacts[i].Username;
                    var unreadMessages = await messageClient.UnreadMessages(messageNotif); //getting unread massages

                    if (unreadMessages != null && unreadMessages.Count() != 0)
                    {
                        ContactsList.Items[i] = Contacts[i].Username + " (" + unreadMessages.Count() + ")"; //checking the contact name
                    }
                    if (unreadMessages.Count() == 0)                                                        //if no unread messages, do nothing
                    {
                        ContactsList.Items[i] = Contacts[i].Username;
                    }
                }
            }
        }
コード例 #3
0
        private async void RadGridView_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            ChatMessages.Items.Clear(); //deleting all messages in a UI

            ActiveUserClient activeUsers = new ActiveUserClient();
            var activeUserInfo           = await activeUsers.ActiveUsers(AccessToken);

            MessageToFrom message = new MessageToFrom();

            message.To = Username;

            foreach (var contact in activeUserInfo)
            {
                if (contact.Username.Contains(ContactsList.SelectedItem.ToString()))
                {
                    message.From = contact.Username; //checking the contact name
                }
            }

            MessageClient messageClient = new MessageClient(AccessToken);
            var           messages      = await messageClient.ReadAllMessages(message); //getting all messages

            foreach (var mess in messages)
            {
                ChatMessages.Items.Add(mess.From + ": " + mess.MessageText);
            }
        }
コード例 #4
0
        private async void SendMessageButtonClick(object sender, RoutedEventArgs e)
        {
            if ((MessageTextbox.Text == "") || (MessageTextbox.Text == "Type your message here..."))
            {
                return;
            }

            MessageClient messageClient = new MessageClient(AccessToken);
            Message       newMessage    = new Message
            {
                MessageText = MessageTextbox.Text,
                From        = Username
            };

            foreach (var contact in Contacts)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    newMessage.To = contact.Username; //checking the contact name
                }
            }

            var isSent = await messageClient.SendMessage(newMessage); //sending a message

            if (isSent)
            {
                MessageTextbox.Text = string.Empty;
                ChatMessages.Items.Add(newMessage.From + ": " + newMessage.MessageText);
            }
        }
コード例 #5
0
ファイル: ChatWindow.xaml.cs プロジェクト: AregPapyan/ChatHub
        private async void RadGridView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ChatMessages.Items.Clear();

            //string currentPath = Environment.CurrentDirectory + "\\token.txt";
            //string accesstoken = File.ReadAllText(currentPath);
            //var accessTokenDeserialised = JsonConvert.DeserializeObject<AuthServerResponse>(accesstoken);

            ActiveUserClient activeUsers = new ActiveUserClient();
            var activeUserInfo           = await activeUsers.ActiveUsers(AccessToken);

            MessageToFrom message = new MessageToFrom();

            message.To = Username;

            MessageClient messageClient = new MessageClient(AccessToken);

            foreach (var contact in activeUserInfo)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    ContactsList.SelectedItem = contact.Username;
                    message.From = contact.Username;

                    await messageClient.MakeMessageRead(message);

                    break;
                }
            }

            var messages = await messageClient.ReadAllMessages(message);


            foreach (var mess in messages)
            {
                ChatMessages.Items.Add(mess.From + ": " + mess.MessageText);
            }


            //ChatMessages.Items.Clear();
            //HttpClient client = new HttpClient();
            //var response = client.GetAsync(string.Format("{0}/{1}/{2}", messageapi, Username, RadGridView.SelectedItem.ToString()));//.Result.Content.ReadAsStringAsync().Result;
            //var jsonresult = response.Result.Content.ReadAsStringAsync().Result;
            //var result = JsonConvert.DeserializeObject<List<Message>>(jsonresult);

            //foreach (var item in result)
            //{
            //    if(!ChatMessages.Items.Contains(item.MessageText)) ChatMessages.Items.Add(item.MessageText);
            //}
            MessageTextbox.Text = "Type your message here...";
        }
コード例 #6
0
ファイル: ChatWindow.xaml.cs プロジェクト: AregPapyan/ChatHub
        private async void SendMessageButtonClick(object sender, RoutedEventArgs e)
        {
            //string currentPath = Environment.CurrentDirectory + "\\token.txt";
            //string accesstoken = File.ReadAllText(currentPath);
            //var accessTokenDeserialised = JsonConvert.DeserializeObject<AuthServerResponse>(accesstoken);

            MessageClient messageClient = new MessageClient(AccessToken);
            Message       newMessage    = new Message();

            newMessage.MessageText = MessageTextbox.Text;
            newMessage.From        = Username;

            foreach (var contact in Contacts)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    newMessage.To = contact.Username;
                }
            }

            var isSent = await messageClient.SendMessage(newMessage);

            if (isSent)
            {
                MessageTextbox.Text = string.Empty;
                ChatMessages.Items.Add(newMessage.From + ": " + newMessage.MessageText);
            }
            //if ((MessageTextbox.Text == "") || (MessageTextbox.Text == "Type your message here...")) return;

            ////Call sendMessageService
            //HttpClient client = new HttpClient();
            ////Post client
            //Message message = new Message(Username, RadGridView.SelectedItem.ToString(), MessageTextbox.Text, false);
            //var Json = JsonConvert.SerializeObject(message);
            //var httpContent = new StringContent(Json, Encoding.UTF8, "application/json");
            //await client.PostAsync(messageapi, httpContent);
            ////post client
            ////Call sendMessageService

            //var response = client.GetAsync(string.Format("{0}/{1}/{2}",messageapi, Username, RadGridView.SelectedItem.ToString()));//.Result.Content.ReadAsStringAsync().Result;
            //var jsonresult = response.Result.Content.ReadAsStringAsync().Result;
            //var result = JsonConvert.DeserializeObject<List<Message>>(jsonresult);

            //foreach (var item in result)
            //{
            //}
            //MessageTextbox.Text = "Type your message here...";
        }
コード例 #7
0
        private async void RadGridView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ChatMessages.Items.Clear();

            ActiveUserClient activeUsers = new ActiveUserClient();
            var activeUserInfo           = await activeUsers.ActiveUsers(AccessToken); //giving client and access token

            MessageToFrom message = new MessageToFrom
            {
                To = Username
            };

            MessageClient messageClient = new MessageClient(AccessToken);

            foreach (var contact in activeUserInfo)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    ContactsList.SelectedItem = contact.Username;
                    message.From = contact.Username;

                    await messageClient.MakeMessageRead(message);

                    break;
                }
            }

            var messages = await messageClient.ReadAllMessages(message); //reading all messages with this contact


            foreach (var mess in messages)
            {
                ChatMessages.Items.Add(mess.From + ": " + mess.MessageText); // adding all messages to a messageItems
            }

            MessageTextbox.Text = "Type your message here...";
        }