Exemplo n.º 1
0
        public void Group(TLDialogBase dialogBase)
        {
            var dialog = dialogBase as TLDialog;

            if (dialog == null)
            {
                return;
            }

            var channel = dialog.With as TLChannel76;

            if (channel == null)
            {
                return;
            }

            var feedId = channel.FeedId != null ? null : new TLInt(1);

            IsWorking = true;
            MTProtoService.ChangeFeedBroadcastAsync(channel.ToInputChannel(), feedId,
                                                    result => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
                //Handle(new TLUpdateDialogPinned76 { Peer = dialog53.Peer, Pinned = pinned });
                channel.FeedId = feedId;
                Execute.ShowDebugMessage(result.ToString());
            }),
                                                    error => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
            }));
        }
Exemplo n.º 2
0
        private static TLFileLocation GetTileImageLocation(TLDialogBase dialog)
        {
            var user    = dialog.With as TLUserBase;
            var chat    = dialog.With as TLChat;
            var channel = dialog.With as TLChannel;

            if (user != null)
            {
                var userProfilePhoto = user.Photo as TLUserProfilePhoto;
                if (userProfilePhoto != null)
                {
                    return(userProfilePhoto.PhotoSmall as TLFileLocation);
                }
            }
            else if (chat != null)
            {
                var chatPhoto = chat.Photo as TLChatPhoto;
                if (chatPhoto != null)
                {
                    return(chatPhoto.PhotoSmall as TLFileLocation);
                }
            }
            else if (channel != null)
            {
                var chatPhoto = channel.Photo as TLChatPhoto;
                if (chatPhoto != null)
                {
                    return(chatPhoto.PhotoSmall as TLFileLocation);
                }
            }

            return(null);
        }
        public static void PinToStartCommon(TLDialogBase dialog)
        {
            if (dialog == null)
            {
                return;
            }
            if (dialog.With == null)
            {
                return;
            }

            var title            = DialogCaptionConverter.Convert(dialog.With);
            var standartTileData = new StandardTileData {
                BackContent = AppResources.AppName, Title = title, BackTitle = title
            };

            var tileNavigationParam = GetTileNavigationParam(dialog);
            var imageLocation       = GetTileImageLocation(dialog);

            var imageUri = GetTileImageUri(imageLocation);

            if (imageUri != null)
            {
                standartTileData.BackgroundImage = imageUri;
            }

            try
            {
                ShellTile.Create(new Uri("/Views/ShellView.xaml?" + tileNavigationParam, UriKind.Relative), standartTileData);
            }
            catch (Exception ex)
            {
                Execute.ShowDebugMessage("Pin tile error " + ex);
            }
        }
 public MessagesRemovedEventArgs(TLDialogBase dialog, TLMessageBase message)
 {
     Dialog   = dialog;
     Messages = new List <TLMessageBase> {
         message
     };
 }
Exemplo n.º 5
0
        public static string GetTileNavigationParam(TLDialogBase dialog)
        {
            var user      = dialog.With as TLUserBase;
            var chat      = dialog.With as TLChatBase;
            var channel   = dialog.With as TLChannel;
            var broadcast = dialog.With as TLBroadcastChat;

            if (user != null)
            {
                if (dialog is TLEncryptedDialog)
                {
                    return("Action=SecondaryTile&encrypteduser_id=" + ((TLUserBase)dialog.With).Id + "&encryptedchat_id=" + dialog.Peer.Id);
                }

                return("Action=SecondaryTile&from_id=" + user.Id);
            }

            if (channel != null)
            {
                return("Action=SecondaryTile&channel_id=" + channel.Id);
            }

            if (broadcast != null)
            {
                return("Action=SecondaryTile&broadcast_id=" + broadcast.Id);
            }

            if (chat != null)
            {
                return("Action=SecondaryTile&chat_id=" + chat.Id);
            }

            return(null);
        }
