private void UpdateAllStickersAsync(TLAllStickers cachedStickers) { var hash = cachedStickers != null ? cachedStickers.Hash : TLString.Empty; IsWorking = true; MTProtoService.GetAllStickersAsync(hash, result => BeginOnUIThread(() => { Execute.ShowDebugMessage(result.ToString()); Status = string.Empty; IsWorking = false; var allStickers = result as TLAllStickers43; if (allStickers != null) { Items.Clear(); var cachedStickers29 = cachedStickers as TLAllStickers29; if (cachedStickers29 != null) { allStickers.ShowStickersTab = cachedStickers29.ShowStickersTab; allStickers.RecentlyUsed = cachedStickers29.RecentlyUsed; allStickers.Date = TLUtils.DateToUniversalTimeTLInt(0, DateTime.Now); } var cachedStickers43 = cachedStickers as TLAllStickers43; if (cachedStickers43 != null) { allStickers.RecentStickers = cachedStickers43.RecentStickers; allStickers.FavedStickers = cachedStickers43.FavedStickers; } cachedStickers = allStickers; StateService.SaveAllStickersAsync(cachedStickers); UpdateSets(allStickers, () => { }); } }), error => BeginOnUIThread(() => { Status = string.Empty; IsWorking = false; Execute.ShowDebugMessage("messages.getAllStickers error " + error); })); }
private void UpdateAllStickersAsync() { BeginOnThreadPool(() => { StateService.GetAllStickersAsync(cachedStickers => { IsWorking = true; MTProtoService.GetAllStickersAsync(TLString.Empty, result => Execute.BeginOnUIThread(() => { Status = string.Empty; IsWorking = false; Items.Clear(); var allStickers = result as TLAllStickers29; if (allStickers != null) { var cachedStickers29 = cachedStickers as TLAllStickers29; if (cachedStickers29 != null) { allStickers.IsDefaultSetVisible = cachedStickers29.IsDefaultSetVisible; allStickers.RecentlyUsed = cachedStickers29.RecentlyUsed; allStickers.Date = TLUtils.DateToUniversalTimeTLInt(0, DateTime.Now); } cachedStickers = allStickers; StateService.SaveAllStickersAsync(cachedStickers); _emoticons.Clear(); _stickerSets.Clear(); for (var i = 0; i < allStickers.Packs.Count; i++) { var emoticon = allStickers.Packs[i].Emoticon.ToString(); foreach (var document in allStickers.Packs[i].Documents) { _emoticons[document.Value] = emoticon; } } for (var i = 0; i < allStickers.Documents.Count; i++) { var document22 = allStickers.Documents[i] as TLDocument22; if (document22 != null) { string emoticon; if (_emoticons.TryGetValue(document22.Id.Value, out emoticon)) { document22.Emoticon = emoticon; } if (document22.StickerSet != null) { var setId = document22.StickerSet.Name; TLVector <TLObject> stickers; if (_stickerSets.TryGetValue(setId, out stickers)) { stickers.Add(new TLStickerItem { Document = document22 }); } else { _stickerSets[setId] = new TLVector <TLObject> { new TLStickerItem { Document = document22 } }; } } } } var firstChunkSize = 10; var count = 0; var delayedItems = new List <TLStickerSetBase>(); for (var i = 0; i < allStickers.Sets.Count; i++) { var set = allStickers.Sets[i]; var setName = set.Id.ToString(); TLVector <TLObject> stickers; if (_stickerSets.TryGetValue(setName, out stickers)) { set.Stickers = stickers; if (set.Stickers.Count > 0) { if (count < firstChunkSize) { Items.Add(set); count++; } else { delayedItems.Add(set); } } } } BeginOnUIThread(TimeSpan.FromSeconds(0.5), () => { foreach (var set in delayedItems) { Items.Add(set); } }); } }), error => BeginOnUIThread(() => { Status = string.Empty; IsWorking = false; Execute.ShowDebugMessage("messages.getAllStickers error " + error); })); }); }); }
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); }); }); }