private async void InboxList_SelectionChanged(object sender, SelectionChangedEventArgs e) { var ClickedItem = InboxList.SelectedItem as InboxViewModel; var Chats = await Api.InstaApi.GetDirectInboxThreadAsync(ClickedItem.TTag); ChatDetails.Items.Clear(); foreach (var chat in Chats.Value.Items.OrderBy(x => x.TimeStamp).ToList()) { if (chat.UserId == Api.Userid) { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#e3e3e3", StrokeThickness = "0", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString(), Text = chat.Text, Dir = FlowDirection.RightToLeft }); } else { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#fff", StrokeThickness = "1", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString(), Text = chat.Text, Dir = FlowDirection.LeftToRight }); } } ChatDetails.SelectedIndex = ChatDetails.Items.Count - 1; ChatDetails.ScrollIntoView(ChatDetails.SelectedItem); }
private async void DispatcherTimer_Tick(object sender, object e) { try { var inbox = await Api.InstaApi.GetDirectInboxAsync(); foreach (var innerinbox in InboxList.Items) { var element = innerinbox as InboxViewModel; var newelement = inbox.Value.Inbox.Threads.Where(x => x.ThreadId == element.TTag).First(); try { if (newelement.Items[0].TimeStamp != element.LMDate) { //element.LastMessage = inbox.Value.Inbox.Threads.Where(x => x.ThreadId == element.TTag).First().Items[0].Text ?? ""; //element.Notify = Visibility.Visible; (InboxList.Items.Where(x => (x as InboxViewModel).TTag == element.TTag).First() as InboxViewModel).LastMessage = newelement.Items[0].Text; (InboxList.Items.Where(x => (x as InboxViewModel).TTag == element.TTag).First() as InboxViewModel).Notify = Visibility.Visible; } } catch { } } if (ChatDetails.Items.Count > 0) { var ClickedItem = InboxList.SelectedItem as InboxViewModel; var Chats = await Api.InstaApi.GetDirectInboxThreadAsync(ClickedItem.TTag); ChatDetails.Items.Clear(); foreach (var chat in Chats.Value.Items.OrderBy(x => x.TimeStamp).ToList()) { if (chat.UserId == Api.Userid) { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#e3e3e3", StrokeThickness = "0", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString(), Text = chat.Text, Dir = FlowDirection.RightToLeft }); } else { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#fff", StrokeThickness = "1", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString(), Text = chat.Text, Dir = FlowDirection.LeftToRight }); } } ChatDetails.SelectedIndex = ChatDetails.Items.Count - 1; ChatDetails.ScrollIntoView(ChatDetails.SelectedItem); } } catch { } }
private async void SendBtn_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(TextToSend.Text)) { SendBtn.IsEnabled = false; //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); var result = await Api.InstaApi.SendDirectMessage((InboxList.SelectedItem as InboxViewModel).UTag, (InboxList.SelectedItem as InboxViewModel).TTag, TextToSend.Text); if (result.Succeeded) { var ClickedItem = InboxList.SelectedItem as InboxViewModel; var Chats = await Api.InstaApi.GetDirectInboxThreadAsync(ClickedItem.TTag); ChatDetails.Items.Clear(); foreach (var chat in Chats.Value.Items.OrderBy(x => x.TimeStamp).ToList()) { if (chat.UserId == Api.Userid) { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#e3e3e3", StrokeThickness = "0", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString() + " " + chat.TimeStamp.ToShortTimeString(), Text = chat.Text, Dir = FlowDirection.RightToLeft }); } else { ChatDetails.Items.Add(new ChatViewModel() { Fill = "#fff", StrokeThickness = "1", ItemId = chat.ItemId, Date = chat.TimeStamp.ToShortDateString() + " " + chat.TimeStamp.ToShortTimeString(), Text = chat.Text, Dir = FlowDirection.LeftToRight }); } } } //stopwatch.Stop(); ChatDetails.SelectedIndex = ChatDetails.Items.Count - 1; ChatDetails.ScrollIntoView(ChatDetails.SelectedItem); TextToSend.Text = ""; SendBtn.IsEnabled = true; } }