Exemplo n.º 6
0
        public void DeleteAndStop(TLDialogBase dialog)
        {
            if (dialog == null)
            {
                return;
            }

            var user = dialog.With as TLUser;

            if (user == null || !user.IsBot)
            {
                return;
            }

            var confirmation = MessageBox.Show(AppResources.DeleteChatConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel);

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

            IsWorking = true;
            MTProtoService.BlockAsync(user.ToInputUser(),
                                      blocked =>
            {
                user.Blocked = TLBool.True;
                CacheService.Commit();

                DeleteHistoryAsync(false, user.ToInputPeer(),
                                   result => BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    CacheService.DeleteDialog(dialog);         // TODO : move this line to MTProtoService

                    if (dialog.With != null)
                    {
                        dialog.With.Bitmap = null;
                    }
                    Items.Remove(dialog);
                }),
                                   error => BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    Execute.ShowDebugMessage("messages.deleteHistory error " + error);
                }));
            },
                                      error => BeginOnUIThread(() =>
            {
                IsWorking = false;
                Execute.ShowDebugMessage("contacts.Block error " + error);
            }));
        }
Exemplo n.º 7
0
        public bool OpenDialogDetails(TLDialogBase dialog)
        {
            ShellViewModel.StartNewTimer();
            //Execute.ShowDebugMessage("OpenDialogDetails");

            if (dialog == null)
            {
                Execute.ShowDebugMessage("OpenDialogDetails dialog=null");
                return(false);
            }
            if (dialog.With == null)
            {
                Execute.ShowDebugMessage("OpenDialogDetails dialog.With=null");
                return(false);
            }

            if (dialog.IsEncryptedChat)
            {
                var encryptedChat = CacheService.GetEncryptedChat(dialog.Peer.Id);

                var user = dialog.With as TLUserBase;
                if (user == null)
                {
                    Execute.ShowDebugMessage("OpenDialogDetails encrypted dialog.With=null");
                    return(false);
                }

                var cachedUser = CacheService.GetUser(user.Id);
                StateService.Participant  = cachedUser ?? user;
                StateService.With         = encryptedChat;
                StateService.Dialog       = dialog;
                StateService.AnimateTitle = true;
                NavigationService.UriFor <SecretDialogDetailsViewModel>().Navigate();
            }
            else
            {
                var settings = dialog.With as INotifySettings;
                if (settings != null)
                {
                    settings.NotifySettings = settings.NotifySettings ?? dialog.NotifySettings;
                }

                var currentBackground = IoC.Get <IStateService>().CurrentBackground;
                StateService.With         = dialog.With;
                StateService.Dialog       = dialog;
                StateService.AnimateTitle = true;
                NavigationService.UriFor <DialogDetailsViewModel>().Navigate();
            }

            return(true);
        }
        private static bool Skip(TLDialogBase d)
        {
            if (d is TLEncryptedDialog)
            {
                return(true);
            }

            var user = d.With as TLUser;

            if (user != null && user.IsSelf)
            {
                return(true);
            }

            if (user != null && user.IsDeleted)
            {
                return(true);
            }

            var channel = d.With as TLChannel;

            if (channel != null && channel.Left.Value)
            {
                return(true);
            }

            var chat = d.With as TLChat41;

            if (chat != null && chat.IsMigrated)
            {
                return(true);
            }

            if (channel != null && !channel.IsMegaGroup && !(channel.IsEditor || channel.Creator))
            {
                return(true);
            }

            var chatForbidden = d.With as TLChatForbidden;

            if (chatForbidden != null)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public static void UnpinFromStart(TLDialogBase dialog)
        {
            if (dialog == null)
            {
                return;
            }
            if (dialog.With == null)
            {
                return;
            }

            var tileNavigationParam = GetTileNavigationParam(dialog);

            var tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(tileNavigationParam));

            if (tile != null)
            {
                tile.Delete();
            }
        }
