public void DeleteMessage(TLMessageBase message) { if (message == null) { return; } var messages = new List <TLMessageBase> { message }; var owner = CurrentItem as TLObject; var channel = CurrentItem as TLChannel; if (channel != null) { var messageCommon = message as TLMessageCommon; if (messageCommon != null) { if (messageCommon.ToId is TLPeerChat) { DialogDetailsViewModel.DeleteMessages(MTProtoService, false, null, null, messages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); return; } } DialogDetailsViewModel.DeleteChannelMessages(MTProtoService, channel, null, null, messages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); return; } if (CurrentItem is TLBroadcastChat) { DeleteMessagesInternal(owner, null, messages); return; } if ((message.Id == null || message.Id.Value == 0) && message.RandomIndex != 0) { DeleteMessagesInternal(owner, null, messages); return; } DialogDetailsViewModel.DeleteMessages(MTProtoService, false, null, null, messages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); }
public void DeleteMessages() { if (Items == null) { return; } var messages = new List <TLMessageBase>(); foreach (var item in Items.Where(x => x.IsSelected)) { messages.Add(item); } if (messages.Count == 0) { return; } var randomItems = new List <TLMessageBase>(); var items = new List <TLMessageBase>(); TLMessageBase lastItem = null; for (var i = 0; i < Items.Count; i++) { var message = Items[i]; if (message.IsSelected) { if (message.Index == 0 && message.RandomIndex != 0) { randomItems.Add(message); lastItem = null; } else if (message.Index != 0) { items.Add(message); lastItem = null; } } else { if (lastItem == null) { lastItem = message; } } } if (randomItems.Count == 0 && items.Count == 0) { return; } IsSelectionEnabled = false; var owner = CurrentItem as TLObject; var channel = CurrentItem as TLChannel; if (channel != null) { var chatMessages = new List <TLMessageBase>(); var channelMessages = new List <TLMessageBase>(); if (channel.MigratedFromChatId != null) { foreach (var item in items) { var message = item as TLMessageCommon; if (message != null && message.ToId is TLPeerChat) { chatMessages.Add(message); } else { channelMessages.Add(message); } } } if (chatMessages.Count > 0) { DialogDetailsViewModel.DeleteChannelMessages(MTProtoService, channel, lastItem, null, channelMessages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); DialogDetailsViewModel.DeleteMessages(MTProtoService, false, lastItem, null, chatMessages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); return; } DialogDetailsViewModel.DeleteChannelMessages(MTProtoService, channel, lastItem, randomItems, items, (result1, result2) => DeleteMessagesInternal(owner, result1, result2), (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); return; } if (CurrentItem is TLBroadcastChat) { DeleteMessagesInternal(owner, null, randomItems); DeleteMessagesInternal(owner, null, items); return; } DialogDetailsViewModel.DeleteMessages(MTProtoService, false, null, randomItems, items, (result1, result2) => DeleteMessagesInternal(owner, result1, result2), (result1, result2) => DeleteMessagesInternal(owner, result1, result2)); }