|
|
@ -9,10 +9,10 @@ import appProfileManager from "../lib/appManagers/appProfileManager"; |
|
|
|
import rootScope from "../lib/rootScope"; |
|
|
|
import rootScope from "../lib/rootScope"; |
|
|
|
import { attachClickEvent, cancelEvent } from "../helpers/dom"; |
|
|
|
import { attachClickEvent, cancelEvent } from "../helpers/dom"; |
|
|
|
import AppMediaViewer, { AppMediaViewerAvatar } from "./appMediaViewer"; |
|
|
|
import AppMediaViewer, { AppMediaViewerAvatar } from "./appMediaViewer"; |
|
|
|
import { Message, Photo } from "../layer"; |
|
|
|
import { Message } from "../layer"; |
|
|
|
import appPeersManager from "../lib/appManagers/appPeersManager"; |
|
|
|
import appPeersManager from "../lib/appManagers/appPeersManager"; |
|
|
|
import appPhotosManager from "../lib/appManagers/appPhotosManager"; |
|
|
|
import appPhotosManager from "../lib/appManagers/appPhotosManager"; |
|
|
|
//import type { LazyLoadQueueIntersector } from "./lazyLoadQueue";
|
|
|
|
import type { LazyLoadQueueIntersector } from "./lazyLoadQueue"; |
|
|
|
|
|
|
|
|
|
|
|
const onAvatarUpdate = (peerId: number) => { |
|
|
|
const onAvatarUpdate = (peerId: number) => { |
|
|
|
appProfileManager.removeFromAvatarsCache(peerId); |
|
|
|
appProfileManager.removeFromAvatarsCache(peerId); |
|
|
@ -98,24 +98,22 @@ export async function openAvatarViewer(target: HTMLElement, peerId: number, midd |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const believeMe: Map<number, Set<AvatarElement>> = new Map(); |
|
|
|
|
|
|
|
const seen: Set<number> = new Set(); |
|
|
|
|
|
|
|
|
|
|
|
export default class AvatarElement extends HTMLElement { |
|
|
|
export default class AvatarElement extends HTMLElement { |
|
|
|
private peerId: number; |
|
|
|
private peerId: number; |
|
|
|
private isDialog = false; |
|
|
|
private isDialog = false; |
|
|
|
public peerTitle: string; |
|
|
|
private peerTitle: string; |
|
|
|
public loadPromises: Promise<any>[]; |
|
|
|
public loadPromises: Promise<any>[]; |
|
|
|
//public lazyLoadQueue: LazyLoadQueueIntersector;
|
|
|
|
public lazyLoadQueue: LazyLoadQueueIntersector; |
|
|
|
//private addedToQueue = false;
|
|
|
|
private addedToQueue = false; |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
|
|
|
super(); |
|
|
|
|
|
|
|
// элемент создан
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connectedCallback() { |
|
|
|
connectedCallback() { |
|
|
|
// браузер вызывает этот метод при добавлении элемента в документ
|
|
|
|
// браузер вызывает этот метод при добавлении элемента в документ
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
|
|
|
|
|
|
|
|
this.isDialog = !!this.getAttribute('dialog'); |
|
|
|
this.isDialog = this.getAttribute('dialog') === '1'; |
|
|
|
if(this.getAttribute('clickable') === '') { |
|
|
|
if(this.getAttribute('clickable') === '') { |
|
|
|
this.setAttribute('clickable', 'set'); |
|
|
|
this.setAttribute('clickable', 'set'); |
|
|
|
let loading = false; |
|
|
|
let loading = false; |
|
|
@ -131,13 +129,21 @@ export default class AvatarElement extends HTMLElement { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* disconnectedCallback() { |
|
|
|
disconnectedCallback() { |
|
|
|
// браузер вызывает этот метод при удалении элемента из документа
|
|
|
|
// браузер вызывает этот метод при удалении элемента из документа
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
|
|
|
|
const set = believeMe.get(this.peerId); |
|
|
|
|
|
|
|
if(set && set.has(this)) { |
|
|
|
|
|
|
|
set.delete(this); |
|
|
|
|
|
|
|
if(!set.size) { |
|
|
|
|
|
|
|
believeMe.delete(this.peerId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(this.lazyLoadQueue) { |
|
|
|
if(this.lazyLoadQueue) { |
|
|
|
this.lazyLoadQueue.unobserve(this); |
|
|
|
this.lazyLoadQueue.unobserve(this); |
|
|
|
} |
|
|
|
} |
|
|
|
} */ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static get observedAttributes(): string[] { |
|
|
|
static get observedAttributes(): string[] { |
|
|
|
return ['peer', 'dialog', 'peer-title'/* массив имён атрибутов для отслеживания их изменений */]; |
|
|
|
return ['peer', 'dialog', 'peer-title'/* массив имён атрибутов для отслеживания их изменений */]; |
|
|
@ -152,36 +158,88 @@ export default class AvatarElement extends HTMLElement { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(+newValue) || +newValue; |
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(+newValue) || +newValue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const wasPeerId = +oldValue; |
|
|
|
|
|
|
|
if(wasPeerId) { |
|
|
|
|
|
|
|
const set = believeMe.get(wasPeerId); |
|
|
|
|
|
|
|
if(set) { |
|
|
|
|
|
|
|
set.delete(this); |
|
|
|
|
|
|
|
if(!set.size) { |
|
|
|
|
|
|
|
believeMe.delete(wasPeerId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
|
this.update(); |
|
|
|
} else if(name === 'peer-title') { |
|
|
|
} else if(name === 'peer-title') { |
|
|
|
this.peerTitle = newValue; |
|
|
|
this.peerTitle = newValue; |
|
|
|
} else if(name === 'dialog') { |
|
|
|
} else if(name === 'dialog') { |
|
|
|
this.isDialog = !!+newValue; |
|
|
|
this.isDialog = newValue === '1'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public update() { |
|
|
|
public update() { |
|
|
|
/* if(this.lazyLoadQueue) { |
|
|
|
if(this.lazyLoadQueue) { |
|
|
|
if(this.addedToQueue) return; |
|
|
|
if(!seen.has(this.peerId)) { |
|
|
|
this.lazyLoadQueue.push({ |
|
|
|
if(this.addedToQueue) return; |
|
|
|
div: this, |
|
|
|
this.addedToQueue = true; |
|
|
|
load: () => { |
|
|
|
|
|
|
|
return appProfileManager.putPhoto(this, this.peerId, this.isDialog, this.peerTitle).finally(() => { |
|
|
|
let set = believeMe.get(this.peerId); |
|
|
|
this.addedToQueue = false; |
|
|
|
if(!set) { |
|
|
|
}); |
|
|
|
set = new Set(); |
|
|
|
|
|
|
|
believeMe.set(this.peerId, set); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.addedToQueue = true; |
|
|
|
set.add(this); |
|
|
|
} else { */ |
|
|
|
|
|
|
|
const res = appProfileManager.putPhoto(this, this.peerId, this.isDialog, this.peerTitle); |
|
|
|
this.lazyLoadQueue.push({ |
|
|
|
if(this.loadPromises && res && res.cached) { |
|
|
|
div: this, |
|
|
|
this.loadPromises.push(res.loadPromise); |
|
|
|
load: () => { |
|
|
|
res.loadPromise.finally(() => { |
|
|
|
seen.add(this.peerId); |
|
|
|
this.loadPromises = undefined; |
|
|
|
return this.update(); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else if(this.addedToQueue) { |
|
|
|
|
|
|
|
this.lazyLoadQueue.unobserve(this); |
|
|
|
} |
|
|
|
} |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seen.add(this.peerId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const res = appProfileManager.putPhoto(this, this.peerId, this.isDialog, this.peerTitle); |
|
|
|
|
|
|
|
const promise = res ? res.loadPromise : Promise.resolve(); |
|
|
|
|
|
|
|
if(this.loadPromises) { |
|
|
|
|
|
|
|
if(res && res.cached) { |
|
|
|
|
|
|
|
this.loadPromises.push(promise); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promise.finally(() => { |
|
|
|
|
|
|
|
this.loadPromises = undefined; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.addedToQueue) { |
|
|
|
|
|
|
|
promise.finally(() => { |
|
|
|
|
|
|
|
this.addedToQueue = false; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const set = believeMe.get(this.peerId); |
|
|
|
|
|
|
|
if(set) { |
|
|
|
|
|
|
|
set.delete(this); |
|
|
|
|
|
|
|
const arr = Array.from(set); |
|
|
|
|
|
|
|
believeMe.delete(this.peerId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(let i = 0, length = arr.length; i < length; ++i) { |
|
|
|
|
|
|
|
arr[i].update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return promise; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
customElements.define("avatar-element", AvatarElement); |
|
|
|
customElements.define('avatar-element', AvatarElement); |
|
|
|