public void DeleteAndExit(TLDialogBase dialog) { if (dialog == null) { return; } if (dialog.Peer is TLPeerUser) { return; } var message = dialog.Peer is TLPeerEncryptedChat ? AppResources.DeleteChatConfirmation : AppResources.DeleteAndExitConfirmation; var result = MessageBox.Show(message, AppResources.Confirm, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } if (dialog.Peer is TLPeerBroadcast) { CacheService.DeleteDialog(dialog); UnpinFromStart(dialog); BeginOnUIThread(() => Items.Remove(dialog)); return; } if (dialog.Peer is TLPeerEncryptedChat) { var encryptedChat = CacheService.GetEncryptedChat(dialog.Peer.Id); if (encryptedChat is TLEncryptedChatDiscarded) { CacheService.DeleteDialog(dialog); UnpinFromStart(dialog); BeginOnUIThread(() => Items.Remove(dialog)); } else { IsWorking = true; MTProtoService.DiscardEncryptionAsync(dialog.Peer.Id, r => { IsWorking = false; CacheService.DeleteDialog(dialog); UnpinFromStart(dialog); BeginOnUIThread(() => Items.Remove(dialog)); }, error => { IsWorking = false; if (error.CodeEquals(ErrorCode.BAD_REQUEST) && error.Message.Value == "ENCRYPTION_ALREADY_DECLINED") { CacheService.DeleteDialog(dialog); UnpinFromStart(dialog); BeginOnUIThread(() => Items.Remove(dialog)); } Execute.ShowDebugMessage("messages.discardEncryption error " + error); }); } return; } if (dialog.Peer is TLPeerChat) { DeleteAndExitDialogCommon( dialog.With as TLChatBase, MTProtoService, () => { CacheService.DeleteDialog(dialog); UnpinFromStart(dialog); BeginOnUIThread(() => Items.Remove(dialog)); }, error => { Execute.ShowDebugMessage("DeleteAndExitDialogCommon error " + error); }); return; } }