Exemplo n.º 10
0
        public DialogItem(TLDialogBase dialog, double panelWidth, DataTemplate template)
        {
            _fixedHeight = 96.0;

            var contentControl = new ContentControl {
                Width = panelWidth, Content = dialog, HorizontalContentAlignment = HorizontalAlignment.Stretch, ContentTemplate = template
            };

            //var binding = new Binding
            //{
            //    Mode = BindingMode.OneWay,
            //    Path = new PropertyPath("LineOne"),
            //    //Converter = new DefaultPhotoConverter(),
            //    //ConverterParameter = StickerHeight
            //};
            //var panelMargin = new Thickness(0.0, 0.0, 0.0, 17.0);
            //var panelActualWidth = panelWidth - panelMargin.Left - panelMargin.Right;
            //var stackPanel = new StackPanel{ Width = panelActualWidth, Margin = panelMargin, Background = new SolidColorBrush(Colors.Transparent) };
            //var firstTextBlock = new TextBlock {TextWrapping = TextWrapping.Wrap, Text = item.LineOne, Style = Application.Current.Resources["PhoneTextExtraLargeStyle"] as Style };
            //firstTextBlock.SetBinding(TextBlock.TextProperty, binding);
            //var secondTextBlock = new TextBlock
            //{
            //    TextWrapping = TextWrapping.Wrap,
            //    Text = item.LineTwo,
            //    Margin = new Thickness(12.0, -6.0, 12.0, 0.0),
            //    Style = Application.Current.Resources["PhoneTextSubtleStyle"] as Style
            //};
            //stackPanel.Children.Add(firstTextBlock);
            //stackPanel.Children.Add(secondTextBlock);
            var listBoxItem = new ListBoxItem {
                Content = contentControl, DataContext = dialog
            };

            //listBoxItem.Tap += Item_OnTap;

            Children.Add(listBoxItem);

            View.Width = panelWidth;
        }
Exemplo n.º 11
0
        private void ContinueDeleteChannel(TLChannel channel)
        {
            TLDialogBase dialog = CacheService.GetDialog(new TLPeerChannel {
                Id = channel.Id
            });

            if (dialog == null)
            {
                dialog = DialogsViewModel.GetChannel(channel.Id);
            }

            if (dialog != null)
            {
                CacheService.DeleteDialog(dialog);
                DialogsViewModel.UnpinFromStart(dialog);
                EventAggregator.Publish(new DialogRemovedEventArgs(dialog));
            }

            NavigationService.RemoveBackEntry();
            NavigationService.RemoveBackEntry();
            NavigationService.GoBack();
        }
Exemplo n.º 12
0
        public void Pin(TLDialogBase dialog)
        {
            var dialog53 = dialog as TLDialog53;

            if (dialog53 != null)
            {
                var pinned = !dialog53.IsPinned;
                IsWorking = true;
                MTProtoService.ToggleDialogPinAsync(pinned, dialog53.Peer,
                                                    result => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    Handle(new TLUpdateDialogPinned76 {
                        Peer = new TLDialogPeer {
                            Peer = dialog53.Peer
                        }, Pinned = pinned
                    });
                }),
                                                    error => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                }));
            }
        }
Exemplo n.º 13
0
        public bool OpenFastDialogDetails(TLDialogBase dialog)
        {
            return(FastCallback(dialog));

            //Execute.ShowDebugMessage("OpenDialogDetails");
        }
