示例#1
0
        private static async void ShowPeerFloodAlert(int reason)
        {
            var dialog = new TLMessageDialog();

            dialog.Title             = Branding.ServiceName;
            dialog.PrimaryButtonText = Strings.Android.OK;

            if (reason != 2)
            {
                dialog.SecondaryButtonText   = Strings.Android.MoreInfo;
                dialog.SecondaryButtonClick += (s, args) =>
                {
                    MessageHelper.NavigateToUsername("spambot", null, null, null);
                };
            }

            if (reason == 0)
            {
                dialog.Message = Strings.Android.NobodyLikesSpam1;
            }
            else if (reason == 1)
            {
                dialog.Message = Strings.Android.NobodyLikesSpam2;
            }
            else if (reason == 2)
            {
                //builder.setMessage((String)args[1]);
            }

            await dialog.ShowQueuedAsync();
        }
示例#2
0
        private async void TerminateExecute(ConnectedWebsite session)
        {
            var bot = ProtoService.GetUser(session.BotUserId);

            if (bot == null)
            {
                return;
            }

            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Resources.AppName;
            dialog.Message             = string.Format(Strings.Resources.TerminateWebSessionQuestion, session.DomainName);
            dialog.PrimaryButtonText   = Strings.Resources.OK;
            dialog.SecondaryButtonText = Strings.Resources.Cancel;
            dialog.CheckBoxLabel       = string.Format(Strings.Resources.TerminateWebSessionStop, bot.FirstName);

            var terminate = await dialog.ShowQueuedAsync();

            if (terminate == ContentDialogResult.Primary)
            {
                var response = await ProtoService.SendAsync(new DisconnectWebsite(session.Id));

                if (response is Ok)
                {
                    Items.Remove(session);
                }
                else if (response is Error error)
                {
                    Execute.ShowDebugMessage("auth.resetWebAuthotization error " + error);
                }

                ProtoService.Send(new BlockUser(bot.Id));
            }
        }
