Example #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 =>
                        {
                        });
                    }
                }
            }
        }