Exemplo n.º 14
0
        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);
            }
        }
        private void LoadDialogs()
        {
            TLDialogBase currentUserDialog = null;

            _dialogs = IoC.Get <ICacheService>().GetDialogs();

            var clearedDialogs = new List <TLDialogBase>();

            foreach (var d in _dialogs)
            {
                if (Skip(d))
                {
                    var user = d.With as TLUser;
                    if (user != null && user.IsSelf)
                    {
                        currentUserDialog = d;
                    }

                    continue;
                }

                clearedDialogs.Add(d);
            }

            if (currentUserDialog != null)
            {
                clearedDialogs.Insert(0, currentUserDialog);
            }
            else
            {
                var currentUser = IoC.Get <ICacheService>().GetUser(new TLInt(IoC.Get <IStateService>().CurrentUserId));

                currentUserDialog = new TLDialog {
                    Peer = new TLPeerUser {
                        Id = currentUser.Id
                    }, With = currentUser
                };
                clearedDialogs.Insert(0, currentUserDialog);
            }

            _dialogsSource = clearedDialogs;

            DialogRow currentRow = null;
            var       rows       = new Group <DialogRow>("group");

            Rows = rows;
            var groups = new ObservableCollection <Group <DialogRow> > {
                rows
            };
            var secondSlice = new List <DialogRow>();

            if (clearedDialogs.Count > 0)
            {
                var maxFirstSliceCount  = 12;
                var maxSecondSliceCount = 24;
                for (var i = 0; i < clearedDialogs.Count; i++)
                {
                    if (i % 4 == 0)
                    {
                        currentRow = new DialogRow();
                        if (i < maxFirstSliceCount)
                        {
                            rows.Add(currentRow);
                        }
                        else if (i < maxSecondSliceCount)
                        {
                            secondSlice.Add(currentRow);
                        }
                    }

                    var d = new DialogItem {
                        Dialog = clearedDialogs[i], Row = currentRow
                    };

                    DialogsSource.Add(d);

                    currentRow.Add(d);
                }
            }

            var lastDialog = _dialogs.LastOrDefault(x => x is TLDialog) as TLDialog;

            UpdateDialogsAsync(lastDialog);

            Execute.BeginOnUIThread(() =>
            {
                SetListVerticalAlignment(Rows.Count);
                Dialogs.ItemsSource = groups;
                Dialogs.Visibility  = Visibility.Visible;
                Dialogs.Opacity     = 0.0;

                Execute.BeginOnUIThread(() =>
                {
                    Dialogs.Opacity        = 1.0;
                    var storyboard         = new Storyboard();
                    var translateAnimaiton = new DoubleAnimationUsingKeyFrames();
                    translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame {
                        KeyTime = TimeSpan.FromSeconds(0.0), Value = Dialogs.ActualHeight
                    });
                    translateAnimaiton.KeyFrames.Add(new EasingDoubleKeyFrame {
                        KeyTime = TimeSpan.FromSeconds(0.4), Value = 0.0, EasingFunction = new ExponentialEase {
                            Exponent = 5.0, EasingMode = EasingMode.EaseOut
                        }
                    });
                    Storyboard.SetTarget(translateAnimaiton, Dialogs);
                    Storyboard.SetTargetProperty(translateAnimaiton, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
                    storyboard.Children.Add(translateAnimaiton);

                    storyboard.Begin();

                    if (secondSlice.Count > 0)
                    {
                        storyboard.Completed += (o, e) =>
                        {
                            foreach (var item in secondSlice)
                            {
                                Rows.Add(item);
                            }
                            _secondSliceLoaded = true;

                            LoadNextSlice();
                        };
                    }
                    else
                    {
                        _secondSliceLoaded = true;

                        LoadNextSlice();
                    }
                });
            });
        }
Exemplo n.º 16
0
 public void PinToStart(TLDialogBase dialog)
 {
     PinToStartCommon(dialog);
 }
