public void Terminate(TLAccountAuthorization authorization) { if (authorization == null) { return; } if (authorization.IsCurrent) { var result = MessageBox.Show(AppResources.LogOutConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } var updatesService = IoC.Get <IUpdatesService>(); var pushService = IoC.Get <IPushService>(); pushService.UnregisterDeviceAsync(() => MTProtoService.LogOutAsync(() => { ContactsHelper.DeleteContactsAsync(null); Execute.BeginOnUIThread(() => { foreach (var activeTile in ShellTile.ActiveTiles) { if (activeTile.NavigationUri.ToString().Contains("Action=SecondaryTile")) { activeTile.Delete(); } } }); })); Telegram.Logs.Log.Write("StartupViewModel SessionsViewModel.Terminate"); SettingsViewModel.LogOutCommon(EventAggregator, MTProtoService, updatesService, CacheService, StateService, pushService, NavigationService); } else { IsWorking = true; MTProtoService.ResetAuthorizationAsync( authorization.Hash, result => BeginOnUIThread(() => { IsWorking = false; Items.Remove(authorization); }), error => { IsWorking = false; Execute.ShowDebugMessage("auth.resetAuthotization error " + error); }); } }
public SnapshotsViewModel(ICacheService cacheService, IUpdatesService updateService, ITelegramEventAggregator eventAggregator) { Items = new ObservableCollection <SnapshotItem>(); _cacheService = cacheService; _updateService = updateService; _eventAggregator = eventAggregator; Execute.BeginOnThreadPool(() => { try { var currentState = _updateService.GetState(); State = currentState; NotifyOfPropertyChange(() => State); var tempDifference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), Telegram.Api.Constants.DifferenceFileName); Difference = tempDifference; NotifyOfPropertyChange(() => Difference); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.DirectoryExists(Constants.SnapshotsDirectoryName)) { foreach (var directory in store.GetDirectoryNames(Constants.SnapshotsDirectoryName + "/*")) { var item = new SnapshotItem { Name = directory }; var stateFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.StateFileName); if (store.FileExists(stateFullFileName)) { var state = TLUtils.OpenObjectFromMTProtoFile <TLState>(new object(), stateFullFileName); item.State = state; } var differenceFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.DifferenceFileName); if (store.FileExists(differenceFullFileName)) { long length; var difference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), differenceFullFileName, out length); item.Difference = difference; item.DifferenceLength = length; } Execute.BeginOnUIThread(() => Items.Add(item)); } } } } catch (Exception ex) { } }); }
public void Handle(TLUpdateNotifySettings notifySettings) { var notifyPeer = notifySettings.Peer as TLNotifyPeer; if (notifyPeer != null) { Execute.BeginOnUIThread(() => { for (var i = 0; i < Items.Count; i++) { var dialog = Items[i] as TLDialog; if (dialog != null && dialog.Peer != null && dialog.Peer.Id.Value == notifyPeer.Peer.Id.Value && dialog.Peer.GetType() == notifyPeer.Peer.GetType()) { dialog.NotifyOfPropertyChange(() => dialog.NotifySettings); dialog.NotifyOfPropertyChange(() => dialog.Self); break; } } }); } var notifyUsers = notifySettings.Peer as TLNotifyUsers; if (notifyUsers != null) { var peerNotifySettings = notifySettings.NotifySettings as TLPeerNotifySettings; if (peerNotifySettings != null) { var settings = StateService.GetNotifySettings(); settings.ContactAlert = peerNotifySettings.MuteUntil == null || peerNotifySettings.MuteUntil.Value == 0; settings.ContactMessagePreview = peerNotifySettings.ShowPreviews != null && peerNotifySettings.ShowPreviews.Value; settings.ContactSound = peerNotifySettings.Sound != null?peerNotifySettings.Sound.ToString() : "default"; StateService.SaveNotifySettingsAsync(settings); } } var notifyChats = notifySettings.Peer as TLNotifyChats; if (notifyChats != null) { var peerNotifySettings = notifySettings.NotifySettings as TLPeerNotifySettings; if (peerNotifySettings != null) { var settings = StateService.GetNotifySettings(); settings.GroupAlert = peerNotifySettings.MuteUntil == null || peerNotifySettings.MuteUntil.Value == 0; settings.GroupMessagePreview = peerNotifySettings.ShowPreviews != null && peerNotifySettings.ShowPreviews.Value; settings.GroupSound = peerNotifySettings.Sound != null?peerNotifySettings.Sound.ToString() : "default"; StateService.SaveNotifySettingsAsync(settings); } } }
private void StopLiveLocation(TLMessage70 message, System.Action callback) { if (message == null) { return; } var mediaGeoLive = message.Media as TLMessageMediaGeoLive; if (mediaGeoLive == null) { return; } var geoPoint = mediaGeoLive.Geo as TLGeoPoint; if (geoPoint == null) { return; } var newGeoPoint = new TLGeoPointEmpty(); var liveLocationsService = IoC.Get <ILiveLocationService>(); liveLocationsService.UpdateAsync(message, newGeoPoint, result => Execute.BeginOnUIThread(() => { LiveLocationBadge = null; NotifyOfPropertyChange(() => LiveLocationBadge); mediaGeoLive.Date = message.Date; mediaGeoLive.EditDate = message.EditDate; mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Geo); mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.EditDate); mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Active); callback.SafeInvoke(); }), error => Execute.BeginOnUIThread(() => { if (error == null || error.CodeEquals(ErrorCode.BAD_REQUEST)) { LiveLocationBadge = null; NotifyOfPropertyChange(() => LiveLocationBadge); mediaGeoLive.Date = message.Date; mediaGeoLive.EditDate = message.EditDate; mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Geo); mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.EditDate); mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Active); callback.SafeInvoke(); } })); }
private void ChangePhoneNumber() { IsWorking = true; NotifyOfPropertyChange(() => CanSignIn); var phoneNumber = PhoneCode + PhoneNumber; _startTime = DateTime.Now; _showHelpTimer.Start(); MTProtoService.SendChangePhoneCodeAsync(new TLString(phoneNumber), null, sentCode => BeginOnUIThread(() => { _showHelpTimer.Stop(); StateService.SentCode = sentCode; StateService.PhoneNumber = new TLString(phoneNumber); StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber)); StateService.PhoneCodeHash = sentCode.PhoneCodeHash; StateService.PhoneRegistered = new TLBool(false); StateService.SendCallTimeout = sentCode.SendCallTimeout; StateService.ChangePhoneNumber = true; var sentCode50 = sentCode as TLSentCode50; if (sentCode50 != null) { StateService.Type = sentCode50.Type; StateService.NextType = sentCode50.NextType; } NavigationService.UriFor <ConfirmViewModel>().Navigate(); IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); }), error => BeginOnUIThread(() => { _lastError = error; IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID)) { MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_NUMBER_OCCUPIED)) { MessageBox.Show(string.Format(AppResources.NewNumberTaken, "+" + phoneNumber), AppResources.Error, MessageBoxButton.OK); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("account.sendChangePhoneCode error " + error); } })); }
private void CheckDisabledFeature(TLObject with, string pmFeatureKey, string chatFeatureKey, string bigChatFeatureKey, System.Action callback) { _cacheService.CheckDisabledFeature( with, pmFeatureKey, chatFeatureKey, bigChatFeatureKey, () => Execute.BeginOnUIThread(callback.SafeInvoke), disabledFeature => Execute.BeginOnUIThread(() => MessageBox.Show(disabledFeature.Description.ToString(), AppResources.AppName, MessageBoxButton.OK))); }
public void Archive(TLStickerSet set) { var set32 = set as TLStickerSet32; if (set32 == null) { return; } var inputStickerSet = new TLInputStickerSetId { Id = set32.Id, AccessHash = set32.AccessHash }; IsWorking = true; MTProtoService.InstallStickerSetAsync(inputStickerSet, TLBool.True, result => BeginOnUIThread(() => { IsWorking = false; set32.Archived = true; Items.Remove(set32); var allStickers43 = StateService.GetAllStickers() as TLAllStickers43; TLMessagesStickerSet messagesSet = null; if (allStickers43 != null) { messagesSet = TLUtils.RemoveStickerSet(allStickers43, set32); StateService.SaveAllStickersAsync(allStickers43); } if (messagesSet != null) { var archivedStickers = StateService.GetArchivedStickers(); if (archivedStickers != null) { TLUtils.AddStickerSetCovered(archivedStickers, messagesSet, archivedStickers.SetsCovered, new TLStickerSetCovered { Cover = messagesSet.Documents.FirstOrDefault() ?? new TLDocumentEmpty { Id = new TLLong(0) }, StickerSet = messagesSet.Set }); archivedStickers.Count.Value = archivedStickers.Sets.Count; UpdateArchivedSetsString(archivedStickers.Count.Value); StateService.SaveArchivedStickersAsync(archivedStickers); } } //EventAggregator.Publish(new UpdateStickerSetsEventArgs(allStickers43)); }), error => BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("messages.installStickerSet error " + error); })); }
public void Next() { if (!CanCreateChannel) { return; } IsWorking = true; NotifyOfPropertyChange(() => CanCreateChannel); // 1 broadcast // 2 mega group MTProtoService.CreateChannelAsync(new TLInt(1), new TLString(Title), new TLString(About), result => Execute.BeginOnUIThread(() => { var updates = result as TLUpdates; if (updates != null) { var channel = updates.Chats.FirstOrDefault() as TLChannel; if (channel != null) { if (_photo != null) { ContinueUploadingPhoto(channel); } else { if (_uploadingPhoto) { _uploadingCallback = () => ContinueUploadingPhoto(channel); } else { ContinueNextStep(channel); } } } } }), error => Execute.BeginOnUIThread(() => { IsWorking = false; NotifyOfPropertyChange(() => CanCreateChannel); if (error.CodeEquals(ErrorCode.BAD_REQUEST)) { if (error.TypeEquals(ErrorType.CHANNELS_TOO_MUCH)) { MessageBox.Show(AppResources.ChannelsTooMuch, AppResources.Error, MessageBoxButton.OK); } } Execute.ShowDebugMessage("channels.createChannel error " + error); })); }
public void BeginOpenStoryboard(bool initialize = false) { LayoutRoot.Opacity = 0.0; var translateYTo = 150.0; var duration = TimeSpan.FromSeconds(0.4); var easingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut, Exponent = 5.0 }; var storyboard = new Storyboard(); var translateAnimation = new DoubleAnimationUsingKeyFrames(); translateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0.0), Value = translateYTo }); translateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = duration, Value = 0.0, EasingFunction = easingFunction }); Storyboard.SetTarget(translateAnimation, LayoutRoot); Storyboard.SetTargetProperty(translateAnimation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)")); storyboard.Children.Add(translateAnimation); var opacityAnimation = new DoubleAnimationUsingKeyFrames(); opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0.0), Value = 0.0 }); opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = duration, Value = 1.0, EasingFunction = easingFunction }); Storyboard.SetTarget(opacityAnimation, LayoutRoot); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(UIElement.Opacity)")); storyboard.Children.Add(opacityAnimation); storyboard.Completed += (o, args) => { if (string.IsNullOrEmpty(ViewModel.Text)) { SearchBox.Focus(); } ViewModel.ForwardInAnimationComplete(); ClosePivotAction.SafeInvoke(Visibility.Collapsed); }; _openStoryboard = storyboard; Execute.BeginOnUIThread(storyboard.Begin); }
public void OpenPhoto() { IsOpen = false; Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.25), async() => { #if WP81 var photoPickerSettings = IoC.Get <IStateService>().GetPhotoPickerSettings(); if (photoPickerSettings != null && photoPickerSettings.External) { var from = _contactEnabled ? "DialogDetailsView" : "SecretDialogDetailsView"; ((App)Application.Current).ChooseFileInfo = new ChooseFileInfo(DateTime.Now); var fileOpenPicker = new FileOpenPicker(); fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.FileTypeFilter.Clear(); fileOpenPicker.FileTypeFilter.Add(".bmp"); fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.FileTypeFilter.Add(".jpeg"); fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.ContinuationData.Add("From", from); fileOpenPicker.ContinuationData.Add("Type", "Image"); if (Environment.OSVersion.Version.Major >= 10) { var result = await fileOpenPicker.PickMultipleFilesAsync(); if (result.Count > 0) { Execute.BeginOnThreadPool(() => { _sendPhotosAction.SafeInvoke(result); }); } } else { fileOpenPicker.PickMultipleFilesAndContinue(); } } else { OpenPhotoPicker(false, (r1, r2) => _sendPhotosAction.SafeInvoke(r1)); } #else ((App)Application.Current).ChooseFileInfo = new ChooseFileInfo(DateTime.Now); var task = new PhotoChooserTask { ShowCamera = true }; task.Completed += (o, e) => Handle(_stateService, e.ChosenPhoto, e.OriginalFileName); task.Show(); #endif }); }
public void DeletePhoto() { var channel = CurrentItem as TLChannel; if (channel != null) { //IsWorking = true; MTProtoService.EditPhotoAsync(channel, new TLInputChatPhotoEmpty(), statedMessage => Execute.BeginOnUIThread(() => { //IsWorking = false; var updates = statedMessage as TLUpdates; if (updates != null) { var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewChannelMessage) as TLUpdateNewChannelMessage; if (updateNewMessage != null) { EventAggregator.Publish(updateNewMessage.Message); } } }), error => Execute.BeginOnUIThread(() => { //IsWorking = false; Execute.ShowDebugMessage("channels.editPhoto error " + error); })); } var chat = CurrentItem as TLChat; if (chat != null) { //IsWorking = true; MTProtoService.EditChatPhotoAsync(chat.Id, new TLInputChatPhotoEmpty(), statedMessage => Execute.BeginOnUIThread(() => { //IsWorking = false; var updates = statedMessage as TLUpdates; if (updates != null) { var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage; if (updateNewMessage != null) { EventAggregator.Publish(updateNewMessage.Message); } } }), error => Execute.BeginOnUIThread(() => { //IsWorking = false; Execute.ShowDebugMessage("messages.editChatPhoto error " + error); })); } }
public SearchVenuesView() { InitializeComponent(); Caption.Background = ShellView.CaptionBrush; Loaded += (o, e) => { Execute.BeginOnUIThread(TimeSpan.FromMilliseconds(500), () => SearchBox.Focus()); }; }
public void Delete(SnapshotItem item) { Execute.BeginOnThreadPool(() => { var deletingSnapshotDirectoryName = item.Name; var deletingSnapshotDirectoryFullName = Path.Combine(Constants.SnapshotsDirectoryName, deletingSnapshotDirectoryName); DeleteDirectory(deletingSnapshotDirectoryFullName); Execute.BeginOnUIThread(() => Items.Remove(item)); }); }
private void LoadSprites(TLAllStickers allStickers, List <Button> buttons) { if (VirtPanel.Children.Count > 0) { return; } var selectRecentlyUsedStickers = false; var selectFirstStickerSet = false; var allStickers43 = allStickers as TLAllStickers43; if (allStickers43 != null && (allStickers43.RecentlyUsed == null || allStickers43.RecentlyUsed.Count == 0)) { if (buttons.Count > 0) { selectFirstStickerSet = true; } } if (!selectFirstStickerSet) { selectRecentlyUsedStickers = true; } if (selectFirstStickerSet) { Execute.BeginOnUIThread(() => { StickerSetButtonOnClick(buttons[0], null); LoadingProgressBar.Visibility = Visibility.Collapsed; return; }); } if (selectRecentlyUsedStickers) { Execute.BeginOnUIThread(() => { if (allStickers == _masks) { RecentMasksButtonOnClick(_recentMasksButton, null); } else if (allStickers == _stickers) { RecentStickersButtonOnClick(_recentStickersButton, null); } LoadingProgressBar.Visibility = Visibility.Collapsed; return; }); } }
public void DeletePhoto() { MTProtoService.UpdateProfilePhotoAsync(new TLInputPhotoEmpty(), new TLInputPhotoCropAuto(), result => { Execute.ShowDebugMessage("photos.updateProfilePhoto result " + result); }, error => { Execute.ShowDebugMessage("photos.updateProfilePhoto error " + error); }); }
private void UpdateNotifySettingsAsync() { if (CurrentContact == null) { return; } var notifySettings = new TLInputPeerNotifySettings78 { Flags = new TLInt(0), MuteUntil = new TLInt(MuteUntil), ShowPreviews = TLBool.True, Sound = string.IsNullOrEmpty(SelectedSound) ? new TLString("default") : new TLString(SelectedSound) }; IsWorking = true; MTProtoService.UpdateNotifySettingsAsync( CurrentContact.ToInputNotifyPeer(), notifySettings, result => { IsWorking = false; CurrentContact.NotifySettings = new TLPeerNotifySettings78 { Flags = new TLInt(0), MuteUntil = new TLInt(MuteUntil), ShowPreviews = notifySettings.ShowPreviews, Sound = notifySettings.Sound }; var dialog = CacheService.GetDialog(new TLPeerUser { Id = CurrentContact.Id }); if (dialog != null) { dialog.NotifySettings = CurrentContact.NotifySettings; dialog.NotifyOfPropertyChange(() => dialog.NotifySettings); dialog.NotifyOfPropertyChange(() => dialog.Self); var settings = dialog.With as INotifySettings; if (settings != null) { settings.NotifySettings = CurrentContact.NotifySettings; } } CacheService.Commit(); }, error => { IsWorking = false; Execute.ShowDebugMessage("account.updateNotifySettings error: " + error); }); }
public void BeginCloseStoryboard(Action callback = null) { if (_openStoryboard.GetCurrentState() == ClockState.Active) { _openStoryboard.Pause(); } ClosePivotAction.SafeInvoke(Visibility.Visible); //LayoutRoot.Background = (Brush)Application.Current.Resources["PhoneBackgroundBrush"]; var translateYTo = 150.0; var duration = TimeSpan.FromSeconds(0.3); var easingFunction = new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 5.0 }; var storyboard = new Storyboard(); var translateAnimation = new DoubleAnimationUsingKeyFrames(); translateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = duration, Value = translateYTo, EasingFunction = easingFunction }); Storyboard.SetTarget(translateAnimation, LayoutRoot); Storyboard.SetTargetProperty(translateAnimation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)")); storyboard.Children.Add(translateAnimation); var opacityAnimation = new DoubleAnimationUsingKeyFrames(); opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = duration, Value = 0.0, EasingFunction = easingFunction }); Storyboard.SetTarget(opacityAnimation, LayoutRoot); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(UIElement.Opacity)")); storyboard.Children.Add(opacityAnimation); if (callback != null) { storyboard.Completed += (o, e) => callback(); } Execute.BeginOnUIThread(() => { storyboard.Begin(); }); }
public void LoadNextSlice() { if (IsWorking || LazyItems.Count > 0 || IsLastSliceLoaded #if WP8 || !_isUpdated #endif ) { return; } IsWorking = true; var maxId = Items.Count == 0 ? 0 : Items.OfType <TLDialog>().Last(x => x.TopMessage != null).TopMessage.Index; var offset = _offset; var limit = Constants.DialogsSlice; //TLUtils.WriteLine(string.Format("{0} messages.getDialogs offset={1} limit={2}", DateTime.Now.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture), offset, limit), LogSeverity.Error); MTProtoService.GetDialogsAsync( #if LAYER_40 new TLInt(offset), new TLInt(limit), #else new TLInt(0), new TLInt(maxId), new TLInt(limit), #endif result => BeginOnUIThread(() => { if (_offset != offset) { return; } _offset += Constants.DialogsSlice; foreach (var dialog in result.Dialogs) { Items.Add(dialog); } AddChannels(_channels); IsWorking = false; IsLastSliceLoaded = result.Dialogs.Count < limit; Status = LazyItems.Count > 0 || Items.Count > 0 ? string.Empty : Status; //TLUtils.WriteLine(string.Format("messages.getDialogs offset={0} limit={1} result={2}", offset, limit, result.Dialogs.Count), LogSeverity.Error); }), error => BeginOnUIThread(() => { IsWorking = false; Status = string.Empty; //TLUtils.WriteLine(string.Format("messages.getDialogs offset={0} limit={1} error={2}", offset, limit, error), LogSeverity.Error); Execute.ShowDebugMessage("messages.getDialogs error " + error); })); }
private void SavePhotoAsync(Action <string> callback = null) { TLFileLocation location = null; var profilePhoto = CurrentItem as TLUserProfilePhoto; if (profilePhoto != null) { location = profilePhoto.PhotoBig as TLFileLocation; } var photo = CurrentItem as TLPhoto; if (photo != null) { TLPhotoSize size = null; var sizes = photo.Sizes.OfType <TLPhotoSize>(); const double width = 640.0; foreach (var photoSize in sizes) { if (size == null || Math.Abs(width - size.W.Value) > Math.Abs(width - photoSize.W.Value)) { size = photoSize; } } if (size == null) { return; } location = size.Location as TLFileLocation; } var chatPhoto = CurrentItem as TLChatPhoto; if (chatPhoto != null) { location = chatPhoto.PhotoBig as TLFileLocation; } if (location == null) { return; } var fileName = String.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); Execute.BeginOnThreadPool(() => ImageViewerViewModel.SavePhoto(fileName, callback)); }
public void DeleteAndStop(TLDialogBase dialog) { if (dialog == null) { return; } var user = dialog.With as TLUser; if (user == null || !user.IsBot) { return; } var confirmation = MessageBox.Show(AppResources.DeleteChatConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel); if (confirmation != MessageBoxResult.OK) { return; } IsWorking = true; MTProtoService.BlockAsync(user.ToInputUser(), blocked => { user.Blocked = TLBool.True; CacheService.Commit(); DeleteHistoryAsync(false, user.ToInputPeer(), result => BeginOnUIThread(() => { IsWorking = false; CacheService.DeleteDialog(dialog); // TODO : move this line to MTProtoService if (dialog.With != null) { dialog.With.Bitmap = null; } Items.Remove(dialog); }), error => BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("messages.deleteHistory error " + error); })); }, error => BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("contacts.Block error " + error); })); }
public void ProcessAsync(Action <IList <TLMessageBase> > callback) { if (Results != null) { IsCanceled = false; callback.SafeInvoke(Results); return; } var source = Source; Execute.BeginOnThreadPool(() => { var items = new List <TLMessageBase>(source.Count); var itemsIndex = new Dictionary <int, int>(source.Count); foreach (var messageBase in source) { var message = messageBase as TLMessage; if (message == null) { continue; } var mediaDocument = message.Media as TLMessageMediaDocument; if (mediaDocument == null) { continue; } var document = mediaDocument.Document as TLDocument; if (document == null) { continue; } var fileName = document.FileName.ToString(); if (string.IsNullOrEmpty(fileName)) { continue; } if (fileName.IndexOf(Text, StringComparison.OrdinalIgnoreCase) >= 0) { itemsIndex[messageBase.Index] = messageBase.Index; items.Add(messageBase); } } ResultsIndex = itemsIndex; Results = items; callback.SafeInvoke(Results); }); }
protected override void OnRemovedFromJournal(JournalEntryRemovedEventArgs e) { //Execute.ShowDebugMessage("OnRemovedFromJournal " + GetType()); var viewModelBase = DataContext as ViewModelBase; if (viewModelBase != null) { Execute.BeginOnThreadPool(viewModelBase.Unsubscribe); } base.OnRemovedFromJournal(e); }
private void CopyLink_OnTap(object sender, GestureEventArgs e) { AppBar.Close(); Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.25), () => { if (string.IsNullOrEmpty(Link)) { return; } Clipboard.SetText(Link); }); }
private static void SaveVideoAsync(TLMessageMediaVideo mediaVideo) { var video = mediaVideo.Video as TLVideo; if (video == null) { return; } var fileName = video.GetFileName(); Execute.BeginOnThreadPool(() => SaveVideo(fileName)); }
private void RunAnimation() { if (_isForwardInAnimation) { _isForwardInAnimation = false; var forwardInAnimation = TelegramTurnstileAnimations.GetAnimation(LayoutRoot, TurnstileTransitionMode.ForwardIn); Execute.BeginOnUIThread(forwardInAnimation.Begin); } else { LayoutRoot.Opacity = 1.0; } }
public void NewBroadcastList() { CacheService.CheckDisabledFeature(Constants.FeatureBroadcastCreate, () => { StateService.RemoveBackEntry = true; NavigationService.UriFor <CreateBroadcastViewModel>().Navigate(); }, disabledFeature => { Execute.BeginOnUIThread(() => MessageBox.Show(disabledFeature.Description.ToString(), AppResources.AppName, MessageBoxButton.OK)); }); }
public bool OpenDialogDetails(TLDialogBase dialog) { ShellViewModel.StartNewTimer(); //Execute.ShowDebugMessage("OpenDialogDetails"); if (dialog == null) { Execute.ShowDebugMessage("OpenDialogDetails dialog=null"); return(false); } if (dialog.With == null) { Execute.ShowDebugMessage("OpenDialogDetails dialog.With=null"); return(false); } if (dialog.IsEncryptedChat) { var encryptedChat = CacheService.GetEncryptedChat(dialog.Peer.Id); var user = dialog.With as TLUserBase; if (user == null) { Execute.ShowDebugMessage("OpenDialogDetails encrypted dialog.With=null"); return(false); } var cachedUser = CacheService.GetUser(user.Id); StateService.Participant = cachedUser ?? user; StateService.With = encryptedChat; StateService.Dialog = dialog; StateService.AnimateTitle = true; NavigationService.UriFor <SecretDialogDetailsViewModel>().Navigate(); } else { var settings = dialog.With as INotifySettings; if (settings != null) { settings.NotifySettings = settings.NotifySettings ?? dialog.NotifySettings; } var currentBackground = IoC.Get <IStateService>().CurrentBackground; StateService.With = dialog.With; StateService.Dialog = dialog; StateService.AnimateTitle = true; NavigationService.UriFor <DialogDetailsViewModel>().Navigate(); } return(true); }
public void Next() { if (!CanCreateChannel) { return; } IsWorking = true; NotifyOfPropertyChange(() => CanCreateChannel); #if LAYER_41 // 1 broadcast // 2 mega group MTProtoService.CreateChannelAsync(new TLInt(2), new TLString(Title), new TLString(About), #else MTProtoService.CreateChannelAsync(new TLInt(1), new TLString(Title), new TLString(About), new TLVector <TLInputUserBase>(), #endif result => Execute.BeginOnUIThread(() => { var updates = result as TLUpdates; if (updates != null) { var channel = updates.Chats.FirstOrDefault() as TLChannel; if (channel != null) { if (_photo != null) { ContinueUploadingPhoto(channel); } else { if (_uploadingPhoto) { _uploadingCallback = () => ContinueUploadingPhoto(channel); } else { ContinueNextStep(channel); } } } } }), error => Execute.BeginOnUIThread(() => { IsWorking = false; NotifyOfPropertyChange(() => CanCreateChannel); Execute.ShowDebugMessage("channels.createChannel error " + error); })); }
public void AddContact() { if (CurrentContact == null) { return; } if (!HasPhone) { return; } var userPhone = new TLString(Phone); if (TLString.IsNullOrEmpty(userPhone)) { return; } IsWorking = true; ImportContactAsync(CurrentContact, userPhone, MTProtoService, result => { if (result.Users.Count > 0) { EventAggregator.Publish(new TLUpdateContactLink24 { UserId = result.Users[0].Id, MyLink = new TLContactLink(), ForeignLink = new TLContactLinkUnknown() }); var userBase = result.Users[0]; if (userBase != null && userBase.IsContact) { ContactsHelper.CreateContactAsync(_fileManager, StateService, userBase); } RaiseImportStatusChanged(new ImportEventArgs { Imported = true }); } BeginOnUIThread(() => { IsWorking = false; NotifyOfPropertyChange(() => HasPhone); }); }, error => BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("contacts.importContacts error " + error); })); }
private static void NavigateToShareTarget(string weblink) { if (string.IsNullOrEmpty(weblink)) { return; } Execute.BeginOnUIThread(() => { Execute.ShowDebugMessage(weblink); var navigationService = IoC.Get <INavigationService>(); navigationService.Navigate(new Uri("/Views/Dialogs/ChooseDialogView.xaml?rndParam=" + TLInt.Random(), UriKind.Relative)); }); }