Пример #1
0
        private async void SearchExecute(string query)
        {
            Query = query;

            var response = await ProtoService.SearchAsync(_dialog.Peer, _query, _from?.ToInputUser(), null, 0, 0, 0, 0, 100);

            if (response.IsSucceeded && response.Result is ITLMessages result)
            {
                if (response.Result is TLMessagesMessagesSlice slice)
                {
                    TotalItems = slice.Count;
                }
                else if (response.Result is TLMessagesChannelMessages channelMessages)
                {
                    TotalItems = channelMessages.Count;
                }
                else
                {
                    TotalItems = result.Messages.Count;
                }

                Items        = new MvxObservableCollection <TLMessageBase>(result.Messages);
                SelectedItem = Items.FirstOrDefault();

                if (_selectedItem != null)
                {
                    await Dialog.LoadMessageSliceAsync(null, _selectedItem.Id);
                }
            }
            else
            {
                // TODO
            }
        }
Пример #2
0
        private void CommonChatsExecute()
        {
            if (_item == null)
            {
                return;
            }

            NavigationService.Navigate(typeof(UserCommonChatsPage), _item.ToInputUser());
        }
Пример #3
0
        public UserPhotosViewModel(IMTProtoService protoService, TLUserFull userFull, TLUser user)
            : base(protoService, null, null)
        {
            //Items = new MvxObservableCollection<GalleryItem>();
            //Initialize(user);

            _peer = user.ToInputUser();
            _user = user;

            Items = new MvxObservableCollection <GalleryItem> {
                new GalleryPhotoItem(userFull.ProfilePhoto as TLPhoto, user)
            };
            SelectedItem = Items[0];
            FirstItem    = Items[0];

            Initialize(user, userFull.ProfilePhoto.Id);
        }
Пример #4
0
        private async void Initialize(TLUser user)
        {
            User = user;

            var full = InMemoryCacheService.Current.GetFullUser(user.Id);

            if (full == null)
            {
                var response = await ProtoService.GetFullUserAsync(user.ToInputUser());

                if (response.IsSucceeded)
                {
                    full = response.Result;
                }
            }

            if (full != null)
            {
                SelectedItem = new GalleryPhotoItem(full.ProfilePhoto as TLPhoto, user);
                FirstItem    = SelectedItem;

                return;
            }

            using (await _loadMoreLock.WaitAsync())
            {
                var response = await ProtoService.GetUserPhotosAsync(User.ToInputUser(), 0, 0, 0);

                if (response.IsSucceeded)
                {
                    if (response.Result is TLPhotosPhotosSlice slice)
                    {
                        TotalItems = slice.Count;
                    }
                    else
                    {
                        TotalItems = response.Result.Photos.Count;
                    }

                    Items.ReplaceWith(response.Result.Photos.OfType <TLPhoto>().Select(x => new GalleryPhotoItem(x, user)));

                    SelectedItem = Items.FirstOrDefault();
                    FirstItem    = Items.FirstOrDefault();
                }
            }
        }
Пример #5
0
        private async void UnblockExecute(TLUser user)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = "Unblock";
            dialog.Message             = "You sure?";
            dialog.PrimaryButtonText   = "Yes";
            dialog.SecondaryButtonText = "No";

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UnblockAsync(user.ToInputUser());

                if (response.IsSucceeded)
                {
                    Items.Remove(user);
                }
            }
        }
Пример #6
0
        private async void UnblockExecute(TLUser user)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Android.AppName;
            dialog.Message             = Strings.Android.AreYouSureUnblockContact;
            dialog.PrimaryButtonText   = Strings.Android.OK;
            dialog.SecondaryButtonText = Strings.Android.Cancel;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UnblockAsync(user.ToInputUser());

                if (response.IsSucceeded)
                {
                    Items.Remove(user);
                }
            }
        }
Пример #7
0
        private async void Initialize(TLUser user, long maxId)
        {
            using (await _loadMoreLock.WaitAsync())
            {
                var response = await ProtoService.GetUserPhotosAsync(user.ToInputUser(), 0, maxId, 0);

                if (response.IsSucceeded)
                {
                    if (response.Result is TLPhotosPhotosSlice slice)
                    {
                        TotalItems = slice.Count;
                    }
                    else
                    {
                        TotalItems = response.Result.Photos.Count;
                    }

                    foreach (var item in response.Result.Photos.Where(x => x.Id < maxId))
                    {
                        Items.Add(new GalleryPhotoItem(item as TLPhoto, user));
                    }
                }
            }
        }