示例#3
0
        //public static void ProcessError(IDispatcherWrapper fragment, Error error, Type request, params object[] args)
        //{
        //    if (error.Code == 406 || error.Message == null)
        //    {
        //        return null;
        //    }

        //    if (request is TL_account_saveSecureValue || request is TL_account_getAuthorizationForm)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_channels_joinChannel ||
        //     request is TL_channels_editAdmin ||
        //     request is TL_channels_inviteToChannel ||
        //     request is TL_messages_addChatUser ||
        //     request is TL_messages_startBot ||
        //     request is TL_channels_editBanned)
        //    {
        //        if (fragment != null)
        //        {
        //            ShowAddUserAlert(error.Message, fragment, (Boolean)args[0]);
        //        }
        //        else
        //        {
        //            if (error.Message.equals("PEER_FLOOD"))
        //            {
        //                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 1);
        //            }
        //        }
        //    }
        //    else if (request is TL_messages_createChat)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowFloodWaitAlert(fragment, error.Message);
        //        }
        //        else
        //        {
        //            ShowAddUserAlert(fragment, error.Message, false);
        //        }
        //    }
        //    else if (request is TL_channels_createChannel)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowFloodWaitAlert(fragment, error.Message);
        //        }
        //        else
        //        {
        //            ShowAddUserAlert(fragment, error.Message, false);
        //        }
        //    }
        //    else if (request is TL_messages_editMessage)
        //    {
        //        if (!error.Message.Equals("MESSAGE_NOT_MODIFIED"))
        //        {
        //            if (fragment != null)
        //            {
        //                ShowSimpleAlert(fragment, Strings.Resources.EditMessageError);
        //            }
        //            else
        //            {
        //                ShowSimpleToast(fragment, Strings.Resources.EditMessageError);
        //            }
        //        }
        //    }
        //    else if (request is TL_messages_sendMessage ||
        //              request is TL_messages_sendMedia ||

        //              request is TL_messages_sendBroadcast ||
        //              request is TL_messages_sendInlineBotResult ||

        //              request is TL_messages_forwardMessages)
        //    {
        //        if (error.Message.Equals("PEER_FLOOD"))
        //        {
        //            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 0);
        //        }
        //    }
        //    else if (request is TL_messages_importChatInvite)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Message.Equals("USERS_TOO_MUCH"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.JoinToGroupErrorFull);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.JoinToGroupErrorNotExist);
        //        }
        //    }
        //    else if (request is TL_messages_getAttachedStickers)
        //    {
        //        if (fragment != null && fragment.getParentActivity() != null)
        //        {
        //            Toast.makeText(fragment.getParentActivity(), Strings.Resources.ErrorOccurred + "\n" + error.text, Toast.LENGTH_SHORT).show();
        //        }
        //    }
        //    else if (request is TL_account_confirmPhone || request is TL_account_verifyPhone || request is TL_account_verifyEmail)
        //    {
        //        if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID") || error.Message.Contains("CODE_INVALID") || error.Message.Contains("CODE_EMPTY"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED") || error.Message.Contains("EMAIL_VERIFY_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_auth_resendCode)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Code != -1000)
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_account_sendConfirmPhoneCode)
        //    {
        //        if (error.Code == 400)
        //        {
        //            return ShowSimpleAlert(fragment, Strings.Resources.CancelLinkExpired);
        //        }
        //        else if (error.Message != null)
        //        {
        //            if (error.Message.StartsWith("FLOOD_WAIT"))
        //            {
        //                return ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //            }
        //            else
        //            {
        //                return ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //            }
        //        }
        //    }
        //    else if (request is TL_account_changePhone)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_account_sendChangePhoneCode)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Message.StartsWith("PHONE_NUMBER_OCCUPIED"))
        //        {
        //            ShowSimpleAlert(fragment, LocaleController.formatString("ChangePhoneNumberOccupied", R.string.ChangePhoneNumberOccupied, (String)args[0]));
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //        }
        //    }
        //    else if (request is TL_updateUserName)
        //    {
        //        switch (error.Message)
        //        {
        //            case "USERNAME_INVALID":
        //                ShowSimpleAlert(fragment, Strings.Resources.UsernameInvalid);
        //                break;
        //            case "USERNAME_OCCUPIED":
        //                ShowSimpleAlert(fragment, Strings.Resources.UsernameInUse);
        //                break;
        //            default:
        //                ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //                break;
        //        }
        //    }
        //    else if (request is TL_contacts_importContacts)
        //    {
        //        if (error == null || error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_account_getPassword || request is TL_account_getTmpPassword)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleToast(fragment, getFloodWaitString(error.Message));
        //        }
        //        else
        //        {
        //            ShowSimpleToast(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_payments_sendPaymentForm)
        //    {
        //        switch (error.Message)
        //        {
        //            case "BOT_PRECHECKOUT_FAILED":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentPrecheckoutFailed);
        //                break;
        //            case "PAYMENT_FAILED":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentFailed);
        //                break;
        //            default:
        //                ShowSimpleToast(fragment, error.Message);
        //                break;
        //        }
        //    }
        //    else if (request is TL_payments_validateRequestedInfo)
        //    {
        //        switch (error.Message)
        //        {
        //            case "SHIPPING_NOT_AVAILABLE":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentNoShippingMethod);
        //                break;
        //            default:
        //                ShowSimpleToast(fragment, error.Message);
        //                break;
        //        }
        //    }
        //}

        private static async void ShowPeerFloodAlert(IDispatcherWrapper fragment, int reason)
        {
            var dialog = new TLMessageDialog();

            dialog.Title             = Strings.Resources.AppName;
            dialog.PrimaryButtonText = Strings.Resources.OK;

            if (reason != 2)
            {
                dialog.SecondaryButtonText   = Strings.Resources.MoreInfo;
                dialog.SecondaryButtonClick += (s, args) =>
                {
                    MessageHelper.NavigateToUsername(null, null, "spambot", null, null, null);
                };
            }

            if (reason == 0)
            {
                dialog.Message = Strings.Resources.NobodyLikesSpam1;
            }
            else if (reason == 1)
            {
                dialog.Message = Strings.Resources.NobodyLikesSpam2;
            }
            else if (reason == 2)
            {
                //builder.setMessage((String)args[1]);
            }

            await dialog.ShowQueuedAsync();
        }
示例#4
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = "Revoke link";
            dialog.Message             = string.Format("Are you sure you want to revoke the link t.me/{0}?\r\n\r\nThe channel \"{1}\" will become private.", channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = "Revoke";
            dialog.SecondaryButtonText = "Cancel";

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
示例#5
0
        private async void RevokeLinkExecute(Chat chat)
        {
            if (chat.Type is ChatTypeSupergroup super)
            {
                var supergroup = ProtoService.GetSupergroup(super.SupergroupId);
                if (supergroup == null)
                {
                    return;
                }

                var dialog = new TLMessageDialog();
                dialog.Title               = Strings.Resources.AppName;
                dialog.Message             = string.Format(Strings.Resources.RevokeLinkAlert, supergroup.Username, chat.Title);
                dialog.PrimaryButtonText   = Strings.Resources.RevokeButton;
                dialog.SecondaryButtonText = Strings.Resources.Cancel;

                var confirm = await dialog.ShowQueuedAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    var response = await ProtoService.SendAsync(new SetSupergroupUsername(supergroup.Id, string.Empty));

                    if (response is Ok)
                    {
                        HasTooMuchUsernames = false;
                        AdminedPublicChannels.Clear();
                    }
                }
            }
        }
