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); }); }
private void UpdateNotifySettings(TLInputPeerBase inputPeer, TLInt muteUntil) { var deviceInfoService = new DeviceInfoService(GetInitConnection(), true, "InteractiveNotificationsBackgroundTask", _id); var eventAggregator = new TelegramEventAggregator(); var cacheService = new InMemoryCacheService(eventAggregator); var updatesService = new UpdatesService(cacheService, eventAggregator); var transportService = new TransportService(); var connectionService = new ConnectionService(deviceInfoService); var publicConfigService = new MockupPublicConfigService(); var manualResetEvent = new ManualResetEvent(false); Log("before init"); var mtProtoService = new MTProtoService(deviceInfoService, updatesService, cacheService, transportService, connectionService, publicConfigService); mtProtoService.Initialized += (o, e) => { Log("init completed"); mtProtoService.GetNotifySettingsAsync(new TLInputNotifyPeer { Peer = inputPeer }, result => { Log("getNotifySettings completed", () => { var peerNotifySettings = result as TLPeerNotifySettings; if (peerNotifySettings != null) { if (muteUntil.Value < int.MaxValue) { muteUntil = TLUtils.DateToUniversalTimeTLInt(mtProtoService.ClientTicksDelta, DateTime.Now.AddSeconds(muteUntil.Value)); } var inputPeerNotifySettings = new TLInputPeerNotifySettings78 { Flags = new TLInt(0), MuteUntil = muteUntil, Sound = peerNotifySettings.Sound, }; mtProtoService.UpdateNotifySettingsAsync(new TLInputNotifyPeer { Peer = inputPeer }, inputPeerNotifySettings, result2 => { Log("setNotifySettings completed", () => { manualResetEvent.Set(); }); }, error2 => { Log(string.Format("setNotifySettings error={0}\n{1}", error2, error2.Exception), async() => { await Task.Delay(TimeSpan.FromSeconds(1.0)); manualResetEvent.Set(); }); }); } else { manualResetEvent.Set(); } }); }, error => { Log(string.Format("getNotifySettings error={0}\n{1}", error, error.Exception), async() => { await Task.Delay(TimeSpan.FromSeconds(1.0)); manualResetEvent.Set(); }); }); }; mtProtoService.InitializationFailed += (o, e) => { Log("init failed"); manualResetEvent.Set(); }; mtProtoService.Initialize(); #if DEBUG manualResetEvent.WaitOne(); #else manualResetEvent.WaitOne(15000); #endif }