2020-10-07 15:57:33 +02:00
|
|
|
|
import appImManager from "../../../lib/appManagers/appImManager";
|
2021-01-20 02:38:59 +01:00
|
|
|
|
import appMessagesManager from "../../../lib/appManagers/appMessagesManager";
|
2020-10-07 15:57:33 +02:00
|
|
|
|
import appPeersManager from "../../../lib/appManagers/appPeersManager";
|
|
|
|
|
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
2021-03-28 20:37:11 +02:00
|
|
|
|
import appUsersManager, { User } from "../../../lib/appManagers/appUsersManager";
|
2020-10-14 14:51:21 +02:00
|
|
|
|
import { logger } from "../../../lib/logger";
|
2020-10-07 15:57:33 +02:00
|
|
|
|
import { RichTextProcessor } from "../../../lib/richtextprocessor";
|
2020-11-15 04:33:47 +01:00
|
|
|
|
import rootScope from "../../../lib/rootScope";
|
2020-12-25 13:53:20 +01:00
|
|
|
|
import AppSearchSuper, { SearchSuperType } from "../../appSearchSuper.";
|
2020-10-07 15:57:33 +02:00
|
|
|
|
import AvatarElement from "../../avatar";
|
|
|
|
|
import Scrollable from "../../scrollable";
|
2021-03-28 20:37:11 +02:00
|
|
|
|
import SidebarSlider, { SliderSuperTab, SliderTab } from "../../slider";
|
2021-03-08 23:15:44 +01:00
|
|
|
|
import CheckboxField from "../../checkboxField";
|
2021-03-13 03:22:42 +01:00
|
|
|
|
import { attachClickEvent } from "../../../helpers/dom";
|
2021-02-15 16:49:58 +01:00
|
|
|
|
import appSidebarRight from "..";
|
|
|
|
|
import { TransitionSlider } from "../../transition";
|
2021-03-11 04:06:44 +01:00
|
|
|
|
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
|
2021-03-12 20:02:05 +01:00
|
|
|
|
import AppEditGroupTab from "./editGroup";
|
2021-03-13 03:22:42 +01:00
|
|
|
|
import PeerTitle from "../../peerTitle";
|
2021-03-13 04:03:59 +01:00
|
|
|
|
import AppEditChannelTab from "./editChannel";
|
|
|
|
|
import AppEditContactTab from "./editContact";
|
2021-03-28 20:37:11 +02:00
|
|
|
|
import appChatsManager, { Channel } from "../../../lib/appManagers/appChatsManager";
|
2021-03-13 13:24:00 +01:00
|
|
|
|
import { Chat } from "../../../layer";
|
2021-03-28 20:37:11 +02:00
|
|
|
|
import Button from "../../button";
|
|
|
|
|
import ButtonIcon from "../../buttonIcon";
|
|
|
|
|
import I18n, { i18n } from "../../../lib/langPack";
|
|
|
|
|
import { SettingSection } from "../../sidebarLeft";
|
|
|
|
|
import Row from "../../row";
|
|
|
|
|
import { copyTextToClipboard } from "../../../helpers/clipboard";
|
|
|
|
|
import { toast } from "../../toast";
|
|
|
|
|
|
|
|
|
|
let setText = (text: string, row: Row) => {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
window.requestAnimationFrame(() => {
|
2021-03-28 20:37:11 +02:00
|
|
|
|
row.title.innerHTML = text;
|
|
|
|
|
row.container.style.display = '';
|
2020-09-24 01:37:22 +02:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-23 02:07:30 +02:00
|
|
|
|
// TODO: отредактированное сообщение не изменится
|
2021-03-28 20:37:11 +02:00
|
|
|
|
export default class AppSharedMediaTab extends SliderSuperTab {
|
2021-03-12 20:02:05 +01:00
|
|
|
|
public editBtn: HTMLElement;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
private peerId = 0;
|
2020-12-23 03:18:24 +01:00
|
|
|
|
private threadId = 0;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
|
|
|
|
public profileContentEl: HTMLDivElement;
|
|
|
|
|
public profileElements: {
|
|
|
|
|
avatar: AvatarElement,
|
|
|
|
|
name: HTMLDivElement,
|
|
|
|
|
subtitle: HTMLDivElement,
|
2021-03-28 20:37:11 +02:00
|
|
|
|
bio: Row,
|
|
|
|
|
username: Row,
|
|
|
|
|
phone: Row,
|
|
|
|
|
notifications: Row
|
2020-09-24 01:37:22 +02:00
|
|
|
|
} = {} as any;
|
2020-12-25 00:19:34 +01:00
|
|
|
|
|
2020-09-24 01:37:22 +02:00
|
|
|
|
public historiesStorage: {
|
2020-12-11 03:06:16 +01:00
|
|
|
|
[peerId: number]: Partial<{
|
2020-12-25 13:53:20 +01:00
|
|
|
|
[type in SearchSuperType]: {mid: number, peerId: number}[]
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}>
|
|
|
|
|
} = {};
|
|
|
|
|
|
2020-10-03 19:45:56 +02:00
|
|
|
|
private log = logger('SM'/* , LogLevels.error */);
|
2020-12-01 16:38:36 +01:00
|
|
|
|
setPeerStatusInterval: number;
|
2020-12-08 20:48:44 +01:00
|
|
|
|
cleaned: boolean;
|
2020-12-25 00:19:34 +01:00
|
|
|
|
searchSuper: AppSearchSuper;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
2021-03-13 03:22:42 +01:00
|
|
|
|
private setBioTimeout: number;
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
constructor(slider: SidebarSlider) {
|
|
|
|
|
super(slider, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected init() {
|
|
|
|
|
this.container.id = 'shared-media-container';
|
|
|
|
|
this.container.classList.add('profile-container');
|
|
|
|
|
|
|
|
|
|
// * 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('Telegram.PeerInfoController'));
|
|
|
|
|
this.editBtn = ButtonIcon('edit');
|
2021-04-04 17:39:17 +02:00
|
|
|
|
//const moreBtn = ButtonIcon('more');
|
2021-03-28 20:37:11 +02:00
|
|
|
|
|
2021-04-04 17:39:17 +02:00
|
|
|
|
transitionFirstItem.append(this.title, this.editBtn/* , moreBtn */);
|
2021-03-28 20:37:11 +02:00
|
|
|
|
|
|
|
|
|
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);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.header.append(transitionContainer);
|
|
|
|
|
|
|
|
|
|
// * body
|
|
|
|
|
|
|
|
|
|
this.profileContentEl = document.createElement('div');
|
|
|
|
|
this.profileContentEl.classList.add('profile-content');
|
|
|
|
|
|
|
|
|
|
const section = new SettingSection({
|
|
|
|
|
noDelimiter: true
|
2021-02-01 04:07:44 +01:00
|
|
|
|
});
|
2021-01-20 02:38:59 +01:00
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.avatar = new AvatarElement();
|
|
|
|
|
this.profileElements.avatar.classList.add('profile-avatar', 'avatar-120');
|
|
|
|
|
this.profileElements.avatar.setAttribute('dialog', '1');
|
|
|
|
|
this.profileElements.avatar.setAttribute('clickable', '');
|
|
|
|
|
|
|
|
|
|
this.profileElements.name = document.createElement('div');
|
|
|
|
|
this.profileElements.name.classList.add('profile-name');
|
|
|
|
|
|
|
|
|
|
this.profileElements.subtitle = document.createElement('div');
|
|
|
|
|
this.profileElements.subtitle.classList.add('profile-subtitle');
|
|
|
|
|
|
|
|
|
|
this.profileElements.bio = new Row({
|
|
|
|
|
title: ' ',
|
|
|
|
|
subtitleLangKey: 'UserBio',
|
|
|
|
|
icon: 'info',
|
2021-04-02 23:45:51 +02:00
|
|
|
|
clickable: (e) => {
|
|
|
|
|
if((e.target as HTMLElement).tagName === 'A') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
appProfileManager.getProfileByPeerId(this.peerId).then(full => {
|
|
|
|
|
copyTextToClipboard(full.about);
|
|
|
|
|
toast(I18n.format('BioCopied', true));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-02 23:45:51 +02:00
|
|
|
|
this.profileElements.bio.title.classList.add('pre-wrap');
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.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.profileElements.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.profileElements.notifications = new Row({
|
|
|
|
|
checkboxField: new CheckboxField({text: 'Notifications'})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
section.content.append(this.profileElements.avatar, this.profileElements.name, this.profileElements.subtitle,
|
|
|
|
|
this.profileElements.bio.container, this.profileElements.username.container, this.profileElements.phone.container, this.profileElements.notifications.container);
|
|
|
|
|
this.profileContentEl.append(section.container);
|
|
|
|
|
this.scrollable.append(this.profileContentEl);
|
2021-02-15 16:49:58 +01:00
|
|
|
|
|
|
|
|
|
const HEADER_HEIGHT = 56;
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.scrollable.onAdditionalScroll = () => {
|
2021-02-15 16:49:58 +01:00
|
|
|
|
const rect = this.searchSuper.nav.getBoundingClientRect();
|
|
|
|
|
if(!rect.width) return;
|
|
|
|
|
|
|
|
|
|
const top = rect.top;
|
|
|
|
|
const isSharedMedia = top <= HEADER_HEIGHT;
|
2021-03-28 20:37:11 +02:00
|
|
|
|
animatedCloseIcon.classList.toggle('state-back', isSharedMedia);
|
2021-02-15 16:49:58 +01:00
|
|
|
|
transition(+isSharedMedia);
|
2021-03-11 23:39:57 +01:00
|
|
|
|
|
|
|
|
|
if(!isSharedMedia) {
|
|
|
|
|
this.searchSuper.goingHard = {};
|
|
|
|
|
}
|
2021-02-15 16:49:58 +01:00
|
|
|
|
};
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
const transition = TransitionSlider(transitionContainer, 'slide-fade', 400, null, false);
|
2021-02-15 16:49:58 +01:00
|
|
|
|
|
|
|
|
|
transition(0);
|
|
|
|
|
|
|
|
|
|
attachClickEvent(this.closeBtn, (e) => {
|
|
|
|
|
if(this.closeBtn.firstElementChild.classList.contains('state-back')) {
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.scrollable.scrollIntoViewNew(this.scrollable.container.firstElementChild as HTMLElement, 'start');
|
2021-02-15 16:49:58 +01:00
|
|
|
|
transition(0);
|
2021-03-28 20:37:11 +02:00
|
|
|
|
animatedCloseIcon.classList.remove('state-back');
|
|
|
|
|
} else if(!this.scrollable.isHeavyAnimationInProgress) {
|
2021-03-10 15:08:28 +01:00
|
|
|
|
appSidebarRight.onCloseBtnClick();
|
2021-02-15 16:49:58 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-12 20:02:05 +01:00
|
|
|
|
attachClickEvent(this.editBtn, (e) => {
|
2021-03-13 04:03:59 +01:00
|
|
|
|
let tab: AppEditGroupTab | AppEditChannelTab | AppEditContactTab;
|
2021-03-12 20:02:05 +01:00
|
|
|
|
if(appPeersManager.isAnyGroup(this.peerId)) {
|
2021-03-12 23:43:18 +01:00
|
|
|
|
tab = new AppEditGroupTab(appSidebarRight);
|
2021-03-12 20:02:05 +01:00
|
|
|
|
} else if(this.peerId > 0) {
|
2021-03-13 04:03:59 +01:00
|
|
|
|
tab = new AppEditContactTab(appSidebarRight);
|
2021-03-12 20:02:05 +01:00
|
|
|
|
} else {
|
2021-03-13 04:03:59 +01:00
|
|
|
|
tab = new AppEditChannelTab(appSidebarRight);
|
2021-03-12 20:02:05 +01:00
|
|
|
|
}
|
2021-03-12 23:43:18 +01:00
|
|
|
|
|
|
|
|
|
if(tab) {
|
2021-03-17 14:05:32 +01:00
|
|
|
|
if(tab instanceof AppEditGroupTab) {
|
|
|
|
|
tab.chatId = -this.peerId;
|
|
|
|
|
} else {
|
|
|
|
|
tab.peerId = this.peerId;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 23:43:18 +01:00
|
|
|
|
tab.open();
|
|
|
|
|
}
|
2021-03-12 20:02:05 +01:00
|
|
|
|
});
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
//this.container.prepend(this.closeBtn.parentElement);
|
|
|
|
|
|
|
|
|
|
this.profileElements.notifications.checkboxField.input.addEventListener('change', (e) => {
|
|
|
|
|
if(!e.isTrusted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-15 16:49:58 +01:00
|
|
|
|
|
2020-09-24 01:37:22 +02:00
|
|
|
|
//let checked = this.profileElements.notificationsCheckbox.checked;
|
2020-12-11 03:06:16 +01:00
|
|
|
|
appMessagesManager.mutePeer(this.peerId);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 04:06:44 +01:00
|
|
|
|
rootScope.on('dialog_notify_settings', (dialog) => {
|
|
|
|
|
if(this.peerId === dialog.peerId) {
|
|
|
|
|
const muted = appNotificationsManager.isPeerLocalMuted(this.peerId, false);
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.notifications.checkboxField.checked = !muted;
|
2020-12-01 16:38:36 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rootScope.on('peer_typings', (e) => {
|
2021-01-08 10:55:37 +01:00
|
|
|
|
const {peerId} = e;
|
2020-12-01 16:38:36 +01:00
|
|
|
|
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(this.peerId === peerId) {
|
2020-12-01 16:38:36 +01:00
|
|
|
|
this.setPeerStatus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-13 03:22:42 +01:00
|
|
|
|
rootScope.on('peer_bio_edit', (peerId) => {
|
|
|
|
|
if(peerId === this.peerId) {
|
|
|
|
|
this.setBio(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-01 16:38:36 +01:00
|
|
|
|
rootScope.on('user_update', (e) => {
|
2021-01-08 10:55:37 +01:00
|
|
|
|
const userId = e;
|
2020-12-01 16:38:36 +01:00
|
|
|
|
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(this.peerId === userId) {
|
2020-12-01 16:38:36 +01:00
|
|
|
|
this.setPeerStatus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.setPeerStatusInterval = window.setInterval(this.setPeerStatus, 60e3);
|
|
|
|
|
|
2020-12-25 00:19:34 +01:00
|
|
|
|
this.searchSuper = new AppSearchSuper([{
|
|
|
|
|
inputFilter: 'inputMessagesFilterPhotoVideo',
|
2021-03-26 18:49:29 +01:00
|
|
|
|
name: 'SharedMediaTab2',
|
|
|
|
|
type: 'media'
|
2020-12-25 00:19:34 +01:00
|
|
|
|
}, {
|
|
|
|
|
inputFilter: 'inputMessagesFilterDocument',
|
2021-03-26 18:49:29 +01:00
|
|
|
|
name: 'SharedFilesTab2',
|
|
|
|
|
type: 'files'
|
2020-12-25 00:19:34 +01:00
|
|
|
|
}, {
|
|
|
|
|
inputFilter: 'inputMessagesFilterUrl',
|
2021-03-26 18:49:29 +01:00
|
|
|
|
name: 'SharedLinksTab2',
|
|
|
|
|
type: 'links'
|
2020-12-25 00:19:34 +01:00
|
|
|
|
}, {
|
|
|
|
|
inputFilter: 'inputMessagesFilterMusic',
|
2021-03-26 18:49:29 +01:00
|
|
|
|
name: 'SharedMusicTab2',
|
|
|
|
|
type: 'music'
|
2021-03-28 20:37:11 +02:00
|
|
|
|
}], this.scrollable/* , undefined, undefined, false */);
|
2020-12-25 00:19:34 +01:00
|
|
|
|
|
|
|
|
|
this.profileContentEl.append(this.searchSuper.container);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 16:38:36 +01:00
|
|
|
|
public setPeerStatus = (needClear = false) => {
|
2020-12-11 03:06:16 +01:00
|
|
|
|
if(!this.peerId) return;
|
2020-12-01 16:38:36 +01:00
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
const peerId = this.peerId;
|
2020-12-01 16:38:36 +01:00
|
|
|
|
if(needClear) {
|
2021-03-13 13:24:00 +01:00
|
|
|
|
this.profileElements.subtitle.innerHTML = ''; // ! HERE U CAN FIND WHITESPACE
|
2020-12-01 16:38:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
appImManager.getPeerStatus(this.peerId).then((subtitle) => {
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(peerId !== this.peerId) {
|
2020-12-01 16:38:36 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.subtitle.textContent = '';
|
|
|
|
|
this.profileElements.subtitle.append(subtitle || '');
|
2020-12-01 16:38:36 +01:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
public renderNewMessages(peerId: number, mids: number[]) {
|
2020-10-26 01:09:42 +01:00
|
|
|
|
if(this.init) return; // * not inited yet
|
2020-10-28 18:49:58 +01:00
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
if(!this.historiesStorage[peerId]) return;
|
2020-10-26 01:09:42 +01:00
|
|
|
|
|
2020-10-23 02:07:30 +02:00
|
|
|
|
mids = mids.slice().reverse(); // ! because it will be ascend sorted array
|
2020-12-25 00:19:34 +01:00
|
|
|
|
for(const type of this.searchSuper.types) {
|
|
|
|
|
const inputFilter = type.inputFilter;
|
2020-12-25 13:53:20 +01:00
|
|
|
|
const filtered = this.searchSuper.filterMessagesByType(mids.map(mid => appMessagesManager.getMessageByPeer(peerId, mid)), inputFilter);
|
2020-10-23 02:07:30 +02:00
|
|
|
|
if(filtered.length) {
|
2020-12-25 00:19:34 +01:00
|
|
|
|
if(this.historiesStorage[peerId][inputFilter]) {
|
2020-12-25 13:53:20 +01:00
|
|
|
|
this.historiesStorage[peerId][inputFilter].unshift(...filtered.map(message => ({mid: message.mid, peerId: message.peerId})));
|
2020-10-28 18:49:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(this.peerId === peerId && this.searchSuper.usedFromHistory[inputFilter] !== -1) {
|
2020-12-25 00:19:34 +01:00
|
|
|
|
this.searchSuper.usedFromHistory[inputFilter] += filtered.length;
|
|
|
|
|
this.searchSuper.performSearchResult(filtered, inputFilter, false);
|
2020-10-23 02:07:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
public deleteDeletedMessages(peerId: number, mids: number[]) {
|
2020-10-26 01:09:42 +01:00
|
|
|
|
if(this.init) return; // * not inited yet
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
if(!this.historiesStorage[peerId]) return;
|
2020-10-28 18:49:58 +01:00
|
|
|
|
|
2020-10-23 02:07:30 +02:00
|
|
|
|
for(const mid of mids) {
|
2020-12-25 00:19:34 +01:00
|
|
|
|
for(const type of this.searchSuper.types) {
|
|
|
|
|
const inputFilter = type.inputFilter;
|
|
|
|
|
|
|
|
|
|
if(!this.historiesStorage[peerId][inputFilter]) continue;
|
2020-10-23 02:07:30 +02:00
|
|
|
|
|
2020-12-25 00:19:34 +01:00
|
|
|
|
const history = this.historiesStorage[peerId][inputFilter];
|
2020-12-25 13:53:20 +01:00
|
|
|
|
const idx = history.findIndex(m => m.mid === mid);
|
2020-10-23 02:07:30 +02:00
|
|
|
|
if(idx !== -1) {
|
|
|
|
|
history.splice(idx, 1);
|
|
|
|
|
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(this.peerId === peerId) {
|
2020-12-25 00:19:34 +01:00
|
|
|
|
const container = this.searchSuper.tabs[inputFilter];
|
2020-12-25 13:53:20 +01:00
|
|
|
|
const div = container.querySelector(`div[data-mid="${mid}"][data-peer-id="${peerId}"]`);
|
2020-10-28 18:49:58 +01:00
|
|
|
|
if(div) {
|
|
|
|
|
div.remove();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-25 00:19:34 +01:00
|
|
|
|
if(this.searchSuper.usedFromHistory[inputFilter] >= (idx + 1)) {
|
|
|
|
|
this.searchSuper.usedFromHistory[inputFilter]--;
|
2020-10-23 02:07:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-23 02:43:19 +02:00
|
|
|
|
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.scrollable.onScroll();
|
2020-10-23 02:07:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 01:37:22 +02:00
|
|
|
|
public cleanupHTML() {
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.bio.container.style.display = 'none';
|
|
|
|
|
this.profileElements.phone.container.style.display = 'none';
|
|
|
|
|
this.profileElements.username.container.style.display = 'none';
|
|
|
|
|
this.profileElements.notifications.container.style.display = '';
|
|
|
|
|
this.profileElements.notifications.checkboxField.checked = true;
|
2021-03-12 20:02:05 +01:00
|
|
|
|
this.editBtn.style.display = 'none';
|
2021-03-13 03:22:42 +01:00
|
|
|
|
if(this.setBioTimeout) {
|
|
|
|
|
window.clearTimeout(this.setBioTimeout);
|
|
|
|
|
this.setBioTimeout = 0;
|
|
|
|
|
}
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
2020-12-25 00:19:34 +01:00
|
|
|
|
this.searchSuper.cleanupHTML();
|
2020-12-25 13:53:20 +01:00
|
|
|
|
this.searchSuper.selectTab(0, false);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setLoadMutex(promise: Promise<any>) {
|
2020-12-25 00:19:34 +01:00
|
|
|
|
this.searchSuper.loadMutex = promise;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 03:18:24 +01:00
|
|
|
|
public setPeer(peerId: number, threadId = 0) {
|
|
|
|
|
if(this.peerId === peerId && this.threadId === peerId) return;
|
2020-12-08 20:48:44 +01:00
|
|
|
|
|
2020-09-24 01:37:22 +02:00
|
|
|
|
if(this.init) {
|
|
|
|
|
this.init();
|
|
|
|
|
this.init = null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
this.peerId = peerId;
|
2020-12-23 03:18:24 +01:00
|
|
|
|
this.threadId = threadId;
|
2020-12-25 13:53:20 +01:00
|
|
|
|
this.searchSuper.setQuery({
|
|
|
|
|
peerId,
|
|
|
|
|
//threadId,
|
|
|
|
|
historyStorage: this.historiesStorage[peerId] ?? (this.historiesStorage[peerId] = {})
|
|
|
|
|
});
|
2020-12-25 00:19:34 +01:00
|
|
|
|
this.cleaned = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public loadSidebarMedia(single: boolean) {
|
|
|
|
|
this.searchSuper.load(single);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fillProfileElements() {
|
2020-12-08 20:48:44 +01:00
|
|
|
|
if(!this.cleaned) return;
|
|
|
|
|
this.cleaned = false;
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
const peerId = this.peerId;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
|
|
|
|
this.cleanupHTML();
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
this.profileElements.avatar.setAttribute('peer', '' + peerId);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
|
|
|
|
|
// username
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(peerId !== rootScope.myId) {
|
2020-12-11 03:06:16 +01:00
|
|
|
|
let username = appPeersManager.getPeerUsername(peerId);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
if(username) {
|
2020-12-11 03:06:16 +01:00
|
|
|
|
setText(appPeersManager.getPeerUsername(peerId), this.profileElements.username);
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 04:06:44 +01:00
|
|
|
|
const muted = appNotificationsManager.isPeerLocalMuted(peerId, false);
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.notifications.checkboxField.checked = !muted;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
} else {
|
|
|
|
|
window.requestAnimationFrame(() => {
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.profileElements.notifications.container.style.display = 'none';
|
2020-09-24 01:37:22 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//let membersLi = this.profileTabs.firstElementChild.children[0] as HTMLLIElement;
|
2020-12-11 03:06:16 +01:00
|
|
|
|
if(peerId > 0) {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
//membersLi.style.display = 'none';
|
|
|
|
|
|
2020-12-11 03:06:16 +01:00
|
|
|
|
let user = appUsersManager.getUser(peerId);
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(user.phone && peerId !== rootScope.myId) {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
setText(user.rPhone, this.profileElements.phone);
|
|
|
|
|
}
|
2021-03-13 03:22:42 +01:00
|
|
|
|
}/* else {
|
|
|
|
|
//membersLi.style.display = appPeersManager.isBroadcast(peerId) ? 'none' : '';
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
this.setBio();
|
|
|
|
|
|
|
|
|
|
this.profileElements.name.innerHTML = '';
|
|
|
|
|
this.profileElements.name.append(new PeerTitle({
|
|
|
|
|
peerId,
|
|
|
|
|
dialog: true
|
|
|
|
|
}).element);
|
|
|
|
|
|
2021-03-13 13:24:00 +01:00
|
|
|
|
if(peerId > 0) {
|
|
|
|
|
if(peerId !== rootScope.myId && appUsersManager.isContact(peerId)) {
|
|
|
|
|
this.editBtn.style.display = '';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const chat: Chat = appChatsManager.getChat(-peerId);
|
|
|
|
|
if(chat._ === 'chat' || (chat as Chat.channel).admin_rights) {
|
|
|
|
|
this.editBtn.style.display = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-13 03:22:42 +01:00
|
|
|
|
|
|
|
|
|
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 => {
|
2020-12-23 03:18:24 +01:00
|
|
|
|
if(this.peerId !== peerId || this.threadId !== threadId) {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
this.log.warn('peer changed');
|
2021-03-13 03:22:42 +01:00
|
|
|
|
return false;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 01:30:23 +01:00
|
|
|
|
if(userFull.rAbout && peerId !== rootScope.myId) {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
setText(userFull.rAbout, this.profileElements.bio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//this.log('userFull', userFull);
|
2021-03-13 03:22:42 +01:00
|
|
|
|
return true;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2021-03-13 03:22:42 +01:00
|
|
|
|
promise = appProfileManager.getChatFull(-peerId, override).then((chatFull) => {
|
2020-12-23 03:18:24 +01:00
|
|
|
|
if(this.peerId !== peerId || this.threadId !== threadId) {
|
2020-09-24 01:37:22 +02:00
|
|
|
|
this.log.warn('peer changed');
|
2021-03-13 03:22:42 +01:00
|
|
|
|
return false;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//this.log('chatInfo res 2:', chatFull);
|
|
|
|
|
|
|
|
|
|
if(chatFull.about) {
|
|
|
|
|
setText(RichTextProcessor.wrapRichText(chatFull.about), this.profileElements.bio);
|
|
|
|
|
}
|
2021-03-13 03:22:42 +01:00
|
|
|
|
|
|
|
|
|
return true;
|
2020-09-24 01:37:22 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2020-12-01 16:38:36 +01:00
|
|
|
|
|
2021-03-13 03:22:42 +01:00
|
|
|
|
promise.then((canSetNext) => {
|
|
|
|
|
if(canSetNext) {
|
|
|
|
|
this.setBioTimeout = window.setTimeout(() => this.setBio(true), 60e3);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpenAfterTimeout() {
|
2021-03-28 20:37:11 +02:00
|
|
|
|
this.scrollable.onScroll();
|
2020-09-24 01:37:22 +02:00
|
|
|
|
}
|
2021-03-10 15:08:28 +01:00
|
|
|
|
}
|