示例#6
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Android.AppName;
            dialog.Message             = string.Format(Strings.Android.RevokeLinkAlert, channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = Strings.Android.RevokeButton;
            dialog.SecondaryButtonText = Strings.Android.Cancel;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
示例#7
0
        public static async void ShowSimpleAlert(String text)
        {
            if (text == null)
            {
                return;
            }

            var dialog = new TLMessageDialog();

            dialog.Title             = Branding.ServiceName;
            dialog.Message           = text;
            dialog.PrimaryButtonText = Strings.Android.OK;

            await dialog.ShowQueuedAsync();
        }
示例#8
0
        public static async void ShowSimpleAlert(IDispatcherWrapper fragment, String text)
        {
            if (text == null)
            {
                return;
            }

            var dialog = new TLMessageDialog();

            dialog.Title             = Strings.Resources.AppName;
            dialog.Message           = text;
            dialog.PrimaryButtonText = Strings.Resources.OK;

            await dialog.ShowQueuedAsync();
        }
示例#9
0
        private async void UnblockExecute(TLUser user)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = "Unblock";
            dialog.Message             = "You sure?";
            dialog.PrimaryButtonText   = "Yes";
            dialog.SecondaryButtonText = "No";

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UnblockAsync(user.ToInputUser());

                if (response.IsSucceeded)
                {
                    Items.Remove(user);
                }
            }
        }
示例#10
0
        private async void UnblockExecute(TLUser user)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Android.AppName;
            dialog.Message             = Strings.Android.AreYouSureUnblockContact;
            dialog.PrimaryButtonText   = Strings.Android.OK;
            dialog.SecondaryButtonText = Strings.Android.Cancel;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UnblockAsync(user.ToInputUser());

                if (response.IsSucceeded)
                {
                    Items.Remove(user);
                }
            }
        }
示例#11
0
        public static async void ShowAddUserAlert(string error, bool channel)
        {
            if (error == null)
            {
                return;
            }

            var dialog = new TLMessageDialog();

            dialog.Title             = Branding.ServiceName;
            dialog.PrimaryButtonText = Strings.Android.OK;

            switch (error)
            {
            case "PEER_FLOOD":
                dialog.Message               = Strings.Android.NobodyLikesSpam2;
                dialog.SecondaryButtonText   = Strings.Android.MoreInfo;
                dialog.SecondaryButtonClick += (s, args) =>
                {
                    MessageHelper.NavigateToUsername("spambot", null, null, null);
                };
                break;

            case "USER_BLOCKED":
            case "USER_BOT":
            case "USER_ID_INVALID":
                dialog.Message = channel ? Strings.Android.ChannelUserCantAdd : Strings.Android.GroupUserCantAdd;
                break;

            case "USERS_TOO_MUCH":
                dialog.Message = channel ? Strings.Android.ChannelUserAddLimit : Strings.Android.GroupUserAddLimit;
                break;

            case "USER_NOT_MUTUAL_CONTACT":
                dialog.Message = channel ? Strings.Android.ChannelUserLeftError : Strings.Android.GroupUserLeftError;
                break;

            case "ADMINS_TOO_MUCH":
                dialog.Message = channel ? Strings.Android.ChannelUserCantAdmin : Strings.Android.GroupUserCantAdmin;
                break;

            case "BOTS_TOO_MUCH":
                dialog.Message = channel ? Strings.Android.ChannelUserCantBot : Strings.Android.GroupUserCantBot;
                break;

            case "USER_PRIVACY_RESTRICTED":
                dialog.Message = channel ? Strings.Android.InviteToChannelError : Strings.Android.InviteToGroupError;
                break;

            case "USERS_TOO_FEW":
                dialog.Message = Strings.Android.CreateGroupError;
                break;

            case "USER_RESTRICTED":
                dialog.Message = Strings.Android.UserRestricted;
                break;

            case "YOU_BLOCKED_USER":
                dialog.Message = Strings.Android.YouBlockedUser;
                break;

            case "CHAT_ADMIN_BAN_REQUIRED":
            case "USER_KICKED":
                dialog.Message = Strings.Android.AddAdminErrorBlacklisted;
                break;

            case "CHAT_ADMIN_INVITE_REQUIRED":
                dialog.Message = Strings.Android.AddAdminErrorNotAMember;
                break;

            case "USER_ADMIN_INVALID":
                dialog.Message = Strings.Android.AddBannedErrorAdmin;
                break;

            default:
                dialog.Message = Strings.Android.ErrorOccurred + "\n" + error;
                break;
            }

            await dialog.ShowQueuedAsync();
        }
