示例#1
0
        public void ClearHistory(TLDialogBase dialog)
        {
            var confirmation = MessageBox.Show(AppResources.ClearHistoryConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel);

            if (confirmation != MessageBoxResult.OK)
            {
                return;
            }

            if (dialog.Peer is TLPeerChannel)
            {
                var channel = (TLChannel)dialog.With;

                MTProtoService.DeleteHistoryAsync(channel.ToInputChannel(),
                                                  result =>
                {
                    CacheService.ClearDialog(dialog.Peer);
                    BeginOnUIThread(() =>
                    {
                        if (dialog.With != null)
                        {
                            dialog.With.ClearBitmap();
                        }

                        dialog.NotifyOfPropertyChange(() => dialog.UnreadCount);
                        var dialog71 = dialog as TLDialog71;
                        if (dialog71 != null)
                        {
                            dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMentionsCount);
                        }
                    });
                },
                                                  error =>
                {
                    Execute.ShowDebugMessage("channels.deleteHistory error " + error);
                });
            }
            else if (dialog.Peer is TLPeerUser)
            {
                var user      = (TLUserBase)dialog.With;
                var inputPeer = user.ToInputPeer();

                DeleteHistoryAsync(true, inputPeer,
                                   result =>
                {
                    CacheService.ClearDialog(dialog.Peer);
                    BeginOnUIThread(() =>
                    {
                        if (dialog.With != null)
                        {
                            dialog.With.ClearBitmap();
                        }

                        dialog.NotifyOfPropertyChange(() => dialog.UnreadCount);
                        var dialog71 = dialog as TLDialog71;
                        if (dialog71 != null)
                        {
                            dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMentionsCount);
                        }
                    });
                },
                                   error =>
                {
                    Execute.ShowDebugMessage("messages.deleteHistory error " + error);
                });
            }
            else if (dialog.Peer is TLPeerChat)
            {
                var chat      = (TLChatBase)dialog.With;
                var inputPeer = chat.ToInputPeer();

                DeleteHistoryAsync(true, inputPeer,
                                   result =>
                {
                    CacheService.ClearDialog(dialog.Peer);
                    BeginOnUIThread(() =>
                    {
                        if (dialog.With != null)
                        {
                            dialog.With.ClearBitmap();
                        }
                        dialog.NotifyOfPropertyChange(() => dialog.UnreadCount);
                        var dialog71 = dialog as TLDialog71;
                        if (dialog71 != null)
                        {
                            dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMentionsCount);
                        }
                    });
                },
                                   error =>
                {
                    Execute.ShowDebugMessage("messages.deleteHistory error " + error);
                });
            }
            else if (dialog.Peer is TLPeerEncryptedChat)
            {
                var chat = CacheService.GetEncryptedChat(dialog.Peer.Id) as TLEncryptedChat;
                if (chat == null)
                {
                    return;
                }

                var flushHistoryAction = new TLDecryptedMessageActionFlushHistory();

                var decryptedTuple = SecretDialogDetailsViewModel.GetDecryptedServiceMessageAndObject(flushHistoryAction, chat, MTProtoService.CurrentUserId, CacheService);

                SecretDialogDetailsViewModel.SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService,
                                                                  CacheService,
                                                                  sentEncryptedMessage =>
                {
                    CacheService.ClearDecryptedHistoryAsync(chat.Id);
                    BeginOnUIThread(() =>
                    {
                        if (dialog.With != null)
                        {
                            dialog.With.ClearBitmap();
                        }

                        dialog.NotifyOfPropertyChange(() => dialog.UnreadCount);
                    });
                });
            }
            else if (dialog.Peer is TLPeerBroadcast)
            {
                var broadcast = CacheService.GetBroadcast(dialog.Peer.Id);
                if (broadcast == null)
                {
                    return;
                }

                CacheService.ClearBroadcastHistoryAsync(broadcast.Id);
            }
        }
        public void ClearHistory(TLDialogBase dialog)
        {
            if (dialog == null)
            {
                return;
            }
            if (dialog.Peer is TLPeerUser)
            {
                return;
            }

            var confirmation = MessageBox.Show(string.Format("{0}?", AppResources.ClearHistory), AppResources.Confirm, MessageBoxButton.OKCancel);

            if (confirmation != MessageBoxResult.OK)
            {
                return;
            }


            if (dialog.Peer is TLPeerChat)
            {
                var chat      = (TLChatBase)dialog.With;
                var inputPeer = chat.ToInputPeer();

                DeleteHistoryAsync(inputPeer,
                                   result =>
                {
                    CacheService.DeleteDialog(dialog);     // TODO : move this line to MTProtoService
                    BeginOnUIThread(() =>
                    {
                        if (dialog.With != null)
                        {
                            dialog.With.Bitmap = null;
                        }
                        Items.Remove(dialog);
                    });
                },
                                   error =>
                {
                    Execute.ShowDebugMessage("messages.deleteHistory error " + error);
                });
            }
            else if (dialog.Peer is TLPeerEncryptedChat)
            {
                var chat = CacheService.GetEncryptedChat(dialog.Peer.Id) as TLEncryptedChat;
                if (chat == null)
                {
                    return;
                }

                var flushHistoryAction = new TLDecryptedMessageActionFlushHistory();

                var decryptedTuple = SecretDialogDetailsViewModel.GetDecryptedServiceMessageAndObject(flushHistoryAction, chat, MTProtoService.CurrentUserId, CacheService);

                SecretDialogDetailsViewModel.SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService,
                                                                  CacheService,
                                                                  sentEncryptedMessage =>
                {
                    chat.SetBitmap(null);
                    CacheService.ClearDecryptedHistoryAsync(chat.Id);
                });
            }
            else if (dialog.Peer is TLPeerBroadcast)
            {
                var broadcast = CacheService.GetBroadcast(dialog.Peer.Id);
                if (broadcast == null)
                {
                    return;
                }

                CacheService.ClearBroadcastHistoryAsync(broadcast.Id);
            }
        }