|
|
@ -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,22 +142,45 @@ 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; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public updateOptions(options: Partial<ArgumentTypes<AvatarElement['updateWithOptions']>[0]>) { |
|
|
|
|
|
|
|
for(let i in options) { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
this[i] = options[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) { |
|
|
|
public updateWithOptions(options: { |
|
|
|
//console.log('avatar changed attribute:', name, oldValue, newValue);
|
|
|
|
peerId: PeerId, |
|
|
|
// вызывается при изменении одного из перечисленных выше атрибутов
|
|
|
|
isDialog?: boolean, |
|
|
|
if(name === 'peer') { |
|
|
|
isBig?: boolean, |
|
|
|
const newPeerId = (newValue || '').toPeerId() || NULL_PEER_ID; |
|
|
|
peerTitle?: string, |
|
|
|
if(this.peerId === newPeerId) { |
|
|
|
lazyLoadQueue?: LazyLoadQueueIntersector, |
|
|
|
|
|
|
|
loadPromises?: Promise<any>[] |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const wasPeerId = this.peerId; |
|
|
|
|
|
|
|
this.updateOptions(options); |
|
|
|
|
|
|
|
const newPeerId = this.peerId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(wasPeerId === newPeerId) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(newPeerId) || newPeerId; |
|
|
|
this.peerId = appPeersManager.getPeerMigratedTo(newPeerId) || newPeerId; |
|
|
|
|
|
|
|
this.dataset.peerId = '' + newPeerId; |
|
|
|
|
|
|
|
|
|
|
|
const wasPeerId = (oldValue || '').toPeerId() || NULL_PEER_ID; |
|
|
|
|
|
|
|
if(wasPeerId) { |
|
|
|
if(wasPeerId) { |
|
|
|
const set = believeMe.get(wasPeerId); |
|
|
|
const set = believeMe.get(wasPeerId); |
|
|
|
if(set) { |
|
|
|
if(set) { |
|
|
@ -188,12 +191,7 @@ export default class AvatarElement extends HTMLElement { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
|
return this.update(); |
|
|
|
} else if(name === 'peer-title') { |
|
|
|
|
|
|
|
this.peerTitle = newValue; |
|
|
|
|
|
|
|
} else if(name === 'dialog') { |
|
|
|
|
|
|
|
this.isDialog = newValue === '1'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private r(onlyThumb = false) { |
|
|
|
private r(onlyThumb = false) { |
|
|
|