示例#12
0
        private async void MessagesDeleteExecute()
        {
            //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 messages = new List <TLMessageCommonBase>(SelectedMessages);

                var dialog = new TLMessageDialog();
                dialog.Title               = "Delete";
                dialog.Message             = messages.Count > 1 ? string.Format("Do you want to delete this {0} messages?", messages.Count) : "Do you want to delete this message?";
                dialog.PrimaryButtonText   = "Yes";
                dialog.SecondaryButtonText = "No";

                var chat = With as TLChat;

                var isOut   = messages.All(x => x.IsOut);
                var toId    = messages.FirstOrDefault().ToId;
                var minDate = messages.OrderBy(x => x.Date).FirstOrDefault().Date;
                var maxDate = messages.OrderByDescending(x => x.Date).FirstOrDefault().Date;

                if ((isOut || (chat != null && (chat.IsCreator || chat.IsAdmin))) && 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 && minDate + config.EditTimeLimit > date && maxDate + 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.ShowQueuedAsync();

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

                    var localMessages  = new List <TLMessageBase>();
                    var remoteMessages = new List <TLMessageBase>();
                    for (int i = 0; i < messages.Count; i++)
                    {
                        var message = messages[i];
                        if (message.Id == 0 && message.RandomId != 0L)
                        {
                            localMessages.Add(message);
                        }
                        else if (message.Id != 0)
                        {
                            remoteMessages.Add(message);
                        }
                    }

                    DeleteMessages(null, localMessages, remoteMessages, revoke, DeleteMessagesInternal, DeleteMessagesInternal);
                }
            }
        }
示例#13
0
        protected override async void SendExecute()
        {
            var user = SelectedItems.FirstOrDefault();

            if (user == null)
            {
                return;
            }

            Task <MTProtoResponse <TLUpdatesBase> > task = null;

            if (_item is TLChannel channel)
            {
                task = ProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> {
                    user.ToInputUser()
                });
            }
            else if (_item is TLChat chat)
            {
                var count  = 100;
                var config = CacheService.GetConfig();
                if (config != null)
                {
                    count = config.ForwardedCountMax;
                }

                task = ProtoService.AddChatUserAsync(chat.Id, user.ToInputUser(), count);
            }

            if (task == null)
            {
                return;
            }

            var response = await task;

            if (response.IsSucceeded)
            {
                NavigationService.GoBack();

                if (response.Result is TLUpdates updates)
                {
                    var newMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                    if (newMessage != null)
                    {
                        Aggregator.Publish(newMessage.Message);
                    }

                    var newChannelMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage;
                    if (newChannelMessage != null)
                    {
                        Aggregator.Publish(newChannelMessage.Message);
                    }
                }
            }
            else
            {
                if (response.Error.TypeEquals(TLErrorType.PEER_FLOOD))
                {
                    var dialog = new TLMessageDialog();
                    dialog.Title               = "Telegram";
                    dialog.Message             = AppResources.PeerFloodAddContact;
                    dialog.PrimaryButtonText   = "More info";
                    dialog.SecondaryButtonText = "OK";

                    var confirm = await dialog.ShowQueuedAsync();

                    if (confirm == ContentDialogResult.Primary)
                    {
                        MessageHelper.HandleTelegramUrl("t.me/SpamBot");
                    }
                }
                else if (response.Error.TypeEquals(TLErrorType.USERS_TOO_MUCH))
                {
                    await TLMessageDialog.ShowAsync(AppResources.UsersTooMuch, "Telegram", "OK");
                }
                else if (response.Error.TypeEquals(TLErrorType.BOTS_TOO_MUCH))
                {
                    await TLMessageDialog.ShowAsync(AppResources.BotsTooMuch, "Telegram", "OK");
                }
                else if (response.Error.TypeEquals(TLErrorType.USER_NOT_MUTUAL_CONTACT))
                {
                    await TLMessageDialog.ShowAsync(AppResources.UserNotMutualContact, "Telegram", "OK");
                }

                Execute.ShowDebugMessage("channels.inviteToChannel error " + response.Error);
            }
        }