Esempio n. 1
0
        public void AddRemoveStickerSet(TLStickerSet32 set)
        {
            if (set == null)
            {
                return;
            }

            var messagesStickerSet = _messagesStickerSets.FirstOrDefault(x => x.Set.Id.Value == set.Id.Value);

            if (messagesStickerSet == null)
            {
                return;
            }

            var stickerSetExists = set.Installed && !set.Archived;
            var inputStickerSet  = new TLInputStickerSetId {
                Id = set.Id, AccessHash = set.AccessHash
            };

            if (!stickerSetExists)
            {
                MTProtoService.InstallStickerSetAsync(inputStickerSet, TLBool.False,
                                                      result => Execute.BeginOnUIThread(() =>
                {
                    Items.Remove(set);

                    var archivedStickers = StateService.GetArchivedStickers();

                    var resultArchive = result as TLStickerSetInstallResultArchive;
                    if (resultArchive != null)
                    {
                        Execute.BeginOnUIThread(() => TelegramViewBase.ShowArchivedStickersMessageBox(resultArchive));

                        var allStickers = StateService.GetAllStickers() as TLAllStickers43;
                        if (allStickers != null)
                        {
                            for (var i = 0; i < resultArchive.Sets.Count; i++)
                            {
                                TLUtils.RemoveStickerSet(allStickers, resultArchive.Sets[i]);
                            }

                            StateService.SaveAllStickersAsync(allStickers);
                        }

                        if (archivedStickers != null)
                        {
                            for (var i = resultArchive.MessagesStickerSets.Count - 1; i >= 0; i--)
                            {
                                TLUtils.AddStickerSetCovered(archivedStickers, resultArchive.MessagesStickerSets[i], archivedStickers.SetsCovered, resultArchive.SetsCovered[i]);

                                for (var j = 0; j < _messagesStickerSets.Count; j++)
                                {
                                    if (_messagesStickerSets[j].Set.Id.Value == resultArchive.MessagesStickerSets[i].Set.Id.Value)
                                    {
                                        _messagesStickerSets.RemoveAt(j);
                                        break;
                                    }
                                }

                                _messagesStickerSets.Insert(0, resultArchive.MessagesStickerSets[i]);
                            }
                        }
                    }

                    if (archivedStickers != null)
                    {
                        TLUtils.RemoveStickerSetCovered(archivedStickers, set, archivedStickers.SetsCovered);

                        StateService.SaveArchivedStickersAsync(archivedStickers);
                    }

                    if (resultArchive != null)
                    {
                        UpdateSets(archivedStickers);
                    }
                    else
                    {
                        set.Installed = true;
                        var set76     = set as TLStickerSet76;
                        if (set76 != null)
                        {
                            set76.InstalledDate = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now);
                        }
                        set.NotifyOfPropertyChange(() => set.Installed);

                        set.Archived = false;
                        set.NotifyOfPropertyChange(() => set.Archived);
                    }

                    var shellViewModel = IoC.Get <ShellViewModel>();
                    shellViewModel.Handle(new TLUpdateNewStickerSet {
                        Stickerset = messagesStickerSet
                    });

                    MTProtoService.SetMessageOnTime(2.0, AppResources.NewStickersAdded);
                }),
                                                      error => Execute.BeginOnUIThread(() =>
                {
                    if (error.CodeEquals(ErrorCode.BAD_REQUEST))
                    {
                        if (error.TypeEquals(ErrorType.STICKERSET_INVALID))
                        {
                            MessageBox.Show(AppResources.StickersNotFound, AppResources.Error, MessageBoxButton.OK);
                        }
                        else
                        {
                            Execute.ShowDebugMessage("messages.installStickerSet error " + error);
                        }
                    }
                    else
                    {
                        Execute.ShowDebugMessage("messages.installStickerSet error " + error);
                    }
                }));
            }
            else
            {
                MTProtoService.UninstallStickerSetAsync(inputStickerSet,
                                                        result => Execute.BeginOnUIThread(() =>
                {
                    set.Installed = false;
                    var set76     = set as TLStickerSet76;
                    if (set76 != null)
                    {
                        set76.InstalledDate = null;
                    }
                    set.NotifyOfPropertyChange(() => set.Installed);

                    set.Archived = false;
                    set.NotifyOfPropertyChange(() => set.Archived);

                    var shellViewModel = IoC.Get <ShellViewModel>();
                    shellViewModel.RemoveStickerSet(set, inputStickerSet);

                    var eventAggregator = EventAggregator;
                    eventAggregator.Publish(new UpdateRemoveStickerSetEventArgs(set));

                    MTProtoService.SetMessageOnTime(2.0, AppResources.StickersRemoved);
                }),
                                                        error => Execute.BeginOnUIThread(() =>
                {
                    Execute.ShowDebugMessage("messages.uninstallStickerSet error " + error);
                }));
            }
        }
        public void AddRemoveStickerSet(TLStickerSet32 set)
        {
            if (set == null)
            {
                return;
            }

            //var featuredStickers = _stickers as TLFeaturedStickers;
            if (AttachedStickers == null)
            {
                return;
            }

            var messagesStickerSet = AttachedStickers.MessagesStickerSets.FirstOrDefault(x => x.Set.Id.Value == set.Id.Value);

            if (messagesStickerSet == null)
            {
                return;
            }

            var stickerSetExists = set.Installed;
            var inputStickerSet  = new TLInputStickerSetId {
                Id = set.Id, AccessHash = set.AccessHash
            };

            if (!stickerSetExists)
            {
                IoC.Get <IMTProtoService>().InstallStickerSetAsync(inputStickerSet, TLBool.False,
                                                                   result => Execute.BeginOnUIThread(() =>
                {
                    var resultArchive = result as TLStickerSetInstallResultArchive;
                    if (resultArchive != null)
                    {
                        TelegramViewBase.ShowArchivedStickersMessageBox(resultArchive);
                    }

                    set.Installed = true;
                    var set76     = set as TLStickerSet76;
                    if (set76 != null)
                    {
                        set76.InstalledDate = TLUtils.DateToUniversalTimeTLInt(IoC.Get <IMTProtoService>().ClientTicksDelta, DateTime.Now);
                    }
                    set.NotifyOfPropertyChange(() => set.Installed);

                    var shellViewModel = IoC.Get <ShellViewModel>();
                    shellViewModel.Handle(new TLUpdateNewStickerSet {
                        Stickerset = messagesStickerSet
                    });

                    IoC.Get <IMTProtoService>().SetMessageOnTime(2.0, AppResources.NewStickersAdded);
                }),
                                                                   error => Execute.BeginOnUIThread(() =>
                {
                    if (error.CodeEquals(ErrorCode.BAD_REQUEST))
                    {
                        if (error.TypeEquals(ErrorType.STICKERSET_INVALID))
                        {
                            MessageBox.Show(AppResources.StickersNotFound, AppResources.Error, MessageBoxButton.OK);
                        }
                        else
                        {
                            Execute.ShowDebugMessage("messages.importChatInvite error " + error);
                        }
                    }
                    else
                    {
                        Execute.ShowDebugMessage("messages.importChatInvite error " + error);
                    }
                }));
            }
            else
            {
                IoC.Get <IMTProtoService>().UninstallStickerSetAsync(inputStickerSet,
                                                                     result => Execute.BeginOnUIThread(() =>
                {
                    set.Installed = false;
                    var set76     = set as TLStickerSet76;
                    if (set76 != null)
                    {
                        set76.InstalledDate = null;
                    }
                    set.NotifyOfPropertyChange(() => set.Installed);

                    var shellViewModel = IoC.Get <ShellViewModel>();
                    if (!set.Masks)
                    {
                        shellViewModel.RemoveStickerSet(set, inputStickerSet);
                    }
                    else
                    {
                        shellViewModel.RemoveMaskSet(set, inputStickerSet);
                    }

                    var eventAggregator = IoC.Get <ITelegramEventAggregator>();
                    eventAggregator.Publish(new UpdateRemoveStickerSetEventArgs(set));

                    IoC.Get <IMTProtoService>().SetMessageOnTime(2.0, AppResources.StickersRemoved);
                }),
                                                                     error =>
                                                                     Execute.BeginOnUIThread(
                                                                         () => { Execute.ShowDebugMessage("messages.uninstallStickerSet error " + error); }));
            }
        }