|
|
@ -4,6 +4,7 @@ import appMessagesManager from "../../lib/appManagers/appMessagesManager"; |
|
|
|
import appPeersManager from "../../lib/appManagers/appPeersManager"; |
|
|
|
import appPeersManager from "../../lib/appManagers/appPeersManager"; |
|
|
|
import rootScope from "../../lib/rootScope"; |
|
|
|
import rootScope from "../../lib/rootScope"; |
|
|
|
import { ripple } from "../ripple"; |
|
|
|
import { ripple } from "../ripple"; |
|
|
|
|
|
|
|
import AvatarElement from "../avatar"; |
|
|
|
|
|
|
|
|
|
|
|
const TAG_NAME = 'replies-element'; |
|
|
|
const TAG_NAME = 'replies-element'; |
|
|
|
|
|
|
|
|
|
|
@ -18,6 +19,7 @@ rootScope.on('replies_updated', (e) => { |
|
|
|
export default class RepliesElement extends HTMLElement { |
|
|
|
export default class RepliesElement extends HTMLElement { |
|
|
|
public message: Message.message; |
|
|
|
public message: Message.message; |
|
|
|
public type: 'footer' | 'beside'; |
|
|
|
public type: 'footer' | 'beside'; |
|
|
|
|
|
|
|
public loadPromises: Promise<any>[]; |
|
|
|
|
|
|
|
|
|
|
|
private updated = false; |
|
|
|
private updated = false; |
|
|
|
|
|
|
|
|
|
|
@ -25,7 +27,7 @@ export default class RepliesElement extends HTMLElement { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connectedCallback() { |
|
|
|
public init() { |
|
|
|
this.render(); |
|
|
|
this.render(); |
|
|
|
this.dataset.postKey = this.message.peerId + '_' + this.message.mid; |
|
|
|
this.dataset.postKey = this.message.peerId + '_' + this.message.mid; |
|
|
|
this.classList.add('replies', 'replies-' + this.type); |
|
|
|
this.classList.add('replies', 'replies-' + this.type); |
|
|
@ -34,17 +36,62 @@ export default class RepliesElement extends HTMLElement { |
|
|
|
public render() { |
|
|
|
public render() { |
|
|
|
const replies = this.message.replies; |
|
|
|
const replies = this.message.replies; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if(this.firstChild) { |
|
|
|
|
|
|
|
this.innerHTML = ''; |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
if(this.type === 'footer') { |
|
|
|
if(this.type === 'footer') { |
|
|
|
let leftHTML = ''; |
|
|
|
let leftPart: HTMLElement; |
|
|
|
|
|
|
|
if(this.firstElementChild) { |
|
|
|
|
|
|
|
leftPart = this.firstElementChild as HTMLElement; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(replies?.recent_repliers) { |
|
|
|
if(replies?.recent_repliers) { |
|
|
|
leftHTML += '<div class="replies-footer-avatars">' |
|
|
|
if(leftPart && !leftPart.classList.contains('replies-footer-avatars')) { |
|
|
|
let l: string[] = []; |
|
|
|
leftPart.remove(); |
|
|
|
replies.recent_repliers/* .slice().reverse() */.forEach((peer) => { |
|
|
|
leftPart = null; |
|
|
|
l.push(`<avatar-element class="avatar-34" dialog="0" peer="${appPeersManager.getPeerId(peer)}"></avatar-element>`); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!leftPart) { |
|
|
|
|
|
|
|
leftPart = document.createElement('div'); |
|
|
|
|
|
|
|
leftPart.classList.add('replies-footer-avatars'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
replies.recent_repliers.slice().reverse().forEach((peer, idx) => { |
|
|
|
|
|
|
|
let avatarElem = leftPart.children[idx] as AvatarElement; |
|
|
|
|
|
|
|
if(!avatarElem) { |
|
|
|
|
|
|
|
avatarElem = new AvatarElement(); |
|
|
|
|
|
|
|
avatarElem.setAttribute('dialog', '0'); |
|
|
|
|
|
|
|
avatarElem.classList.add('avatar-34'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.loadPromises) { |
|
|
|
|
|
|
|
avatarElem.loadPromises = this.loadPromises; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avatarElem.setAttribute('peer', '' + appPeersManager.getPeerId(peer)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!avatarElem.parentNode) { |
|
|
|
|
|
|
|
leftPart.append(avatarElem); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
leftHTML += l.reverse().join('') + '</div>'; |
|
|
|
|
|
|
|
|
|
|
|
// if were 3 and became 2
|
|
|
|
|
|
|
|
(Array.from(leftPart.children) as HTMLElement[]).slice(replies.recent_repliers.length).forEach(el => el.remove()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
leftHTML = '<span class="tgico-comments"></span>'; |
|
|
|
if(leftPart && !leftPart.classList.contains('tgico-comments')) { |
|
|
|
|
|
|
|
leftPart.remove(); |
|
|
|
|
|
|
|
leftPart = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!leftPart) { |
|
|
|
|
|
|
|
leftPart = document.createElement('span'); |
|
|
|
|
|
|
|
leftPart.classList.add('tgico-comments'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!leftPart.parentElement) { |
|
|
|
|
|
|
|
this.append(leftPart); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let text: string; |
|
|
|
let text: string; |
|
|
@ -63,11 +110,21 @@ export default class RepliesElement extends HTMLElement { |
|
|
|
this.classList.toggle('is-unread', replies.read_max_id < replies.max_id && (!historyStorage.readMaxId || historyStorage.readMaxId < replies.max_id)); |
|
|
|
this.classList.toggle('is-unread', replies.read_max_id < replies.max_id && (!historyStorage.readMaxId || historyStorage.readMaxId < replies.max_id)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.innerHTML = `${leftHTML}<span class="replies-footer-text">${text}</span><span class="tgico-next"></span>`; |
|
|
|
let textSpan = this.children[1] as HTMLElement; |
|
|
|
|
|
|
|
if(!textSpan) { |
|
|
|
|
|
|
|
textSpan = document.createElement('span'); |
|
|
|
|
|
|
|
textSpan.classList.add('replies-footer-text'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const iconSpan = document.createElement('span'); |
|
|
|
|
|
|
|
iconSpan.classList.add('tgico-next'); |
|
|
|
|
|
|
|
|
|
|
|
const rippleContainer = document.createElement('div'); |
|
|
|
const rippleContainer = document.createElement('div'); |
|
|
|
this.append(rippleContainer); |
|
|
|
|
|
|
|
ripple(rippleContainer); |
|
|
|
ripple(rippleContainer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.append(textSpan, iconSpan, rippleContainer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textSpan.innerHTML = text; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.classList.add('bubble-beside-button'); |
|
|
|
this.classList.add('bubble-beside-button'); |
|
|
|
this.innerHTML = `<span class="tgico-commentssticker"></span><span class="replies-beside-text">${replies?.replies ? formatNumber(replies.replies, 0) : ''}</span>`; |
|
|
|
this.innerHTML = `<span class="tgico-commentssticker"></span><span class="replies-beside-text">${replies?.replies ? formatNumber(replies.replies, 0) : ''}</span>`; |
|
|
@ -78,6 +135,10 @@ export default class RepliesElement extends HTMLElement { |
|
|
|
appMessagesManager.updateMessage(this.message.peerId, this.message.mid, 'replies_updated'); |
|
|
|
appMessagesManager.updateMessage(this.message.peerId, this.message.mid, 'replies_updated'); |
|
|
|
this.updated = true; |
|
|
|
this.updated = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.loadPromises) { |
|
|
|
|
|
|
|
this.loadPromises = undefined; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|