public void DeleteMessages()
        {
            if (Items == null)
            {
                return;
            }

            var messages = Items.Where(x => ((TLMessageBase)x).IsSelected).Cast <TLMessageBase>().ToList();

            if (messages.Count == 0)
            {
                return;
            }

            var randomItems = messages.Where(x => (x.Id == null || x.Id.Value == 0) && x.RandomId != null).ToList();
            var items       = messages.Where(x => x.Id != null && x.Id.Value != 0).ToList();

            if (randomItems.Count > 0 || items.Count > 0)
            {
                IsSelectionEnabled = false;
            }

            var owner = Peer as TLObject;

            if (Peer is TLBroadcastChat)
            {
                DeleteMessagesInternal(owner, null, randomItems);
                DeleteMessagesInternal(owner, null, items);
                return;
            }

            DialogDetailsViewModel.DeleteMessages(MTProtoService, null, randomItems, items, (result1, result2) => DeleteMessagesInternal(owner, result1, result2), (result1, result2) => DeleteMessagesInternal(owner, result1, result2));
        }
        public void DeleteMessage(TLMessage message)
        {
            if (message == null)
            {
                return;
            }

            var messages = new List <TLMessageBase> {
                message
            };

            var owner = Peer as TLObject;

            if (Peer 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, null, messages, null, (result1, result2) => DeleteMessagesInternal(owner, result1, result2));
        }
Example #3
0
        public void DeleteDialog(TLDialogBase dialogBase)
        {
            var dialog = dialogBase as TLDialog;

            if (dialog == null)
            {
                return;
            }

            var message = dialog.TopMessage as TLMessageCommon;

            if (message == null)
            {
                return;
            }

            var messages = new List <TLMessageBase> {
                message
            };

            var owner = message.Out.Value ? CacheService.GetUser(message.ToId.Id) : message.From;

            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));
        }
Example #4
0
        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));
        }
Example #5
0
        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 = messages.Where(x => (x.Id == null || x.Id.Value == 0) && x.RandomId != null).ToList();
            var items       = messages.Where(x => x.Id != null && x.Id.Value != 0).ToList();

            if (randomItems.Count == 0 && items.Count == 0)
            {
                return;
            }

            IsSelectionEnabled = false;

            var owner = CurrentItem as TLObject;

            if (CurrentItem is TLBroadcastChat)
            {
                DeleteMessagesInternal(owner, randomItems);
                DeleteMessagesInternal(owner, items);
                return;
            }

            DialogDetailsViewModel.DeleteMessages(MTProtoService, null, randomItems, items, (result1, result2) => DeleteMessagesInternal(owner, result2), (result1, result2) => DeleteMessagesInternal(owner, result2));
        }
Example #6
0
        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));
        }