@ -5,7 +5,6 @@
* /
* /
import emoticonsDropdown , { EmoticonsDropdown , EMOTICONSSTICKERGROUP , EmoticonsTab } from ".." ;
import emoticonsDropdown , { EmoticonsDropdown , EMOTICONSSTICKERGROUP , EmoticonsTab } from ".." ;
import findUpAttribute from "../../../helpers/dom/findUpAttribute" ;
import findUpClassName from "../../../helpers/dom/findUpClassName" ;
import findUpClassName from "../../../helpers/dom/findUpClassName" ;
import mediaSizes from "../../../helpers/mediaSizes" ;
import mediaSizes from "../../../helpers/mediaSizes" ;
import { MessagesAllStickers , StickerSet } from "../../../layer" ;
import { MessagesAllStickers , StickerSet } from "../../../layer" ;
@ -22,62 +21,72 @@ import PopupStickers from "../../popups/stickers";
import Scrollable , { ScrollableX } from "../../scrollable" ;
import Scrollable , { ScrollableX } from "../../scrollable" ;
import StickyIntersector from "../../stickyIntersector" ;
import StickyIntersector from "../../stickyIntersector" ;
import { wrapSticker , wrapStickerSetThumb } from "../../wrappers" ;
import { wrapSticker , wrapStickerSetThumb } from "../../wrappers" ;
import ButtonIcon from "../../buttonIcon" ;
import positionElementByIndex from "../../../helpers/dom/positionElementByIndex" ;
import VisibilityIntersector , { OnVisibilityChange } from "../../visibilityIntersector" ;
import findAndSplice from "../../../helpers/array/findAndSplice" ;
export class SuperStickerRenderer {
export class SuperStickerRenderer {
public lazyLoadQueue : LazyLoadQueueRepeat ;
public lazyLoadQueue : LazyLoadQueueRepeat ;
private animatedDivs : Set < HTMLDivElement > = new Set ( ) ;
private animated : Set < HTMLElement > = new Set ( ) ;
constructor (
constructor (
private regularLazyLoadQueue : LazyLoadQueue ,
private regularLazyLoadQueue : LazyLoadQueue ,
private group : string ,
private group : string ,
private managers : AppManagers
private managers : AppManagers ,
private options? : IntersectionObserverInit
) {
) {
this . lazyLoadQueue = new LazyLoadQueueRepeat ( undefined , ( target , visible ) = > {
this . lazyLoadQueue = new LazyLoadQueueRepeat ( undefined , ( { target , visible } ) = > {
if ( ! visible ) {
if ( ! visible ) {
this . processInvisibleDiv ( target as HTMLDivElemen t ) ;
this . processInvisible ( target ) ;
}
}
} ) ;
} , options ) ;
}
}
public clear() {
public clear() {
this . lazyLoadQueue . clear ( ) ;
this . lazyLoadQueue . clear ( ) ;
}
}
public renderSticker ( doc : MyDocument , div? : HTMLDivElement , loadPromises? : Promise < any > [ ] ) {
public renderSticker ( doc : MyDocument , element? : HTMLElement , loadPromises? : Promise < any > [ ] ) {
if ( ! div ) {
if ( ! element ) {
div = document . createElement ( 'div' ) ;
element = document . createElement ( 'div' ) ;
div . classList . add ( 'grid-item' , 'super-sticker' ) ;
element . classList . add ( 'grid-item' , 'super-sticker' ) ;
element . dataset . docId = '' + doc . id ;
if ( doc . animated ) {
if ( doc . animated ) {
this . observeAnimatedDiv ( div ) ;
this . observeAnimated ( element ) ;
}
}
}
}
// * This will wrap only a thumb
// * This will wrap only a thumb
wrapSticker ( {
/* !doc.animated && */ wrapSticker ( {
doc ,
doc ,
div ,
div : element ,
lazyLoadQueue : this.regularLazyLoadQueue ,
lazyLoadQueue : this.regularLazyLoadQueue ,
group : this.group ,
group : this.group ,
onlyThumb : doc.animated ,
onlyThumb : doc.animated ,
loadPromises
loadPromises
} ) ;
} ) ;
return div ;
return element ;
}
}
public observeAnimatedDiv ( div : HTMLDivElement ) {
public observeAnimated ( element : HTMLElement ) {
this . animatedDivs . add ( div ) ;
this . animated . add ( element ) ;
this . lazyLoadQueue . observe ( {
this . lazyLoadQueue . observe ( {
div ,
div : element ,
load : this.processVisibleDiv
load : this.processVisible
} ) ;
} ) ;
}
}
private checkAnimationContainer = ( div : HTMLElement , visible : boolean ) = > {
public unobserveAnimated ( element : HTMLElement ) {
this . animated . delete ( element ) ;
this . lazyLoadQueue . unobserve ( element ) ;
}
private checkAnimationContainer = ( element : HTMLElement , visible : boolean ) = > {
//console.error('checkAnimationContainer', div, visible);
//console.error('checkAnimationContainer', div, visible);
const players = animationIntersector . getAnimations ( div ) ;
const players = animationIntersector . getAnimations ( element ) ;
players . forEach ( ( player ) = > {
players . forEach ( ( player ) = > {
if ( ! visible ) {
if ( ! visible ) {
animationIntersector . checkAnimation ( player , true , true ) ;
animationIntersector . checkAnimation ( player , true , true ) ;
@ -87,8 +96,8 @@ export class SuperStickerRenderer {
} ) ;
} ) ;
} ;
} ;
private processVisibleDiv = async ( div : HTMLElement ) = > {
private processVisible = async ( element : HTMLElement ) = > {
const docId = div . dataset . docId ;
const docId = element . dataset . docId ;
const doc = await this . managers . appDocsManager . getDoc ( docId ) ;
const doc = await this . managers . appDocsManager . getDoc ( docId ) ;
const size = mediaSizes . active . esgSticker . width ;
const size = mediaSizes . active . esgSticker . width ;
@ -97,7 +106,7 @@ export class SuperStickerRenderer {
const promise = wrapSticker ( {
const promise = wrapSticker ( {
doc ,
doc ,
div : div as HTMLDivE lement,
div : e lement,
width : size ,
width : size ,
height : size ,
height : size ,
lazyLoadQueue : null ,
lazyLoadQueue : null ,
@ -109,7 +118,7 @@ export class SuperStickerRenderer {
promise . then ( ( ) = > {
promise . then ( ( ) = > {
//clearTimeout(timeout);
//clearTimeout(timeout);
this . checkAnimationContainer ( div , this . lazyLoadQueue . intersector . isVisible ( div ) ) ;
this . checkAnimationContainer ( element , this . lazyLoadQueue . intersector . isVisible ( element ) ) ;
} ) ;
} ) ;
/ * l e t t i m e o u t = w i n d o w . s e t T i m e o u t ( ( ) = > {
/ * l e t t i m e o u t = w i n d o w . s e t T i m e o u t ( ( ) = > {
@ -119,123 +128,140 @@ export class SuperStickerRenderer {
return promise ;
return promise ;
} ;
} ;
public processInvisibleDiv = async ( div : HTMLElement ) = > {
public processInvisible = async ( element : HTMLElement ) = > {
const docId = div . dataset . docId ;
const docId = element . dataset . docId ;
const doc = await this . managers . appDocsManager . getDoc ( docId ) ;
const doc = await this . managers . appDocsManager . getDoc ( docId ) ;
//console.log('STICKER INvisible:', /* div, */docId);
//console.log('STICKER INvisible:', /* div, */docId);
this . checkAnimationContainer ( div , false ) ;
this . checkAnimationContainer ( element , false ) ;
div . innerHTML = '' ;
element . textContent = '' ;
this . renderSticker ( doc , div as HTMLDivElement ) ;
this . renderSticker ( doc , element as HTMLDivElement ) ;
} ;
} ;
}
}
type StickersTabCategory = {
elements : {
container : HTMLElement ,
title : HTMLElement ,
items : HTMLElement ,
menuTab : HTMLElement ,
menuTabPadding : HTMLElement
} ,
set : StickerSet . stickerSet ,
items : {
document : MyDocument ,
element : HTMLElement
} [ ]
} ;
const RECENT_STICKERS_COUNT = 20 ;
export default class StickersTab implements EmoticonsTab {
export default class StickersTab implements EmoticonsTab {
private content : HTMLElement ;
private content : HTMLElement ;
private stickersDiv : HTMLElement ;
private stickerSets : { [ id : string ] : {
stickers : HTMLElement ,
tab : HTMLElement
} } = { } ;
private recentDiv : HTMLElement ;
private categories : { [ id : string ] : StickersTabCategory } ;
private recentStickers : MyDocument [ ] = [ ] ;
private categoriesMap : Map < HTMLElement , StickersTabCategory > ;
private categoriesIntersector : VisibilityIntersector ;
private scroll : Scrollable ;
private scroll : Scrollable ;
private menu : HTMLElement ;
private menu : HTMLElement ;
private mounted = false ;
private mounted = false ;
private queueCategoryPush : { element : HTMLElement , prepend : boolean } [ ] = [ ] ;
private stickyIntersector : StickyIntersector ;
private stickyIntersector : StickyIntersector ;
private superStickerRenderer : SuperStickerRenderer ;
private superStickerRenderer : SuperStickerRenderer ;
constructor ( private managers : AppManagers ) {
constructor ( private managers : AppManagers ) {
this . categories = { } ;
this . categoriesMap = new Map ( ) ;
}
}
categoryPush ( categoryDiv : HTMLElement , categoryTitle : DocumentFragment | string = '' , promise : Promise < MyDocument [ ] > , prepend? : boolean ) {
private createCategory ( stickerSet : StickerSet.stickerSet , _title : HTMLElement | DocumentFragment ) {
//if((docs.length % 5) !== 0) categoryDiv.classList.add('not-full');
const container = document . createElement ( 'div' ) ;
container . classList . add ( 'emoji-category' , 'hide' ) ;
const itemsDiv = document . createElement ( 'div' ) ;
const items = document . createElement ( 'div' ) ;
itemsDiv . classList . add ( 'category-items' , 'super-stickers' ) ;
items . classList . add ( 'category-items' , 'super-stickers' ) ;
const titleDiv = document . createElement ( 'div' ) ;
const title = document . createElement ( 'div' ) ;
titleDiv . classList . add ( 'category-title' ) ;
title . classList . add ( 'category-title' ) ;
title . append ( _title ) ;
if ( categoryTitle ) {
const menuTab = ButtonIcon ( undefined , { noRipple : true } ) ;
if ( typeof ( categoryTitle ) === 'string' ) titleDiv . innerHTML = categoryTitle ;
menuTab . classList . add ( 'menu-horizontal-div-item' ) ;
else titleDiv . append ( categoryTitle ) ;
}
categoryDiv . append ( titleDiv , itemsDiv ) ;
const menuTabPadding = document . createElement ( 'div' ) ;
menuTabPadding . classList . add ( 'menu-horizontal-div-item-padding' ) ;
this . stickyIntersector . observeStickyHeaderChanges ( categoryDiv ) ;
menuTab . append ( menuTabPadding ) ;
this . queueCategoryPush . push ( { element : categoryDiv , prepend } ) ;
const category : StickersTabCategory = {
elements : {
container ,
title ,
items ,
menuTab ,
menuTabPadding
} ,
set : stickerSet ,
items : [ ]
} ;
promise . then ( ( documents ) = > {
container . append ( title , items ) ;
documents . forEach ( ( doc ) = > {
//if(doc._ === 'documentEmpty') return;
itemsDiv . append ( this . superStickerRenderer . renderSticker ( doc ) ) ;
} ) ;
if ( this . queueCategoryPush . length ) {
this . categories [ stickerSet . id ] = category ;
this . queueCategoryPush . forEach ( ( { element , prepend } ) = > {
this . categoriesMap . set ( container , category ) ;
if ( prepend ) {
if ( this . recentDiv . parentElement ) {
this . categoriesIntersector . observe ( container ) ;
this . stickersDiv . prepend ( element ) ;
this . stickersDiv . prepend ( this . recentDiv ) ;
} else {
this . stickersDiv . prepend ( element ) ;
}
} else this . stickersDiv . append ( element ) ;
} ) ;
this . queueCategoryPush . length = 0 ;
}
} ) ;
return { titleDiv } ;
return category ;
}
}
async renderStickerSet ( set : StickerSet . stickerSet , prepend = false ) {
private categoryPush (
const categoryDiv = document . createElement ( 'div' ) ;
category : StickersTabCategory ,
categoryDiv . classList . add ( 'sticker-category' ) ;
promise : Promise < MyDocument [ ] >
categoryDiv . dataset . id = '' + set . id ;
) {
categoryDiv . dataset . access_hash = '' + set . access_hash ;
const { container , items } = category . elements ;
this . stickyIntersector . observeStickyHeaderChanges ( container ) ;
promise . then ( ( documents ) = > {
documents . forEach ( ( document ) = > {
const element = this . superStickerRenderer . renderSticker ( document ) ;
category . items . push ( { document , element } ) ;
// items.append(element);
} ) ;
const containerWidth = 410 ;
const stickerSize = mediaSizes . active . esgSticker . width ;
const button = document . createElement ( 'button' ) ;
const itemsPerRow = Math . floor ( containerWidth / stickerSize ) ;
button . classList . add ( 'btn-icon' , 'menu-horizontal-div-item' ) ;
const rows = Math . ceil ( documents . length / itemsPerRow ) ;
const height = rows * stickerSize ;
items . style . height = height + 'px' ;
this . stickerSets [ set . id ] = {
container . classList . remove ( 'hide' ) ;
stickers : categoryDiv ,
} ) ;
tab : button
}
} ;
if ( prepend ) {
private async renderStickerSet ( set : StickerSet . stickerSet , prepend = false ) {
this . menu . insertBefore ( button , this . menu . firstElementChild . nextSibling ) ;
const category = this . createCategory ( set , wrapEmojiText ( set . title ) ) ;
} else {
const { menuTab , menuTabPadding , container } = category . elements ;
this . menu . append ( button ) ;
}
//stickersScroll.append(categoryDiv);
positionElementByIndex ( menuTab , this . menu , prepend ? 1 : 0xFFFF ) ;
const promise = this . managers . appStickersManager . getStickerSet ( set ) ;
const promise = this . managers . appStickersManager . getStickerSet ( set ) ;
this . categoryPush ( categoryDiv , wrapEmojiText ( set . title ) , promise . then ( ( stickerSet ) = > stickerSet . documents as MyDocument [ ] ) , prepend ) ;
this . categoryPush (
const stickerSet = await promise ;
category ,
promise . then ( ( stickerSet ) = > stickerSet . documents as MyDocument [ ] )
) ;
// const stickerSet = await promise;
positionElementByIndex ( container , this . scroll . container , prepend ? 1 : 0xFFFF , - 1 ) ;
//console.log('got stickerSet', stickerSet, li);
wrapStickerSetThumb ( {
wrapStickerSetThumb ( {
set ,
set ,
container : button ,
container : menuTabPadding ,
group : EMOTICONSSTICKERGROUP ,
group : EMOTICONSSTICKERGROUP ,
lazyLoadQueue : EmoticonsDropdown.lazyLoadQueue ,
lazyLoadQueue : EmoticonsDropdown.lazyLoadQueue ,
width : 32 ,
width : 32 ,
@ -244,21 +270,18 @@ export default class StickersTab implements EmoticonsTab {
} ) ;
} ) ;
}
}
init() {
public init() {
this . content = document . getElementById ( 'content-stickers' ) ;
this . content = document . getElementById ( 'content-stickers' ) ;
//let stickersDiv = contentStickersDiv.querySelector('.os-content') as HTMLDivElement;
this . recentDiv = document . createElement ( 'div' ) ;
const menuWrapper = this . content . previousElementSibling as HTMLDivElement ;
this . recentDiv . classList . add ( 'sticker-category' , 'stickers-recent' ) ;
let menuWrapper = this . content . previousElementSibling as HTMLDivElement ;
this . menu = menuWrapper . firstElementChild as HTMLUListElement ;
this . menu = menuWrapper . firstElementChild as HTMLUListElement ;
le t menuScroll = new ScrollableX ( menuWrapper ) ;
const menuScroll = new ScrollableX ( menuWrapper ) ;
this . stickersDiv = document . createElement ( 'div' ) ;
this . scroll = new Scrollable ( this . content , 'STICKERS' ) ;
this . stickersDiv . classList . add ( 'stickers-categories' ) ;
this . scroll . onAdditionalScroll = ( ) = > {
this . content . append ( this . stickersDiv ) ;
setTyping ( ) ;
} ;
/ * s t i c k e r s D i v . a d d E v e n t L i s t e n e r ( ' m o u s e o v e r ' , ( e ) = > {
/ * s t i c k e r s D i v . a d d E v e n t L i s t e n e r ( ' m o u s e o v e r ' , ( e ) = > {
let target = e . target as HTMLElement ;
let target = e . target as HTMLElement ;
@ -277,30 +300,43 @@ export default class StickersTab implements EmoticonsTab {
}
}
} ) ; * /
} ) ; * /
rootScope . addEventListener ( 'stickers_installed' , ( e ) = > {
const onCategoryVisibility : OnVisibilityChange = ( { target , visible , entry } ) = > {
const set : StickerSet . stickerSet = e ;
const category = this . categoriesMap . get ( target ) ;
// console.log('roll the windows up', category, target, visible, entry);
if ( ! this . stickerSets [ set . id ] && this . mounted ) {
if ( ! visible ) {
category . elements . items . textContent = '' ;
} else {
category . elements . items . append ( . . . category . items . map ( ( { element } ) = > element ) ) ;
}
} ;
const intersectionOptions : IntersectionObserverInit = { root : emoticonsDropdown.getElement ( ) } ;
this . categoriesIntersector = new VisibilityIntersector ( onCategoryVisibility , intersectionOptions ) ;
rootScope . addEventListener ( 'stickers_installed' , ( set ) = > {
if ( ! this . categories [ set . id ] && this . mounted ) {
this . renderStickerSet ( set , true ) ;
this . renderStickerSet ( set , true ) ;
}
}
} ) ;
} ) ;
rootScope . addEventListener ( 'stickers_deleted' , ( e ) = > {
rootScope . addEventListener ( 'stickers_deleted' , ( { id } ) = > {
const set : StickerSet . stickerSet = e ;
const set = this . categories [ id ] ;
if ( set && this . mounted ) {
if ( this . stickerSets [ set . id ] && this . mounted ) {
set . elements . container . remove ( ) ;
const elements = this . stickerSets [ set . id ] ;
set . elements . menuTab . remove ( ) ;
elements . stickers . remove ( ) ;
this . categoriesIntersector . unobserve ( set . elements . container ) ;
elements . tab . remove ( ) ;
set . items . forEach ( ( { element } ) = > this . superStickerRenderer . unobserveAnimated ( element ) ) ;
delete this . stickerSets [ set . id ] ;
delete this . categories [ id ] ;
this . categoriesMap . delete ( set . elements . container ) ;
}
}
} ) ;
} ) ;
this . stickersDiv . addEventListener ( 'click' , ( e ) = > {
this . scroll . container . addEventListener ( 'click' , ( e ) = > {
const target = e . target as HTMLElement ;
const target = e . target as HTMLElement ;
if ( findUpClassName ( target , 'category-title' ) ) {
if ( findUpClassName ( target , 'category-title' ) ) {
const el = findUpAttribute ( target , 'data-id' ) ;
const container = findUpClassName ( target , 'emoji-category' ) ;
new PopupStickers ( { id : el.dataset.id , access_hash : el.dataset.access_hash } ) . show ( ) ;
const category = this . categoriesMap . get ( container ) ;
new PopupStickers ( { id : category.set.id , access_hash : category.set.access_hash } ) . show ( ) ;
return ;
return ;
}
}
@ -311,12 +347,6 @@ export default class StickersTab implements EmoticonsTab {
rootScope . dispatchEvent ( 'choosing_sticker' , ! cancel ) ;
rootScope . dispatchEvent ( 'choosing_sticker' , ! cancel ) ;
} ;
} ;
this . scroll = new Scrollable ( this . content , 'STICKERS' ) ;
this . scroll . setVirtualContainer ( this . stickersDiv ) ;
this . scroll . onAdditionalScroll = ( ) = > {
setTyping ( ) ;
} ;
emoticonsDropdown . addEventListener ( 'closed' , ( ) = > {
emoticonsDropdown . addEventListener ( 'closed' , ( ) = > {
setTyping ( true ) ;
setTyping ( true ) ;
} ) ;
} ) ;
@ -329,20 +359,19 @@ export default class StickersTab implements EmoticonsTab {
const preloader = putPreloader ( this . content , true ) ;
const preloader = putPreloader ( this . content , true ) ;
const recentCategory = this . createCategory ( { id : 'recent' } as any , i18n ( 'Stickers.Recent' ) ) ;
recentCategory . elements . title . classList . add ( 'disable-hover' ) ;
recentCategory . elements . menuTab . classList . add ( 'tgico-recent' , 'active' ) ;
recentCategory . elements . menuTabPadding . remove ( ) ;
positionElementByIndex ( recentCategory . elements . container , this . scroll . container , 0 ) ;
positionElementByIndex ( recentCategory . elements . menuTab , this . menu , 0 ) ;
Promise . all ( [
Promise . all ( [
this . managers . appStickersManager . getRecentStickers ( ) . then ( ( stickers ) = > {
this . managers . appStickersManager . getRecentStickers ( ) . then ( ( stickers ) = > {
this . recentStickers = stickers . stickers . slice ( 0 , 20 ) as MyDocument [ ] ;
const sliced = stickers . stickers . slice ( 0 , RECENT_STICKERS_COUNT ) as MyDocument [ ] ;
//stickersScroll.prepend(categoryDiv);
this . stickerSets [ 'recent' ] = {
stickers : this.recentDiv ,
tab : this.menu.firstElementChild as HTMLElement
} ;
preloader . remove ( ) ;
preloader . remove ( ) ;
const { titleDiv } = this . categoryPush ( this . recentDiv , '' , Promise . resolve ( this . recentStickers ) , true ) ;
this . categoryPush ( recentCategory , Promise . resolve ( sliced ) ) ;
titleDiv . append ( i18n ( 'Stickers.Recent' ) ) ;
} ) ,
} ) ,
this . managers . appStickersManager . getAllStickers ( ) . then ( ( res ) = > {
this . managers . appStickersManager . getAllStickers ( ) . then ( ( res ) = > {
@ -357,38 +386,61 @@ export default class StickersTab implements EmoticonsTab {
setTyping ( ) ;
setTyping ( ) ;
} ) ;
} ) ;
this . superStickerRenderer = new SuperStickerRenderer ( EmoticonsDropdown . lazyLoadQueue , EMOTICONSSTICKERGROUP , this . managers ) ;
this . superStickerRenderer = new SuperStickerRenderer ( EmoticonsDropdown . lazyLoadQueue , EMOTICONSSTICKERGROUP , this . managers , intersectionOptions ) ;
const rendererLazyLoadQueue = this . superStickerRenderer . lazyLoadQueue ;
emoticonsDropdown . addLazyLoadQueueRepeat ( rendererLazyLoadQueue , this . superStickerRenderer . processInvisible ) ;
// emoticonsDropdown.addEventListener('close', () => {
// this.categoriesIntersector.lock();
// });
emoticonsDropdown . addLazyLoadQueueRepeat ( this . superStickerRenderer . lazyLoadQueue , this . superStickerRenderer . processInvisibleDiv ) ;
// emoticonsDropdown.addEventListener('closed', () => {
// for(const [container] of this.categoriesMap) {
// onCategoryVisibility(container, false);
// }
// });
/ * s e t I n t e r v a l ( ( ) = > {
// emoticonsDropdown.addEventListener('opened', () => {
// @ts-ignore
// this.categoriesIntersector.unlockAndRefresh();
const players = Object . values ( lottieLoader . players ) . filter ( ( p ) = > p . width === 80 ) ;
// });
// setInterval(() => {
// // @ts-ignore
// const players = Object.values(lottieLoader.players).filter((p) => p.width >= 80);
console . log ( 'STICKERS RENDERED IN PANEL:' , players . length , players . filter ( ( p ) = > ! p . paused ) . length , this . superStickerRenderer . lazyLoadQueue . intersector . getVisible ( ) . length ) ;
// console.log(
} , . 25 e3 ) ; * /
// 'STICKERS RENDERED IN PANEL:',
// players.length,
// players.filter((p) => !p.paused).length,
// rendererLazyLoadQueue.intersector.getVisible().length
// );
// }, .25e3);
this . init = null ;
this . init = null ;
}
}
pushRecentSticker ( doc : MyDocument ) {
public pushRecentSticker ( doc : MyDocument ) {
this . managers . appStickersManager . pushRecentSticker ( doc ) ;
this . managers . appStickersManager . pushRecentSticker ( doc . id ) ;
if ( ! this . recentDiv ? . parentElement ) {
const set = this . categories [ 'recent' ] ;
if ( ! set ) {
return ;
return ;
}
}
let div = this . recentDiv . querySelector ( ` [data-doc-id=" ${ doc . id } "] ` ) ;
const items = set . elements . items ;
if ( ! div ) {
let item = findAndSplice ( set . items , ( item ) = > item . document . id === doc . id ) ;
div = this . superStickerRenderer . renderSticker ( doc ) ;
if ( ! item ) {
item = {
element : this.superStickerRenderer.renderSticker ( doc ) ,
document : doc
} ;
}
}
const items = this . recentDiv . querySelector ( '.category-items' ) ;
set . items . unshift ( item ) ;
items . prepend ( div ) ;
if ( items . childElementCount ) items . prepend ( item . element ) ;
if ( items . childElementCount > RECENT_STICKERS_COUNT ) {
if ( items . childElementCount > 20 ) {
( Array . from ( items . children ) as HTMLElement [ ] ) . slice ( RECENT_STICKERS_COUNT ) . forEach ( ( el ) = > el . remove ( ) ) ;
( Array . from ( items . children ) as HTMLElement [ ] ) . slice ( 20 ) . forEach ( ( el ) = > el . remove ( ) ) ;
}
}
}
}