Пример #1
0
        public void AddToFavedStickers(TLMessageBase messageBase)
        {
            if (messageBase == null)
            {
                return;
            }

            var message = messageBase as TLMessage;

            if (message == null || !message.IsSticker())
            {
                return;
            }

            var mediaDocument = message.Media as TLMessageMediaDocument;

            if (mediaDocument == null)
            {
                return;
            }

            var document = mediaDocument.Document as TLDocument22;

            if (document != null)
            {
                var allStickers = StateService.GetAllStickers() as TLAllStickers43;
                if (allStickers != null)
                {
                    var favedStickers = allStickers.FavedStickers;
                    if (favedStickers != null)
                    {
                        var unfave = favedStickers.Documents.FirstOrDefault(x => x.Index == document.Index) != null;

                        MTProtoService.FaveStickerAsync(new TLInputDocument {
                            Id = document.Id, AccessHash = document.AccessHash
                        }, new TLBool(unfave),
                                                        result => Execute.BeginOnUIThread(() =>
                        {
                            if (unfave)
                            {
                                favedStickers.RemoveSticker(document);
                            }
                            else
                            {
                                favedStickers.AddSticker(document);
                            }

                            allStickers.FavedStickers = favedStickers;
                            StateService.SaveAllStickersAsync(allStickers);

                            EmojiControl emojiControl;
                            if (unfave)
                            {
                                MTProtoService.GetFavedStickersAsync(allStickers.FavedStickers.Hash,
                                                                     result2 =>
                                {
                                    var favedStickers2 = result2 as TLFavedStickers;
                                    if (favedStickers2 != null)
                                    {
                                        allStickers.FavedStickers = favedStickers;
                                        StateService.SaveAllStickersAsync(allStickers);

                                        Execute.BeginOnUIThread(() =>
                                        {
                                            if (EmojiControl.TryGetInstance(out emojiControl))
                                            {
                                                emojiControl.ResetFavedStickers();
                                            }
                                        });
                                    }
                                },
                                                                     error2 =>
                                {
                                });
                            }

                            if (EmojiControl.TryGetInstance(out emojiControl))
                            {
                                emojiControl.ResetFavedStickers();
                            }
                        }),
                                                        error =>
                        {
                        });
                    }
                }
            }
        }
Пример #2
0
        public void GetAllStickersAsync()
        {
            StateService.GetAllStickersAsync(cachedStickers =>
            {
                Stickers = cachedStickers;

                var cachedStickers43 = cachedStickers as TLAllStickers43;
                if (cachedStickers43 != null &&
                    cachedStickers43.FavedStickers == null)
                {
                    MTProtoService.GetFavedStickersAsync(new TLInt(0),
                                                         result =>
                    {
                        var favedStickers = result as TLFavedStickers;
                        if (favedStickers != null)
                        {
                            cachedStickers43.FavedStickers = favedStickers;
                            StateService.SaveAllStickersAsync(cachedStickers43);
                        }
                    },
                                                         error =>
                    {
                    });
                }

                var featuredStickers = StateService.GetFeaturedStickers();
                if (featuredStickers == null)
                {
                    MTProtoService.GetFeaturedStickersAsync(true, new TLInt(0),
                                                            result =>
                    {
                        featuredStickers = result as TLFeaturedStickers;
                        if (featuredStickers != null)
                        {
                            StateService.SaveFeaturedStickersAsync(featuredStickers);
                        }
                    },
                                                            error =>
                    {
                    });
                }

                var cachedStickers29 = cachedStickers as TLAllStickers29;
                if (cachedStickers29 != null &&
                    cachedStickers29.Date != null &&
                    cachedStickers29.Date.Value != 0)
                {
                    var date = TLUtils.ToDateTime(cachedStickers29.Date);
                    if (
                        date < DateTime.Now.AddSeconds(Constants.GetAllStickersInterval))
                    {
                        return;
                    }
                }

                var hash = cachedStickers != null ? cachedStickers.Hash ?? TLString.Empty : TLString.Empty;

                MTProtoService.GetAllStickersAsync(hash,
                                                   result =>
                {
                    var allStickers = result as TLAllStickers43;
                    if (allStickers != null)
                    {
                        if (cachedStickers29 != null)
                        {
                            allStickers.ShowStickersTab = cachedStickers29.ShowStickersTab;
                            allStickers.RecentlyUsed    = cachedStickers29.RecentlyUsed;
                            allStickers.Date            = TLUtils.DateToUniversalTimeTLInt(0, DateTime.Now);
                        }
                        if (cachedStickers43 != null)
                        {
                            allStickers.RecentStickers = cachedStickers43.RecentStickers;
                            allStickers.FavedStickers  = cachedStickers43.FavedStickers;
                        }
                        Stickers       = allStickers;
                        cachedStickers = allStickers;
                        StateService.SaveAllStickersAsync(cachedStickers);
                    }
                },
                                                   error =>
                {
                    Execute.ShowDebugMessage("messages.getAllStickers error " + error);
                });
            });
        }