private async void ThemeDeleteExecute(ThemeCustomInfo theme) { var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.DeleteThemeAlert, Strings.Resources.AppName, Strings.Resources.Delete, Strings.Resources.Cancel); if (confirm != ContentDialogResult.Primary) { return; } try { var file = await StorageFile.GetFileFromPathAsync(theme.Path); await file.DeleteAsync(); } catch { } if (Settings.Appearance.RequestedThemePath == theme.Path) { await SetThemeAsync(new ThemeBundledInfo { Parent = theme.Parent }); } else { await RefreshThemesAsync(); } }
private async void DialogDeleteExecute(Chat chat) { var message = Strings.Resources.AreYouSureDeleteAndExit; if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeSecret) { message = Strings.Resources.AreYouSureDeleteThisChat; } else if (chat.Type is ChatTypeSupergroup super) { message = super.IsChannel ? Strings.Resources.ChannelLeaveAlert : Strings.Resources.MegaLeaveAlert; } var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { if (chat.Type is ChatTypeSecret secret) { await ProtoService.SendAsync(new CloseSecretChat(secret.SecretChatId)); } else if (chat.Type is ChatTypeBasicGroup || chat.Type is ChatTypeSupergroup) { await ProtoService.SendAsync(new SetChatMemberStatus(chat.Id, ProtoService.GetMyId(), new ChatMemberStatusLeft())); } ProtoService.Send(new DeleteChatHistory(chat.Id, true)); } }
protected override async void SendExecute(User user) { if (user == null) { return; } var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.AreYouSureSecretChat, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm != ContentDialogResult.Primary) { return; } Function request; var existing = ProtoService.GetSecretChatForUser(user.Id); if (existing != null) { request = new CreateSecretChat(existing.Id); } else { request = new CreateNewSecretChat(user.Id); } var response = await ProtoService.SendAsync(request); if (response is Chat chat) { NavigationService.NavigateToChat(chat); NavigationService.RemoveLast(); } }
private async void ForgotExecute() { if (_passwordBase == null) { // TODO: ... return; } if (_passwordBase.HasRecovery) { IsLoading = true; var response = await LegacyService.RequestPasswordRecoveryAsync(); if (response.IsSucceeded) { await TLMessageDialog.ShowAsync(string.Format("We have sent a recovery code to the e-mail you provided:\n\n{0}", response.Result.EmailPattern), "Telegram", "OK"); } else if (response.Error != null) { IsLoading = false; await new TLMessageDialog(response.Error.ErrorMessage ?? "Error message", response.Error.ErrorCode.ToString()).ShowQueuedAsync(); } } else { await TLMessageDialog.ShowAsync("Since you haven't provided a recovery e-mail when setting up your password, your remaining options are either to remember your password or to reset your account.", "Sorry", "OK"); //IsResettable = true; } }
private async void UnblockExecute() { if (Item is TLUser user) { var confirm = await TLMessageDialog.ShowAsync(Strings.Android.AreYouSureUnblockContact, Strings.Android.AppName, Strings.Android.OK, Strings.Android.Cancel); if (confirm != ContentDialogResult.Primary) { return; } var result = await ProtoService.UnblockAsync(user.ToInputUser()); if (result.IsSucceeded && result.Result) { if (Full is TLUserFull full) { full.IsBlocked = false; full.RaisePropertyChanged(() => full.IsBlocked); } CacheService.Commit(); Aggregator.Publish(new TLUpdateUserBlocked { UserId = user.Id, Blocked = false }); if (user.IsBot) { NavigationService.GoBack(); } } } }
private async void ForgotExecute() { if (_parameters == null) { // TODO: ... return; } if (_parameters.Password.HasRecovery) { IsLoading = true; var response = await ProtoService.RequestPasswordRecoveryAsync(); if (response.IsSucceeded) { await TLMessageDialog.ShowAsync(string.Format(Strings.Android.RestoreEmailSent, response.Result.EmailPattern), Strings.Android.AppName, Strings.Android.OK); // TODO: show recovery page } else if (response.Error != null) { IsLoading = false; await TLMessageDialog.ShowAsync(response.Error.ErrorMessage, Strings.Android.AppName, Strings.Android.OK); } } else { await TLMessageDialog.ShowAsync(Strings.Android.RestorePasswordNoEmailText, Strings.Android.RestorePasswordNoEmailTitle, Strings.Android.OK); IsResettable = true; } }
private async void ChatsClearExecute() { var chats = SelectedItems.ToList(); var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.AreYouSureClearHistoryFewChats, Locale.Declension("ChatsSelected", chats.Count), Strings.Resources.ClearHistory, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { Delegate?.ShowChatsUndo(chats, UndoType.Clear, items => { foreach (var undo in items) { _deletedChats.Remove(undo.Id); Handle(undo.Id, undo.Order); } }, items => { var clear = items.FirstOrDefault(); if (clear == null) { return; } ProtoService.Send(new DeleteChatHistory(clear.Id, false, false)); }); } Delegate?.SetSelectionMode(false); SelectedItems.Clear(); }
private async void Option_Click(object sender, RoutedEventArgs e) { if (_message?.SchedulingState != null) { await TLMessageDialog.ShowAsync(Strings.Resources.MessageScheduledVote, Strings.Resources.AppName, Strings.Resources.OK); return; } var button = sender as PollOptionControl; if (button.IsChecked == true) { return; } var option = button.Tag as PollOption; if (option == null) { return; } var poll = _message?.Content as MessagePoll; if (poll == null) { return; } _message.Delegate.VotePoll(_message, option); }
private async void Initialize() { if (!Settings.IsContactsSyncRequested) { Settings.IsContactsSyncRequested = true; var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.ContactsPermissionAlert, Strings.Resources.AppName, Strings.Resources.ContactsPermissionAlertContinue, Strings.Resources.ContactsPermissionAlertNotNow); if (confirm != Windows.UI.Xaml.Controls.ContentDialogResult.Primary) { Settings.IsContactsSyncEnabled = false; await _contactsService.RemoveAsync(); } if (Settings.IsContactsSyncEnabled) { ProtoService.Send(new GetContacts(), async result => { if (result is Telegram.Td.Api.Users users) { await _contactsService.SyncAsync(users); } }); } } }
protected override async void DeleteExecute() { var confirm = await TLMessageDialog.ShowAsync(Strings.Android.AreYouSureDeletePhoto, Strings.Android.AppName, Strings.Android.OK, Strings.Android.Cancel); if (confirm == ContentDialogResult.Primary && _selectedItem is GalleryPhotoItem item) { //var response = await ProtoService.UpdateProfilePhotoAsync(new TLInputPhotoEmpty()); var response = await ProtoService.DeletePhotosAsync(new TLVector <TLInputPhotoBase> { new TLInputPhoto { Id = item.Photo.Id, AccessHash = item.Photo.AccessHash } }); if (response.IsSucceeded) { var index = Items.IndexOf(item); if (index < Items.Count - 1) { Items.Remove(item); SelectedItem = Items[index > 0 ? index - 1 : index]; TotalItems--; } else { NavigationService.GoBack(); } } } }
private async void ClearCacheExecute() { IsLoading = true; var folder = await StorageFolder.GetFolderFromPathAsync(FileUtils.GetTempFileName(string.Empty)); var queryOptions = new QueryOptions(); queryOptions.FolderDepth = FolderDepth.Deep; var query = folder.CreateFileQueryWithOptions(queryOptions); var result = await query.GetFilesAsync(); foreach (var file in result) { try { await file.DeleteAsync(); await UpdateCacheSizeAsync(); } catch { } } IsLoading = false; await UpdateCacheSizeAsync(); await TLMessageDialog.ShowAsync("Done", "Done", "Done"); }
protected override async void DeleteExecute() { var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.AreYouSureDeletePhoto, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary && _selectedItem is GalleryProfilePhotoItem item) { var response = await ProtoService.SendAsync(new DeleteProfilePhoto(item.Id)); if (response is Ok) { NavigationService.GoBack(); //var index = Items.IndexOf(item); //if (index < Items.Count - 1) //{ // Items.Remove(item); // SelectedItem = Items[index > 0 ? index - 1 : index]; // TotalItems--; //} //else //{ // NavigationService.GoBack(); //} } } else if (confirm == ContentDialogResult.Primary && _selectedItem is GalleryUserProfilePhotoItem profileItem) { var response = await ProtoService.SendAsync(new DeleteProfilePhoto(profileItem.Id)); if (response is Ok) { NavigationService.GoBack(); } } }
private async void DeleteAccountExecute() { var config = InMemoryCacheService.Current.GetConfig(); if (config == null) { return; } // THIS CODE WILL RUN ONLY IF FIRST CONFIGURED SERVER IP IS TEST SERVER if (config.TestMode) { var dialog = new InputDialog(); var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary && dialog.Text.Equals(Self.Phone) && Self.Username != "frayxrulez") { var really = await TLMessageDialog.ShowAsync("REAAAALLY???", "REALLYYYY???", "YES", "NO I DON'T WANT TO"); if (really == ContentDialogResult.Primary) { await ProtoService.DeleteAccountAsync("Testing registration"); App.Current.Exit(); } } } }
private async void LogoutExecute() { var confirm = await TLMessageDialog.ShowAsync("Are you sure you want to logout?", "Unigram", "OK", "Cancel"); if (confirm != ContentDialogResult.Primary) { return; } await _pushService.UnregisterAsync(); var response = await ProtoService.LogOutAsync(); if (response.IsSucceeded) { await _contactsService.UnsyncContactsAsync(); SettingsHelper.IsAuthorized = false; SettingsHelper.UserId = 0; ProtoService.ClearQueue(); _updatesService.ClearState(); _stickersService.Cleanup(); CacheService.ClearAsync(); CacheService.ClearConfigImportAsync(); await TLMessageDialog.ShowAsync("The app will be closed. Relaunch it to login again.", "Unigram", "OK"); App.Current.Exit(); } else { } }
private async void SendExecute() { var contact = new TLInputPhoneContact { ClientId = GetHashCode(), FirstName = FirstName, LastName = LastName, Phone = "+" + PhoneCode + PhoneNumber }; var response = await ProtoService.ImportContactsAsync(new TLVector <TLInputContactBase> { contact }); if (response.IsSucceeded) { if (response.Result.Users.Count > 0) { Aggregator.Publish(new TLUpdateContactLink { UserId = response.Result.Users[0].Id, MyLink = new TLContactLinkContact(), ForeignLink = new TLContactLinkUnknown() }); } else { await TLMessageDialog.ShowAsync(Strings.Android.ContactNotRegistered, Strings.Android.AppName, Strings.Android.Invite, Strings.Android.Cancel); } } else { await TLMessageDialog.ShowAsync(Strings.Android.ContactNotRegistered, Strings.Android.AppName, Strings.Android.Invite, Strings.Android.Cancel); } }
private async void UseActivatedArgs(IActivatedEventArgs args, INavigationService service, AuthorizationState state) { try { switch (state) { case AuthorizationStateReady ready: //App.Current.NavigationService.Navigate(typeof(Views.MainPage)); UseActivatedArgs(args, service); break; case AuthorizationStateWaitPhoneNumber waitPhoneNumber: Execute.Initialize(); service.Navigate(typeof(Views.IntroPage)); break; case AuthorizationStateWaitCode waitCode: service.Navigate(waitCode.IsRegistered ? typeof(Views.SignIn.SignInSentCodePage) : typeof(Views.SignIn.SignUpPage)); break; case AuthorizationStateWaitPassword waitPassword: if (!string.IsNullOrEmpty(waitPassword.RecoveryEmailAddressPattern)) { await TLMessageDialog.ShowAsync(string.Format(Strings.Resources.RestoreEmailSent, waitPassword.RecoveryEmailAddressPattern), Strings.Resources.AppName, Strings.Resources.OK); } service.Navigate(typeof(Views.SignIn.SignInPasswordPage)); break; } } catch { } }
public void Handle(UpdateServiceNotification update) { var caption = update.Content.GetCaption(); if (caption == null) { return; } var text = caption.Text; if (string.IsNullOrEmpty(text)) { return; } WindowContext.Default().Dispatcher.Dispatch(async() => { if (update.Type.StartsWith("AUTH_KEY_DROP_")) { var confirm = await TLMessageDialog.ShowAsync(text, Strings.Resources.AppName, Strings.Resources.LogOut, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { _protoService.Send(new Destroy()); } } else { await TLMessageDialog.ShowAsync(text, Strings.Resources.AppName, Strings.Resources.OK); } }); }
private async void ForgotExecute() { if (_parameters == null) { // TODO: ... return; } if (_parameters.HasRecoveryEmailAddress) { IsLoading = true; var response = await ProtoService.SendAsync(new RequestAuthenticationPasswordRecovery()); if (response is Error error) { IsLoading = false; await TLMessageDialog.ShowAsync(error.Message, Strings.Resources.AppName, Strings.Resources.OK); } } else { await TLMessageDialog.ShowAsync(Strings.Resources.RestorePasswordNoEmailText, Strings.Resources.RestorePasswordNoEmailTitle, Strings.Resources.OK); IsResettable = true; } }
private async void ParticipantRemoveExecute(TLChatParticipantBase participant) { if (participant == null || participant.User == null) { return; } var confirm = await TLMessageDialog.ShowAsync(string.Format("Do you want to remove {0} from the group {1}?", participant.User.FullName, _item.DisplayName), "Remove", "OK", "Cancel"); if (confirm == ContentDialogResult.Primary) { var response = await ProtoService.DeleteChatUserAsync(_item.Id, participant.User.ToInputUser()); if (response.IsSucceeded) { if (response.Result is TLUpdates updates) { var newMessage = updates.Updates.OfType <TLUpdateNewMessage>().FirstOrDefault(); if (newMessage != null) { Aggregator.Publish(newMessage); } } } } }
private async void ResetExecute() { var confirm = await TLMessageDialog.ShowAsync("This action can't be undone.\n\nIf you reset your account, all your messages and chats will be deleted.", "Warning", "Reset", "Cancel"); if (confirm == ContentDialogResult.Primary) { IsLoading = true; var response = await ProtoService.DeleteAccountAsync("Forgot password"); if (response.IsSucceeded) { var logout = await ProtoService.LogOutAsync(); var state = new SignUpPage.NavigationParameters { PhoneNumber = _parameters.PhoneNumber, PhoneCode = _parameters.PhoneCode, Result = _parameters.Result, }; NavigationService.Navigate(typeof(SignUpPage), state); } else if (response.Error != null) { IsLoading = false; await new TLMessageDialog(response.Error.ErrorMessage ?? "Error message", response.Error.ErrorCode.ToString()).ShowQueuedAsync(); } } }
protected override async void SendExecute(User user) { var count = ProtoService.GetOption <OptionValueInteger>("forwarded_messages_count_max"); var chat = _chat; if (chat == null) { return; } if (user == null) { return; } var confirm = await TLMessageDialog.ShowAsync(string.Format(Strings.Resources.AddToTheGroup, user.GetFullName()), Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm != ContentDialogResult.Primary) { return; } ProtoService.Send(new AddChatMember(chat.Id, user.Id, count?.Value ?? 0)); NavigationService.GoBack(); }
private async void DeleteExecute() { var chat = _chat; if (chat == null) { return; } if (chat.Type is ChatTypeBasicGroup basic) { var message = Strings.Resources.MegaDeleteAlert; var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { await ProtoService.SendAsync(new SetChatMemberStatus(chat.Id, ProtoService.GetMyId(), new ChatMemberStatusLeft())); var response = await ProtoService.SendAsync(new DeleteChatHistory(chat.Id, true)); if (response is Ok) { NavigationService.RemovePeerFromStack(chat.Id); } else if (response is Error error) { // TODO: ... } } } }
private async void Stickers_Click(object sender, RoutedEventArgs e) { var channel = ViewModel.With as TLChannel; if (channel != null && channel.HasBannedRights && (channel.BannedRights.IsSendStickers || channel.BannedRights.IsSendGifs)) { await TLMessageDialog.ShowAsync("The admins of this group restricted you from posting stickers here.", "Warning", "OK"); return; } if (StickersPanel.Visibility == Visibility.Collapsed) { Focus(FocusState.Programmatic); TextField.Focus(FocusState.Programmatic); InputPane.GetForCurrentView().TryHide(); StickersPanel.Visibility = Visibility.Visible; ViewModel.OpenStickersCommand.Execute(null); } else { Focus(FocusState.Programmatic); TextField.Focus(FocusState.Keyboard); StickersPanel.Visibility = Visibility.Collapsed; } }
private async void UnblockExecute() { if (Item is TLUser user) { var confirm = await TLMessageDialog.ShowAsync("Are you sure you want to unblock this contact?", "Telegram", "OK", "Cancel"); if (confirm != ContentDialogResult.Primary) { return; } var result = await ProtoService.UnblockAsync(user.ToInputUser()); if (result.IsSucceeded && result.Result) { CacheService.Commit(); Aggregator.Publish(new TLUpdateUserBlocked { UserId = user.Id, Blocked = false }); if (user.IsBot) { NavigationService.GoBack(); } } } }
private async void CallExecute() { if (_item == null || _full == null) { return; } if (_full.IsPhoneCallsAvailable && !_item.IsSelf && ApiInformation.IsApiContractPresent("Windows.ApplicationModel.Calls.CallsVoipContract", 1)) { try { var coordinator = VoipCallCoordinator.GetDefault(); var result = await coordinator.ReserveCallResourcesAsync("Unigram.Tasks.VoIPCallTask"); if (result == VoipPhoneCallResourceReservationStatus.Success) { await VoIPConnection.Current.SendRequestAsync("voip.startCall", _item); } } catch { await TLMessageDialog.ShowAsync("Something went wrong. Please, try to close and relaunch the app.", "Unigram", "OK"); } } }
private async void SendExecute() { var response = await ProtoService.SendAsync(new ImportContacts(new[] { new Contact() })); if (response is ImportedContacts imported) { if (imported.UserIds.Count > 0) { var create = await ProtoService.SendAsync(new CreatePrivateChat(imported.UserIds[0], false)); if (create is Chat chat) { NavigationService.NavigateToChat(chat); } } else { await TLMessageDialog.ShowAsync(Strings.Resources.ContactNotRegistered, Strings.Resources.AppName, Strings.Resources.Invite, Strings.Resources.Cancel); } } else { await TLMessageDialog.ShowAsync(Strings.Resources.ContactNotRegistered, Strings.Resources.AppName, Strings.Resources.Invite, Strings.Resources.Cancel); } }
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.ShowAsync(); 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(); } } }
private async void DeleteExecute() { var chat = _chat; if (chat == null) { return; } if (chat.Type is ChatTypeSupergroup super) { var message = super.IsChannel ? Strings.Resources.ChannelDeleteAlert : Strings.Resources.MegaDeleteAlert; var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { var response = await ProtoService.SendAsync(new DeleteSupergroup(super.SupergroupId)); if (response is Ok) { NavigationService.RemovePeerFromStack(chat.Id); } else if (response is Error error) { // TODO: ... } } } }
public async Task <bool> VerifyRightsAsync(Chat chat, Func <ChatMemberStatusRestricted, bool> permission, string forever, string temporary) { if (chat.Type is ChatTypeSupergroup super) { var supergroup = ProtoService.GetSupergroup(super.SupergroupId); if (supergroup == null) { return(false); } if (supergroup.Status is ChatMemberStatusRestricted restricted && !permission(restricted)) { if (restricted.IsForever()) { await TLMessageDialog.ShowAsync(forever, Strings.Resources.AppName, Strings.Resources.OK); } else { await TLMessageDialog.ShowAsync(string.Format(temporary, BindConvert.Current.BannedUntil(restricted.RestrictedUntilDate)), Strings.Resources.AppName, Strings.Resources.OK); } return(true); } } return(false); }
protected override async void SendExecute(User user) { var chat = _chat; if (chat == null) { return; } if (user == null) { return; } var confirm = await TLMessageDialog.ShowAsync(string.Format(Strings.Resources.AddToTheGroup, user.GetFullName()), Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel); if (confirm != ContentDialogResult.Primary) { return; } ProtoService.Send(new AddChatMember(chat.Id, user.Id, CacheService.Options.ForwardedMessageCountMax)); NavigationService.GoBack(); }