|
|
|
@ -4,711 +4,26 @@
@@ -4,711 +4,26 @@
|
|
|
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
import appImManager from "../../../lib/appManagers/appImManager"; |
|
|
|
|
import appMessagesManager, { AppMessagesManager, MyMessage } from "../../../lib/appManagers/appMessagesManager"; |
|
|
|
|
import appPeersManager from "../../../lib/appManagers/appPeersManager"; |
|
|
|
|
import appProfileManager from "../../../lib/appManagers/appProfileManager"; |
|
|
|
|
import appUsersManager, { User } from "../../../lib/appManagers/appUsersManager"; |
|
|
|
|
import { RichTextProcessor } from "../../../lib/richtextprocessor"; |
|
|
|
|
import appMessagesManager from "../../../lib/appManagers/appMessagesManager"; |
|
|
|
|
import appUsersManager from "../../../lib/appManagers/appUsersManager"; |
|
|
|
|
import rootScope from "../../../lib/rootScope"; |
|
|
|
|
import AppSearchSuper, { SearchSuperType } from "../../appSearchSuper."; |
|
|
|
|
import AvatarElement, { openAvatarViewer } from "../../avatar"; |
|
|
|
|
import SidebarSlider, { SliderSuperTab } from "../../slider"; |
|
|
|
|
import CheckboxField from "../../checkboxField"; |
|
|
|
|
import appSidebarRight from ".."; |
|
|
|
|
import { TransitionSlider } from "../../transition"; |
|
|
|
|
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager"; |
|
|
|
|
import AppEditChatTab from "./editChat"; |
|
|
|
|
import PeerTitle from "../../peerTitle"; |
|
|
|
|
import AppEditContactTab from "./editContact"; |
|
|
|
|
import appChatsManager, { Channel } from "../../../lib/appManagers/appChatsManager"; |
|
|
|
|
import { Chat, Message, MessageAction, ChatFull, Photo } from "../../../layer"; |
|
|
|
|
import appChatsManager from "../../../lib/appManagers/appChatsManager"; |
|
|
|
|
import Button from "../../button"; |
|
|
|
|
import ButtonIcon from "../../buttonIcon"; |
|
|
|
|
import I18n, { i18n, LangPackKey } from "../../../lib/langPack"; |
|
|
|
|
import { generateDelimiter, SettingSection } from "../../sidebarLeft"; |
|
|
|
|
import Row from "../../row"; |
|
|
|
|
import { copyTextToClipboard } from "../../../helpers/clipboard"; |
|
|
|
|
import { toast, toastNew } from "../../toast"; |
|
|
|
|
import { fastRaf } from "../../../helpers/schedulers"; |
|
|
|
|
import appPhotosManager from "../../../lib/appManagers/appPhotosManager"; |
|
|
|
|
import renderImageFromUrl from "../../../helpers/dom/renderImageFromUrl"; |
|
|
|
|
import SwipeHandler from "../../swipeHandler"; |
|
|
|
|
import { MOUNT_CLASS_TO } from "../../../config/debug"; |
|
|
|
|
import { i18n, LangPackKey } from "../../../lib/langPack"; |
|
|
|
|
import { toastNew } from "../../toast"; |
|
|
|
|
import AppAddMembersTab from "../../sidebarLeft/tabs/addMembers"; |
|
|
|
|
import PopupPickUser from "../../popups/pickUser"; |
|
|
|
|
import PopupPeer, { PopupPeerButtonCallbackCheckboxes, PopupPeerCheckboxOptions } from "../../popups/peer"; |
|
|
|
|
import Scrollable from "../../scrollable"; |
|
|
|
|
import { IS_TOUCH_SUPPORTED } from "../../../environment/touchSupport"; |
|
|
|
|
import { IS_FIREFOX } from "../../../environment/userAgent"; |
|
|
|
|
import appDownloadManager from "../../../lib/appManagers/appDownloadManager"; |
|
|
|
|
import ButtonCorner from "../../buttonCorner"; |
|
|
|
|
import { cancelEvent } from "../../../helpers/dom/cancelEvent"; |
|
|
|
|
import { attachClickEvent } from "../../../helpers/dom/clickEvent"; |
|
|
|
|
import replaceContent from "../../../helpers/dom/replaceContent"; |
|
|
|
|
import appAvatarsManager from "../../../lib/appManagers/appAvatarsManager"; |
|
|
|
|
import generateVerifiedIcon from "../../generateVerifiedIcon"; |
|
|
|
|
import ListLoader from "../../../helpers/listLoader"; |
|
|
|
|
import { forEachReverse } from "../../../helpers/array"; |
|
|
|
|
|
|
|
|
|
let setText = (text: string, row: Row) => { |
|
|
|
|
//fastRaf(() => {
|
|
|
|
|
row.title.innerHTML = text; |
|
|
|
|
row.container.style.display = ''; |
|
|
|
|
//});
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const PARALLAX_SUPPORTED = !IS_FIREFOX && false; |
|
|
|
|
|
|
|
|
|
export function filterChatPhotosMessages(value: { |
|
|
|
|
count: number; |
|
|
|
|
next_rate: number; |
|
|
|
|
offset_id_offset: number; |
|
|
|
|
history: MyMessage[]; |
|
|
|
|
}) { |
|
|
|
|
forEachReverse(value.history, (message, idx, arr) => { |
|
|
|
|
if(!((message as Message.messageService).action as MessageAction.messageActionChatEditPhoto).photo) { |
|
|
|
|
arr.splice(idx, 1); |
|
|
|
|
if(value.count !== undefined) { |
|
|
|
|
--value.count; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class PeerProfileAvatars { |
|
|
|
|
private static BASE_CLASS = 'profile-avatars'; |
|
|
|
|
private static SCALE = PARALLAX_SUPPORTED ? 2 : 1; |
|
|
|
|
private static TRANSLATE_TEMPLATE = PARALLAX_SUPPORTED ? `translate3d({x}, 0, -1px) scale(${PeerProfileAvatars.SCALE})` : 'translate({x}, 0)'; |
|
|
|
|
public container: HTMLElement; |
|
|
|
|
public avatars: HTMLElement; |
|
|
|
|
public gradient: HTMLElement; |
|
|
|
|
public info: HTMLElement; |
|
|
|
|
public arrowPrevious: HTMLElement; |
|
|
|
|
public arrowNext: HTMLElement; |
|
|
|
|
private tabs: HTMLDivElement; |
|
|
|
|
private listLoader: ListLoader<string | Message.messageService>; |
|
|
|
|
private peerId: number; |
|
|
|
|
|
|
|
|
|
constructor(public scrollable: Scrollable) { |
|
|
|
|
this.container = document.createElement('div'); |
|
|
|
|
this.container.classList.add(PeerProfileAvatars.BASE_CLASS + '-container'); |
|
|
|
|
|
|
|
|
|
this.avatars = document.createElement('div'); |
|
|
|
|
this.avatars.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatars'); |
|
|
|
|
|
|
|
|
|
this.gradient = document.createElement('div'); |
|
|
|
|
this.gradient.classList.add(PeerProfileAvatars.BASE_CLASS + '-gradient'); |
|
|
|
|
|
|
|
|
|
this.info = document.createElement('div'); |
|
|
|
|
this.info.classList.add(PeerProfileAvatars.BASE_CLASS + '-info'); |
|
|
|
|
|
|
|
|
|
this.tabs = document.createElement('div'); |
|
|
|
|
this.tabs.classList.add(PeerProfileAvatars.BASE_CLASS + '-tabs'); |
|
|
|
|
|
|
|
|
|
this.arrowPrevious = document.createElement('div'); |
|
|
|
|
this.arrowPrevious.classList.add(PeerProfileAvatars.BASE_CLASS + '-arrow'); |
|
|
|
|
|
|
|
|
|
/* const previousIcon = document.createElement('i'); |
|
|
|
|
previousIcon.classList.add(PeerProfileAvatars.BASE_CLASS + '-arrow-icon', 'tgico-previous'); |
|
|
|
|
this.arrowBack.append(previousIcon); */ |
|
|
|
|
|
|
|
|
|
this.arrowNext = document.createElement('div'); |
|
|
|
|
this.arrowNext.classList.add(PeerProfileAvatars.BASE_CLASS + '-arrow', PeerProfileAvatars.BASE_CLASS + '-arrow-next'); |
|
|
|
|
|
|
|
|
|
/* const nextIcon = document.createElement('i'); |
|
|
|
|
nextIcon.classList.add(PeerProfileAvatars.BASE_CLASS + '-arrow-icon', 'tgico-next'); |
|
|
|
|
this.arrowNext.append(nextIcon); */ |
|
|
|
|
|
|
|
|
|
this.container.append(this.avatars, this.gradient, this.info, this.tabs, this.arrowPrevious, this.arrowNext); |
|
|
|
|
|
|
|
|
|
const checkScrollTop = () => { |
|
|
|
|
if(this.scrollable.scrollTop !== 0) { |
|
|
|
|
this.scrollable.scrollIntoViewNew(this.scrollable.container.firstElementChild as HTMLElement, 'start'); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const SWITCH_ZONE = 1 / 3; |
|
|
|
|
let cancel = false; |
|
|
|
|
let freeze = false; |
|
|
|
|
attachClickEvent(this.container, async(_e) => { |
|
|
|
|
if(freeze) { |
|
|
|
|
cancelEvent(_e); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(cancel) { |
|
|
|
|
cancel = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!checkScrollTop()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const rect = this.container.getBoundingClientRect(); |
|
|
|
|
|
|
|
|
|
// const e = (_e as TouchEvent).touches ? (_e as TouchEvent).touches[0] : _e as MouseEvent;
|
|
|
|
|
const e = _e; |
|
|
|
|
const x = e.pageX; |
|
|
|
|
|
|
|
|
|
const clickX = x - rect.left; |
|
|
|
|
if((!this.listLoader.previous.length && !this.listLoader.next.length) |
|
|
|
|
|| (clickX > (rect.width * SWITCH_ZONE) && clickX < (rect.width - rect.width * SWITCH_ZONE))) { |
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
|
|
|
|
|
const targets: {element: HTMLElement, item: string | Message.messageService}[] = []; |
|
|
|
|
this.listLoader.previous.concat(this.listLoader.current, this.listLoader.next).forEach((item, idx) => { |
|
|
|
|
targets.push({ |
|
|
|
|
element: /* null */this.avatars.children[idx] as HTMLElement, |
|
|
|
|
item |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const prevTargets = targets.slice(0, this.listLoader.previous.length); |
|
|
|
|
const nextTargets = targets.slice(this.listLoader.previous.length + 1); |
|
|
|
|
|
|
|
|
|
const target = this.avatars.children[this.listLoader.previous.length] as HTMLElement; |
|
|
|
|
freeze = true; |
|
|
|
|
openAvatarViewer(target, peerId, () => peerId === this.peerId, this.listLoader.current, prevTargets, nextTargets); |
|
|
|
|
freeze = false; |
|
|
|
|
} else { |
|
|
|
|
const centerX = rect.right - (rect.width / 2); |
|
|
|
|
const toRight = x > centerX; |
|
|
|
|
|
|
|
|
|
// this.avatars.classList.remove('no-transition');
|
|
|
|
|
// fastRaf(() => {
|
|
|
|
|
this.avatars.classList.add('no-transition'); |
|
|
|
|
void this.avatars.offsetLeft; // reflow
|
|
|
|
|
|
|
|
|
|
let distance: number; |
|
|
|
|
if(this.listLoader.index === 0 && !toRight) distance = this.listLoader.count - 1; |
|
|
|
|
else if(this.listLoader.index === (this.listLoader.count - 1) && toRight) distance = -(this.listLoader.count - 1); |
|
|
|
|
else distance = toRight ? 1 : -1; |
|
|
|
|
this.listLoader.go(distance); |
|
|
|
|
|
|
|
|
|
fastRaf(() => { |
|
|
|
|
this.avatars.classList.remove('no-transition'); |
|
|
|
|
}); |
|
|
|
|
// });
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const cancelNextClick = () => { |
|
|
|
|
cancel = true; |
|
|
|
|
document.body.addEventListener(IS_TOUCH_SUPPORTED ? 'touchend' : 'click', (e) => { |
|
|
|
|
cancel = false; |
|
|
|
|
}, {once: true}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let width = 0, x = 0, lastDiffX = 0, lastIndex = 0, minX = 0; |
|
|
|
|
const swipeHandler = new SwipeHandler({ |
|
|
|
|
element: this.avatars, |
|
|
|
|
onSwipe: (xDiff, yDiff) => { |
|
|
|
|
lastDiffX = xDiff; |
|
|
|
|
let lastX = x + xDiff * -PeerProfileAvatars.SCALE; |
|
|
|
|
if(lastX > 0) lastX = 0; |
|
|
|
|
else if(lastX < minX) lastX = minX; |
|
|
|
|
|
|
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', lastX + 'px'); |
|
|
|
|
//console.log(xDiff, yDiff);
|
|
|
|
|
return false; |
|
|
|
|
}, |
|
|
|
|
verifyTouchTarget: (e) => { |
|
|
|
|
if(!checkScrollTop()) { |
|
|
|
|
cancelNextClick(); |
|
|
|
|
cancelEvent(e); |
|
|
|
|
return false; |
|
|
|
|
} else if(this.container.classList.contains('is-single') || freeze) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
onFirstSwipe: () => { |
|
|
|
|
const rect = this.avatars.getBoundingClientRect(); |
|
|
|
|
width = rect.width; |
|
|
|
|
minX = -width * (this.tabs.childElementCount - 1); |
|
|
|
|
|
|
|
|
|
/* lastIndex = whichChild(this.tabs.querySelector('.active')); |
|
|
|
|
x = -width * lastIndex; */ |
|
|
|
|
x = rect.left - this.container.getBoundingClientRect().left; |
|
|
|
|
|
|
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', x + 'px'); |
|
|
|
|
|
|
|
|
|
this.container.classList.add('is-swiping'); |
|
|
|
|
this.avatars.classList.add('no-transition'); |
|
|
|
|
void this.avatars.offsetLeft; // reflow
|
|
|
|
|
}, |
|
|
|
|
onReset: () => { |
|
|
|
|
const addIndex = Math.ceil(Math.abs(lastDiffX) / (width / PeerProfileAvatars.SCALE)) * (lastDiffX >= 0 ? 1 : -1); |
|
|
|
|
cancelNextClick(); |
|
|
|
|
|
|
|
|
|
//console.log(addIndex);
|
|
|
|
|
|
|
|
|
|
this.avatars.classList.remove('no-transition'); |
|
|
|
|
fastRaf(() => { |
|
|
|
|
this.listLoader.go(addIndex); |
|
|
|
|
this.container.classList.remove('is-swiping'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public setPeer(peerId: number) { |
|
|
|
|
this.peerId = peerId; |
|
|
|
|
|
|
|
|
|
const photo = appPeersManager.getPeerPhoto(peerId); |
|
|
|
|
if(!photo) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const listLoader: PeerProfileAvatars['listLoader'] = this.listLoader = new ListLoader<string | Message.messageService>({ |
|
|
|
|
loadCount: 50, |
|
|
|
|
loadMore: (anchor, older, loadCount) => { |
|
|
|
|
if(!older) return Promise.resolve({count: undefined, items: []}); |
|
|
|
|
|
|
|
|
|
if(peerId > 0) { |
|
|
|
|
const maxId: string = (anchor || listLoader.current) as any; |
|
|
|
|
return appPhotosManager.getUserPhotos(peerId, maxId, loadCount).then(value => { |
|
|
|
|
return { |
|
|
|
|
count: value.count, |
|
|
|
|
items: value.photos |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
const promises: [Promise<ChatFull>, ReturnType<AppMessagesManager['getSearch']>] = [] as any; |
|
|
|
|
if(!listLoader.current) { |
|
|
|
|
promises.push(appProfileManager.getChatFull(-peerId)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
promises.push(appMessagesManager.getSearch({ |
|
|
|
|
peerId, |
|
|
|
|
maxId: Number.MAX_SAFE_INTEGER, |
|
|
|
|
inputFilter: { |
|
|
|
|
_: 'inputMessagesFilterChatPhotos' |
|
|
|
|
}, |
|
|
|
|
limit: loadCount, |
|
|
|
|
backLimit: 0 |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
return Promise.all(promises).then((result) => { |
|
|
|
|
const value = result.pop() as typeof result[1]; |
|
|
|
|
|
|
|
|
|
filterChatPhotosMessages(value); |
|
|
|
|
|
|
|
|
|
if(!listLoader.current) { |
|
|
|
|
const chatFull = result[0]; |
|
|
|
|
const message = value.history.findAndSplice(m => { |
|
|
|
|
return ((m as Message.messageService).action as MessageAction.messageActionChannelEditPhoto).photo.id === chatFull.chat_photo.id; |
|
|
|
|
}) as Message.messageService; |
|
|
|
|
|
|
|
|
|
listLoader.current = message || appMessagesManager.generateFakeAvatarMessage(this.peerId, chatFull.chat_photo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//console.log('avatars loaded:', value);
|
|
|
|
|
return { |
|
|
|
|
count: value.count, |
|
|
|
|
items: value.history |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
processItem: this.processItem, |
|
|
|
|
onJump: (item, older) => { |
|
|
|
|
const id = this.listLoader.index; |
|
|
|
|
//const nextId = Math.max(0, id);
|
|
|
|
|
const x = 100 * PeerProfileAvatars.SCALE * id; |
|
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', `-${x}%`); |
|
|
|
|
|
|
|
|
|
const activeTab = this.tabs.querySelector('.active'); |
|
|
|
|
if(activeTab) activeTab.classList.remove('active'); |
|
|
|
|
|
|
|
|
|
const tab = this.tabs.children[id] as HTMLElement; |
|
|
|
|
tab.classList.add('active'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if(photo._ === 'userProfilePhoto') { |
|
|
|
|
listLoader.current = photo.photo_id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.processItem(listLoader.current); |
|
|
|
|
|
|
|
|
|
// listLoader.loaded
|
|
|
|
|
listLoader.load(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public addTab() { |
|
|
|
|
const tab = document.createElement('div'); |
|
|
|
|
tab.classList.add(PeerProfileAvatars.BASE_CLASS + '-tab'); |
|
|
|
|
this.tabs.append(tab); |
|
|
|
|
|
|
|
|
|
if(this.tabs.childElementCount === 1) { |
|
|
|
|
tab.classList.add('active'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.container.classList.toggle('is-single', this.tabs.childElementCount <= 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public processItem = (photoId: string | Message.messageService) => { |
|
|
|
|
const avatar = document.createElement('div'); |
|
|
|
|
avatar.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatar'); |
|
|
|
|
|
|
|
|
|
let photo: Photo.photo; |
|
|
|
|
if(photoId) { |
|
|
|
|
photo = typeof(photoId) === 'string' ? |
|
|
|
|
appPhotosManager.getPhoto(photoId) : |
|
|
|
|
(photoId.action as MessageAction.messageActionChannelEditPhoto).photo as Photo.photo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const img = new Image(); |
|
|
|
|
img.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatar-image'); |
|
|
|
|
img.draggable = false; |
|
|
|
|
|
|
|
|
|
if(photo) { |
|
|
|
|
const size = appPhotosManager.choosePhotoSize(photo, 420, 420, false); |
|
|
|
|
appPhotosManager.preloadPhoto(photo, size).then(() => { |
|
|
|
|
const cacheContext = appDownloadManager.getCacheContext(photo, size.type); |
|
|
|
|
renderImageFromUrl(img, cacheContext.url, () => { |
|
|
|
|
avatar.append(img); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
const photo = appPeersManager.getPeerPhoto(this.peerId); |
|
|
|
|
appAvatarsManager.putAvatar(avatar, this.peerId, photo, 'photo_big', img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.avatars.append(avatar); |
|
|
|
|
|
|
|
|
|
this.addTab(); |
|
|
|
|
|
|
|
|
|
return photoId; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class PeerProfile { |
|
|
|
|
public element: HTMLElement; |
|
|
|
|
public avatars: PeerProfileAvatars; |
|
|
|
|
private avatar: AvatarElement; |
|
|
|
|
private section: SettingSection; |
|
|
|
|
private name: HTMLDivElement; |
|
|
|
|
private subtitle: HTMLDivElement; |
|
|
|
|
private bio: Row; |
|
|
|
|
private username: Row; |
|
|
|
|
private phone: Row; |
|
|
|
|
private notifications: Row; |
|
|
|
|
|
|
|
|
|
private cleaned: boolean; |
|
|
|
|
private setBioTimeout: number; |
|
|
|
|
private setPeerStatusInterval: number; |
|
|
|
|
|
|
|
|
|
private peerId = 0; |
|
|
|
|
private threadId: number; |
|
|
|
|
|
|
|
|
|
constructor(public scrollable: Scrollable) { |
|
|
|
|
if(!PARALLAX_SUPPORTED) { |
|
|
|
|
this.scrollable.container.classList.add('no-parallax'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public init() { |
|
|
|
|
this.init = null; |
|
|
|
|
|
|
|
|
|
this.element = document.createElement('div'); |
|
|
|
|
this.element.classList.add('profile-content'); |
|
|
|
|
|
|
|
|
|
this.section = new SettingSection({ |
|
|
|
|
noDelimiter: true |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.avatar = new AvatarElement(); |
|
|
|
|
this.avatar.classList.add('profile-avatar', 'avatar-120'); |
|
|
|
|
this.avatar.setAttribute('dialog', '1'); |
|
|
|
|
this.avatar.setAttribute('clickable', ''); |
|
|
|
|
|
|
|
|
|
this.name = document.createElement('div'); |
|
|
|
|
this.name.classList.add('profile-name'); |
|
|
|
|
|
|
|
|
|
this.subtitle = document.createElement('div'); |
|
|
|
|
this.subtitle.classList.add('profile-subtitle'); |
|
|
|
|
|
|
|
|
|
this.bio = new Row({ |
|
|
|
|
title: ' ', |
|
|
|
|
subtitleLangKey: 'UserBio', |
|
|
|
|
icon: 'info', |
|
|
|
|
clickable: (e) => { |
|
|
|
|
if((e.target as HTMLElement).tagName === 'A') { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
appProfileManager.getProfileByPeerId(this.peerId).then(full => { |
|
|
|
|
copyTextToClipboard(full.about); |
|
|
|
|
toast(I18n.format('BioCopied', true)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.bio.title.classList.add('pre-wrap'); |
|
|
|
|
|
|
|
|
|
this.username = new Row({ |
|
|
|
|
title: ' ', |
|
|
|
|
subtitleLangKey: 'Username', |
|
|
|
|
icon: 'username', |
|
|
|
|
clickable: () => { |
|
|
|
|
const peer: Channel | User = appPeersManager.getPeer(this.peerId); |
|
|
|
|
copyTextToClipboard('@' + peer.username); |
|
|
|
|
toast(I18n.format('UsernameCopied', true)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.phone = new Row({ |
|
|
|
|
title: ' ', |
|
|
|
|
subtitleLangKey: 'Phone', |
|
|
|
|
icon: 'phone', |
|
|
|
|
clickable: () => { |
|
|
|
|
const peer: User = appUsersManager.getUser(this.peerId); |
|
|
|
|
copyTextToClipboard('+' + peer.phone); |
|
|
|
|
toast(I18n.format('PhoneCopied', true)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.notifications = new Row({ |
|
|
|
|
checkboxField: new CheckboxField({toggle: true}), |
|
|
|
|
titleLangKey: 'Notifications', |
|
|
|
|
icon: 'unmute' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.section.content.append(this.phone.container, this.username.container, this.bio.container, this.notifications.container); |
|
|
|
|
|
|
|
|
|
this.element.append(this.section.container, generateDelimiter()); |
|
|
|
|
|
|
|
|
|
this.notifications.checkboxField.input.addEventListener('change', (e) => { |
|
|
|
|
if(!e.isTrusted) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//let checked = this.notificationsCheckbox.checked;
|
|
|
|
|
appMessagesManager.mutePeer(this.peerId); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialog_notify_settings', (dialog) => { |
|
|
|
|
if(this.peerId === dialog.peerId) { |
|
|
|
|
const muted = appNotificationsManager.isPeerLocalMuted(this.peerId, false); |
|
|
|
|
this.notifications.checkboxField.checked = !muted; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('peer_typings', ({peerId}) => { |
|
|
|
|
if(this.peerId === peerId) { |
|
|
|
|
this.setPeerStatus(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('peer_bio_edit', (peerId) => { |
|
|
|
|
if(peerId === this.peerId) { |
|
|
|
|
this.setBio(true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('user_update', (userId) => { |
|
|
|
|
if(this.peerId === userId) { |
|
|
|
|
this.setPeerStatus(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('contacts_update', (userId) => { |
|
|
|
|
if(this.peerId === userId) { |
|
|
|
|
const user = appUsersManager.getUser(userId); |
|
|
|
|
if(!user.pFlags.self) { |
|
|
|
|
if(user.phone) { |
|
|
|
|
setText(appUsersManager.formatUserPhone(user.phone), this.phone); |
|
|
|
|
} else { |
|
|
|
|
this.phone.container.style.display = 'none'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.setPeerStatusInterval = window.setInterval(this.setPeerStatus, 60e3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public setPeerStatus = (needClear = false) => { |
|
|
|
|
if(!this.peerId) return; |
|
|
|
|
|
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
appImManager.setPeerStatus(this.peerId, this.subtitle, needClear, true, () => peerId === this.peerId); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public cleanupHTML() { |
|
|
|
|
this.bio.container.style.display = 'none'; |
|
|
|
|
this.phone.container.style.display = 'none'; |
|
|
|
|
this.username.container.style.display = 'none'; |
|
|
|
|
this.notifications.container.style.display = ''; |
|
|
|
|
this.notifications.checkboxField.checked = true; |
|
|
|
|
if(this.setBioTimeout) { |
|
|
|
|
window.clearTimeout(this.setBioTimeout); |
|
|
|
|
this.setBioTimeout = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public setAvatar() { |
|
|
|
|
if(this.peerId !== rootScope.myId) { |
|
|
|
|
const photo = appPeersManager.getPeerPhoto(this.peerId); |
|
|
|
|
|
|
|
|
|
if(photo) { |
|
|
|
|
const oldAvatars = this.avatars; |
|
|
|
|
this.avatars = new PeerProfileAvatars(this.scrollable); |
|
|
|
|
this.avatars.setPeer(this.peerId); |
|
|
|
|
this.avatars.info.append(this.name, this.subtitle); |
|
|
|
|
|
|
|
|
|
this.avatar.remove(); |
|
|
|
|
|
|
|
|
|
if(oldAvatars) oldAvatars.container.replaceWith(this.avatars.container); |
|
|
|
|
else this.element.prepend(this.avatars.container); |
|
|
|
|
|
|
|
|
|
if(PARALLAX_SUPPORTED) { |
|
|
|
|
this.scrollable.container.classList.add('parallax'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(PARALLAX_SUPPORTED) { |
|
|
|
|
this.scrollable.container.classList.remove('parallax'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.avatars) { |
|
|
|
|
this.avatars.container.remove(); |
|
|
|
|
this.avatars = undefined; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.avatar.setAttribute('peer', '' + this.peerId); |
|
|
|
|
|
|
|
|
|
this.section.content.prepend(this.avatar, this.name, this.subtitle); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public fillProfileElements() { |
|
|
|
|
if(!this.cleaned) return; |
|
|
|
|
this.cleaned = false; |
|
|
|
|
|
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
|
|
|
|
|
this.cleanupHTML(); |
|
|
|
|
|
|
|
|
|
this.setAvatar(); |
|
|
|
|
|
|
|
|
|
// username
|
|
|
|
|
if(peerId !== rootScope.myId) { |
|
|
|
|
let username = appPeersManager.getPeerUsername(peerId); |
|
|
|
|
if(username) { |
|
|
|
|
setText(appPeersManager.getPeerUsername(peerId), this.username); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const muted = appNotificationsManager.isPeerLocalMuted(peerId, false); |
|
|
|
|
this.notifications.checkboxField.checked = !muted; |
|
|
|
|
} else { |
|
|
|
|
fastRaf(() => { |
|
|
|
|
this.notifications.container.style.display = 'none'; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//let membersLi = this.profileTabs.firstElementChild.children[0] as HTMLLIElement;
|
|
|
|
|
if(peerId > 0) { |
|
|
|
|
//membersLi.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
let user = appUsersManager.getUser(peerId); |
|
|
|
|
if(user.phone && peerId !== rootScope.myId) { |
|
|
|
|
setText(appUsersManager.formatUserPhone(user.phone), this.phone); |
|
|
|
|
} |
|
|
|
|
}/* else { |
|
|
|
|
//membersLi.style.display = appPeersManager.isBroadcast(peerId) ? 'none' : '';
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
this.setBio(); |
|
|
|
|
|
|
|
|
|
replaceContent(this.name, new PeerTitle({ |
|
|
|
|
peerId, |
|
|
|
|
dialog: true, |
|
|
|
|
}).element); |
|
|
|
|
|
|
|
|
|
const peer = appPeersManager.getPeer(peerId); |
|
|
|
|
if(peer?.pFlags?.verified) { |
|
|
|
|
this.name.append(generateVerifiedIcon()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setPeerStatus(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public setBio(override?: true) { |
|
|
|
|
if(this.setBioTimeout) { |
|
|
|
|
window.clearTimeout(this.setBioTimeout); |
|
|
|
|
this.setBioTimeout = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const peerId = this.peerId; |
|
|
|
|
const threadId = this.threadId; |
|
|
|
|
|
|
|
|
|
if(!peerId) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let promise: Promise<boolean>; |
|
|
|
|
if(peerId > 0) { |
|
|
|
|
promise = appProfileManager.getProfile(peerId, override).then(userFull => { |
|
|
|
|
if(this.peerId !== peerId || this.threadId !== threadId) { |
|
|
|
|
//this.log.warn('peer changed');
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(userFull.rAbout && peerId !== rootScope.myId) { |
|
|
|
|
setText(userFull.rAbout, this.bio); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('userFull', userFull);
|
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
promise = appProfileManager.getChatFull(-peerId, override).then((chatFull) => { |
|
|
|
|
if(this.peerId !== peerId || this.threadId !== threadId) { |
|
|
|
|
//this.log.warn('peer changed');
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('chatInfo res 2:', chatFull);
|
|
|
|
|
|
|
|
|
|
if(chatFull.about) { |
|
|
|
|
setText(RichTextProcessor.wrapRichText(chatFull.about), this.bio); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
promise.then((canSetNext) => { |
|
|
|
|
if(canSetNext) { |
|
|
|
|
this.setBioTimeout = window.setTimeout(() => this.setBio(true), 60e3); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public setPeer(peerId: number, threadId = 0) { |
|
|
|
|
if(this.peerId === peerId && this.threadId === peerId) return; |
|
|
|
|
|
|
|
|
|
if(this.init) { |
|
|
|
|
this.init(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.peerId = peerId; |
|
|
|
|
this.threadId = threadId; |
|
|
|
|
|
|
|
|
|
this.cleaned = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
import PeerProfile from "../../peerProfile"; |
|
|
|
|
|
|
|
|
|
// TODO: отредактированное сообщение не изменится
|
|
|
|
|
export default class AppSharedMediaTab extends SliderSuperTab { |
|
|
|
@ -803,16 +118,16 @@ export default class AppSharedMediaTab extends SliderSuperTab {
@@ -803,16 +118,16 @@ export default class AppSharedMediaTab extends SliderSuperTab {
|
|
|
|
|
transition(0); |
|
|
|
|
animatedCloseIcon.classList.remove('state-back'); |
|
|
|
|
} else if(!this.scrollable.isHeavyAnimationInProgress) { |
|
|
|
|
appSidebarRight.onCloseBtnClick(); |
|
|
|
|
this.slider.onCloseBtnClick(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
attachClickEvent(this.editBtn, (e) => { |
|
|
|
|
let tab: AppEditChatTab | AppEditContactTab; |
|
|
|
|
if(this.peerId < 0) { |
|
|
|
|
tab = new AppEditChatTab(appSidebarRight); |
|
|
|
|
tab = new AppEditChatTab(this.slider); |
|
|
|
|
} else { |
|
|
|
|
tab = new AppEditContactTab(appSidebarRight); |
|
|
|
|
tab = new AppEditContactTab(this.slider); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(tab) { |
|
|
|
@ -838,6 +153,21 @@ export default class AppSharedMediaTab extends SliderSuperTab {
@@ -838,6 +153,21 @@ export default class AppSharedMediaTab extends SliderSuperTab {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('history_multiappend', (msgIdsByPeer) => { |
|
|
|
|
for(const peerId in msgIdsByPeer) { |
|
|
|
|
this.renderNewMessages(+peerId, Array.from(msgIdsByPeer[peerId])); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('history_delete', ({peerId, msgs}) => { |
|
|
|
|
this.deleteDeletedMessages(peerId, Array.from(msgs)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Calls when message successfully sent and we have an id
|
|
|
|
|
rootScope.addEventListener('message_sent', ({message}) => { |
|
|
|
|
this.renderNewMessages(message.peerId, [message.mid]); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//this.container.prepend(this.closeBtn.parentElement);
|
|
|
|
|
|
|
|
|
|
this.searchSuper = new AppSearchSuper({ |
|
|
|
@ -1120,4 +450,4 @@ export default class AppSharedMediaTab extends SliderSuperTab {
@@ -1120,4 +450,4 @@ export default class AppSharedMediaTab extends SliderSuperTab {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.AppSharedMediaTab = AppSharedMediaTab); |
|
|
|
|
// MOUNT_CLASS_TO && (MOUNT_CLASS_TO.AppSharedMediaTab = AppSharedMediaTab);
|
|
|
|
|