2021-04-08 17:52:31 +04:00
|
|
|
/*
|
|
|
|
* https://github.com/morethanwords/tweb
|
|
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
2020-10-07 16:57:33 +03:00
|
|
|
import appImManager from "../../../lib/appManagers/appImManager";
|
2021-04-13 20:19:52 +04:00
|
|
|
import appMessagesManager, { AppMessagesManager } from "../../../lib/appManagers/appMessagesManager";
|
2020-10-07 16:57:33 +03:00
|
|
|
import appPeersManager from "../../../lib/appManagers/appPeersManager";
|
|
|
|
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
2021-03-28 22:37:11 +04:00
|
|
|
import appUsersManager, { User } from "../../../lib/appManagers/appUsersManager";
|
2020-10-07 16:57:33 +03:00
|
|
|
import { RichTextProcessor } from "../../../lib/richtextprocessor";
|
2020-11-15 05:33:47 +02:00
|
|
|
import rootScope from "../../../lib/rootScope";
|
2020-12-25 14:53:20 +02:00
|
|
|
import AppSearchSuper, { SearchSuperType } from "../../appSearchSuper.";
|
2021-04-13 20:19:52 +04:00
|
|
|
import AvatarElement, { openAvatarViewer } from "../../avatar";
|
2021-04-06 19:06:42 +04:00
|
|
|
import SidebarSlider, { SliderSuperTab } from "../../slider";
|
2021-03-09 02:15:44 +04:00
|
|
|
import CheckboxField from "../../checkboxField";
|
2021-04-13 20:19:52 +04:00
|
|
|
import { attachClickEvent, replaceContent, cancelEvent } from "../../../helpers/dom";
|
2021-02-15 19:49:58 +04:00
|
|
|
import appSidebarRight from "..";
|
|
|
|
import { TransitionSlider } from "../../transition";
|
2021-03-11 07:06:44 +04:00
|
|
|
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
|
2021-05-05 14:50:32 +04:00
|
|
|
import AppEditChatTab from "./editChat";
|
2021-03-13 06:22:42 +04:00
|
|
|
import PeerTitle from "../../peerTitle";
|
2021-03-13 07:03:59 +04:00
|
|
|
import AppEditContactTab from "./editContact";
|
2021-03-28 22:37:11 +04:00
|
|
|
import appChatsManager, { Channel } from "../../../lib/appManagers/appChatsManager";
|
2021-04-13 20:19:52 +04:00
|
|
|
import { Chat, Message, MessageAction, ChatFull, Photo } from "../../../layer";
|
2021-03-28 22:37:11 +04:00
|
|
|
import Button from "../../button";
|
|
|
|
import ButtonIcon from "../../buttonIcon";
|
2021-04-10 17:52:21 +04:00
|
|
|
import I18n, { i18n, LangPackKey } from "../../../lib/langPack";
|
2021-03-28 22:37:11 +04:00
|
|
|
import { SettingSection } from "../../sidebarLeft";
|
|
|
|
import Row from "../../row";
|
|
|
|
import { copyTextToClipboard } from "../../../helpers/clipboard";
|
|
|
|
import { toast } from "../../toast";
|
2021-04-06 19:06:42 +04:00
|
|
|
import { fastRaf } from "../../../helpers/schedulers";
|
|
|
|
import { safeAssign } from "../../../helpers/object";
|
|
|
|
import { forEachReverse } from "../../../helpers/array";
|
|
|
|
import appPhotosManager from "../../../lib/appManagers/appPhotosManager";
|
|
|
|
import renderImageFromUrl from "../../../helpers/dom/renderImageFromUrl";
|
2021-04-07 21:11:08 +04:00
|
|
|
import SwipeHandler from "../../swipeHandler";
|
2021-04-09 20:44:43 +04:00
|
|
|
import { MOUNT_CLASS_TO } from "../../../config/debug";
|
2021-04-10 17:52:21 +04:00
|
|
|
import AppAddMembersTab from "../../sidebarLeft/tabs/addMembers";
|
|
|
|
import PopupPickUser from "../../popups/pickUser";
|
|
|
|
import PopupPeer from "../../popups/peer";
|
2021-04-13 20:19:52 +04:00
|
|
|
import Scrollable from "../../scrollable";
|
|
|
|
import { isTouchSupported } from "../../../helpers/touchSupport";
|
2021-04-23 16:44:19 +04:00
|
|
|
import { isFirefox } from "../../../helpers/userAgent";
|
2021-05-01 22:49:32 +04:00
|
|
|
import appDownloadManager from "../../../lib/appManagers/appDownloadManager";
|
2021-05-03 23:17:50 +04:00
|
|
|
import ButtonCorner from "../../buttonCorner";
|
2021-03-28 22:37:11 +04:00
|
|
|
|
|
|
|
let setText = (text: string, row: Row) => {
|
2021-04-18 15:55:56 +04:00
|
|
|
//fastRaf(() => {
|
2021-03-28 22:37:11 +04:00
|
|
|
row.title.innerHTML = text;
|
|
|
|
row.container.style.display = '';
|
2021-04-18 15:55:56 +04:00
|
|
|
//});
|
2020-09-24 02:37:22 +03:00
|
|
|
};
|
|
|
|
|
2021-04-23 16:44:19 +04:00
|
|
|
const PARALLAX_SUPPORTED = !isFirefox;
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
type ListLoaderResult<T> = {count: number, items: any[]};
|
|
|
|
class ListLoader<T> {
|
|
|
|
public current: T;
|
|
|
|
public previous: T[] = [];
|
|
|
|
public next: T[] = [];
|
2021-04-07 11:56:18 +04:00
|
|
|
public count: number;
|
2020-09-24 02:37:22 +03:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public tempId = 0;
|
|
|
|
public loadMore: (anchor: T, older: boolean) => Promise<ListLoaderResult<T>>;
|
|
|
|
public processItem: (item: any) => false | T;
|
2021-04-07 11:56:18 +04:00
|
|
|
public onJump: (item: T, older: boolean) => void;
|
2021-04-06 19:06:42 +04:00
|
|
|
public loadCount = 50;
|
|
|
|
public reverse = false; // reverse means next = higher msgid
|
2020-09-24 02:37:22 +03:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public loadedAllUp = false;
|
|
|
|
public loadedAllDown = false;
|
|
|
|
public loadPromiseUp: Promise<void>;
|
|
|
|
public loadPromiseDown: Promise<void>;
|
2020-12-25 01:19:34 +02:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
constructor(options: {
|
|
|
|
loadMore: ListLoader<T>['loadMore'],
|
|
|
|
loadCount: ListLoader<T>['loadCount'],
|
|
|
|
processItem?: ListLoader<T>['processItem'],
|
2021-04-07 11:56:18 +04:00
|
|
|
onJump: ListLoader<T>['onJump'],
|
2021-04-06 19:06:42 +04:00
|
|
|
}) {
|
|
|
|
safeAssign(this, options);
|
2020-09-24 02:37:22 +03:00
|
|
|
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
}
|
2021-03-13 06:22:42 +04:00
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
get index() {
|
|
|
|
return this.count !== undefined ? this.previous.length : -1;
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public go(length: number) {
|
|
|
|
let items: T[], item: T;
|
|
|
|
if(length > 0) {
|
|
|
|
items = this.next.splice(0, length);
|
|
|
|
item = items.pop();
|
2021-04-07 11:56:18 +04:00
|
|
|
if(!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.previous.push(this.current, ...items);
|
2021-04-06 19:06:42 +04:00
|
|
|
} else {
|
2021-04-07 11:56:18 +04:00
|
|
|
items = this.previous.splice(this.previous.length + length, -length);
|
2021-04-06 19:06:42 +04:00
|
|
|
item = items.shift();
|
2021-04-07 11:56:18 +04:00
|
|
|
if(!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.next.unshift(...items, this.current);
|
2021-04-06 19:06:42 +04:00
|
|
|
}
|
2021-04-07 11:56:18 +04:00
|
|
|
|
|
|
|
this.current = item;
|
|
|
|
this.onJump(item, length > 0);
|
2021-03-28 22:37:11 +04:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public load(older: boolean) {
|
|
|
|
if(older && this.loadedAllDown) return Promise.resolve();
|
|
|
|
else if(!older && this.loadedAllUp) return Promise.resolve();
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(older && this.loadPromiseDown) return this.loadPromiseDown;
|
|
|
|
else if(!older && this.loadPromiseUp) return this.loadPromiseUp;
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
/* const loadCount = 50;
|
|
|
|
const backLimit = older ? 0 : loadCount; */
|
|
|
|
|
|
|
|
let anchor: T;
|
|
|
|
if(older) {
|
|
|
|
anchor = this.reverse ? this.previous[0] : this.next[this.next.length - 1];
|
|
|
|
} else {
|
|
|
|
anchor = this.reverse ? this.next[this.next.length - 1] : this.previous[0];
|
|
|
|
}
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
const promise = this.loadMore(anchor, older).then(result => {
|
|
|
|
if(result.items.length < this.loadCount) {
|
|
|
|
if(older) this.loadedAllDown = true;
|
|
|
|
else this.loadedAllUp = true;
|
|
|
|
}
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
if(this.count === undefined) {
|
|
|
|
this.count = result.count || result.items.length;
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
const method = older ? result.items.forEach.bind(result.items) : forEachReverse.bind(null, result.items);
|
|
|
|
method((item: any) => {
|
|
|
|
const processed = this.processItem ? this.processItem(item) : item;
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(!processed) return;
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(older) {
|
|
|
|
if(this.reverse) this.previous.unshift(processed);
|
|
|
|
else this.next.push(processed);
|
|
|
|
} else {
|
|
|
|
if(this.reverse) this.next.push(processed);
|
|
|
|
else this.previous.unshift(processed);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, () => {}).then(() => {
|
|
|
|
if(older) this.loadPromiseDown = null;
|
|
|
|
else this.loadPromiseUp = null;
|
|
|
|
});
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(older) this.loadPromiseDown = promise;
|
|
|
|
else this.loadPromiseUp = promise;
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
class PeerProfileAvatars {
|
2021-04-23 16:44:19 +04:00
|
|
|
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)';
|
2021-04-06 19:06:42 +04:00
|
|
|
public container: HTMLElement;
|
|
|
|
public avatars: HTMLElement;
|
2021-04-13 20:19:52 +04:00
|
|
|
public gradient: HTMLElement;
|
2021-04-06 19:06:42 +04:00
|
|
|
public info: HTMLElement;
|
2021-04-23 16:44:19 +04:00
|
|
|
private tabs: HTMLDivElement;
|
|
|
|
private listLoader: ListLoader<string | Message.messageService>;
|
|
|
|
private peerId: number;
|
2020-09-24 02:37:22 +03:00
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
constructor(public scrollable: Scrollable) {
|
2021-04-06 19:06:42 +04:00
|
|
|
this.container = document.createElement('div');
|
|
|
|
this.container.classList.add(PeerProfileAvatars.BASE_CLASS + '-container');
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.avatars = document.createElement('div');
|
|
|
|
this.avatars.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatars');
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
this.gradient = document.createElement('div');
|
|
|
|
this.gradient.classList.add(PeerProfileAvatars.BASE_CLASS + '-gradient');
|
2021-04-10 21:28:41 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.info = document.createElement('div');
|
|
|
|
this.info.classList.add(PeerProfileAvatars.BASE_CLASS + '-info');
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
this.tabs = document.createElement('div');
|
|
|
|
this.tabs.classList.add(PeerProfileAvatars.BASE_CLASS + '-tabs');
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
this.container.append(this.avatars, this.gradient, this.info, this.tabs);
|
2021-04-06 19:06:42 +04:00
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
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;
|
2021-04-07 21:11:08 +04:00
|
|
|
let cancel = false;
|
2021-04-13 20:19:52 +04:00
|
|
|
let freeze = false;
|
|
|
|
attachClickEvent(this.container, async(_e) => {
|
|
|
|
if(freeze) {
|
|
|
|
cancelEvent(_e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-07 21:11:08 +04:00
|
|
|
if(cancel) {
|
|
|
|
cancel = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
if(!checkScrollTop()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
const rect = this.container.getBoundingClientRect();
|
|
|
|
|
|
|
|
const e = (_e as TouchEvent).touches ? (_e as TouchEvent).touches[0] : _e as MouseEvent;
|
|
|
|
const x = e.pageX;
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
const clickX = x - rect.left;
|
2021-04-13 22:48:46 +04:00
|
|
|
if((!this.listLoader.previous.length && !this.listLoader.next.length)
|
|
|
|
|| (clickX > (rect.width * SWITCH_ZONE) && clickX < (rect.width - rect.width * SWITCH_ZONE))) {
|
2021-04-13 20:19:52 +04:00
|
|
|
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);
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
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.listLoader.go(toRight ? 1 : -1);
|
|
|
|
// });
|
|
|
|
}
|
2021-04-07 21:11:08 +04:00
|
|
|
});
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
const cancelNextClick = () => {
|
|
|
|
cancel = true;
|
|
|
|
document.body.addEventListener(isTouchSupported ? 'touchend' : 'click', (e) => {
|
|
|
|
cancel = false;
|
|
|
|
}, {once: true});
|
|
|
|
};
|
|
|
|
|
2021-04-07 21:11:08 +04:00
|
|
|
let width = 0, x = 0, lastDiffX = 0, lastIndex = 0, minX = 0;
|
|
|
|
const swipeHandler = new SwipeHandler({
|
|
|
|
element: this.avatars,
|
|
|
|
onSwipe: (xDiff, yDiff) => {
|
|
|
|
lastDiffX = xDiff;
|
2021-04-23 16:44:19 +04:00
|
|
|
let lastX = x + xDiff * -PeerProfileAvatars.SCALE;
|
2021-04-07 21:11:08 +04:00
|
|
|
if(lastX > 0) lastX = 0;
|
|
|
|
else if(lastX < minX) lastX = minX;
|
|
|
|
|
2021-04-23 16:44:19 +04:00
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', lastX + 'px');
|
2021-04-07 21:11:08 +04:00
|
|
|
//console.log(xDiff, yDiff);
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
verifyTouchTarget: (e) => {
|
2021-04-13 20:19:52 +04:00
|
|
|
if(!checkScrollTop()) {
|
|
|
|
cancelNextClick();
|
|
|
|
cancelEvent(e);
|
|
|
|
return false;
|
|
|
|
} else if(this.tabs.classList.contains('hide') || freeze) {
|
2021-04-07 21:11:08 +04:00
|
|
|
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;
|
|
|
|
|
2021-04-23 16:44:19 +04:00
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', x + 'px');
|
2021-04-07 21:11:08 +04:00
|
|
|
|
|
|
|
this.avatars.classList.add('no-transition');
|
|
|
|
void this.avatars.offsetLeft; // reflow
|
|
|
|
},
|
|
|
|
onReset: () => {
|
2021-04-23 16:44:19 +04:00
|
|
|
const addIndex = Math.ceil(Math.abs(lastDiffX) / (width / PeerProfileAvatars.SCALE)) * (lastDiffX >= 0 ? 1 : -1);
|
2021-04-13 20:19:52 +04:00
|
|
|
cancelNextClick();
|
2021-04-07 21:11:08 +04:00
|
|
|
|
|
|
|
//console.log(addIndex);
|
|
|
|
|
|
|
|
this.avatars.classList.remove('no-transition');
|
|
|
|
fastRaf(() => {
|
|
|
|
this.listLoader.go(addIndex);
|
|
|
|
});
|
|
|
|
}
|
2021-04-06 19:06:42 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public setPeer(peerId: number) {
|
|
|
|
this.peerId = peerId;
|
|
|
|
|
|
|
|
const photo = appPeersManager.getPeerPhoto(peerId);
|
|
|
|
if(!photo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadCount = 50;
|
2021-04-13 20:19:52 +04:00
|
|
|
const listLoader: PeerProfileAvatars['listLoader'] = this.listLoader = new ListLoader<string | Message.messageService>({
|
2021-04-06 19:06:42 +04:00
|
|
|
loadCount,
|
|
|
|
loadMore: (anchor, older) => {
|
2021-04-13 20:19:52 +04:00
|
|
|
if(peerId > 0) {
|
|
|
|
return appPhotosManager.getUserPhotos(peerId, (anchor || listLoader.current) as any, loadCount).then(result => {
|
|
|
|
return {
|
|
|
|
count: result.count,
|
|
|
|
items: result.photos
|
|
|
|
};
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const promises: [Promise<ChatFull>, ReturnType<AppMessagesManager['getSearch']>] = [] as any;
|
|
|
|
if(!listLoader.current) {
|
2021-04-16 17:30:42 +04:00
|
|
|
promises.push(appProfileManager.getChatFull(-peerId));
|
2021-04-13 20:19:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2021-04-06 19:06:42 +04:00
|
|
|
},
|
2021-04-07 11:56:18 +04:00
|
|
|
processItem: this.processItem,
|
|
|
|
onJump: (item, older) => {
|
|
|
|
const id = this.listLoader.index;
|
|
|
|
//const nextId = Math.max(0, id);
|
2021-04-23 16:44:19 +04:00
|
|
|
const x = 100 * PeerProfileAvatars.SCALE * id;
|
|
|
|
this.avatars.style.transform = PeerProfileAvatars.TRANSLATE_TEMPLATE.replace('{x}', `-${x}%`);
|
2021-04-07 11:56:18 +04:00
|
|
|
|
|
|
|
const activeTab = this.tabs.querySelector('.active');
|
|
|
|
if(activeTab) activeTab.classList.remove('active');
|
|
|
|
|
|
|
|
const tab = this.tabs.children[id] as HTMLElement;
|
|
|
|
tab.classList.add('active');
|
|
|
|
}
|
2021-04-06 19:06:42 +04:00
|
|
|
});
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
if(photo._ === 'userProfilePhoto') {
|
|
|
|
listLoader.current = photo.photo_id;
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.processItem(listLoader.current);
|
|
|
|
|
|
|
|
listLoader.load(true);
|
|
|
|
}
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
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');
|
|
|
|
}
|
2021-04-07 21:11:08 +04:00
|
|
|
|
|
|
|
this.tabs.classList.toggle('hide', this.tabs.childElementCount <= 1);
|
2021-04-07 11:56:18 +04:00
|
|
|
}
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
public processItem = (photoId: string | Message.messageService) => {
|
2021-04-06 19:06:42 +04:00
|
|
|
const avatar = document.createElement('div');
|
|
|
|
avatar.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatar');
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
let photo: Photo.photo;
|
|
|
|
if(photoId) {
|
|
|
|
photo = typeof(photoId) === 'string' ?
|
|
|
|
appPhotosManager.getPhoto(photoId) :
|
|
|
|
(photoId.action as MessageAction.messageActionChannelEditPhoto).photo as Photo.photo;
|
|
|
|
}
|
|
|
|
|
2021-04-07 21:11:08 +04:00
|
|
|
const img = new Image();
|
|
|
|
img.classList.add(PeerProfileAvatars.BASE_CLASS + '-avatar-image');
|
|
|
|
img.draggable = false;
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(photo) {
|
2021-05-01 22:49:32 +04:00
|
|
|
const size = appPhotosManager.choosePhotoSize(photo, 420, 420, false);
|
|
|
|
appPhotosManager.preloadPhoto(photo, size).then(() => {
|
|
|
|
const cacheContext = appDownloadManager.getCacheContext(photo, size.type);
|
|
|
|
renderImageFromUrl(img, cacheContext.url, () => {
|
2021-04-06 19:06:42 +04:00
|
|
|
avatar.append(img);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const photo = appPeersManager.getPeerPhoto(this.peerId);
|
2021-04-07 21:11:08 +04:00
|
|
|
appProfileManager.putAvatar(avatar, this.peerId, photo, 'photo_big', img);
|
2021-04-06 19:06:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.avatars.append(avatar);
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
this.addTab();
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
return photoId;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class PeerProfile {
|
|
|
|
public element: HTMLElement;
|
2021-04-07 11:56:18 +04:00
|
|
|
public avatars: PeerProfileAvatars;
|
2021-04-06 19:06:42 +04:00
|
|
|
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;
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
constructor(public scrollable: Scrollable) {
|
2021-04-23 16:44:19 +04:00
|
|
|
if(!PARALLAX_SUPPORTED) {
|
|
|
|
this.scrollable.container.classList.add('no-parallax');
|
|
|
|
}
|
2021-04-13 20:19:52 +04:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public init() {
|
|
|
|
this.init = null;
|
|
|
|
|
|
|
|
this.element = document.createElement('div');
|
|
|
|
this.element.classList.add('profile-content');
|
|
|
|
|
|
|
|
this.section = new SettingSection({
|
2021-03-28 22:37:11 +04:00
|
|
|
noDelimiter: true
|
2021-02-01 05:07:44 +02:00
|
|
|
});
|
2021-01-20 05:38:59 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.avatar = new AvatarElement();
|
|
|
|
this.avatar.classList.add('profile-avatar', 'avatar-120');
|
|
|
|
this.avatar.setAttribute('dialog', '1');
|
|
|
|
this.avatar.setAttribute('clickable', '');
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.name = document.createElement('div');
|
|
|
|
this.name.classList.add('profile-name');
|
2021-03-28 22:37:11 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.subtitle = document.createElement('div');
|
|
|
|
this.subtitle.classList.add('profile-subtitle');
|
|
|
|
|
|
|
|
this.bio = new Row({
|
2021-03-28 22:37:11 +04:00
|
|
|
title: ' ',
|
|
|
|
subtitleLangKey: 'UserBio',
|
|
|
|
icon: 'info',
|
2021-04-03 01:45:51 +04:00
|
|
|
clickable: (e) => {
|
|
|
|
if((e.target as HTMLElement).tagName === 'A') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-28 22:37:11 +04:00
|
|
|
appProfileManager.getProfileByPeerId(this.peerId).then(full => {
|
|
|
|
copyTextToClipboard(full.about);
|
|
|
|
toast(I18n.format('BioCopied', true));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.bio.title.classList.add('pre-wrap');
|
2021-04-03 01:45:51 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.username = new Row({
|
2021-03-28 22:37:11 +04:00
|
|
|
title: ' ',
|
|
|
|
subtitleLangKey: 'Username',
|
|
|
|
icon: 'username',
|
|
|
|
clickable: () => {
|
|
|
|
const peer: Channel | User = appPeersManager.getPeer(this.peerId);
|
|
|
|
copyTextToClipboard('@' + peer.username);
|
|
|
|
toast(I18n.format('UsernameCopied', true));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.phone = new Row({
|
2021-03-28 22:37:11 +04:00
|
|
|
title: ' ',
|
|
|
|
subtitleLangKey: 'Phone',
|
|
|
|
icon: 'phone',
|
|
|
|
clickable: () => {
|
|
|
|
const peer: User = appUsersManager.getUser(this.peerId);
|
|
|
|
copyTextToClipboard('+' + peer.phone);
|
|
|
|
toast(I18n.format('PhoneCopied', true));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.notifications = new Row({
|
2021-04-13 20:19:52 +04:00
|
|
|
checkboxField: new CheckboxField({toggle: true}),
|
|
|
|
titleLangKey: 'Notifications',
|
|
|
|
icon: 'unmute'
|
2021-03-28 22:37:11 +04:00
|
|
|
});
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
this.section.content.append(this.phone.container, this.username.container, this.bio.container, this.notifications.container);
|
2021-04-13 20:19:52 +04:00
|
|
|
|
|
|
|
const delimiter = document.createElement('div');
|
|
|
|
delimiter.classList.add('gradient-delimiter');
|
|
|
|
|
|
|
|
this.element.append(this.section.container, delimiter);
|
2021-04-06 19:06:42 +04:00
|
|
|
|
|
|
|
this.notifications.checkboxField.input.addEventListener('change', (e) => {
|
|
|
|
if(!e.isTrusted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//let checked = this.notificationsCheckbox.checked;
|
|
|
|
appMessagesManager.mutePeer(this.peerId);
|
|
|
|
});
|
|
|
|
|
|
|
|
rootScope.on('dialog_notify_settings', (dialog) => {
|
|
|
|
if(this.peerId === dialog.peerId) {
|
|
|
|
const muted = appNotificationsManager.isPeerLocalMuted(this.peerId, false);
|
|
|
|
this.notifications.checkboxField.checked = !muted;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rootScope.on('peer_typings', (e) => {
|
|
|
|
const {peerId} = e;
|
|
|
|
|
|
|
|
if(this.peerId === peerId) {
|
|
|
|
this.setPeerStatus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rootScope.on('peer_bio_edit', (peerId) => {
|
|
|
|
if(peerId === this.peerId) {
|
|
|
|
this.setBio(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rootScope.on('user_update', (e) => {
|
|
|
|
const userId = e;
|
|
|
|
|
|
|
|
if(this.peerId === userId) {
|
|
|
|
this.setPeerStatus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setPeerStatusInterval = window.setInterval(this.setPeerStatus, 60e3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setPeerStatus = (needClear = false) => {
|
|
|
|
if(!this.peerId) return;
|
|
|
|
|
|
|
|
const peerId = this.peerId;
|
2021-04-20 22:00:38 +04:00
|
|
|
appImManager.setPeerStatus(this.peerId, this.subtitle, needClear, true, () => peerId === this.peerId);
|
2021-04-06 19:06:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
public setAvatar() {
|
2021-04-10 22:29:58 +04:00
|
|
|
if(this.peerId !== rootScope.myId) {
|
|
|
|
const photo = appPeersManager.getPeerPhoto(this.peerId);
|
2021-04-07 11:56:18 +04:00
|
|
|
|
2021-04-10 22:29:58 +04:00
|
|
|
if(photo) {
|
|
|
|
const oldAvatars = this.avatars;
|
2021-04-13 20:19:52 +04:00
|
|
|
this.avatars = new PeerProfileAvatars(this.scrollable);
|
2021-04-10 22:29:58 +04:00
|
|
|
this.avatars.setPeer(this.peerId);
|
|
|
|
this.avatars.info.append(this.name, this.subtitle);
|
2021-04-07 11:56:18 +04:00
|
|
|
|
2021-04-10 22:29:58 +04:00
|
|
|
this.avatar.remove();
|
|
|
|
|
|
|
|
if(oldAvatars) oldAvatars.container.replaceWith(this.avatars.container);
|
|
|
|
else this.element.prepend(this.avatars.container);
|
2021-04-07 11:56:18 +04:00
|
|
|
|
2021-04-23 16:44:19 +04:00
|
|
|
if(PARALLAX_SUPPORTED) {
|
|
|
|
this.scrollable.container.classList.add('parallax');
|
|
|
|
}
|
2021-04-13 20:19:52 +04:00
|
|
|
|
2021-04-10 22:29:58 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 11:56:18 +04:00
|
|
|
|
2021-04-23 16:44:19 +04:00
|
|
|
if(PARALLAX_SUPPORTED) {
|
|
|
|
this.scrollable.container.classList.remove('parallax');
|
|
|
|
}
|
2021-04-13 20:19:52 +04:00
|
|
|
|
2021-04-10 22:29:58 +04:00
|
|
|
if(this.avatars) {
|
|
|
|
this.avatars.container.remove();
|
|
|
|
this.avatars = undefined;
|
2021-04-07 11:56:18 +04:00
|
|
|
}
|
2021-04-10 22:29:58 +04:00
|
|
|
|
|
|
|
this.avatar.setAttribute('peer', '' + this.peerId);
|
|
|
|
|
|
|
|
this.section.content.prepend(this.avatar, this.name, this.subtitle);
|
2021-04-07 11:56:18 +04:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
public fillProfileElements() {
|
|
|
|
if(!this.cleaned) return;
|
|
|
|
this.cleaned = false;
|
|
|
|
|
|
|
|
const peerId = this.peerId;
|
|
|
|
|
|
|
|
this.cleanupHTML();
|
|
|
|
|
2021-04-07 11:56:18 +04:00
|
|
|
this.setAvatar();
|
2021-04-06 19:06:42 +04:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
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) {
|
2021-04-26 18:33:51 +04:00
|
|
|
setText(appUsersManager.formatUserPhone(user.phone), this.phone);
|
2021-04-06 19:06:42 +04:00
|
|
|
}
|
|
|
|
}/* else {
|
|
|
|
//membersLi.style.display = appPeersManager.isBroadcast(peerId) ? 'none' : '';
|
|
|
|
} */
|
|
|
|
|
|
|
|
this.setBio();
|
|
|
|
|
|
|
|
replaceContent(this.name, new PeerTitle({
|
|
|
|
peerId,
|
|
|
|
dialog: true
|
|
|
|
}).element);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: отредактированное сообщение не изменится
|
|
|
|
export default class AppSharedMediaTab extends SliderSuperTab {
|
2021-04-09 20:44:43 +04:00
|
|
|
private editBtn: HTMLElement;
|
2021-04-06 19:06:42 +04:00
|
|
|
|
|
|
|
private peerId = 0;
|
|
|
|
private threadId = 0;
|
|
|
|
|
2021-04-09 20:44:43 +04:00
|
|
|
private historiesStorage: {
|
2021-04-06 19:06:42 +04:00
|
|
|
[peerId: number]: Partial<{
|
|
|
|
[type in SearchSuperType]: {mid: number, peerId: number}[]
|
|
|
|
}>
|
|
|
|
} = {};
|
|
|
|
|
|
|
|
private searchSuper: AppSearchSuper;
|
|
|
|
|
2021-04-09 20:44:43 +04:00
|
|
|
private profile: PeerProfile;
|
2021-04-16 17:30:42 +04:00
|
|
|
peerChanged: boolean;
|
2021-04-06 19:06:42 +04:00
|
|
|
|
|
|
|
constructor(slider: SidebarSlider) {
|
|
|
|
super(slider, false);
|
|
|
|
}
|
|
|
|
|
2021-04-09 20:44:43 +04:00
|
|
|
public init() {
|
2021-04-11 03:14:57 +04:00
|
|
|
//const perf = performance.now();
|
2021-04-09 20:44:43 +04:00
|
|
|
|
|
|
|
this.container.classList.add('shared-media-container', 'profile-container');
|
2021-04-06 19:06:42 +04:00
|
|
|
|
|
|
|
// * header
|
|
|
|
const newCloseBtn = Button('btn-icon sidebar-close-button', {noRipple: true});
|
|
|
|
this.closeBtn.replaceWith(newCloseBtn);
|
|
|
|
this.closeBtn = newCloseBtn;
|
|
|
|
|
|
|
|
const animatedCloseIcon = document.createElement('div');
|
|
|
|
animatedCloseIcon.classList.add('animated-close-icon');
|
|
|
|
newCloseBtn.append(animatedCloseIcon);
|
|
|
|
|
|
|
|
const transitionContainer = document.createElement('div');
|
|
|
|
transitionContainer.className = 'transition slide-fade';
|
|
|
|
|
|
|
|
const transitionFirstItem = document.createElement('div');
|
|
|
|
transitionFirstItem.classList.add('transition-item');
|
|
|
|
|
|
|
|
this.title.append(i18n('Profile'));
|
|
|
|
this.editBtn = ButtonIcon('edit');
|
|
|
|
//const moreBtn = ButtonIcon('more');
|
|
|
|
|
|
|
|
transitionFirstItem.append(this.title, this.editBtn/* , moreBtn */);
|
|
|
|
|
|
|
|
const transitionLastItem = document.createElement('div');
|
|
|
|
transitionLastItem.classList.add('transition-item');
|
|
|
|
|
|
|
|
const secondTitle: HTMLElement = this.title.cloneNode() as any;
|
|
|
|
secondTitle.append(i18n('PeerInfo.SharedMedia'));
|
|
|
|
|
|
|
|
transitionLastItem.append(secondTitle);
|
|
|
|
|
|
|
|
transitionContainer.append(transitionFirstItem, transitionLastItem);
|
|
|
|
|
|
|
|
this.header.append(transitionContainer);
|
|
|
|
|
|
|
|
// * body
|
|
|
|
|
2021-04-13 20:19:52 +04:00
|
|
|
this.profile = new PeerProfile(this.scrollable);
|
2021-04-06 19:06:42 +04:00
|
|
|
this.profile.init();
|
|
|
|
|
|
|
|
this.scrollable.append(this.profile.element);
|
2021-02-15 19:49:58 +04:00
|
|
|
|
|
|
|
const HEADER_HEIGHT = 56;
|
2021-03-28 22:37:11 +04:00
|
|
|
this.scrollable.onAdditionalScroll = () => {
|
2021-02-15 19:49:58 +04:00
|
|
|
const rect = this.searchSuper.nav.getBoundingClientRect();
|
|
|
|
if(!rect.width) return;
|
|
|
|
|
2021-04-26 18:33:51 +04:00
|
|
|
const top = rect.top - 1;
|
2021-02-15 19:49:58 +04:00
|
|
|
const isSharedMedia = top <= HEADER_HEIGHT;
|
2021-03-28 22:37:11 +04:00
|
|
|
animatedCloseIcon.classList.toggle('state-back', isSharedMedia);
|
2021-04-13 20:19:52 +04:00
|
|
|
this.searchSuper.container.classList.toggle('is-full-viewport', isSharedMedia);
|
2021-02-15 19:49:58 +04:00
|
|
|
transition(+isSharedMedia);
|
2021-03-12 02:39:57 +04:00
|
|
|
|
|
|
|
if(!isSharedMedia) {
|
2021-04-07 21:11:08 +04:00
|
|
|
this.searchSuper.cleanScrollPositions();
|
2021-03-12 02:39:57 +04:00
|
|
|
}
|
2021-02-15 19:49:58 +04:00
|
|
|
};
|
|
|
|
|
2021-03-28 22:37:11 +04:00
|
|
|
const transition = TransitionSlider(transitionContainer, 'slide-fade', 400, null, false);
|
2021-02-15 19:49:58 +04:00
|
|
|
|
|
|
|
transition(0);
|
|
|
|
|
|
|
|
attachClickEvent(this.closeBtn, (e) => {
|
|
|
|
if(this.closeBtn.firstElementChild.classList.contains('state-back')) {
|
2021-03-28 22:37:11 +04:00
|
|
|
this.scrollable.scrollIntoViewNew(this.scrollable.container.firstElementChild as HTMLElement, 'start');
|
2021-02-15 19:49:58 +04:00
|
|
|
transition(0);
|
2021-03-28 22:37:11 +04:00
|
|
|
animatedCloseIcon.classList.remove('state-back');
|
|
|
|
} else if(!this.scrollable.isHeavyAnimationInProgress) {
|
2021-03-10 18:08:28 +04:00
|
|
|
appSidebarRight.onCloseBtnClick();
|
2021-02-15 19:49:58 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-12 23:02:05 +04:00
|
|
|
attachClickEvent(this.editBtn, (e) => {
|
2021-05-05 14:50:32 +04:00
|
|
|
let tab: AppEditChatTab | AppEditContactTab;
|
|
|
|
if(this.peerId < 0) {
|
|
|
|
tab = new AppEditChatTab(appSidebarRight);
|
2021-03-12 23:02:05 +04:00
|
|
|
} else {
|
2021-05-05 14:50:32 +04:00
|
|
|
tab = new AppEditContactTab(appSidebarRight);
|
2021-03-12 23:02:05 +04:00
|
|
|
}
|
2021-03-13 02:43:18 +04:00
|
|
|
|
|
|
|
if(tab) {
|
2021-05-05 14:50:32 +04:00
|
|
|
if(tab instanceof AppEditChatTab) {
|
2021-03-17 17:05:32 +04:00
|
|
|
tab.chatId = -this.peerId;
|
|
|
|
} else {
|
|
|
|
tab.peerId = this.peerId;
|
|
|
|
}
|
|
|
|
|
2021-03-13 02:43:18 +04:00
|
|
|
tab.open();
|
|
|
|
}
|
2021-03-12 23:02:05 +04:00
|
|
|
});
|
|
|
|
|
2021-03-28 22:37:11 +04:00
|
|
|
//this.container.prepend(this.closeBtn.parentElement);
|
|
|
|
|
2021-04-07 21:11:08 +04:00
|
|
|
this.searchSuper = new AppSearchSuper({
|
|
|
|
mediaTabs: [{
|
|
|
|
inputFilter: 'inputMessagesFilterEmpty',
|
|
|
|
name: 'PeerMedia.Members',
|
|
|
|
type: 'members'
|
|
|
|
}, {
|
|
|
|
inputFilter: 'inputMessagesFilterPhotoVideo',
|
|
|
|
name: 'SharedMediaTab2',
|
|
|
|
type: 'media'
|
|
|
|
}, {
|
|
|
|
inputFilter: 'inputMessagesFilterDocument',
|
|
|
|
name: 'SharedFilesTab2',
|
|
|
|
type: 'files'
|
|
|
|
}, {
|
|
|
|
inputFilter: 'inputMessagesFilterUrl',
|
|
|
|
name: 'SharedLinksTab2',
|
|
|
|
type: 'links'
|
|
|
|
}, {
|
|
|
|
inputFilter: 'inputMessagesFilterMusic',
|
|
|
|
name: 'SharedMusicTab2',
|
|
|
|
type: 'music'
|
2021-04-10 23:39:36 +04:00
|
|
|
}, {
|
|
|
|
inputFilter: 'inputMessagesFilterVoice',
|
|
|
|
name: 'SharedVoiceTab2',
|
|
|
|
type: 'voice'
|
2021-04-07 21:11:08 +04:00
|
|
|
}],
|
2021-04-10 17:52:21 +04:00
|
|
|
scrollable: this.scrollable,
|
|
|
|
onChangeTab: (mediaTab) => {
|
|
|
|
let timeout = mediaTab.type === 'members' && rootScope.settings.animationsEnabled ? 250 : 0;
|
|
|
|
setTimeout(() => {
|
|
|
|
btnAddMembers.classList.toggle('is-hidden', mediaTab.type !== 'members');
|
|
|
|
}, timeout);
|
|
|
|
}
|
2021-04-07 21:11:08 +04:00
|
|
|
});
|
2021-04-09 20:44:43 +04:00
|
|
|
|
|
|
|
this.profile.element.append(this.searchSuper.container);
|
|
|
|
|
2021-05-03 23:17:50 +04:00
|
|
|
const btnAddMembers = ButtonCorner({icon: 'addmember_filled'});
|
2021-04-09 20:44:43 +04:00
|
|
|
this.content.append(btnAddMembers);
|
|
|
|
|
2021-04-10 17:52:21 +04:00
|
|
|
btnAddMembers.addEventListener('click', () => {
|
|
|
|
const id = -this.peerId;
|
|
|
|
const isChannel = appChatsManager.isChannel(id);
|
|
|
|
|
|
|
|
const showConfirmation = (peerIds: number[], callback: () => void) => {
|
|
|
|
let titleLangKey: LangPackKey = 'GroupAddMembers', descriptionLangKey: LangPackKey, descriptionLangArgs: any[];
|
|
|
|
|
|
|
|
if(peerIds.length > 1) {
|
|
|
|
descriptionLangKey = 'PeerInfo.Confirm.AddMembers1';
|
|
|
|
descriptionLangArgs = [peerIds.length];
|
|
|
|
} else {
|
|
|
|
descriptionLangKey = 'PeerInfo.Confirm.AddMember';
|
|
|
|
descriptionLangArgs = [new PeerTitle({
|
|
|
|
peerId: peerIds[0],
|
|
|
|
onlyFirstName: true
|
|
|
|
}).element];
|
|
|
|
}
|
|
|
|
|
|
|
|
new PopupPeer('popup-add-members', {
|
|
|
|
peerId: -id,
|
|
|
|
titleLangKey,
|
|
|
|
descriptionLangKey,
|
|
|
|
descriptionLangArgs,
|
|
|
|
buttons: [{
|
|
|
|
langKey: 'Add',
|
|
|
|
callback: () => {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}).show();
|
|
|
|
};
|
|
|
|
|
|
|
|
if(isChannel) {
|
|
|
|
const tab = new AppAddMembersTab(this.slider);
|
|
|
|
tab.open({
|
|
|
|
peerId: this.peerId,
|
|
|
|
type: 'channel',
|
|
|
|
skippable: false,
|
|
|
|
takeOut: (peerIds) => {
|
|
|
|
showConfirmation(peerIds, () => {
|
|
|
|
tab.attachToPromise(appChatsManager.inviteToChannel(id, peerIds));
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
title: 'GroupAddMembers',
|
|
|
|
placeholder: 'SendMessageTo'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
new PopupPickUser({
|
|
|
|
peerTypes: ['contacts'],
|
|
|
|
placeholder: 'Search',
|
|
|
|
onSelect: (peerId) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
showConfirmation([peerId], () => {
|
|
|
|
appChatsManager.addChatUser(id, peerId);
|
|
|
|
});
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-11 03:14:57 +04:00
|
|
|
//console.log('construct shared media time:', performance.now() - perf);
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 04:06:16 +02:00
|
|
|
public renderNewMessages(peerId: number, mids: number[]) {
|
2020-10-26 02:09:42 +02:00
|
|
|
if(this.init) return; // * not inited yet
|
2020-10-28 19:49:58 +02:00
|
|
|
|
2020-12-11 04:06:16 +02:00
|
|
|
if(!this.historiesStorage[peerId]) return;
|
2020-10-26 02:09:42 +02:00
|
|
|
|
2020-10-23 03:07:30 +03:00
|
|
|
mids = mids.slice().reverse(); // ! because it will be ascend sorted array
|
2021-04-10 23:39:36 +04:00
|
|
|
for(const mediaTab of this.searchSuper.mediaTabs) {
|
|
|
|
const inputFilter = mediaTab.inputFilter;
|
2020-12-25 14:53:20 +02:00
|
|
|
const filtered = this.searchSuper.filterMessagesByType(mids.map(mid => appMessagesManager.getMessageByPeer(peerId, mid)), inputFilter);
|
2020-10-23 03:07:30 +03:00
|
|
|
if(filtered.length) {
|
2020-12-25 01:19:34 +02:00
|
|
|
if(this.historiesStorage[peerId][inputFilter]) {
|
2020-12-25 14:53:20 +02:00
|
|
|
this.historiesStorage[peerId][inputFilter].unshift(...filtered.map(message => ({mid: message.mid, peerId: message.peerId})));
|
2020-10-28 19:49:58 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 02:30:23 +02:00
|
|
|
if(this.peerId === peerId && this.searchSuper.usedFromHistory[inputFilter] !== -1) {
|
2020-12-25 01:19:34 +02:00
|
|
|
this.searchSuper.usedFromHistory[inputFilter] += filtered.length;
|
2021-04-10 23:39:36 +04:00
|
|
|
this.searchSuper.performSearchResult(filtered, mediaTab, false);
|
2020-10-23 03:07:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 04:06:16 +02:00
|
|
|
public deleteDeletedMessages(peerId: number, mids: number[]) {
|
2020-10-26 02:09:42 +02:00
|
|
|
if(this.init) return; // * not inited yet
|
|
|
|
|
2020-12-11 04:06:16 +02:00
|
|
|
if(!this.historiesStorage[peerId]) return;
|
2020-10-28 19:49:58 +02:00
|
|
|
|
2020-10-23 03:07:30 +03:00
|
|
|
for(const mid of mids) {
|
2021-04-07 21:11:08 +04:00
|
|
|
for(const type of this.searchSuper.mediaTabs) {
|
2020-12-25 01:19:34 +02:00
|
|
|
const inputFilter = type.inputFilter;
|
|
|
|
|
|
|
|
if(!this.historiesStorage[peerId][inputFilter]) continue;
|
2020-10-23 03:07:30 +03:00
|
|
|
|
2020-12-25 01:19:34 +02:00
|
|
|
const history = this.historiesStorage[peerId][inputFilter];
|
2020-12-25 14:53:20 +02:00
|
|
|
const idx = history.findIndex(m => m.mid === mid);
|
2020-10-23 03:07:30 +03:00
|
|
|
if(idx !== -1) {
|
|
|
|
history.splice(idx, 1);
|
|
|
|
|
2021-02-04 02:30:23 +02:00
|
|
|
if(this.peerId === peerId) {
|
2020-12-25 01:19:34 +02:00
|
|
|
const container = this.searchSuper.tabs[inputFilter];
|
2020-12-25 14:53:20 +02:00
|
|
|
const div = container.querySelector(`div[data-mid="${mid}"][data-peer-id="${peerId}"]`);
|
2020-10-28 19:49:58 +02:00
|
|
|
if(div) {
|
|
|
|
div.remove();
|
|
|
|
}
|
|
|
|
|
2020-12-25 01:19:34 +02:00
|
|
|
if(this.searchSuper.usedFromHistory[inputFilter] >= (idx + 1)) {
|
|
|
|
this.searchSuper.usedFromHistory[inputFilter]--;
|
2020-10-23 03:07:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 03:43:19 +03:00
|
|
|
|
2021-03-28 22:37:11 +04:00
|
|
|
this.scrollable.onScroll();
|
2020-10-23 03:07:30 +03:00
|
|
|
}
|
|
|
|
|
2020-09-24 02:37:22 +03:00
|
|
|
public cleanupHTML() {
|
2021-04-11 03:14:57 +04:00
|
|
|
// const perf = performance.now();
|
2021-04-06 19:06:42 +04:00
|
|
|
this.profile.cleanupHTML();
|
|
|
|
|
2021-03-12 23:02:05 +04:00
|
|
|
this.editBtn.style.display = 'none';
|
2021-04-07 21:11:08 +04:00
|
|
|
|
2021-04-09 20:44:43 +04:00
|
|
|
this.searchSuper.cleanupHTML(true);
|
|
|
|
|
|
|
|
this.container.classList.toggle('can-add-members', this.searchSuper.canViewMembers() && appChatsManager.hasRights(-this.peerId, 'invite_users'));
|
|
|
|
|
2021-04-11 03:14:57 +04:00
|
|
|
// console.log('cleanupHTML shared media time:', performance.now() - perf);
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public setLoadMutex(promise: Promise<any>) {
|
2020-12-25 01:19:34 +02:00
|
|
|
this.searchSuper.loadMutex = promise;
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
|
|
|
|
2020-12-23 04:18:24 +02:00
|
|
|
public setPeer(peerId: number, threadId = 0) {
|
2021-04-16 17:30:42 +04:00
|
|
|
if(this.peerId === peerId && this.threadId === threadId) return false;
|
2020-12-08 21:48:44 +02:00
|
|
|
|
2021-04-09 20:44:43 +04:00
|
|
|
this.peerId = peerId;
|
|
|
|
this.threadId = threadId;
|
2021-04-16 17:30:42 +04:00
|
|
|
this.peerChanged = true;
|
2021-04-09 20:44:43 +04:00
|
|
|
|
2020-09-24 02:37:22 +03:00
|
|
|
if(this.init) {
|
|
|
|
this.init();
|
|
|
|
this.init = null;
|
|
|
|
}
|
|
|
|
|
2020-12-25 14:53:20 +02:00
|
|
|
this.searchSuper.setQuery({
|
|
|
|
peerId,
|
|
|
|
//threadId,
|
|
|
|
historyStorage: this.historiesStorage[peerId] ?? (this.historiesStorage[peerId] = {})
|
|
|
|
});
|
2020-12-25 01:19:34 +02:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.profile.setPeer(peerId, threadId);
|
2021-04-16 17:30:42 +04:00
|
|
|
|
|
|
|
return true;
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public fillProfileElements() {
|
2021-04-16 17:30:42 +04:00
|
|
|
if(!this.peerChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.peerChanged = false;
|
|
|
|
|
2021-04-07 21:11:08 +04:00
|
|
|
this.cleanupHTML();
|
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
this.profile.fillProfileElements();
|
2021-03-13 06:22:42 +04:00
|
|
|
|
2021-04-06 19:06:42 +04:00
|
|
|
if(this.peerId > 0) {
|
|
|
|
if(this.peerId !== rootScope.myId && appUsersManager.isContact(this.peerId)) {
|
2021-03-13 16:24:00 +04:00
|
|
|
this.editBtn.style.display = '';
|
|
|
|
}
|
|
|
|
} else {
|
2021-04-06 19:06:42 +04:00
|
|
|
const chat: Chat = appChatsManager.getChat(-this.peerId);
|
2021-03-13 16:24:00 +04:00
|
|
|
if(chat._ === 'chat' || (chat as Chat.channel).admin_rights) {
|
|
|
|
this.editBtn.style.display = '';
|
|
|
|
}
|
|
|
|
}
|
2021-03-13 06:22:42 +04:00
|
|
|
}
|
|
|
|
|
2021-04-13 23:29:33 +04:00
|
|
|
public loadSidebarMedia(single: boolean, justLoad = false) {
|
|
|
|
this.searchSuper.load(single, justLoad);
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onOpenAfterTimeout() {
|
2021-03-28 22:37:11 +04:00
|
|
|
this.scrollable.onScroll();
|
2020-09-24 02:37:22 +03:00
|
|
|
}
|
2021-03-10 18:08:28 +04:00
|
|
|
}
|
2021-04-09 20:44:43 +04:00
|
|
|
|
|
|
|
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.AppSharedMediaTab = AppSharedMediaTab);
|