private async void GetConvo(MessageThread messagethread) { reader = messagethread.ChatConversation.GetMessageReader(); list = await reader.ReadBatchAsync(); foreach (var item in list) { if (item.IsIncoming) { var mesage = new Message { Body = item.Body, Alignment = HorizontalAlignment.Left, Color = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorDark1"], DateTime = item.LocalTimestamp.DateTime.ToString("MM/dd, HH:mm"), Margin = new Thickness(10, 10, 60, 10) }; Conversation.Add(mesage); } else { var mesage = new Message { Body = item.Body, Alignment = HorizontalAlignment.Left, Color = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorLight1"], DateTime = item.LocalTimestamp.DateTime.ToString("MM/dd, HH:mm"), Margin = new Thickness(60, 10, 10, 10) }; Conversation.Add(mesage); } } var ordered = Conversation.OrderBy(x => x.DateTime); ConversationList.ItemsSource = ordered; ConversationList.ScrollIntoView(ordered.Last()); if (messagethread.ChatConversation.Participants.Count > 1) { var list = new List <MenuFlyoutItem>(); var flyout = new MenuFlyout(); for (int i = 0; i > messagethread.ChatConversation.Participants.Count; i++) { var flyitem = new MenuFlyoutItem { Text = messagethread.ChatConversation.Participants[i], Tag = messagethread.ChatConversation.Participants[i] }; flyitem.Tapped += Flyitem_Tapped; flyout.Items.Add(flyitem); } CallButton.Flyout = flyout; } else { CallButton.Tag = messagethread.ChatConversation.Participants.FirstOrDefault(); CallButton.Click += CallButton_Click; } }
private async Task <string> Getrecentmessage(string mostRecentMessageId, ChatMessageReader chatMessageReader) { var Recentmessage = new ChatMessage(); var batch = await chatMessageReader.ReadBatchAsync(); var item = batch.Where(x => x.Id == mostRecentMessageId); Recentmessage = item.FirstOrDefault(); var body = Recentmessage.Body; return(body); }
private async Task <string> GetrecentmessageTime(string mostRecentMessageId, ChatMessageReader chatMessageReader) { var Recentmessage = new ChatMessage(); var batch = await chatMessageReader.ReadBatchAsync(); var item = batch.Where(x => x.Id == mostRecentMessageId); Recentmessage = item.FirstOrDefault(); var time = Recentmessage.LocalTimestamp.LocalDateTime.GetDateTimeFormats()[0]; return(time); }
public async void Run(IBackgroundTaskInstance taskInstance) { // A message has been received from a sender not on the block list. // We must decide whether to block it or to allow it. var deferral = taskInstance.GetDeferral(); Dictionary <string, ChatMessageTransportKind> transportIdToTransportKind = new Dictionary <string, ChatMessageTransportKind>(); // Prepare the mapping for TransportKind check var transports = await ChatMessageManager.GetTransportsAsync(); foreach (ChatMessageTransport transport in transports) { transportIdToTransportKind[transport.TransportId] = transport.TransportKind; } ChatMessageStore msgStore = await ChatMessageManager.RequestStoreAsync(); // Untriaged is a transient status for less than 1 second. // If a message is not blocked in time, the status will be changed by system. // The message blocked by block list will not fire this trigger. ChatMessageReader msgReader = msgStore.GetMessageReader(TimeSpan.FromSeconds(1)); var msgList = await msgReader.ReadBatchAsync(); foreach (ChatMessage msg in msgList) { if (transportIdToTransportKind[msg.TransportId] == ChatMessageTransportKind.Untriaged) { // Check if the message should be blocked. // This sample blocks messages whose text is "block me". if (msg.Body == "block me") { try { await ChatMessageBlocking.MarkMessageAsBlockedAsync(msg.Id, true); } catch (System.UnauthorizedAccessException) { // Untriaged message will be recalled by system in 1 second. Toast.Send("Block failed due to timeout"); } } } } deferral.Complete(); }