private async void ToggleMuteExecute() { if (_item == null || _full == null) { return; } var notifySettings = _full.NotifySettings as TLPeerNotifySettings; if (notifySettings != null) { var muteUntil = notifySettings.MuteUntil == int.MaxValue ? 0 : int.MaxValue; var settings = new TLInputPeerNotifySettings { MuteUntil = muteUntil, IsShowPreviews = notifySettings.IsShowPreviews, IsSilent = notifySettings.IsSilent, Sound = notifySettings.Sound }; var response = await ProtoService.UpdateNotifySettingsAsync(new TLInputNotifyPeer { Peer = _item.ToInputPeer() }, settings); if (response.IsSucceeded) { notifySettings.MuteUntil = muteUntil; RaisePropertyChanged(() => AreNotificationsEnabled); Full.RaisePropertyChanged(() => Full.NotifySettings); var dialog = CacheService.GetDialog(_item.ToPeer()); if (dialog != null) { dialog.NotifySettings = _full.NotifySettings; dialog.RaisePropertyChanged(() => dialog.NotifySettings); dialog.RaisePropertyChanged(() => dialog.IsMuted); dialog.RaisePropertyChanged(() => dialog.Self); } CacheService.Commit(); } } }
public void ForwardInAnimationComplete() { UpdateItems(); if (StateService.Participant != null) { var participant = StateService.Participant; StateService.Participant = null; var channel = CurrentItem as TLChannel; if (channel == null) { return; } IsWorking = true; MTProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> { participant.ToInputUser() }, result => Execute.BeginOnUIThread(() => { if (channel.ParticipantsCount != null) { channel.ParticipantsCount = new TLInt(channel.ParticipantsCount.Value + 1); } CacheService.Commit(); IsWorking = false; Items.Insert(0, participant); Status = Items.Count > 0 ? string.Empty : AppResources.NoUsersHere; }), error => Execute.BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("channels.inviteToChannel error " + error); })); } }
private async void BlockExecute() { if (Item is TLUser user) { var confirm = await TLMessageDialog.ShowAsync("Are you sure you want to block this contact?", "Telegram", "OK", "Cancel"); if (confirm != ContentDialogResult.Primary) { return; } var result = await ProtoService.BlockAsync(user.ToInputUser()); if (result.IsSucceeded && result.Result) { CacheService.Commit(); Aggregator.Publish(new TLUpdateUserBlocked { UserId = user.Id, Blocked = true }); } } }
private async void UnblockExecute() { var user = Item as TLUser; if (user != null) { 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(); } } } }
public void UnblockContact() { if (CurrentContact == null) { return; } var confirmation = IsBot ? MessageBoxResult.OK : MessageBox.Show(AppResources.UnblockContactConfirmation, AppResources.AppName, MessageBoxButton.OKCancel); if (confirmation == MessageBoxResult.OK) { IsWorking = true; MTProtoService.UnblockAsync(CurrentContact.ToInputUser(), result => BeginOnUIThread(() => { IsWorking = false; CurrentContact.Blocked = TLBool.False; CacheService.Commit(); EventAggregator.Publish(new TLUpdateUserBlocked { UserId = CurrentContact.Id, Blocked = TLBool.False }); if (IsBot) { NavigationService.GoBack(); } }), error => BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("contacts.unblock error " + error); })); } }
public void Done() { if (_currentItem == null) { return; } if (IsWorking) { return; } var username = Username; if (username != null && username.StartsWith("@")) { username = username.Substring(1, username.Length - 1); } IsWorking = true; MTProtoService.UpdateUsernameAsync(_currentItem.ToInputChannel(), new TLString(username), user => BeginOnUIThread(() => { var userName = _currentItem as IUserName; if (userName != null) { userName.UserName = new TLString(username); CacheService.Commit(); EventAggregator.Publish(new ChannelNameChangedEventArgs(_currentItem)); } IsWorking = false; NavigationService.GoBack(); }), error => BeginOnUIThread(() => { if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { HasError = true; Error = AppResources.FloodWaitString; MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { var messageBuilder = new StringBuilder(); messageBuilder.AppendLine(AppResources.ServerErrorMessage); messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.updateUsername"); messageBuilder.AppendLine("Result: " + error); HasError = true; Error = AppResources.ServerError; MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_NOT_MODIFIED)) { HasError = false; Error = " "; NavigationService.GoBack(); } else if (TLRPCError.TypeEquals(error, ErrorType.CHANNELS_ADMIN_PUBLIC_TOO_MUCH)) { var message = AppResources.ChannelsAdminPublicTooMuchShort; HasError = true; Error = message; MessageBox.Show(message, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_INVALID)) { var message = IsMegaGroup ? AppResources.SupergroupNameInvalid : AppResources.ChannelNameInvalid; HasError = true; Error = message; MessageBox.Show(message, AppResources.Error, MessageBoxButton.OK); } else if (TLRPCError.TypeEquals(error, ErrorType.USERNAME_OCCUPIED)) { var message = IsMegaGroup ? AppResources.SupergroupNameOccupied : AppResources.ChannelNameOccupied; HasError = true; Error = message; MessageBox.Show(message, AppResources.Error, MessageBoxButton.OK); } else { HasError = true; Error = error.ToString(); //Execute.BeginOnUIThread(() => NavigationService.GoBack()); } } else { HasError = true; Error = string.Empty; Execute.ShowDebugMessage("channel.updateUsername error " + error); } IsWorking = false; })); }
public void OpenMedia(TLDecryptedMessage message) #endif { if (message == null) { return; } if (message.Status == MessageStatus.Sending) { return; } if (message.Media.UploadingProgress > 0.0 && message.Media.UploadingProgress < 1.0) { return; } var mediaPhoto = message.Media as TLDecryptedMessageMediaPhoto; if (mediaPhoto != null) { var location = mediaPhoto.File as TLEncryptedFile; if (location != null) { var fileName = String.Format("{0}_{1}_{2}.jpg", location.Id, location.DCId, location.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists(fileName)) { message.Media.IsCanceled = false; message.Media.DownloadingProgress = 0.01; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(location, mediaPhoto); return; } } } if (!message.Out.Value && message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0 && mediaPhoto.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + message.TTL.Value * TimeSpan.TicksPerSecond); mediaPhoto.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; AddToTTLQueue(message, mediaPhoto.TTLParams, result => { DeleteMessage(false, message); SplitGroupedMessages(new List <TLLong> { message.RandomId }); }); CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); #if DEBUG Execute.BeginOnUIThread(() => Items.Insert(0, decryptedTuple.Item1)); #endif SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { }); }); } message.Unread = new TLBool(false); message.Status = MessageStatus.Read; CacheService.SyncDecryptedMessage(message, Chat, r => { }); if (mediaPhoto.IsCanceled) { mediaPhoto.IsCanceled = false; mediaPhoto.NotifyOfPropertyChange(() => mediaPhoto.Photo); mediaPhoto.NotifyOfPropertyChange(() => mediaPhoto.Self); return; } StateService.CurrentDecryptedPhotoMessage = message; StateService.CurrentDecryptedMediaMessages = message.TTL.Value > 0? new List <TLDecryptedMessage>() : UngroupEnumerator(Items) .OfType <TLDecryptedMessage>() .Where(x => x.TTL.Value == 0 && (x.Media is TLDecryptedMessageMediaPhoto || x.IsVideo())) .ToList(); OpenImageViewer(); return; } var mediaGeo = message.Media as TLDecryptedMessageMediaGeoPoint; if (mediaGeo != null) { OpenLocation(message); return; } var mediaVideo = message.Media as TLDecryptedMessageMediaVideo; if (mediaVideo != null) { var fileLocation = mediaVideo.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("{0}_{1}_{2}.mp4", fileLocation.Id, fileLocation.DCId, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.FileExists(fileName)) { var mediaVideo17 = mediaVideo as TLDecryptedMessageMediaVideo17; if (mediaVideo17 != null) { if (!message.Out.Value) { if (message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0) { if (mediaVideo17.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + Math.Max(mediaVideo17.Duration.Value + 1, message.TTL.Value) * TimeSpan.TicksPerSecond); mediaVideo17.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; message.Unread = new TLBool(false); message.Status = MessageStatus.Read; AddToTTLQueue(message, mediaVideo17.TTLParams, result => { DeleteMessage(false, message); SplitGroupedMessages(new List <TLLong> { message.RandomId }); }); CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); #if DEBUG Execute.BeginOnUIThread(() => Items.Insert(0, decryptedTuple.Item1)); #endif SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { }); }); } } } } var launcher = new MediaPlayerLauncher(); launcher.Location = MediaLocationType.Data; launcher.Media = new Uri(fileName, UriKind.Relative); launcher.Show(); } else { mediaVideo.DownloadingProgress = 0.001; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(fileLocation, mediaVideo); } } return; } var mediaAudio = message.Media as TLDecryptedMessageMediaAudio; if (mediaAudio != null) { var fileLocation = mediaAudio.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("audio{0}_{1}.wav", fileLocation.Id, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists(fileName)) { mediaAudio.DownloadingProgress = 0.001; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(fileLocation, mediaAudio); } else { if (mediaAudio.IsCanceled) { mediaAudio.IsCanceled = false; mediaAudio.NotifyOfPropertyChange(() => mediaAudio.ThumbSelf); return; } var mediaAudio17 = mediaAudio as TLDecryptedMessageMediaAudio17; if (mediaAudio17 != null) { if (!message.Out.Value) { if (message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0) { if (mediaAudio17.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + Math.Max(mediaAudio17.Duration.Value + 1, message.TTL.Value) * TimeSpan.TicksPerSecond); mediaAudio17.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; message.Unread = new TLBool(false); message.Status = MessageStatus.Read; CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); #if DEBUG Execute.BeginOnUIThread(() => Items.Insert(0, decryptedTuple.Item1)); #endif SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { }); }); } } } } } } return; } var mediaDocument = message.Media as TLDecryptedMessageMediaDocument; if (mediaDocument != null) { if (message.IsVoice()) { var fileLocation = mediaDocument.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("audio{0}_{1}.wav", fileLocation.Id, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists(fileName)) { mediaDocument.DownloadingProgress = 0.001; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(fileLocation, mediaDocument); } else { if (mediaDocument.IsCanceled) { mediaDocument.IsCanceled = false; mediaDocument.NotifyOfPropertyChange(() => mediaDocument.ThumbSelf); return; } var mediaDocument45 = mediaDocument as TLDecryptedMessageMediaDocument45; if (mediaDocument45 != null) { if (!message.Out.Value) { var message45 = message as TLDecryptedMessage45; if (message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0) { if (mediaDocument45.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + Math.Max(mediaDocument45.Duration.Value + 1, message.TTL.Value) * TimeSpan.TicksPerSecond); mediaDocument45.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; message.Unread = new TLBool(false); message.Status = MessageStatus.Read; CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); #if DEBUG Execute.BeginOnUIThread(() => Items.Insert(0, decryptedTuple.Item1)); #endif SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { if (message45 != null) { message45.SetListened(); message45.Media.NotListened = false; message45.Media.NotifyOfPropertyChange(() => message45.Media.NotListened); CacheService.Commit(); } }); }); } } else { ReadMessageContents(message45); } } } } } return; } else if (message.IsVideo()) { var fileLocation = mediaDocument.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("{0}_{1}_{2}.mp4", fileLocation.Id, fileLocation.DCId, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.FileExists(fileName)) { var mediaVideo17 = mediaDocument as TLDecryptedMessageMediaDocument45; if (mediaVideo17 != null) { if (!message.Out.Value) { if (message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0) { if (mediaVideo17.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + Math.Max(mediaVideo17.Duration.Value + 1, message.TTL.Value) * TimeSpan.TicksPerSecond); mediaVideo17.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; message.Unread = new TLBool(false); message.Status = MessageStatus.Read; AddToTTLQueue(message, mediaVideo17.TTLParams, result => { DeleteMessage(false, message); SplitGroupedMessages(new List <TLLong> { message.RandomId }); }); CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); #if DEBUG Execute.BeginOnUIThread(() => Items.Insert(0, decryptedTuple.Item1)); #endif SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { }); }); } } } } var launcher = new MediaPlayerLauncher(); launcher.Location = MediaLocationType.Data; launcher.Media = new Uri(fileName, UriKind.Relative); launcher.Show(); } else { mediaDocument.DownloadingProgress = 0.001; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(fileLocation, mediaDocument); } } return; } else { var fileLocation = mediaDocument.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("{0}_{1}_{2}.{3}", fileLocation.Id, fileLocation.DCId, fileLocation.AccessHash, fileLocation.FileExt ?? mediaDocument.FileExt); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.FileExists(fileName)) { #if WP8 StorageFile pdfFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName); Windows.System.Launcher.LaunchFileAsync(pdfFile); #endif } else { mediaDocument.DownloadingProgress = 0.001; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.DownloadFile(fileLocation, mediaDocument); } } } return; } #if DEBUG MessageBox.Show("Tap on media"); #endif }
public void ForwardInAnimationComplete() { UpdateItems(); if (StateService.Participant != null) { var participant = StateService.Participant; StateService.Participant = null; var channel = CurrentItem as TLChannel; if (channel == null) { return; } IsWorking = true; MTProtoService.InviteToChannelAsync(channel.ToInputChannel(), new TLVector <TLInputUserBase> { participant.ToInputUser() }, result => Execute.BeginOnUIThread(() => { if (channel.ParticipantsCount != null) { channel.ParticipantsCount = new TLInt(channel.ParticipantsCount.Value + 1); } CacheService.Commit(); IsWorking = false; Items.Insert(0, participant); Status = Items.Count > 0 ? string.Empty : AppResources.NoUsersHere; }), error => Execute.BeginOnUIThread(() => { IsWorking = false; if (error.TypeEquals(ErrorType.PEER_FLOOD)) { //MessageBox.Show(AppResources.PeerFloodAddContact, AppResources.Error, MessageBoxButton.OK); ShellViewModel.ShowCustomMessageBox(AppResources.PeerFloodAddContact, AppResources.Error, AppResources.MoreInfo.ToLowerInvariant(), AppResources.Ok.ToLowerInvariant(), result => { if (result == CustomMessageBoxResult.RightButton) { TelegramViewBase.NavigateToUsername(MTProtoService, Constants.SpambotUsername, null, null, null); } }); } else if (error.TypeEquals(ErrorType.USERS_TOO_MUCH)) { MessageBox.Show(AppResources.UsersTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_CHANNELS_TOO_MUCH)) { MessageBox.Show(AppResources.UserChannelsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.BOTS_TOO_MUCH)) { MessageBox.Show(AppResources.BotsTooMuch, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.USER_NOT_MUTUAL_CONTACT)) { MessageBox.Show(AppResources.UserNotMutualContact, AppResources.Error, MessageBoxButton.OK); } Execute.ShowDebugMessage("channels.inviteToChannel error " + error); })); } }
private void UpdateNotifySettingsAsync() { if (CurrentItem == null) { return; } var notifySettings = new TLInputPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(MuteUntil), ShowPreviews = new TLBool(true), Sound = string.IsNullOrEmpty(SelectedSound) ? new TLString("default") : new TLString(SelectedSound) }; IsWorking = true; MTProtoService.UpdateNotifySettingsAsync( CurrentItem.ToInputNotifyPeer(), notifySettings, result => { IsWorking = false; CurrentItem.NotifySettings = new TLPeerNotifySettings { EventsMask = new TLInt(1), MuteUntil = new TLInt(MuteUntil), ShowPreviews = notifySettings.ShowPreviews, Sound = notifySettings.Sound }; var channel = CurrentItem as TLChannel; var peer = channel != null ? (TLPeerBase) new TLPeerChannel { Id = CurrentItem.Id } : new TLPeerChat { Id = CurrentItem.Id }; TLDialogBase dialog = CacheService.GetDialog(peer); if (dialog == null) { if (channel != null) { dialog = DialogsViewModel.GetChannel(channel.Id); } } if (dialog != null) { dialog.NotifySettings = CurrentItem.NotifySettings; dialog.NotifyOfPropertyChange(() => dialog.NotifySettings); var settings = dialog.With as INotifySettings; if (settings != null) { settings.NotifySettings = CurrentItem.NotifySettings; } } CacheService.Commit(); }, error => { IsWorking = false; Execute.ShowDebugMessage("account.updateNotifySettings error: " + error); }); }