Esempio n. 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);
            }
        }
Esempio n. 2
0
        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);
            });
        }