|
|
@ -16,12 +16,12 @@ import { cancelEvent } from "../helpers/dom/cancelEvent"; |
|
|
|
import appAvatarsManager from "../lib/appManagers/appAvatarsManager"; |
|
|
|
import appAvatarsManager from "../lib/appManagers/appAvatarsManager"; |
|
|
|
import AppMediaViewer from "./appMediaViewer"; |
|
|
|
import AppMediaViewer from "./appMediaViewer"; |
|
|
|
import AppMediaViewerAvatar from "./appMediaViewerAvatar"; |
|
|
|
import AppMediaViewerAvatar from "./appMediaViewerAvatar"; |
|
|
|
import { NULL_PEER_ID } from "../lib/mtproto/mtproto_config"; |
|
|
|
|
|
|
|
import isObject from "../helpers/object/isObject"; |
|
|
|
import isObject from "../helpers/object/isObject"; |
|
|
|
|
|
|
|
import { ArgumentTypes } from "../types"; |
|
|
|
|
|
|
|
|
|
|
|
const onAvatarUpdate = (peerId: PeerId) => { |
|
|
|
const onAvatarUpdate = (peerId: PeerId) => { |
|
|
|
appAvatarsManager.removeFromAvatarsCache(peerId); |
|
|
|
appAvatarsManager.removeFromAvatarsCache(peerId); |
|
|
|
(Array.from(document.querySelectorAll('avatar-element[peer="' + peerId + '"]')) as AvatarElement[]).forEach(elem => { |
|
|
|
(Array.from(document.querySelectorAll('avatar-element[data-peer-id="' + peerId + '"]')) as AvatarElement[]).forEach(elem => { |
|
|
|
//console.log('updating avatar:', elem);
|
|
|
|
//console.log('updating avatar:', elem);
|
|
|
|
elem.update(); |
|
|
|
elem.update(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -118,34 +118,14 @@ const believeMe: Map<PeerId, Set<AvatarElement>> = new Map(); |
|
|
|
const seen: Set<PeerId> = new Set(); |
|
|
|
const seen: Set<PeerId> = new Set(); |
|
|
|
|
|
|
|
|
|
|
|
export default class AvatarElement extends HTMLElement { |
|
|
|
export default class AvatarElement extends HTMLElement { |
|
|
|
private peerId: PeerId; |
|
|
|
public peerId: PeerId; |
|
|
|
private isDialog: boolean; |
|
|
|
public isDialog: boolean; |
|
|
|
private peerTitle: string; |
|
|
|
public peerTitle: string; |
|
|
|
public loadPromises: Promise<any>[]; |
|
|
|
public loadPromises: Promise<any>[]; |
|
|
|
public lazyLoadQueue: LazyLoadQueueIntersector; |
|
|
|
public lazyLoadQueue: LazyLoadQueueIntersector; |
|
|
|
public isBig: boolean; |
|
|
|
public isBig: boolean; |
|
|
|
private addedToQueue = false; |
|
|
|
private addedToQueue = false; |
|
|
|
|
|
|
|
|
|
|
|
connectedCallback() { |
|
|
|
|
|
|
|
// браузер вызывает этот метод при добавлении элемента в документ
|
|
|
|
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.isDialog = this.getAttribute('dialog') === '1'; |
|
|
|
|
|
|
|
if(this.getAttribute('clickable') === '') { |
|
|
|
|
|
|
|
this.setAttribute('clickable', 'set'); |
|
|
|
|
|
|
|
let loading = false; |
|
|
|
|
|
|
|
attachClickEvent(this, async(e) => { |
|
|
|
|
|
|
|
cancelEvent(e); |
|
|
|
|
|
|
|
if(loading) return; |
|
|
|
|
|
|
|
//console.log('avatar clicked');
|
|
|
|
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
|
|
|
loading = true; |
|
|
|
|
|
|
|
await openAvatarViewer(this, this.peerId, () => this.peerId === peerId); |
|
|
|
|
|
|
|
loading = false; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
disconnectedCallback() { |
|
|
|
disconnectedCallback() { |
|
|
|
// браузер вызывает этот метод при удалении элемента из документа
|
|
|
|
// браузер вызывает этот метод при удалении элемента из документа
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
|
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
|
|
|
@ -162,38 +142,56 @@ export default class AvatarElement extends HTMLElement { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static get observedAttributes(): string[] { |
|
|
|
public attachClickEvent() { |
|
|
|
return ['peer', 'dialog', 'peer-title'/* массив имён атрибутов для отслеживания их изменений */]; |
|
|
|
let loading = false; |
|
|
|
|
|
|
|
attachClickEvent(this, async(e) => { |
|
|
|
|
|
|
|
cancelEvent(e); |
|
|
|
|
|
|
|
if(loading) return; |
|
|
|
|
|
|
|
//console.log('avatar clicked');
|
|
|
|
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
|
|
|
loading = true; |
|
|
|
|
|
|
|
await openAvatarViewer(this, this.peerId, () => this.peerId === peerId); |
|
|
|
|
|
|
|
loading = false; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) { |
|
|
|
public updateOptions(options: Partial<ArgumentTypes<AvatarElement['updateWithOptions']>[0]>) { |
|
|
|
//console.log('avatar changed attribute:', name, oldValue, newValue);
|
|
|
|
for(let i in options) { |
|
|
|
// вызывается при изменении одного из перечисленных выше атрибутов
|
|
|
|
// @ts-ignore
|
|
|
|
if(name === 'peer') { |
|
|
|
this[i] = options[i]; |
|
|
|
const newPeerId = (newValue || '').toPeerId() || NULL_PEER_ID; |
|
|
|
} |
|
|
|
if(this.peerId === newPeerId) { |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
public updateWithOptions(options: { |
|
|
|
|
|
|
|
peerId: PeerId, |
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(newPeerId) || newPeerId; |
|
|
|
isDialog?: boolean, |
|
|
|
|
|
|
|
isBig?: boolean, |
|
|
|
const wasPeerId = (oldValue || '').toPeerId() || NULL_PEER_ID; |
|
|
|
peerTitle?: string, |
|
|
|
if(wasPeerId) { |
|
|
|
lazyLoadQueue?: LazyLoadQueueIntersector, |
|
|
|
const set = believeMe.get(wasPeerId); |
|
|
|
loadPromises?: Promise<any>[] |
|
|
|
if(set) { |
|
|
|
}) { |
|
|
|
set.delete(this); |
|
|
|
const wasPeerId = this.peerId; |
|
|
|
if(!set.size) { |
|
|
|
this.updateOptions(options); |
|
|
|
believeMe.delete(wasPeerId); |
|
|
|
const newPeerId = this.peerId; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(wasPeerId === newPeerId) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(newPeerId) || newPeerId; |
|
|
|
|
|
|
|
this.dataset.peerId = '' + newPeerId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(wasPeerId) { |
|
|
|
|
|
|
|
const set = believeMe.get(wasPeerId); |
|
|
|
|
|
|
|
if(set) { |
|
|
|
|
|
|
|
set.delete(this); |
|
|
|
|
|
|
|
if(!set.size) { |
|
|
|
|
|
|
|
believeMe.delete(wasPeerId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
|
|
|
|
|
} else if(name === 'peer-title') { |
|
|
|
|
|
|
|
this.peerTitle = newValue; |
|
|
|
|
|
|
|
} else if(name === 'dialog') { |
|
|
|
|
|
|
|
this.isDialog = newValue === '1'; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private r(onlyThumb = false) { |
|
|
|
private r(onlyThumb = false) { |
|
|
|