Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

import { MOUNT_CLASS_TO } from "../config/debug";
import appPeersManager from "../lib/appManagers/appPeersManager";
import rootScope from "../lib/rootScope";
export type PeerTitleOptions = {
peerId: number,
plainText?: boolean,
onlyFirstName?: boolean,
dialog?: boolean
};
const weakMap: WeakMap<HTMLElement, PeerTitle> = new WeakMap();
MOUNT_CLASS_TO.peerTitleWeakMap = weakMap;
rootScope.on('peer_title_edit', (peerId) => {
const elements = Array.from(document.querySelectorAll(`.peer-title[data-peer-id="${peerId}"]`)) as HTMLElement[];
elements.forEach(element => {
const peerTitle = weakMap.get(element);
//console.log('in the summer silence i was doing nothing', peerTitle, peerId);
if(peerTitle) {
peerTitle.update();
}
});
});
export default class PeerTitle {
public element: HTMLElement;
public peerId: number;
public plainText = false;
public onlyFirstName = false;
public dialog = false;
constructor(options: PeerTitleOptions) {
this.element = document.createElement('span');
this.element.classList.add('peer-title');
this.update(options);
weakMap.set(this.element, this);
}
public update(options?: PeerTitleOptions) {
if(options) {
for(let i in options) {
// @ts-ignore
this.element.dataset[i] = options[i] ? '' + (typeof(options[i]) === 'boolean' ? +options[i] : options[i]) : '0';
// @ts-ignore
this[i] = options[i];
}
}
if(this.peerId !== rootScope.myId || !this.dialog) {
this.element.innerHTML = appPeersManager.getPeerTitle(this.peerId, this.plainText, this.onlyFirstName);
} else {
this.element.innerHTML = this.onlyFirstName ? 'Saved' : 'Saved Messages';
}
}
}