Exemplo n.º 17
0
        public void ChangeUnreadMark(TLDialogBase dialogBase)
        {
            var dialog71 = dialogBase as TLDialog71;

            if (dialog71 == null)
            {
                return;
            }

            if (dialog71.UnreadMark ||
                dialog71.UnreadMentionsCount != null && dialog71.UnreadMentionsCount.Value > 0 ||
                dialog71.UnreadCount != null && dialog71.UnreadCount.Value > 0)
            {
                if (dialog71.UnreadMark)
                {
                    MTProtoService.MarkDialogUnreadAsync(false, new TLInputDialogPeer {
                        Peer = MTProtoService.PeerToInputPeer(dialog71.Peer)
                    },
                                                         result => BeginOnUIThread(() =>
                    {
                        dialog71.UnreadMark = !dialog71.UnreadMark;
                        dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMark);
                    }),
                                                         error =>
                    {
                        Execute.ShowDebugMessage("messages.markDialogUnread error " + error);
                    });
                }

                var channel = dialog71.With as TLChannel;
                if (dialog71.UnreadCount != null && dialog71.UnreadCount.Value > 0)
                {
                    if (channel != null)
                    {
                        MTProtoService.ReadHistoryAsync(channel, new TLInt(int.MaxValue),
                                                        result => BeginOnUIThread(() =>
                        {
                            dialog71.UnreadCount = new TLInt(0);
                            dialog71.NotifyOfPropertyChange(() => dialog71.UnreadCount);
                        }),
                                                        error =>
                        {
                            Execute.ShowDebugMessage("channels.readHistory error " + error);
                        });
                    }
                    else
                    {
                        MTProtoService.ReadHistoryAsync(MTProtoService.PeerToInputPeer(dialog71.Peer),
                                                        new TLInt(int.MaxValue), new TLInt(0),
                                                        result => BeginOnUIThread(() =>
                        {
                            dialog71.UnreadCount = new TLInt(0);
                            dialog71.NotifyOfPropertyChange(() => dialog71.UnreadCount);
                        }),
                                                        error =>
                        {
                            Execute.ShowDebugMessage("messages.readHistory error " + error);
                        });
                    }
                }
                if (dialog71.UnreadMentionsCount != null && dialog71.UnreadMentionsCount.Value > 0)
                {
                    MTProtoService.ReadMentionsAsync(MTProtoService.PeerToInputPeer(dialog71.Peer),
                                                     result => BeginOnUIThread(() =>
                    {
                        dialog71.UnreadMentionsCount = new TLInt(0);
                        dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMentionsCount);
                    }),
                                                     error =>
                    {
                        Execute.ShowDebugMessage("messages.readMentions error " + error);
                    });
                }
            }
            else
            {
                MTProtoService.MarkDialogUnreadAsync(true, new TLInputDialogPeer {
                    Peer = MTProtoService.PeerToInputPeer(dialog71.Peer)
                },
                                                     result => BeginOnUIThread(() =>
                {
                    dialog71.UnreadMark = !dialog71.UnreadMark;
                    dialog71.NotifyOfPropertyChange(() => dialog71.UnreadMark);
                }),
                                                     error =>
                {
                    Execute.ShowDebugMessage("messages.markDialogUnread error " + error);
                });
            }
        }
Exemplo n.º 18
0
 public MessagesRemovedEventArgs(TLDialogBase dialog, IList <TLMessageBase> messages)
 {
     Dialog   = dialog;
     Messages = messages;
 }
Exemplo n.º 19
0
 public MessagesRemovedEventArgs(TLDialogBase dialog, TLDecryptedMessageBase message)
 {
     Dialog           = dialog;
     DecryptedMessage = message;
 }
 public TopMessageUpdatedEventArgs(TLDialogBase dialog, TLDecryptedMessageBase message)
 {
     Dialog           = dialog;
     DecryptedMessage = message;
 }
Exemplo n.º 21
0
 public ChannelAvailableMessagesEventArgs(TLDialogBase dialog, TLInt availableMinId)
 {
     Dialog         = dialog;
     AvailableMinId = availableMinId;
 }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
0
 public DialogAddedEventArgs(TLDialogBase dialog)
 {
     Dialog = dialog;
 }
Exemplo n.º 24
0
 public DialogRemovedEventArgs(TLDialogBase dialog)
 {
     Dialog = dialog;
 }
Exemplo n.º 25
0
        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;
            }
        }
