Ejemplo n.º 1
0
        private async void MessageDeleteExecute(MessageViewModel message)
        {
            if (message == null)
            {
                return;
            }

            var chat = message.GetChat();

            if (chat == null)
            {
                return;
            }

            //if (message != null && message.Media is TLMessageMediaGroup groupMedia)
            //{
            //    ExpandSelection(new[] { message });
            //    MessagesDeleteExecute();
            //    return;
            //}

            if (message != null && !message.IsOutgoing && !message.IsChannelPost && chat.Type is ChatTypeSupergroup super && !super.IsChannel)
            {
                var sender = message.GetSenderUser();
                var dialog = new DeleteChannelMessageDialog(1, sender?.GetFullName());

                var result = await dialog.ShowQueuedAsync();

                if (result == ContentDialogResult.Primary)
                {
                    if (dialog.DeleteAll)
                    {
                        ProtoService.Send(new DeleteChatMessagesFromUser(chat.Id, message.SenderUserId));
                    }
                    else
                    {
                        ProtoService.Send(new DeleteMessages(chat.Id, new[] { message.Id }, true));
                    }

                    if (dialog.BanUser)
                    {
                        ProtoService.Send(new SetChatMemberStatus(chat.Id, message.SenderUserId, new ChatMemberStatusBanned()));
                    }

                    if (dialog.ReportSpam && chat.Type is ChatTypeSupergroup supertype)
                    {
                        ProtoService.Send(new ReportSupergroupSpam(supertype.SupergroupId, message.SenderUserId, new[] { message.Id }));
                    }
                }
            }
Ejemplo n.º 2
0
        private async void MessageDeleteExecute(TLMessageBase messageBase)
        {
            if (messageBase == null)
            {
                return;
            }

            var message = messageBase as TLMessage;

            if (message != null && !message.IsOut && !message.IsPost && Peer is TLInputPeerChannel)
            {
                var dialog = new DeleteChannelMessageDialog();

                var result = await dialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    var channel = With as TLChannel;

                    if (dialog.DeleteAll)
                    {
                        // TODO
                    }
                    else
                    {
                        var messages = new List <TLMessageBase>()
                        {
                            messageBase
                        };
                        if (messageBase.Id == 0 && messageBase.RandomId != 0L)
                        {
                            DeleteMessagesInternal(null, messages);
                            return;
                        }

                        DeleteMessages(null, null, messages, true, null, DeleteMessagesInternal);
                    }

                    if (dialog.BanUser)
                    {
                        var response = await ProtoService.KickFromChannelAsync(channel, message.From.ToInputUser(), true);

                        if (response.IsSucceeded)
                        {
                            var updates = response.Result as TLUpdates;
                            if (updates != null)
                            {
                                var newChannelMessageUpdate = updates.Updates.OfType <TLUpdateNewChannelMessage>().FirstOrDefault();
                                if (newChannelMessageUpdate != null)
                                {
                                    Aggregator.Publish(newChannelMessageUpdate.Message);
                                }
                            }
                        }
                    }

                    if (dialog.ReportSpam)
                    {
                        var response = await ProtoService.ReportSpamAsync(channel.ToInputChannel(), message.From.ToInputUser(), new TLVector <int> {
                            message.Id
                        });
                    }
                }
            }
            else
            {
                var dialog = new TLMessageDialog();
                dialog.Title               = "Delete";
                dialog.Message             = "Do you want to delete this message?";
                dialog.PrimaryButtonText   = "Yes";
                dialog.SecondaryButtonText = "No";

                var chat = With as TLChat;

                if (message != null && (message.IsOut || (chat != null && (chat.IsCreator || chat.IsAdmin))) && message.ToId.Id != SettingsHelper.UserId && (Peer is TLInputPeerUser || Peer is TLInputPeerChat))
                {
                    var date   = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now);
                    var config = CacheService.GetConfig();
                    if (config != null && message.Date + config.EditTimeLimit > date)
                    {
                        var user = With as TLUser;
                        if (user != null)
                        {
                            dialog.CheckBoxLabel = string.Format("Delete for {0}", user.FullName);
                        }

                        //var chat = With as TLChat;
                        if (chat != null)
                        {
                            dialog.CheckBoxLabel = "Delete for everyone";
                        }
                    }
                }
                else if (Peer is TLInputPeerUser)
                {
                    dialog.Message += "\r\n\r\nThis will delete it just for you.";
                }
                else if (Peer is TLInputPeerChat)
                {
                    dialog.Message += "\r\n\r\nThis will delete it just for you, not for other participants of the chat.";
                }
                else if (Peer is TLInputPeerChannel)
                {
                    dialog.Message += "\r\n\r\nThis will delete it for everyone in this chat.";
                }

                var result = await dialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    var revoke = dialog.IsChecked == true;

                    var messages = new List <TLMessageBase>()
                    {
                        messageBase
                    };
                    if (messageBase.Id == 0 && messageBase.RandomId != 0L)
                    {
                        DeleteMessagesInternal(null, messages);
                        return;
                    }

                    DeleteMessages(null, null, messages, revoke, null, DeleteMessagesInternal);
                }
            }
        }