Пример #8
0
        public void Notify(TLMessageCommonBase messageCommon)
        {
            //if (this._stateService.SuppressNotifications)
            //{
            //    return;
            //}
            if (messageCommon.IsOut)
            {
                return;
            }

            if (!messageCommon.IsUnread)
            {
                return;
            }

            if (messageCommon is TLMessage message && message.IsSilent)
            {
                return;
            }

            TLUser from = null;

            if (messageCommon.FromId != null && messageCommon.FromId.Value >= 0)
            {
                from = CacheService.GetUser(messageCommon.FromId) as TLUser;
                if (from == null)
                {
                    return;
                }
            }

            try
            {
                TLObject   activeDialog = CheckActiveDialog();
                TLPeerBase toId         = messageCommon.ToId;
                var        fromId       = messageCommon.FromId;
                var        suppress     = false;
                TLDialog   dialog       = null;
                if (toId is TLPeerChat && activeDialog is TLChat && toId.Id == ((TLChat)activeDialog).Id)
                {
                    suppress = true;
                }
                if (toId is TLPeerChannel && activeDialog is TLChannel && toId.Id == ((TLChannel)activeDialog).Id)
                {
                    suppress = true;
                }
                else if (toId is TLPeerUser && activeDialog is TLUserBase && ((from != null && from.IsSelf) || fromId.Value == ((TLUserBase)activeDialog).Id))
                {
                    suppress = true;
                }

                if (!suppress)
                {
                    TLChatBase chat    = null;
                    TLUser     user    = null;
                    TLChannel  channel = null;
                    if (messageCommon.ToId is TLPeerChat)
                    {
                        chat   = CacheService.GetChat(messageCommon.ToId.Id);
                        dialog = CacheService.GetDialog(new TLPeerChat
                        {
                            Id = messageCommon.ToId.Id
                        });
                    }
                    else if (messageCommon.ToId is TLPeerChannel)
                    {
                        chat    = CacheService.GetChat(messageCommon.ToId.Id);
                        channel = (chat as TLChannel);
                        dialog  = CacheService.GetDialog(new TLPeerChannel {
                            ChannelId = messageCommon.ToId.Id
                        });
                    }
                    else if (messageCommon.IsOut)
                    {
                        user   = CacheService.GetUser(messageCommon.ToId.Id) as TLUser;
                        dialog = CacheService.GetDialog(new TLPeerUser {
                            UserId = messageCommon.ToId.Id
                        });
                    }
                    else
                    {
                        user   = CacheService.GetUser(messageCommon.FromId) as TLUser;
                        dialog = CacheService.GetDialog(new TLPeerUser {
                            UserId = messageCommon.FromId.Value
                        });
                    }

                    var now = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now);
                    if (chat != null)
                    {
                        var notifySettingsBase = CacheService.GetFullChat(chat.Id)?.NotifySettings;
                        if (notifySettingsBase == null)
                        {
                            notifySettingsBase = ((dialog != null) ? dialog.NotifySettings : null);
                        }

                        if (notifySettingsBase == null)
                        {
                            if (channel != null)
                            {
                                ProtoService.GetFullChannelAsync(channel.ToInputChannel(), chatFull =>
                                {
                                    //chat.NotifySettings = chatFull.FullChat.NotifySettings;
                                    if (dialog != null)
                                    {
                                        dialog.NotifySettings = chatFull.FullChat.NotifySettings;

                                        Execute.BeginOnUIThread(() =>
                                        {
                                            dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                            dialog.RaisePropertyChanged(() => dialog.Self);
                                        });
                                    }
                                }, null);
                            }
                            else
                            {
                                ProtoService.GetFullChatAsync(chat.Id, chatFull =>
                                {
                                    //chat.NotifySettings = chatFull.FullChat.NotifySettings;
                                    if (dialog != null)
                                    {
                                        dialog.NotifySettings = chatFull.FullChat.NotifySettings;

                                        Execute.BeginOnUIThread(() =>
                                        {
                                            dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                            dialog.RaisePropertyChanged(() => dialog.Self);
                                        });
                                    }
                                }, null);
                            }
                        }

                        var notifySettings = notifySettingsBase as TLPeerNotifySettings;
                        suppress = (notifySettings == null || notifySettings.MuteUntil > now);
                    }

                    if (user != null)
                    {
                        var notifySettingsBase = CacheService.GetFullUser(user.Id)?.NotifySettings;
                        if (notifySettingsBase == null)
                        {
                            notifySettingsBase = ((dialog != null) ? dialog.NotifySettings : null);
                        }

                        if (notifySettingsBase == null)
                        {
                            ProtoService.GetFullUserAsync(user.ToInputUser(), userFull =>
                            {
                                //user.NotifySettings = userFull.NotifySettings;
                                if (dialog != null)
                                {
                                    dialog.NotifySettings = userFull.NotifySettings;

                                    Execute.BeginOnUIThread(() =>
                                    {
                                        dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                        dialog.RaisePropertyChanged(() => dialog.Self);
                                    });
                                }
                            }, null);
                        }

                        var notifySettings = notifySettingsBase as TLPeerNotifySettings;
                        suppress = (notifySettings == null || notifySettings.MuteUntil > now || user.IsSelf);
                    }

                    if (!suppress)
                    {
                        if (dialog != null)
                        {
                            suppress = CheckLastNotificationTime(dialog, now);
                        }

                        if (!suppress)
                        {
                            if (ApplicationSettings.Current.InAppPreview)
                            {
                                // TODO
                            }

                            if (_lastNotificationTime.HasValue)
                            {
                                var totalSeconds = (DateTime.Now - _lastNotificationTime.Value).TotalSeconds;
                                if (totalSeconds > 0.0 && totalSeconds < 2.0)
                                {
                                    suppress = true;
                                }
                            }

                            _lastNotificationTime = DateTime.Now;

                            if (suppress)
                            {
                                Log.Write(string.Format("Cancel notification reason=[lastNotificationTime] msg_id={0} last_notification_time={1}, now={2}", messageCommon.Id, _lastNotificationTime, DateTime.Now), null);
                            }
                            else
                            {
                                if (ApplicationSettings.Current.InAppVibrate)
                                {
                                    _vibrationService.VibrateAsync();
                                }

                                if (ApplicationSettings.Current.InAppSounds)
                                {
                                    //if (_notificationPlayer == null)
                                    //{
                                    //    _notificationPlayer = new MediaPlayer();
                                    //    _notificationPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Sounds/Default.wav"));
                                    //}

                                    //_notificationPlayer.Pause();
                                    //_notificationPlayer.PlaybackSession.Position = TimeSpan.Zero;
                                    //_notificationPlayer.Play();



                                    //string text = "Sounds/Default.wav";
                                    //if (toId is TLPeerChat && !string.IsNullOrEmpty(s.GroupSound))
                                    //{
                                    //    text = "Sounds/" + s.GroupSound + ".wav";
                                    //}
                                    //else if (!string.IsNullOrEmpty(s.ContactSound))
                                    //{
                                    //    text = "Sounds/" + s.ContactSound + ".wav";
                                    //}
                                    //if (toId is TLPeerChat && chat != null && chat.NotifySettings is TLPeerNotifySettings)
                                    //{
                                    //    text = "Sounds/" + ((TLPeerNotifySettings)chat.NotifySettings).Sound.Value + ".wav";
                                    //}
                                    //else if (toId is TLPeerUser && user != null && user.NotifySettings is TLPeerNotifySettings)
                                    //{
                                    //    text = "Sounds/" + ((TLPeerNotifySettings)user.NotifySettings).Sound.Value + ".wav";
                                    //}
                                    //if (!Utils.XapContentFileExists(text))
                                    //{
                                    //    text = "Sounds/Default.wav";
                                    //}
                                    //System.IO.Stream stream = TitleContainer.OpenStream(text);
                                    //SoundEffect soundEffect = SoundEffect.FromStream(stream);
                                    //FrameworkDispatcher.Update();
                                    //soundEffect.Play();
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                TLUtils.WriteLine(ex.ToString(), LogSeverity.Error);
            }
        }