Exemplo n.º 26
0
        public void ForwardInAnimationComplete()
        {
            Execute.BeginOnThreadPool(() =>
            {
                _recentResults = _recentResults ?? TLUtils.OpenObjectFromMTProtoFile <TLVector <TLResultInfo> >(_recentSyncRoot, Constants.RecentSearchResultsFileName) ?? new TLVector <TLResultInfo>();

                var recent = new List <TLObject>();
                foreach (var result in _recentResults)
                {
                    if (result.Type.ToString() == "user")
                    {
                        var user = CacheService.GetUser(result.Id);
                        if (user != null)
                        {
                            recent.Add(user);
                            if (user.Dialog == null)
                            {
                                user.Dialog = CacheService.GetDialog(new TLPeerUser {
                                    Id = user.Id
                                });
                            }
                        }
                    }

                    if (result.Type.ToString() == "chat")
                    {
                        var chat = CacheService.GetChat(result.Id);
                        if (chat != null)
                        {
                            recent.Add(chat);
                            if (chat.Dialog == null)
                            {
                                TLDialogBase dialog = CacheService.GetDialog(new TLPeerChat {
                                    Id = chat.Id
                                });
                                if (dialog == null)
                                {
                                    if (chat is TLChannel)
                                    {
                                        dialog = DialogsViewModel.GetChannel(chat.Id);
                                    }
                                }
                                chat.Dialog = dialog;
                            }
                        }
                    }
                }

                Execute.BeginOnUIThread(() =>
                {
                    if (!string.IsNullOrEmpty(Text))
                    {
                        return;
                    }

                    Recent.Clear();
                    foreach (var recentItem in recent)
                    {
                        Recent.Add(recentItem);
                    }

                    NotifyOfPropertyChange(() => ShowRecent);
                });
            });
        }
Exemplo n.º 27
0
        public void ProcessAsync(Action <IList <TLObject> > callback)
        {
            if (Results != null)
            {
                IsCanceled = false;
                callback.SafeInvoke(Results);
                return;
            }

            var usersSource = UsersSource;
            var chatsSource = ChatsSource;

            Execute.BeginOnThreadPool(() =>
            {
                var useFastSearch = !Text.Contains(" ");

                var userResults = new List <TLUserBase>(usersSource.Count);
                foreach (var contact in usersSource)
                {
                    if (IsUserValid(contact, Text) ||
                        IsUserValid(contact, TransliterateText) ||
                        IsUsernameValid(contact as IUserName, Text))
                    {
                        userResults.Add(contact);
                    }
                }

                var chatsResults = new List <TLChatBase>(chatsSource.Count);
                foreach (var chat in chatsSource)
                {
                    if (IsChatValid(chat, Text, useFastSearch) ||
                        IsChatValid(chat, TransliterateText, useFastSearch) ||
                        IsUsernameValid(chat as IUserName, Text))
                    {
                        chatsResults.Add(chat);
                    }
                }

                Results          = new List <TLObject>(userResults.Count + chatsResults.Count);
                UserResultsIndex = new Dictionary <int, TLUserBase>();
                ChatResultsIndex = new Dictionary <int, TLChatBase>();
                foreach (var userResult in userResults)
                {
                    Results.Add(userResult);
                    UserResultsIndex[userResult.Index] = userResult;
                    if (userResult.Dialog == null)
                    {
                        userResult.Dialog = _cacheService.GetDialog(new TLPeerUser {
                            Id = userResult.Id
                        });
                    }
                }
                foreach (var chatResult in chatsResults)
                {
                    Results.Add(chatResult);
                    ChatResultsIndex[chatResult.Index] = chatResult;
                    if (chatResult.Dialog == null)
                    {
                        TLDialogBase dialog = _cacheService.GetDialog(new TLPeerChat {
                            Id = chatResult.Id
                        });
                        if (dialog == null)
                        {
                            if (chatResult is TLChannel)
                            {
                                dialog = DialogsViewModel.GetChannel(chatResult.Id);
                            }
                        }
                        chatResult.Dialog = dialog;
                    }
                }

                Execute.BeginOnUIThread(() => callback.SafeInvoke(Results));
            });
        }
Exemplo n.º 28
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);
            });
        }