Browse Source

Networker connection status

master
Eduard Kuzmenko 4 years ago
parent
commit
d9b1b31108
  1. 6
      src/components/animationIntersector.ts
  2. 6
      src/components/appMediaPlaybackController.ts
  3. 8
      src/components/appMediaViewer.ts
  4. 10
      src/components/appSearch.ts
  5. 14
      src/components/appSelectPeers.ts
  6. 6
      src/components/audio.ts
  7. 4
      src/components/avatar.ts
  8. 4
      src/components/bubbleGroups.ts
  9. 6
      src/components/chat/audio.ts
  10. 10
      src/components/chat/contextMenu.ts
  11. 18
      src/components/chat/input.ts
  12. 4
      src/components/chat/search.ts
  13. 6
      src/components/dialogsContextMenu.ts
  14. 6
      src/components/emoticonsDropdown/index.ts
  15. 6
      src/components/emoticonsDropdown/tabs/stickers.ts
  16. 6
      src/components/poll.ts
  17. 6
      src/components/popup.ts
  18. 6
      src/components/popupCreatePoll.ts
  19. 8
      src/components/popupDeleteMessages.ts
  20. 11
      src/components/sidebarLeft/index.ts
  21. 10
      src/components/sidebarLeft/tabs/chatFolders.ts
  22. 6
      src/components/sidebarLeft/tabs/contacts.ts
  23. 4
      src/components/sidebarLeft/tabs/editProfile.ts
  24. 4
      src/components/sidebarLeft/tabs/includedChats.ts
  25. 4
      src/components/sidebarLeft/tabs/settings.ts
  26. 16
      src/components/sidebarRight/tabs/sharedMedia.ts
  27. 6
      src/lib/appManagers/AppInlineBotsManager.ts
  28. 16
      src/lib/appManagers/apiUpdatesManager.ts
  29. 10
      src/lib/appManagers/appChatsManager.ts
  30. 96
      src/lib/appManagers/appDialogsManager.ts
  31. 4
      src/lib/appManagers/appDownloadManager.ts
  32. 46
      src/lib/appManagers/appImManager.ts
  33. 114
      src/lib/appManagers/appMessagesManager.ts
  34. 6
      src/lib/appManagers/appPeersManager.ts
  35. 6
      src/lib/appManagers/appPollsManager.ts
  36. 4
      src/lib/appManagers/appStateManager.ts
  37. 10
      src/lib/appManagers/appStickersManager.ts
  38. 26
      src/lib/appManagers/appUsersManager.ts
  39. 6
      src/lib/appManagers/appWebPagesManager.ts
  40. 8
      src/lib/mtproto/apiManager.ts
  41. 4
      src/lib/mtproto/mtproto.worker.ts
  42. 8
      src/lib/mtproto/mtprotoworker.ts
  43. 95
      src/lib/mtproto/networker.ts
  44. 3
      src/lib/mtproto/networkerFactory.ts
  45. 14
      src/lib/mtproto/transports/websocket.ts
  46. 54
      src/lib/rootScope.ts
  47. 14
      src/lib/storages/filters.ts
  48. 73
      src/scss/partials/_leftSidebar.scss
  49. 4
      src/scss/style.scss
  50. 10
      src/types.d.ts

6
src/components/animationIntersector.ts

@ -1,7 +1,7 @@
import { isInDOM } from "../helpers/dom"; import { isInDOM } from "../helpers/dom";
import { RLottiePlayer } from "../lib/lottieLoader"; import { RLottiePlayer } from "../lib/lottieLoader";
import { MOUNT_CLASS_TO } from "../lib/mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../lib/mtproto/mtproto_config";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { isSafari } from "../helpers/userAgent"; import { isSafari } from "../helpers/userAgent";
export interface AnimationItem { export interface AnimationItem {
@ -22,7 +22,7 @@ export class AnimationIntersector {
constructor() { constructor() {
this.observer = new IntersectionObserver((entries) => { this.observer = new IntersectionObserver((entries) => {
if($rootScope.idle.isIDLE) return; if(rootScope.idle.isIDLE) return;
for(const entry of entries) { for(const entry of entries) {
const target = entry.target; const target = entry.target;
@ -99,7 +99,7 @@ export class AnimationIntersector {
} }
public checkAnimations(blurred?: boolean, group?: string, destroy = false) { public checkAnimations(blurred?: boolean, group?: string, destroy = false) {
if($rootScope.idle.isIDLE) return; if(rootScope.idle.isIDLE) return;
const groups = group /* && false */ ? [group] : Object.keys(this.byGroups); const groups = group /* && false */ ? [group] : Object.keys(this.byGroups);

6
src/components/appMediaPlaybackController.ts

@ -1,4 +1,4 @@
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import appDocsManager, {MyDocument} from "../lib/appManagers/appDocsManager"; import appDocsManager, {MyDocument} from "../lib/appManagers/appDocsManager";
import { CancellablePromise, deferredPromise } from "../helpers/cancellablePromise"; import { CancellablePromise, deferredPromise } from "../helpers/cancellablePromise";
@ -66,7 +66,7 @@ class AppMediaPlaybackController {
// audio_pause не успеет сработать без таймаута // audio_pause не успеет сработать без таймаута
setTimeout(() => { setTimeout(() => {
$rootScope.$broadcast('audio_play', {doc, mid}); rootScope.broadcast('audio_play', {doc, mid});
}, 0); }, 0);
}); });
@ -158,7 +158,7 @@ class AppMediaPlaybackController {
} }
onPause = (e: Event) => { onPause = (e: Event) => {
$rootScope.$broadcast('audio_pause'); rootScope.broadcast('audio_pause');
}; };
onEnded = (e: Event) => { onEnded = (e: Event) => {

8
src/components/appMediaViewer.ts

@ -10,7 +10,7 @@ import appPhotosManager from "../lib/appManagers/appPhotosManager";
import { logger } from "../lib/logger"; import { logger } from "../lib/logger";
import VideoPlayer from "../lib/mediaPlayer"; import VideoPlayer from "../lib/mediaPlayer";
import { RichTextProcessor } from "../lib/richtextprocessor"; import { RichTextProcessor } from "../lib/richtextprocessor";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent, fillPropertyValue, findUpClassName, generatePathData } from "../helpers/dom"; import { cancelEvent, fillPropertyValue, findUpClassName, generatePathData } from "../helpers/dom";
import animationIntersector from "./animationIntersector"; import animationIntersector from "./animationIntersector";
import appMediaPlaybackController from "./appMediaPlaybackController"; import appMediaPlaybackController from "./appMediaPlaybackController";
@ -253,7 +253,7 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
promise.finally(() => { promise.finally(() => {
this.wholeDiv.remove(); this.wholeDiv.remove();
$rootScope.overlayIsActive = false; rootScope.overlayIsActive = false;
animationIntersector.checkAnimations(false); animationIntersector.checkAnimations(false);
}); });
@ -868,7 +868,7 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
this.pageEl.insertBefore(this.wholeDiv, mainColumns); this.pageEl.insertBefore(this.wholeDiv, mainColumns);
void this.wholeDiv.offsetLeft; // reflow void this.wholeDiv.offsetLeft; // reflow
this.wholeDiv.classList.add('active'); this.wholeDiv.classList.add('active');
$rootScope.overlayIsActive = true; rootScope.overlayIsActive = true;
animationIntersector.checkAnimations(true); animationIntersector.checkAnimations(true);
} }
@ -1324,7 +1324,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
else fromRight = this.currentMessageID > mid ? 1 : -1; else fromRight = this.currentMessageID > mid ? 1 : -1;
} else { } else {
this.reverse = reverse; this.reverse = reverse;
this.peerID = $rootScope.selectedPeerID; this.peerID = rootScope.selectedPeerID;
} }
this.currentMessageID = mid; this.currentMessageID = mid;

10
src/components/appSearch.ts

@ -8,7 +8,7 @@ import { formatPhoneNumber } from "./misc";
import appChatsManager from "../lib/appManagers/appChatsManager"; import appChatsManager from "../lib/appManagers/appChatsManager";
import SearchInput from "./searchInput"; import SearchInput from "./searchInput";
import { Peer } from "../layer"; import { Peer } from "../layer";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { escapeRegExp } from "../helpers/string"; import { escapeRegExp } from "../helpers/string";
export class SearchGroup { export class SearchGroup {
@ -137,7 +137,7 @@ export default class AppSearch {
private renderSaved() { private renderSaved() {
const group = this.searchGroups.contacts; const group = this.searchGroups.contacts;
let {dialog, dom} = appDialogsManager.addDialog($rootScope.myID, group.list, false); let {dialog, dom} = appDialogsManager.addDialog(rootScope.myID, group.list, false);
dom.lastMessageSpan.innerHTML = 'chat with yourself'; dom.lastMessageSpan.innerHTML = 'chat with yourself';
group.setActive(); group.setActive();
} }
@ -161,7 +161,7 @@ export default class AppSearch {
if(!this.peerID && !maxID && !this.loadedContacts) { if(!this.peerID && !maxID && !this.loadedContacts) {
let renderedSaved = false; let renderedSaved = false;
if('saved messages'.includes(query.toLowerCase()) if('saved messages'.includes(query.toLowerCase())
|| appUsersManager.getUser($rootScope.myID).sortName.includes(query.toLowerCase())/* && this.searchGroups.hasOwnProperty('saved') */) { || appUsersManager.getUser(rootScope.myID).sortName.includes(query.toLowerCase())/* && this.searchGroups.hasOwnProperty('saved') */) {
this.renderSaved(); this.renderSaved();
renderedSaved = true; renderedSaved = true;
} }
@ -174,7 +174,7 @@ export default class AppSearch {
this.loadedContacts = true; this.loadedContacts = true;
// set saved message as first peer to render // set saved message as first peer to render
const peer = contacts.my_results.findAndSplice(p => (p as Peer.peerUser).user_id == $rootScope.myID); const peer = contacts.my_results.findAndSplice(p => (p as Peer.peerUser).user_id == rootScope.myID);
if(peer) { if(peer) {
contacts.my_results.unshift(peer); contacts.my_results.unshift(peer);
} }
@ -184,7 +184,7 @@ export default class AppSearch {
let setResults = (results: Peer[], group: SearchGroup, showMembersCount = false) => { let setResults = (results: Peer[], group: SearchGroup, showMembersCount = false) => {
// ! because contacts.search returns duplicates in my_results // ! because contacts.search returns duplicates in my_results
new Set(results.map(peer => appPeersManager.getPeerID(peer))).forEach((peerID) => { new Set(results.map(peer => appPeersManager.getPeerID(peer))).forEach((peerID) => {
if(peerID == $rootScope.myID) { if(peerID == rootScope.myID) {
if(!renderedSaved) { if(!renderedSaved) {
this.renderSaved(); this.renderSaved();
} }

14
src/components/appSelectPeers.ts

@ -4,7 +4,7 @@ import appMessagesManager, { Dialog } from "../lib/appManagers/appMessagesManage
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import appPhotosManager from "../lib/appManagers/appPhotosManager"; import appPhotosManager from "../lib/appManagers/appPhotosManager";
import appUsersManager from "../lib/appManagers/appUsersManager"; import appUsersManager from "../lib/appManagers/appUsersManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent, findUpAttribute, findUpClassName } from "../helpers/dom"; import { cancelEvent, findUpAttribute, findUpClassName } from "../helpers/dom";
import Scrollable from "./scrollable"; import Scrollable from "./scrollable";
@ -168,9 +168,9 @@ export default class AppSelectPeers {
if(!this.offsetIndex && this.folderID == 0 && if(!this.offsetIndex && this.folderID == 0 &&
(!this.query (!this.query
|| 'saved messages'.includes(this.query.toLowerCase()) || 'saved messages'.includes(this.query.toLowerCase())
|| appUsersManager.getUser($rootScope.myID).sortName.includes(this.query.toLowerCase())) && || appUsersManager.getUser(rootScope.myID).sortName.includes(this.query.toLowerCase())) &&
this.peerType.includes('dialogs')) { this.peerType.includes('dialogs')) {
this.renderResultsFunc([$rootScope.myID]); this.renderResultsFunc([rootScope.myID]);
} }
} }
@ -193,7 +193,7 @@ export default class AppSelectPeers {
const newOffsetIndex = dialogs[dialogs.length - 1].index || 0; const newOffsetIndex = dialogs[dialogs.length - 1].index || 0;
dialogs = dialogs.slice(); dialogs = dialogs.slice();
dialogs.findAndSplice(d => d.peerID == $rootScope.myID); // no my account dialogs.findAndSplice(d => d.peerID == rootScope.myID); // no my account
if(this.chatRightsAction) { if(this.chatRightsAction) {
dialogs = dialogs.filter(d => { dialogs = dialogs.filter(d => {
@ -242,7 +242,7 @@ export default class AppSelectPeers {
this.cachedContacts = (await this.promise)[0].slice(); */ this.cachedContacts = (await this.promise)[0].slice(); */
this.promise = appUsersManager.getContacts(this.query); this.promise = appUsersManager.getContacts(this.query);
this.cachedContacts = (await this.promise).slice(); this.cachedContacts = (await this.promise).slice();
this.cachedContacts.findAndSplice(userID => userID == $rootScope.myID); // no my account this.cachedContacts.findAndSplice(userID => userID == rootScope.myID); // no my account
this.promise = null; this.promise = null;
} }
@ -327,7 +327,7 @@ export default class AppSelectPeers {
let subtitle = ''; let subtitle = '';
if(peerID < 0) { if(peerID < 0) {
subtitle = appChatsManager.getChatMembersString(-peerID); subtitle = appChatsManager.getChatMembersString(-peerID);
} else if(peerID == $rootScope.myID) { } else if(peerID == rootScope.myID) {
subtitle = 'chat with yourself'; subtitle = 'chat with yourself';
} else { } else {
subtitle = appUsersManager.getUserStatusString(peerID); subtitle = appUsersManager.getUserStatusString(peerID);
@ -359,7 +359,7 @@ export default class AppSelectPeers {
div.dataset.key = '' + peerID; div.dataset.key = '' + peerID;
if(typeof(peerID) === 'number') { if(typeof(peerID) === 'number') {
if(title === undefined) { if(title === undefined) {
title = peerID == $rootScope.myID ? 'Saved' : appPeersManager.getPeerTitle(peerID, false, true); title = peerID == rootScope.myID ? 'Saved' : appPeersManager.getPeerTitle(peerID, false, true);
} }
avatarEl.setAttribute('peer', '' + peerID); avatarEl.setAttribute('peer', '' + peerID);

6
src/components/audio.ts

@ -9,10 +9,10 @@ import { Download } from "../lib/appManagers/appDownloadManager";
import mediaSizes from "../helpers/mediaSizes"; import mediaSizes from "../helpers/mediaSizes";
import { isSafari } from "../helpers/userAgent"; import { isSafari } from "../helpers/userAgent";
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import './middleEllipsis'; import './middleEllipsis';
$rootScope.$on('messages_media_read', e => { rootScope.on('messages_media_read', e => {
const mids = e.detail; const mids = e.detail;
mids.forEach(mid => { mids.forEach(mid => {
@ -64,7 +64,7 @@ function wrapVoiceMessage(doc: MyDocument, audioEl: AudioElement, mid: number) {
audioEl.classList.add('is-voice'); audioEl.classList.add('is-voice');
const message = appMessagesManager.getMessage(mid); const message = appMessagesManager.getMessage(mid);
const isOut = message.fromID == $rootScope.myID && message.peerID != $rootScope.myID; const isOut = message.fromID == rootScope.myID && message.peerID != rootScope.myID;
let isUnread = message && message.pFlags.media_unread; let isUnread = message && message.pFlags.media_unread;
if(isUnread) { if(isUnread) {
audioEl.classList.add('is-unread'); audioEl.classList.add('is-unread');

4
src/components/avatar.ts

@ -1,10 +1,10 @@
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import appProfileManager from "../lib/appManagers/appProfileManager"; import appProfileManager from "../lib/appManagers/appProfileManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent } from "../helpers/dom"; import { cancelEvent } from "../helpers/dom";
import AppMediaViewer, { AppMediaViewerAvatar } from "./appMediaViewer"; import AppMediaViewer, { AppMediaViewerAvatar } from "./appMediaViewer";
$rootScope.$on('avatar_update', (e) => { rootScope.on('avatar_update', (e) => {
let peerID = e.detail; let peerID = e.detail;
appProfileManager.removeFromAvatarsCache(peerID); appProfileManager.removeFromAvatarsCache(peerID);

4
src/components/bubbleGroups.ts

@ -1,4 +1,4 @@
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { generatePathData } from "../helpers/dom"; import { generatePathData } from "../helpers/dom";
export default class BubbleGroups { export default class BubbleGroups {
@ -25,7 +25,7 @@ export default class BubbleGroups {
let group: HTMLDivElement[]; let group: HTMLDivElement[];
// fix for saved messages forward to self // fix for saved messages forward to self
if(fromID == $rootScope.myID && $rootScope.selectedPeerID == $rootScope.myID && message.fwdFromID == fromID) { if(fromID == rootScope.myID && rootScope.selectedPeerID == rootScope.myID && message.fwdFromID == fromID) {
fromID = -fromID; fromID = -fromID;
} }

6
src/components/chat/audio.ts

@ -1,7 +1,7 @@
import appMessagesManager from "../../lib/appManagers/appMessagesManager"; import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import appPeersManager from "../../lib/appManagers/appPeersManager"; import appPeersManager from "../../lib/appManagers/appPeersManager";
import { RichTextProcessor } from "../../lib/richtextprocessor"; import { RichTextProcessor } from "../../lib/richtextprocessor";
import $rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { cancelEvent } from "../../helpers/dom"; import { cancelEvent } from "../../helpers/dom";
import appMediaPlaybackController from "../appMediaPlaybackController"; import appMediaPlaybackController from "../appMediaPlaybackController";
import DivAndCaption from "../divAndCaption"; import DivAndCaption from "../divAndCaption";
@ -32,7 +32,7 @@ export class ChatAudio extends PinnedContainer {
this.wrapper.prepend(this.toggleEl); this.wrapper.prepend(this.toggleEl);
$rootScope.$on('audio_play', (e) => { rootScope.on('audio_play', (e) => {
const {doc, mid} = e.detail; const {doc, mid} = e.detail;
let title: string, subtitle: string; let title: string, subtitle: string;
@ -51,7 +51,7 @@ export class ChatAudio extends PinnedContainer {
this.toggle(false); this.toggle(false);
}); });
$rootScope.$on('audio_pause', () => { rootScope.on('audio_pause', () => {
this.toggleEl.classList.remove('flip-icon'); this.toggleEl.classList.remove('flip-icon');
}); });
} }

10
src/components/chat/contextMenu.ts

@ -4,7 +4,7 @@ import appImManager from "../../lib/appManagers/appImManager";
import appMessagesManager from "../../lib/appManagers/appMessagesManager"; import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import appPeersManager from "../../lib/appManagers/appPeersManager"; import appPeersManager from "../../lib/appManagers/appPeersManager";
import appPollsManager, { Poll } from "../../lib/appManagers/appPollsManager"; import appPollsManager, { Poll } from "../../lib/appManagers/appPollsManager";
import $rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { cancelEvent, cancelSelection, findUpClassName } from "../../helpers/dom"; import { cancelEvent, cancelSelection, findUpClassName } from "../../helpers/dom";
import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu"; import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu";
import { attachContextMenuListener, openBtnMenu, positionMenu } from "../misc"; import { attachContextMenuListener, openBtnMenu, positionMenu } from "../misc";
@ -58,7 +58,7 @@ export default class ChatContextMenu {
} }
} }
this.peerID = $rootScope.selectedPeerID; this.peerID = rootScope.selectedPeerID;
//this.msgID = msgID; //this.msgID = msgID;
this.target = e.target as HTMLElement; this.target = e.target as HTMLElement;
@ -152,7 +152,7 @@ export default class ChatContextMenu {
const message = appMessagesManager.getMessage(this.msgID); const message = appMessagesManager.getMessage(this.msgID);
// for new layer // for new layer
// return this.msgID > 0 && message._ != 'messageService' && appImManager.pinnedMsgID != this.msgID && (this.peerID > 0 || appChatsManager.hasRights(-this.peerID, 'pin')); // return this.msgID > 0 && message._ != 'messageService' && appImManager.pinnedMsgID != this.msgID && (this.peerID > 0 || appChatsManager.hasRights(-this.peerID, 'pin'));
return this.msgID > 0 && message._ != 'messageService' && appImManager.pinnedMsgID != this.msgID && (this.peerID == $rootScope.myID || (this.peerID < 0 && appChatsManager.hasRights(-this.peerID, 'pin'))); return this.msgID > 0 && message._ != 'messageService' && appImManager.pinnedMsgID != this.msgID && (this.peerID == rootScope.myID || (this.peerID < 0 && appChatsManager.hasRights(-this.peerID, 'pin')));
} }
}, { }, {
icon: 'unpin', icon: 'unpin',
@ -263,11 +263,11 @@ export default class ChatContextMenu {
}; };
private onPinClick = () => { private onPinClick = () => {
new PopupPinMessage($rootScope.selectedPeerID, this.msgID); new PopupPinMessage(rootScope.selectedPeerID, this.msgID);
}; };
private onUnpinClick = () => { private onUnpinClick = () => {
new PopupPinMessage($rootScope.selectedPeerID, 0); new PopupPinMessage(rootScope.selectedPeerID, 0);
}; };
private onRetractVote = () => { private onRetractVote = () => {

18
src/components/chat/input.ts

@ -10,7 +10,7 @@ import apiManager from "../../lib/mtproto/mtprotoworker";
//import Recorder from '../opus-recorder/dist/recorder.min'; //import Recorder from '../opus-recorder/dist/recorder.min';
import opusDecodeController from "../../lib/opusDecodeController"; import opusDecodeController from "../../lib/opusDecodeController";
import { RichTextProcessor } from "../../lib/richtextprocessor"; import { RichTextProcessor } from "../../lib/richtextprocessor";
import $rootScope from '../../lib/rootScope'; import rootScope from '../../lib/rootScope';
import { cancelEvent, findUpClassName, getRichValue, isInputEmpty, serializeNodes } from "../../helpers/dom"; import { cancelEvent, findUpClassName, getRichValue, isInputEmpty, serializeNodes } from "../../helpers/dom";
import ButtonMenu, { ButtonMenuItemOptions } from '../buttonMenu'; import ButtonMenu, { ButtonMenuItemOptions } from '../buttonMenu';
import emoticonsDropdown from "../emoticonsDropdown"; import emoticonsDropdown from "../emoticonsDropdown";
@ -151,7 +151,7 @@ export class ChatInput {
this.updateSendBtn(); this.updateSendBtn();
$rootScope.$on('peer_changed', (e) => { rootScope.on('peer_changed', (e) => {
const peerID = e.detail; const peerID = e.detail;
const visible = this.attachMenuButtons.filter(button => { const visible = this.attachMenuButtons.filter(button => {
@ -249,12 +249,12 @@ export class ChatInput {
if(!value.trim() && !serializeNodes(Array.from(this.messageInput.childNodes)).trim()) { if(!value.trim() && !serializeNodes(Array.from(this.messageInput.childNodes)).trim()) {
this.messageInput.innerHTML = ''; this.messageInput.innerHTML = '';
appMessagesManager.setTyping($rootScope.selectedPeerID, 'sendMessageCancelAction'); appMessagesManager.setTyping(rootScope.selectedPeerID, 'sendMessageCancelAction');
} else { } else {
const time = Date.now(); const time = Date.now();
if(time - this.lastTimeType >= 6000) { if(time - this.lastTimeType >= 6000) {
this.lastTimeType = time; this.lastTimeType = time;
appMessagesManager.setTyping($rootScope.selectedPeerID, 'sendMessageTypingAction'); appMessagesManager.setTyping(rootScope.selectedPeerID, 'sendMessageTypingAction');
} }
} }
@ -299,8 +299,8 @@ export class ChatInput {
}, false); }, false);
document.addEventListener('paste', (e) => { document.addEventListener('paste', (e) => {
const peerID = $rootScope.selectedPeerID; const peerID = rootScope.selectedPeerID;
if(!peerID || $rootScope.overlayIsActive || (peerID < 0 && !appChatsManager.hasRights(peerID, 'send', 'send_media'))) { if(!peerID || rootScope.overlayIsActive || (peerID < 0 && !appChatsManager.hasRights(peerID, 'send', 'send_media'))) {
return; return;
} }
@ -341,7 +341,7 @@ export class ChatInput {
this.sendMessage(); this.sendMessage();
} }
} else { } else {
if($rootScope.selectedPeerID < 0 && !appChatsManager.hasRights($rootScope.selectedPeerID, 'send', 'send_media')) { if(rootScope.selectedPeerID < 0 && !appChatsManager.hasRights(rootScope.selectedPeerID, 'send', 'send_media')) {
toast(POSTING_MEDIA_NOT_ALLOWED); toast(POSTING_MEDIA_NOT_ALLOWED);
return; return;
} }
@ -544,9 +544,9 @@ export class ChatInput {
} }
}); });
} else if(this.helperType == 'reply') { } else if(this.helperType == 'reply') {
appImManager.setPeer($rootScope.selectedPeerID, this.replyToMsgID); appImManager.setPeer(rootScope.selectedPeerID, this.replyToMsgID);
} else if(this.helperType == 'edit') { } else if(this.helperType == 'edit') {
appImManager.setPeer($rootScope.selectedPeerID, this.editMsgID); appImManager.setPeer(rootScope.selectedPeerID, this.editMsgID);
} }
}); });
} }

4
src/components/chat/search.ts

@ -1,5 +1,5 @@
import appImManager from "../../lib/appManagers/appImManager"; import appImManager from "../../lib/appManagers/appImManager";
import $rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { cancelEvent, whichChild, findUpTag } from "../../helpers/dom"; import { cancelEvent, whichChild, findUpTag } from "../../helpers/dom";
import AppSearch, { SearchGroup } from "../appSearch"; import AppSearch, { SearchGroup } from "../appSearch";
import PopupDatePicker from "../popupDatepicker"; import PopupDatePicker from "../popupDatepicker";
@ -73,7 +73,7 @@ export class ChatSearch {
this.selectResult(this.searchGroup.list.children[0] as HTMLElement); this.selectResult(this.searchGroup.list.children[0] as HTMLElement);
} }
}); });
this.appSearch.beginSearch($rootScope.selectedPeerID); this.appSearch.beginSearch(rootScope.selectedPeerID);
//appImManager.topbar.parentElement.insertBefore(this.results, appImManager.bubblesContainer); //appImManager.topbar.parentElement.insertBefore(this.results, appImManager.bubblesContainer);
appImManager.bubblesContainer.append(this.results); appImManager.bubblesContainer.append(this.results);

6
src/components/dialogsContextMenu.ts

@ -3,7 +3,7 @@ import appDialogsManager from "../lib/appManagers/appDialogsManager";
import appImManager from "../lib/appManagers/appImManager"; import appImManager from "../lib/appManagers/appImManager";
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { findUpTag } from "../helpers/dom"; import { findUpTag } from "../helpers/dom";
import { parseMenuButtonsTo, positionMenu, openBtnMenu } from "./misc"; import { parseMenuButtonsTo, positionMenu, openBtnMenu } from "./misc";
import { PopupButton } from "./popup"; import { PopupButton } from "./popup";
@ -166,7 +166,7 @@ export default class DialogsContextMenu {
this.selectedID = +li.getAttribute('data-peerID'); this.selectedID = +li.getAttribute('data-peerID');
const dialog = appMessagesManager.getDialogByPeerID(this.selectedID)[0]; const dialog = appMessagesManager.getDialogByPeerID(this.selectedID)[0];
const notOurDialog = dialog.peerID != $rootScope.myID; const notOurDialog = dialog.peerID != rootScope.myID;
// archive button // archive button
if(notOurDialog) { if(notOurDialog) {
@ -231,7 +231,7 @@ export default class DialogsContextMenu {
} else { } else {
deleteButtonText = 'Delete'; deleteButtonText = 'Delete';
//deleteButtonText = 'Delete chat'; //deleteButtonText = 'Delete chat';
this.peerType = this.selectedID == $rootScope.myID ? 'saved' : 'chat'; this.peerType = this.selectedID == rootScope.myID ? 'saved' : 'chat';
} }
(this.buttons.delete.firstElementChild as HTMLElement).innerText = deleteButtonText; (this.buttons.delete.firstElementChild as HTMLElement).innerText = deleteButtonText;

6
src/components/emoticonsDropdown/index.ts

@ -2,7 +2,7 @@ import { isTouchSupported } from "../../helpers/touchSupport";
import appChatsManager from "../../lib/appManagers/appChatsManager"; import appChatsManager from "../../lib/appManagers/appChatsManager";
import appImManager from "../../lib/appManagers/appImManager"; import appImManager from "../../lib/appManagers/appImManager";
import { MOUNT_CLASS_TO } from "../../lib/mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../../lib/mtproto/mtproto_config";
import $rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { findUpClassName, findUpTag, whichChild } from "../../helpers/dom"; import { findUpClassName, findUpTag, whichChild } from "../../helpers/dom";
import animationIntersector from "../animationIntersector"; import animationIntersector from "../animationIntersector";
import { horizontalMenu } from "../horizontalMenu"; import { horizontalMenu } from "../horizontalMenu";
@ -157,7 +157,7 @@ export class EmoticonsDropdown {
(this.tabsEl.children[1] as HTMLLIElement).click(); // set emoji tab (this.tabsEl.children[1] as HTMLLIElement).click(); // set emoji tab
this.tabs[0].init(); // onTransitionEnd не вызовется, т.к. это первая открытая вкладка this.tabs[0].init(); // onTransitionEnd не вызовется, т.к. это первая открытая вкладка
$rootScope.$on('peer_changed', this.checkRights); rootScope.on('peer_changed', this.checkRights);
this.checkRights(); this.checkRights();
} }
@ -174,7 +174,7 @@ export class EmoticonsDropdown {
}; };
public checkRights = () => { public checkRights = () => {
const peerID = $rootScope.selectedPeerID; const peerID = rootScope.selectedPeerID;
const children = this.tabsEl.children; const children = this.tabsEl.children;
const tabsElements = Array.from(children) as HTMLElement[]; const tabsElements = Array.from(children) as HTMLElement[];

6
src/components/emoticonsDropdown/tabs/stickers.ts

@ -8,7 +8,7 @@ import appStickersManager from "../../../lib/appManagers/appStickersManager";
import lottieLoader from "../../../lib/lottieLoader"; import lottieLoader from "../../../lib/lottieLoader";
import apiManager from "../../../lib/mtproto/mtprotoworker"; import apiManager from "../../../lib/mtproto/mtprotoworker";
import { RichTextProcessor } from "../../../lib/richtextprocessor"; import { RichTextProcessor } from "../../../lib/richtextprocessor";
import $rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import animationIntersector from "../../animationIntersector"; import animationIntersector from "../../animationIntersector";
import { LazyLoadQueueRepeat } from "../../lazyLoadQueue"; import { LazyLoadQueueRepeat } from "../../lazyLoadQueue";
import { putPreloader, renderImageFromUrl } from "../../misc"; import { putPreloader, renderImageFromUrl } from "../../misc";
@ -256,7 +256,7 @@ export default class StickersTab implements EmoticonsTab {
} }
}); */ }); */
$rootScope.$on('stickers_installed', (e) => { rootScope.on('stickers_installed', (e) => {
const set: StickerSet.stickerSet = e.detail; const set: StickerSet.stickerSet = e.detail;
if(!this.stickerSets[set.id] && this.mounted) { if(!this.stickerSets[set.id] && this.mounted) {
@ -264,7 +264,7 @@ export default class StickersTab implements EmoticonsTab {
} }
}); });
$rootScope.$on('stickers_deleted', (e) => { rootScope.on('stickers_deleted', (e) => {
const set: StickerSet.stickerSet = e.detail; const set: StickerSet.stickerSet = e.detail;
if(this.stickerSets[set.id] && this.mounted) { if(this.stickerSets[set.id] && this.mounted) {

6
src/components/poll.ts

@ -4,7 +4,7 @@ import appImManager from "../lib/appManagers/appImManager";
import appPollsManager, { Poll, PollResults } from "../lib/appManagers/appPollsManager"; import appPollsManager, { Poll, PollResults } from "../lib/appManagers/appPollsManager";
import serverTimeManager from "../lib/mtproto/serverTimeManager"; import serverTimeManager from "../lib/mtproto/serverTimeManager";
import { RichTextProcessor } from "../lib/richtextprocessor"; import { RichTextProcessor } from "../lib/richtextprocessor";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent, findUpClassName } from "../helpers/dom"; import { cancelEvent, findUpClassName } from "../helpers/dom";
import { ripple } from "./ripple"; import { ripple } from "./ripple";
import appSidebarRight from "./sidebarRight"; import appSidebarRight from "./sidebarRight";
@ -65,7 +65,7 @@ export const roundPercents = (percents: number[]) => {
}; };
const connectedPolls: {id: string, element: PollElement}[] = []; const connectedPolls: {id: string, element: PollElement}[] = [];
$rootScope.$on('poll_update', (e) => { rootScope.on('poll_update', (e) => {
const {poll, results} = e.detail as {poll: Poll, results: PollResults}; const {poll, results} = e.detail as {poll: Poll, results: PollResults};
//console.log('poll_update', poll, results); //console.log('poll_update', poll, results);
@ -78,7 +78,7 @@ $rootScope.$on('poll_update', (e) => {
} }
}); });
$rootScope.$on('peer_changed', () => { rootScope.on('peer_changed', () => {
if(prevQuizHint) { if(prevQuizHint) {
hideQuizHint(prevQuizHint, prevQuizHintOnHide, prevQuizHintTimeout); hideQuizHint(prevQuizHint, prevQuizHintOnHide, prevQuizHintTimeout);
} }

6
src/components/popup.ts

@ -1,4 +1,4 @@
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent, findUpClassName } from "../helpers/dom"; import { cancelEvent, findUpClassName } from "../helpers/dom";
import { ripple } from "./ripple"; import { ripple } from "./ripple";
@ -103,7 +103,7 @@ export class PopupElement {
document.body.append(this.element); document.body.append(this.element);
void this.element.offsetWidth; // reflow void this.element.offsetWidth; // reflow
this.element.classList.add('active'); this.element.classList.add('active');
$rootScope.overlayIsActive = true; rootScope.overlayIsActive = true;
} }
public destroy = () => { public destroy = () => {
@ -112,7 +112,7 @@ export class PopupElement {
window.removeEventListener('keydown', this._onKeyDown, {capture: true}); window.removeEventListener('keydown', this._onKeyDown, {capture: true});
if(this.closeBtn) this.closeBtn.removeEventListener('click', this.destroy); if(this.closeBtn) this.closeBtn.removeEventListener('click', this.destroy);
$rootScope.overlayIsActive = false; rootScope.overlayIsActive = false;
setTimeout(() => { setTimeout(() => {
this.element.remove(); this.element.remove();

6
src/components/popupCreatePoll.ts

@ -1,7 +1,7 @@
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import appPollsManager, { Poll } from "../lib/appManagers/appPollsManager"; import appPollsManager, { Poll } from "../lib/appManagers/appPollsManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { cancelEvent, findUpTag, getRichValue, isInputEmpty, whichChild } from "../helpers/dom"; import { cancelEvent, findUpTag, getRichValue, isInputEmpty, whichChild } from "../helpers/dom";
import CheckboxField from "./checkbox"; import CheckboxField from "./checkbox";
import InputField from "./inputField"; import InputField from "./inputField";
@ -57,7 +57,7 @@ export default class PopupCreatePoll extends PopupElement {
settingsCaption.classList.add('caption'); settingsCaption.classList.add('caption');
settingsCaption.innerText = 'Settings'; settingsCaption.innerText = 'Settings';
const peerID = $rootScope.selectedPeerID; const peerID = rootScope.selectedPeerID;
if(!appPeersManager.isBroadcast(peerID)) { if(!appPeersManager.isBroadcast(peerID)) {
this.anonymousCheckboxField = CheckboxField('Anonymous Voting', 'anonymous'); this.anonymousCheckboxField = CheckboxField('Anonymous Voting', 'anonymous');
@ -213,7 +213,7 @@ export default class PopupCreatePoll extends PopupElement {
//console.log('Will try to create poll:', inputMediaPoll); //console.log('Will try to create poll:', inputMediaPoll);
appMessagesManager.sendOther($rootScope.selectedPeerID, inputMediaPoll); appMessagesManager.sendOther(rootScope.selectedPeerID, inputMediaPoll);
}; };
onInput = (e: Event) => { onInput = (e: Event) => {

8
src/components/popupDeleteMessages.ts

@ -1,13 +1,13 @@
import appChatsManager from "../lib/appManagers/appChatsManager"; import appChatsManager from "../lib/appManagers/appChatsManager";
import appMessagesManager from "../lib/appManagers/appMessagesManager"; import appMessagesManager from "../lib/appManagers/appMessagesManager";
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import $rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { PopupButton } from "./popup"; import { PopupButton } from "./popup";
import PopupPeer from "./popupPeer"; import PopupPeer from "./popupPeer";
export default class PopupDeleteMessages { export default class PopupDeleteMessages {
constructor(mids: number[], onConfirm?: () => void) { constructor(mids: number[], onConfirm?: () => void) {
const peerID = $rootScope.selectedPeerID; const peerID = rootScope.selectedPeerID;
const firstName = appPeersManager.getPeerTitle(peerID, false, true); const firstName = appPeersManager.getPeerTitle(peerID, false, true);
mids = mids.slice(); mids = mids.slice();
@ -20,7 +20,7 @@ export default class PopupDeleteMessages {
title = `Delete ${mids.length == 1 ? '' : mids.length + ' '}Message${mids.length == 1 ? '' : 's'}?`; title = `Delete ${mids.length == 1 ? '' : mids.length + ' '}Message${mids.length == 1 ? '' : 's'}?`;
description = `Are you sure you want to delete ${mids.length == 1 ? 'this message' : 'these messages'}?`; description = `Are you sure you want to delete ${mids.length == 1 ? 'this message' : 'these messages'}?`;
if(peerID == $rootScope.myID) { if(peerID == rootScope.myID) {
buttons = [{ buttons = [{
text: 'DELETE', text: 'DELETE',
isDanger: true, isDanger: true,
@ -46,7 +46,7 @@ export default class PopupDeleteMessages {
if(chat._ == 'chat') { if(chat._ == 'chat') {
const canRevoke = hasRights ? mids.slice() : mids.filter(mid => { const canRevoke = hasRights ? mids.slice() : mids.filter(mid => {
const message = appMessagesManager.getMessage(mid); const message = appMessagesManager.getMessage(mid);
return message.fromID == $rootScope.myID; return message.fromID == rootScope.myID;
}); });
if(canRevoke.length) { if(canRevoke.length) {

11
src/components/sidebarLeft/index.ts

@ -7,11 +7,11 @@ import appPeersManager from "../../lib/appManagers/appPeersManager";
import appStateManager from "../../lib/appManagers/appStateManager"; import appStateManager from "../../lib/appManagers/appStateManager";
import appUsersManager from "../../lib/appManagers/appUsersManager"; import appUsersManager from "../../lib/appManagers/appUsersManager";
import { MOUNT_CLASS_TO } from "../../lib/mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../../lib/mtproto/mtproto_config";
import $rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { findUpClassName, findUpTag } from "../../helpers/dom"; import { findUpClassName, findUpTag } from "../../helpers/dom";
import AppSearch, { SearchGroup } from "../appSearch"; import AppSearch, { SearchGroup } from "../appSearch";
import "../avatar"; import "../avatar";
import { parseMenuButtonsTo } from "../misc"; import { parseMenuButtonsTo, putPreloader } from "../misc";
import { ScrollableX } from "../scrollable"; import { ScrollableX } from "../scrollable";
import SearchInput from "../searchInput"; import SearchInput from "../searchInput";
import SidebarSlider from "../slider"; import SidebarSlider from "../slider";
@ -133,7 +133,7 @@ export class AppSidebarLeft extends SidebarSlider {
[AppSidebarLeft.SLIDERITEMSIDS.newGroup]: newGroupTab, [AppSidebarLeft.SLIDERITEMSIDS.newGroup]: newGroupTab,
[AppSidebarLeft.SLIDERITEMSIDS.settings]: settingsTab, [AppSidebarLeft.SLIDERITEMSIDS.settings]: settingsTab,
[AppSidebarLeft.SLIDERITEMSIDS.editProfile]: editProfileTab, [AppSidebarLeft.SLIDERITEMSIDS.editProfile]: editProfileTab,
[AppSidebarLeft.SLIDERITEMSIDS.chatFolders]: this.chatFoldersTab = new AppChatFoldersTab(appMessagesManager, appPeersManager, this, apiManagerProxy, $rootScope), [AppSidebarLeft.SLIDERITEMSIDS.chatFolders]: this.chatFoldersTab = new AppChatFoldersTab(appMessagesManager, appPeersManager, this, apiManagerProxy, rootScope),
[AppSidebarLeft.SLIDERITEMSIDS.editFolder]: editFolderTab, [AppSidebarLeft.SLIDERITEMSIDS.editFolder]: editFolderTab,
[AppSidebarLeft.SLIDERITEMSIDS.includedChats]: includedChatsTab, [AppSidebarLeft.SLIDERITEMSIDS.includedChats]: includedChatsTab,
}); });
@ -141,7 +141,8 @@ export class AppSidebarLeft extends SidebarSlider {
//this._selectTab(0); // make first tab as default //this._selectTab(0); // make first tab as default
this.searchInput = new SearchInput('Telegram Search'); this.searchInput = new SearchInput('Telegram Search');
this.sidebarEl.querySelector('.item-main .sidebar-header').append(this.searchInput.container); const sidebarHeader = this.sidebarEl.querySelector('.item-main .sidebar-header');
sidebarHeader.append(this.searchInput.container);
this.toolsBtn = this.sidebarEl.querySelector('.sidebar-tools-button') as HTMLButtonElement; this.toolsBtn = this.sidebarEl.querySelector('.sidebar-tools-button') as HTMLButtonElement;
this.backBtn = this.sidebarEl.querySelector('.sidebar-back-button') as HTMLButtonElement; this.backBtn = this.sidebarEl.querySelector('.sidebar-back-button') as HTMLButtonElement;
@ -321,7 +322,7 @@ export class AppSidebarLeft extends SidebarSlider {
}); });
}); });
$rootScope.$on('dialogs_archived_unread', (e) => { rootScope.on('dialogs_archived_unread', (e) => {
this.archivedCount.innerText = '' + formatNumber(e.detail.count, 1); this.archivedCount.innerText = '' + formatNumber(e.detail.count, 1);
this.archivedCount.classList.toggle('hide', !e.detail.count); this.archivedCount.classList.toggle('hide', !e.detail.count);
}); });

10
src/components/sidebarLeft/tabs/chatFolders.ts

@ -10,7 +10,7 @@ import type { MyDialogFilter } from "../../../lib/storages/filters";
import type { AppPeersManager } from "../../../lib/appManagers/appPeersManager"; import type { AppPeersManager } from "../../../lib/appManagers/appPeersManager";
import type { AppSidebarLeft } from ".."; import type { AppSidebarLeft } from "..";
import type { DialogFilterSuggested, DialogFilter } from "../../../layer"; import type { DialogFilterSuggested, DialogFilter } from "../../../layer";
import type _$rootScope from "../../../lib/rootScope"; import type _rootScope from "../../../lib/rootScope";
export default class AppChatFoldersTab implements SliderTab { export default class AppChatFoldersTab implements SliderTab {
public container: HTMLElement; public container: HTMLElement;
@ -22,7 +22,7 @@ export default class AppChatFoldersTab implements SliderTab {
private filtersRendered: {[filterID: number]: HTMLElement} = {}; private filtersRendered: {[filterID: number]: HTMLElement} = {};
constructor(private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager, private appSidebarLeft: AppSidebarLeft, private apiManager: ApiManagerProxy, private $rootScope: typeof _$rootScope) { constructor(private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager, private appSidebarLeft: AppSidebarLeft, private apiManager: ApiManagerProxy, private rootScope: typeof _rootScope) {
} }
@ -127,7 +127,7 @@ export default class AppChatFoldersTab implements SliderTab {
} }
}); });
this.$rootScope.$on('filter_update', (e) => { this.rootScope.on('filter_update', (e) => {
const filter = e.detail; const filter = e.detail;
if(this.filtersRendered.hasOwnProperty(filter.id)) { if(this.filtersRendered.hasOwnProperty(filter.id)) {
this.renderFolder(filter, null, this.filtersRendered[filter.id]); this.renderFolder(filter, null, this.filtersRendered[filter.id]);
@ -138,7 +138,7 @@ export default class AppChatFoldersTab implements SliderTab {
this.getSuggestedFilters(); this.getSuggestedFilters();
}); });
this.$rootScope.$on('filter_delete', (e) => { this.rootScope.on('filter_delete', (e) => {
const filter = e.detail; const filter = e.detail;
if(this.filtersRendered.hasOwnProperty(filter.id)) { if(this.filtersRendered.hasOwnProperty(filter.id)) {
/* for(const suggested of this.suggestedFilters) { /* for(const suggested of this.suggestedFilters) {
@ -153,7 +153,7 @@ export default class AppChatFoldersTab implements SliderTab {
} }
}); });
this.$rootScope.$on('filter_order', (e) => { this.rootScope.on('filter_order', (e) => {
const order = e.detail; const order = e.detail;
order.forEach((filterID, idx) => { order.forEach((filterID, idx) => {
const div = this.filtersRendered[filterID]; const div = this.filtersRendered[filterID];

6
src/components/sidebarLeft/tabs/contacts.ts

@ -4,7 +4,7 @@ import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
import appPhotosManager from "../../../lib/appManagers/appPhotosManager"; import appPhotosManager from "../../../lib/appManagers/appPhotosManager";
import appSidebarLeft, { AppSidebarLeft } from ".."; import appSidebarLeft, { AppSidebarLeft } from "..";
import $rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import SearchInput from "../../searchInput"; import SearchInput from "../../searchInput";
// TODO: поиск по людям глобальный, если не нашло в контактах никого // TODO: поиск по людям глобальный, если не нашло в контактах никого
@ -70,10 +70,10 @@ export default class AppContactsTab implements SliderTab {
const contacts = [..._contacts]; const contacts = [..._contacts];
if(!query) { if(!query) {
contacts.findAndSplice(u => u == $rootScope.myID); contacts.findAndSplice(u => u == rootScope.myID);
} }
/* if(query && 'saved messages'.includes(query.toLowerCase())) { /* if(query && 'saved messages'.includes(query.toLowerCase())) {
contacts.unshift($rootScope.myID); contacts.unshift(rootScope.myID);
} */ } */
let sorted = contacts let sorted = contacts

4
src/components/sidebarLeft/tabs/editProfile.ts

@ -5,7 +5,7 @@ import appProfileManager from "../../../lib/appManagers/appProfileManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
import apiManager from "../../../lib/mtproto/mtprotoworker"; import apiManager from "../../../lib/mtproto/mtprotoworker";
import RichTextProcessor from "../../../lib/richtextprocessor"; import RichTextProcessor from "../../../lib/richtextprocessor";
import $rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import AvatarElement from "../../avatar"; import AvatarElement from "../../avatar";
import InputField from "../../inputField"; import InputField from "../../inputField";
import PopupAvatar from "../../popupAvatar"; import PopupAvatar from "../../popupAvatar";
@ -225,7 +225,7 @@ export default class AppEditProfileTab implements SliderTab {
} }
}); });
this.avatarElem.setAttribute('peer', '' + $rootScope.myID); this.avatarElem.setAttribute('peer', '' + rootScope.myID);
if(!this.avatarElem.parentElement) { if(!this.avatarElem.parentElement) {
this.canvas.parentElement.append(this.avatarElem); this.canvas.parentElement.append(this.avatarElem);
} }

4
src/components/sidebarLeft/tabs/includedChats.ts

@ -5,7 +5,7 @@ import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
import appPeersManager from "../../../lib/appManagers/appPeersManager"; import appPeersManager from "../../../lib/appManagers/appPeersManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
import { MyDialogFilter as DialogFilter } from "../../../lib/storages/filters"; import { MyDialogFilter as DialogFilter } from "../../../lib/storages/filters";
import $rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import { copy } from "../../../helpers/object"; import { copy } from "../../../helpers/object";
export default class AppIncludedChatsTab implements SliderTab { export default class AppIncludedChatsTab implements SliderTab {
@ -109,7 +109,7 @@ export default class AppIncludedChatsTab implements SliderTab {
let subtitle = ''; let subtitle = '';
if(peerID > 0) { if(peerID > 0) {
if(peerID == $rootScope.myID) { if(peerID == rootScope.myID) {
subtitle = 'Chat with yourself'; subtitle = 'Chat with yourself';
} else if(appUsersManager.isBot(peerID)) { } else if(appUsersManager.isBot(peerID)) {
subtitle = 'Bot'; subtitle = 'Bot';

4
src/components/sidebarLeft/tabs/settings.ts

@ -1,7 +1,7 @@
import { SliderTab } from "../../slider"; import { SliderTab } from "../../slider";
import AvatarElement from "../../avatar"; import AvatarElement from "../../avatar";
import { parseMenuButtonsTo } from "../../misc"; import { parseMenuButtonsTo } from "../../misc";
//import $rootScope from "../../lib/rootScope"; //import rootScope from "../../lib/rootScope";
import apiManager from "../../../lib/mtproto/mtprotoworker"; import apiManager from "../../../lib/mtproto/mtprotoworker";
import appSidebarLeft, { AppSidebarLeft } from ".."; import appSidebarLeft, { AppSidebarLeft } from "..";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
@ -26,7 +26,7 @@ export default class AppSettingsTab implements SliderTab {
constructor() { constructor() {
parseMenuButtonsTo(this.buttons, this.container.querySelector('.profile-buttons').children); parseMenuButtonsTo(this.buttons, this.container.querySelector('.profile-buttons').children);
/* $rootScope.$on('user_auth', (e) => { /* rootScope.$on('user_auth', (e) => {
this.fillElements(); this.fillElements();
}); */ }); */

16
src/components/sidebarRight/tabs/sharedMedia.ts

@ -7,7 +7,7 @@ import appProfileManager from "../../../lib/appManagers/appProfileManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager"; import appUsersManager from "../../../lib/appManagers/appUsersManager";
import { logger } from "../../../lib/logger"; import { logger } from "../../../lib/logger";
import { RichTextProcessor } from "../../../lib/richtextprocessor"; import { RichTextProcessor } from "../../../lib/richtextprocessor";
import $rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import AppMediaViewer from "../../appMediaViewer"; import AppMediaViewer from "../../appMediaViewer";
import AvatarElement from "../../avatar"; import AvatarElement from "../../avatar";
import { horizontalMenu } from "../../horizontalMenu"; import { horizontalMenu } from "../../horizontalMenu";
@ -408,7 +408,7 @@ export default class AppSharedMediaTab implements SliderTab {
const load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200)) const load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200))
.then(() => { .then(() => {
if($rootScope.selectedPeerID != peerID) { if(rootScope.selectedPeerID != peerID) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -551,7 +551,7 @@ export default class AppSharedMediaTab implements SliderTab {
if(webpage.photo) { if(webpage.photo) {
let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 60, 60)) let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 60, 60))
.then(() => { .then(() => {
if($rootScope.selectedPeerID != peerID) { if(rootScope.selectedPeerID != peerID) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -701,7 +701,7 @@ export default class AppSharedMediaTab implements SliderTab {
this.log(logStr + 'search house of glass', type, value); this.log(logStr + 'search house of glass', type, value);
if($rootScope.selectedPeerID != peerID) { if(rootScope.selectedPeerID != peerID) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -826,14 +826,14 @@ export default class AppSharedMediaTab implements SliderTab {
} }
public fillProfileElements() { public fillProfileElements() {
let peerID = this.peerID = $rootScope.selectedPeerID; let peerID = this.peerID = rootScope.selectedPeerID;
this.cleanupHTML(); this.cleanupHTML();
this.profileElements.avatar.setAttribute('peer', '' + peerID); this.profileElements.avatar.setAttribute('peer', '' + peerID);
// username // username
if(peerID != $rootScope.myID) { if(peerID != rootScope.myID) {
let username = appPeersManager.getPeerUsername(peerID); let username = appPeersManager.getPeerUsername(peerID);
if(username) { if(username) {
setText(appPeersManager.getPeerUsername(peerID), this.profileElements.username); setText(appPeersManager.getPeerUsername(peerID), this.profileElements.username);
@ -859,7 +859,7 @@ export default class AppSharedMediaTab implements SliderTab {
//membersLi.style.display = 'none'; //membersLi.style.display = 'none';
let user = appUsersManager.getUser(peerID); let user = appUsersManager.getUser(peerID);
if(user.phone && peerID != $rootScope.myID) { if(user.phone && peerID != rootScope.myID) {
setText(user.rPhone, this.profileElements.phone); setText(user.rPhone, this.profileElements.phone);
} }
@ -869,7 +869,7 @@ export default class AppSharedMediaTab implements SliderTab {
return; return;
} }
if(userFull.rAbout && peerID != $rootScope.myID) { if(userFull.rAbout && peerID != rootScope.myID) {
setText(userFull.rAbout, this.profileElements.bio); setText(userFull.rAbout, this.profileElements.bio);
} }

6
src/lib/appManagers/AppInlineBotsManager.ts

@ -102,7 +102,7 @@ export class AppInlineBotsManager {
} }
ConfigStorage.set({inline_bots_popular: result}) ConfigStorage.set({inline_bots_popular: result})
$rootScope.$broadcast('inline_bots_popular') rootScope.$broadcast('inline_bots_popular')
}) })
} }
@ -217,7 +217,7 @@ export class AppInlineBotsManager {
var setHash = {} var setHash = {}
setHash['inline_switch_pm' + botID] = {peer: peerString, time: tsNow()} setHash['inline_switch_pm' + botID] = {peer: peerString, time: tsNow()}
Storage.set(setHash) Storage.set(setHash)
$rootScope.$broadcast('history_focus', {peerString: AppPeersManager.getPeerString(botID)}) rootScope.$broadcast('history_focus', {peerString: AppPeersManager.getPeerString(botID)})
AppMessagesManager.startBot(botID, 0, startParam) AppMessagesManager.startBot(botID, 0, startParam)
} }
@ -239,7 +239,7 @@ export class AppInlineBotsManager {
} }
function switchInlineQuery (botID, toPeerString, query) { function switchInlineQuery (botID, toPeerString, query) {
$rootScope.$broadcast('history_focus', { rootScope.$broadcast('history_focus', {
peerString: toPeerString, peerString: toPeerString,
attachment: { attachment: {
_: 'inline_query', _: 'inline_query',

16
src/lib/appManagers/apiUpdatesManager.ts

@ -2,7 +2,7 @@
import { logger, LogLevels } from '../logger'; import { logger, LogLevels } from '../logger';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config'; import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config';
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
//import networkerFactory from '../mtproto/networkerFactory'; //import networkerFactory from '../mtproto/networkerFactory';
import appChatsManager from "./appChatsManager"; import appChatsManager from "./appChatsManager";
import appPeersManager from "./appPeersManager"; import appPeersManager from "./appPeersManager";
@ -151,10 +151,10 @@ export class ApiUpdatesManager {
case 'updateShortChatMessage': { case 'updateShortChatMessage': {
this.log('updateShortMessage | updateShortChatMessage', {...updateMessage}); this.log('updateShortMessage | updateShortChatMessage', {...updateMessage});
const isOut = updateMessage.pFlags.out; const isOut = updateMessage.pFlags.out;
const fromID = updateMessage.from_id || (isOut ? $rootScope.myID : updateMessage.user_id); const fromID = updateMessage.from_id || (isOut ? rootScope.myID : updateMessage.user_id);
const toID = updateMessage.chat_id const toID = updateMessage.chat_id
? -updateMessage.chat_id ? -updateMessage.chat_id
: (updateMessage.user_id || $rootScope.myID); : (updateMessage.user_id || rootScope.myID);
this.processUpdate({ this.processUpdate({
_: 'updateNewMessage', _: 'updateNewMessage',
@ -217,7 +217,7 @@ export class ApiUpdatesManager {
updatesState.date = differenceResult.date; updatesState.date = differenceResult.date;
updatesState.seq = differenceResult.seq; updatesState.seq = differenceResult.seq;
updatesState.syncLoading = false; updatesState.syncLoading = false;
$rootScope.$broadcast('stateSynchronized'); rootScope.broadcast('stateSynchronized');
return false; return false;
} }
@ -266,7 +266,7 @@ export class ApiUpdatesManager {
this.getDifference(); this.getDifference();
} else { } else {
// this.log('finished get diff') // this.log('finished get diff')
$rootScope.$broadcast('stateSynchronized'); rootScope.broadcast('stateSynchronized');
updatesState.syncLoading = false; updatesState.syncLoading = false;
} }
}, () => { }, () => {
@ -299,7 +299,7 @@ export class ApiUpdatesManager {
if(differenceResult._ == 'updates.channelDifferenceEmpty') { if(differenceResult._ == 'updates.channelDifferenceEmpty') {
this.log('apply channel empty diff', differenceResult); this.log('apply channel empty diff', differenceResult);
channelState.syncLoading = false; channelState.syncLoading = false;
$rootScope.$broadcast('stateSynchronized'); rootScope.broadcast('stateSynchronized');
return false; return false;
} }
@ -337,7 +337,7 @@ export class ApiUpdatesManager {
this.getChannelDifference(channelID); this.getChannelDifference(channelID);
} else { } else {
this.log('finished channel get diff'); this.log('finished channel get diff');
$rootScope.$broadcast('stateSynchronized'); rootScope.broadcast('stateSynchronized');
channelState.syncLoading = false; channelState.syncLoading = false;
} }
}, () => { }, () => {
@ -519,7 +519,7 @@ export class ApiUpdatesManager {
} }
public saveUpdate(update: any) { public saveUpdate(update: any) {
$rootScope.$broadcast('apiUpdate', update); rootScope.broadcast('apiUpdate', update);
} }
public attach() { public attach() {

10
src/lib/appManagers/appChatsManager.ts

@ -4,7 +4,7 @@ import { ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputCha
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import apiUpdatesManager from "./apiUpdatesManager"; import apiUpdatesManager from "./apiUpdatesManager";
import appMessagesManager from "./appMessagesManager"; import appMessagesManager from "./appMessagesManager";
import appProfileManager from "./appProfileManager"; import appProfileManager from "./appProfileManager";
@ -74,14 +74,14 @@ export class AppChatsManager {
public megagroupOnlines: {[id: number]: {timestamp: number, onlines: number}} = {}; public megagroupOnlines: {[id: number]: {timestamp: number, onlines: number}} = {};
constructor() { constructor() {
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
// console.log('on apiUpdate', update) // console.log('on apiUpdate', update)
const update = e.detail; const update = e.detail;
switch(update._) { switch(update._) {
case 'updateChannel': case 'updateChannel':
const channelID = update.channel_id; const channelID = update.channel_id;
//console.log('updateChannel:', update); //console.log('updateChannel:', update);
$rootScope.$broadcast('channel_settings', {channelID: channelID}); rootScope.broadcast('channel_settings', {channelID: channelID});
break; break;
} }
}); });
@ -143,7 +143,7 @@ export class AppChatsManager {
} }
safeReplaceObject(oldChat, chat); safeReplaceObject(oldChat, chat);
$rootScope.$broadcast('chat_update', chat.id); rootScope.broadcast('chat_update', chat.id);
} }
if(this.cachedPhotoLocations[chat.id] !== undefined) { if(this.cachedPhotoLocations[chat.id] !== undefined) {
@ -152,7 +152,7 @@ export class AppChatsManager {
} }
if(changedPhoto) { if(changedPhoto) {
$rootScope.$broadcast('avatar_update', -chat.id); rootScope.broadcast('avatar_update', -chat.id);
} }
} }

96
src/lib/appManagers/appDialogsManager.ts

@ -12,7 +12,7 @@ import { isTouchSupported } from "../../helpers/touchSupport";
import { isSafari } from "../../helpers/userAgent"; import { isSafari } from "../../helpers/userAgent";
import { logger, LogLevels } from "../logger"; import { logger, LogLevels } from "../logger";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import { findUpClassName, positionElementByIndex } from "../../helpers/dom"; import { findUpClassName, positionElementByIndex } from "../../helpers/dom";
import appImManager, { AppImManager } from "./appImManager"; import appImManager, { AppImManager } from "./appImManager";
import appMessagesManager, { Dialog } from "./appMessagesManager"; import appMessagesManager, { Dialog } from "./appMessagesManager";
@ -21,6 +21,9 @@ import appPeersManager from './appPeersManager';
import appStateManager from "./appStateManager"; import appStateManager from "./appStateManager";
import appUsersManager, { User } from "./appUsersManager"; import appUsersManager, { User } from "./appUsersManager";
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import Button from "../../components/button";
import SetTransition from "../../components/singleTransition";
import AppStorage from '../storage';
type DialogDom = { type DialogDom = {
avatarEl: AvatarElement, avatarEl: AvatarElement,
@ -94,7 +97,11 @@ export class AppDialogsManager {
this.folders.menuScrollContainer = this.folders.menu.parentElement; this.folders.menuScrollContainer = this.folders.menu.parentElement;
this.scroll = this._scroll = new Scrollable(this.chatsContainer, 'CL', 500); const bottomPart = document.createElement('div');
bottomPart.classList.add('connection-status-bottom');
bottomPart.append(this.folders.container);
this.scroll = this._scroll = new Scrollable(bottomPart, 'CL', 500);
this.scroll.onScrolledTop = this.onChatsScrollTop; this.scroll.onScrolledTop = this.onChatsScrollTop;
this.scroll.onScrolledBottom = this.onChatsScroll; this.scroll.onScrolledBottom = this.onChatsScroll;
this.scroll.setVirtualContainer(this.chatList); this.scroll.setVirtualContainer(this.chatList);
@ -140,13 +147,13 @@ export class AppDialogsManager {
(window as any).addElement = add; (window as any).addElement = add;
} }
$rootScope.$on('user_update', (e) => { rootScope.on('user_update', (e) => {
const userID = e.detail; const userID = e.detail;
const user = appUsersManager.getUser(userID); const user = appUsersManager.getUser(userID);
const dialog = appMessagesManager.getDialogByPeerID(user.id)[0]; const dialog = appMessagesManager.getDialogByPeerID(user.id)[0];
//console.log('updating user:', user, dialog); //console.log('updating user:', user, dialog);
if(dialog && !appUsersManager.isBot(dialog.peerID) && dialog.peerID != $rootScope.myID) { if(dialog && !appUsersManager.isBot(dialog.peerID) && dialog.peerID != rootScope.myID) {
const online = user.status?._ == 'userStatusOnline'; const online = user.status?._ == 'userStatusOnline';
const dom = this.getDialogDom(dialog.peerID); const dom = this.getDialogDom(dialog.peerID);
@ -155,12 +162,12 @@ export class AppDialogsManager {
} }
} }
if($rootScope.selectedPeerID == user.id) { if(rootScope.selectedPeerID == user.id) {
appImManager.setPeerStatus(); appImManager.setPeerStatus();
} }
}); });
/* $rootScope.$on('dialog_top', (e) => { /* rootScope.$on('dialog_top', (e) => {
const dialog = e.detail; const dialog = e.detail;
this.setLastMessage(dialog); this.setLastMessage(dialog);
@ -169,7 +176,7 @@ export class AppDialogsManager {
this.setFiltersUnreadCount(); this.setFiltersUnreadCount();
}); */ }); */
$rootScope.$on('dialog_flush', (e) => { rootScope.on('dialog_flush', (e) => {
const peerID: number = e.detail.peerID; const peerID: number = e.detail.peerID;
const dialog = appMessagesManager.getDialogByPeerID(peerID)[0]; const dialog = appMessagesManager.getDialogByPeerID(peerID)[0];
if(dialog) { if(dialog) {
@ -179,7 +186,7 @@ export class AppDialogsManager {
} }
}); });
$rootScope.$on('dialogs_multiupdate', (e) => { rootScope.on('dialogs_multiupdate', (e) => {
const dialogs = e.detail; const dialogs = e.detail;
for(const id in dialogs) { for(const id in dialogs) {
@ -191,7 +198,7 @@ export class AppDialogsManager {
this.setFiltersUnreadCount(); this.setFiltersUnreadCount();
}); });
$rootScope.$on('dialog_drop', (e) => { rootScope.on('dialog_drop', (e) => {
const {peerID, dialog} = e.detail; const {peerID, dialog} = e.detail;
const dom = this.getDialogDom(peerID); const dom = this.getDialogDom(peerID);
@ -203,14 +210,14 @@ export class AppDialogsManager {
this.setFiltersUnreadCount(); this.setFiltersUnreadCount();
}); });
$rootScope.$on('dialog_unread', (e) => { rootScope.on('dialog_unread', (e) => {
const info = e.detail; const info = e.detail;
const dialog = appMessagesManager.getDialogByPeerID(info.peerID)[0]; const dialog = appMessagesManager.getDialogByPeerID(info.peerID)[0];
if(dialog) { if(dialog) {
this.setUnreadMessages(dialog); this.setUnreadMessages(dialog);
if(dialog.peerID == $rootScope.selectedPeerID) { if(dialog.peerID == rootScope.selectedPeerID) {
appImManager.updateUnreadByDialog(dialog); appImManager.updateUnreadByDialog(dialog);
} }
@ -219,14 +226,14 @@ export class AppDialogsManager {
} }
}); });
$rootScope.$on('dialog_notify_settings', e => { rootScope.on('dialog_notify_settings', e => {
const dialog = appMessagesManager.getDialogByPeerID(e.detail)[0]; const dialog = appMessagesManager.getDialogByPeerID(e.detail)[0];
if(dialog) { if(dialog) {
this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted
} }
}); });
$rootScope.$on('peer_changed', (e) => { rootScope.on('peer_changed', (e) => {
let peerID = e.detail; let peerID = e.detail;
let lastPeerID = this.lastActiveListElement && +this.lastActiveListElement.getAttribute('data-peerID'); let lastPeerID = this.lastActiveListElement && +this.lastActiveListElement.getAttribute('data-peerID');
@ -244,7 +251,7 @@ export class AppDialogsManager {
} }
}); });
$rootScope.$on('filter_update', (e) => { rootScope.on('filter_update', (e) => {
const filter: DialogFilter = e.detail; const filter: DialogFilter = e.detail;
if(!this.filtersRendered[filter.id]) { if(!this.filtersRendered[filter.id]) {
this.addFilter(filter); this.addFilter(filter);
@ -264,7 +271,7 @@ export class AppDialogsManager {
elements.title.innerHTML = RichTextProcessor.wrapEmojiText(filter.title); elements.title.innerHTML = RichTextProcessor.wrapEmojiText(filter.title);
}); });
$rootScope.$on('filter_delete', (e) => { rootScope.on('filter_delete', (e) => {
const filter: DialogFilter = e.detail; const filter: DialogFilter = e.detail;
const elements = this.filtersRendered[filter.id]; const elements = this.filtersRendered[filter.id];
if(!elements) return; if(!elements) return;
@ -284,7 +291,7 @@ export class AppDialogsManager {
} }
}); });
$rootScope.$on('filter_order', (e) => { rootScope.on('filter_order', (e) => {
const order = e.detail; const order = e.detail;
const containerToAppend = this.folders.menu.firstElementChild as HTMLUListElement; const containerToAppend = this.folders.menu.firstElementChild as HTMLUListElement;
@ -303,7 +310,7 @@ export class AppDialogsManager {
}); });
const foldersScrollable = new ScrollableX(this.folders.menuScrollContainer); const foldersScrollable = new ScrollableX(this.folders.menuScrollContainer);
this.chatsContainer.prepend(this.folders.menuScrollContainer); bottomPart.prepend(this.folders.menuScrollContainer);
const selectTab = horizontalMenu(this.folders.menu, this.folders.container, (id, tabContent) => { const selectTab = horizontalMenu(this.folders.menu, this.folders.container, (id, tabContent) => {
/* if(id != 0) { /* if(id != 0) {
id += 1; id += 1;
@ -346,6 +353,49 @@ export class AppDialogsManager {
}); });
}); });
const statusDiv = document.createElement('div');
statusDiv.classList.add('connection-status');
const networkButton = Button('btn-primary bg-warning connection-status-button');
networkButton.innerText = 'Waiting for network...';
putPreloader(networkButton);
statusDiv.append(networkButton);
this.chatsContainer.append(statusDiv, bottomPart);
rootScope.on('connection_status_change', e => {
const status = e.detail;
console.log(status);
setConnectionStatus();
});
const setConnectionStatus = () => {
AppStorage.get<number>('dc').then(baseDcID => {
if(setFirstConnectionTimeout) {
clearTimeout(setFirstConnectionTimeout);
setFirstConnectionTimeout = 0;
}
const status = rootScope.connectionStatus['NET-' + baseDcID];
SetTransition(statusDiv, 'is-not-connected', !status?.online, 200);
});
};
let setFirstConnectionTimeout = window.setTimeout(setConnectionStatus, 2e3);
/* let bool = true;
document.addEventListener('dblclick', () => {
rootScope.broadcast('connection_status_change', {
dcID: 5,
isFileDownload: false,
isFileNetworker: false,
isFileUpload: false,
name: "NET-5",
online: bool = !bool,
_: "networkerStatus"
});
}); */
/* const mutationObserver = new MutationObserver((mutationList, observer) => { /* const mutationObserver = new MutationObserver((mutationList, observer) => {
}); });
@ -754,7 +804,7 @@ export class AppDialogsManager {
const senderBold = document.createElement('b'); const senderBold = document.createElement('b');
let str = ''; let str = '';
if(sender.id == $rootScope.myID) { if(sender.id == rootScope.myID) {
str = 'You'; str = 'You';
} else { } else {
//str = sender.first_name || sender.last_name || sender.username; //str = sender.first_name || sender.last_name || sender.username;
@ -808,7 +858,7 @@ export class AppDialogsManager {
const lastMessage = appMessagesManager.getMessage(dialog.top_message); const lastMessage = appMessagesManager.getMessage(dialog.top_message);
if(lastMessage._ != 'messageEmpty' && !lastMessage.deleted && if(lastMessage._ != 'messageEmpty' && !lastMessage.deleted &&
lastMessage.fromID == $rootScope.myID && lastMessage.peerID != $rootScope.myID/* && lastMessage.fromID == rootScope.myID && lastMessage.peerID != rootScope.myID/* &&
dialog.read_outbox_max_id */) { // maybe comment, 06.20.2020 dialog.read_outbox_max_id */) { // maybe comment, 06.20.2020
const outgoing = (lastMessage.pFlags && lastMessage.pFlags.unread) const outgoing = (lastMessage.pFlags && lastMessage.pFlags.unread)
/* && dialog.read_outbox_max_id != 0 */; // maybe uncomment, 31.01.2020 /* && dialog.read_outbox_max_id != 0 */; // maybe uncomment, 31.01.2020
@ -851,7 +901,7 @@ export class AppDialogsManager {
this.accumulateArchivedTimeout = 0; this.accumulateArchivedTimeout = 0;
const dialogs = appMessagesManager.dialogsStorage.getFolder(1); const dialogs = appMessagesManager.dialogsStorage.getFolder(1);
const sum = dialogs.reduce((acc, dialog) => acc + dialog.unread_count, 0); const sum = dialogs.reduce((acc, dialog) => acc + dialog.unread_count, 0);
$rootScope.$broadcast('dialogs_archived_unread', {count: sum}); rootScope.broadcast('dialogs_archived_unread', {count: sum});
}, 0); }, 0);
} }
@ -906,7 +956,7 @@ export class AppDialogsManager {
avatarEl.setAttribute('peer', '' + peerID); avatarEl.setAttribute('peer', '' + peerID);
avatarEl.classList.add('dialog-avatar'); avatarEl.classList.add('dialog-avatar');
if(drawStatus && peerID != $rootScope.myID && dialog.peer) { if(drawStatus && peerID != rootScope.myID && dialog.peer) {
const peer = dialog.peer; const peer = dialog.peer;
switch(peer._) { switch(peer._) {
@ -932,7 +982,7 @@ export class AppDialogsManager {
const titleSpan = document.createElement('span'); const titleSpan = document.createElement('span');
if(peerID == $rootScope.myID && meAsSaved) { if(peerID == rootScope.myID && meAsSaved) {
title = onlyFirstName ? 'Saved' : 'Saved Messages'; title = onlyFirstName ? 'Saved' : 'Saved Messages';
} }
@ -1037,7 +1087,7 @@ export class AppDialogsManager {
this.doms[dialog.peerID] = dom; this.doms[dialog.peerID] = dom;
if($rootScope.selectedPeerID == peerID) { if(rootScope.selectedPeerID == peerID) {
li.classList.add('active'); li.classList.add('active');
this.lastActiveListElement = li; this.lastActiveListElement = li;
} }

4
src/lib/appManagers/appDownloadManager.ts

@ -1,4 +1,4 @@
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import { deferredPromise, CancellablePromise } from "../../helpers/cancellablePromise"; import { deferredPromise, CancellablePromise } from "../../helpers/cancellablePromise";
import type { DownloadOptions } from "../mtproto/apiFileManager"; import type { DownloadOptions } from "../mtproto/apiFileManager";
@ -30,7 +30,7 @@ export class AppDownloadManager {
private uploadID = 0; private uploadID = 0;
constructor() { constructor() {
$rootScope.$on('download_progress', (e) => { rootScope.on('download_progress', (e) => {
const details = e.detail as {done: number, fileName: string, total: number, offset: number}; const details = e.detail as {done: number, fileName: string, total: number, offset: number};
this.progress[details.fileName] = details; this.progress[details.fileName] = details;

46
src/lib/appManagers/appImManager.ts

@ -39,7 +39,7 @@ import { logger, LogLevels } from "../logger";
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config'; import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config';
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
import { cancelEvent, findUpClassName, findUpTag, placeCaretAtEnd, whichChild } from "../../helpers/dom"; import { cancelEvent, findUpClassName, findUpTag, placeCaretAtEnd, whichChild } from "../../helpers/dom";
import apiUpdatesManager from './apiUpdatesManager'; import apiUpdatesManager from './apiUpdatesManager';
import appChatsManager, { Channel, Chat } from "./appChatsManager"; import appChatsManager, { Channel, Chat } from "./appChatsManager";
@ -163,7 +163,7 @@ export class AppImManager {
public hideRightSidebar = false; public hideRightSidebar = false;
get myID() { get myID() {
return $rootScope.myID; return rootScope.myID;
} }
constructor() { constructor() {
@ -230,7 +230,7 @@ export class AppImManager {
this.btnJoin.parentElement.insertBefore(this.pinnedMessageContainer.divAndCaption.container, this.btnJoin); this.btnJoin.parentElement.insertBefore(this.pinnedMessageContainer.divAndCaption.container, this.btnJoin);
// will call when message is sent (only 1) // will call when message is sent (only 1)
$rootScope.$on('history_append', (e) => { rootScope.on('history_append', (e) => {
let details = e.detail; let details = e.detail;
if(!this.scrolledAllDown) { if(!this.scrolledAllDown) {
@ -241,7 +241,7 @@ export class AppImManager {
}); });
// will call when sent for update pos // will call when sent for update pos
$rootScope.$on('history_update', (e) => { rootScope.on('history_update', (e) => {
let details = e.detail; let details = e.detail;
if(details.mid && details.peerID == this.peerID) { if(details.mid && details.peerID == this.peerID) {
@ -262,7 +262,7 @@ export class AppImManager {
} }
}); });
$rootScope.$on('history_multiappend', (e) => { rootScope.on('history_multiappend', (e) => {
const msgIDsByPeer = e.detail; const msgIDsByPeer = e.detail;
for(const peerID in msgIDsByPeer) { for(const peerID in msgIDsByPeer) {
@ -274,7 +274,7 @@ export class AppImManager {
this.renderNewMessagesByIDs(msgIDs); this.renderNewMessagesByIDs(msgIDs);
}); });
$rootScope.$on('history_delete', (e) => { rootScope.on('history_delete', (e) => {
const {peerID, msgs} = e.detail; const {peerID, msgs} = e.detail;
const mids = Object.keys(msgs).map(s => +s); const mids = Object.keys(msgs).map(s => +s);
@ -285,14 +285,14 @@ export class AppImManager {
} }
}); });
$rootScope.$on('dialog_flush', (e) => { rootScope.on('dialog_flush', (e) => {
let peerID: number = e.detail.peerID; let peerID: number = e.detail.peerID;
if(this.peerID == peerID) { if(this.peerID == peerID) {
this.deleteMessagesByIDs(Object.keys(this.bubbles).map(m => +m)); this.deleteMessagesByIDs(Object.keys(this.bubbles).map(m => +m));
} }
}); });
$rootScope.$on('chat_update', (e) => { rootScope.on('chat_update', (e) => {
const peerID: number = e.detail; const peerID: number = e.detail;
if(this.peerID == -peerID) { if(this.peerID == -peerID) {
const chat = appChatsManager.getChat(peerID) as Channel | Chat; const chat = appChatsManager.getChat(peerID) as Channel | Chat;
@ -302,7 +302,7 @@ export class AppImManager {
}); });
// Calls when message successfully sent and we have an ID // Calls when message successfully sent and we have an ID
$rootScope.$on('message_sent', (e) => { rootScope.on('message_sent', (e) => {
const {tempID, mid} = e.detail; const {tempID, mid} = e.detail;
this.log('message_sent', e.detail); this.log('message_sent', e.detail);
@ -386,7 +386,7 @@ export class AppImManager {
} }
}); });
$rootScope.$on('message_edit', (e) => { rootScope.on('message_edit', (e) => {
const {peerID, mid} = e.detail; const {peerID, mid} = e.detail;
if(peerID != this.peerID) return; if(peerID != this.peerID) return;
@ -395,7 +395,7 @@ export class AppImManager {
this.renderMessage(mounted.message, true, false, mounted.bubble, false); this.renderMessage(mounted.message, true, false, mounted.bubble, false);
}); });
$rootScope.$on('album_edit', (e) => { rootScope.on('album_edit', (e) => {
const {peerID, groupID, deletedMids} = e.detail; const {peerID, groupID, deletedMids} = e.detail;
if(peerID != this.peerID) return; if(peerID != this.peerID) return;
@ -407,7 +407,7 @@ export class AppImManager {
this.renderMessage(appMessagesManager.getMessage(renderMaxID), true, false, this.bubbles[maxID], false); this.renderMessage(appMessagesManager.getMessage(renderMaxID), true, false, this.bubbles[maxID], false);
}); });
$rootScope.$on('peer_pinned_message', (e) => { rootScope.on('peer_pinned_message', (e) => {
const peerID = e.detail; const peerID = e.detail;
if(peerID == this.peerID) { if(peerID == this.peerID) {
@ -418,7 +418,7 @@ export class AppImManager {
} }
}); });
$rootScope.$on('messages_downloaded', (e) => { rootScope.on('messages_downloaded', (e) => {
const mids: number[] = e.detail; const mids: number[] = e.detail;
mids.forEach(mid => { mids.forEach(mid => {
@ -448,13 +448,13 @@ export class AppImManager {
}); });
}); });
$rootScope.$on('dialog_drop', (e) => { rootScope.on('dialog_drop', (e) => {
if(e.detail.peerID == this.peerID) { if(e.detail.peerID == this.peerID) {
this.setPeer(0); this.setPeer(0);
} }
}); });
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
const update = e.detail; const update = e.detail;
this.handleUpdate(update); this.handleUpdate(update);
@ -463,12 +463,12 @@ export class AppImManager {
window.addEventListener('blur', () => { window.addEventListener('blur', () => {
animationIntersector.checkAnimations(true); animationIntersector.checkAnimations(true);
this.offline = $rootScope.idle.isIDLE = true; this.offline = rootScope.idle.isIDLE = true;
this.updateStatus(); this.updateStatus();
clearInterval(this.updateStatusInterval); clearInterval(this.updateStatusInterval);
window.addEventListener('focus', () => { window.addEventListener('focus', () => {
this.offline = $rootScope.idle.isIDLE = false; this.offline = rootScope.idle.isIDLE = false;
this.updateStatus(); this.updateStatus();
this.updateStatusInterval = window.setInterval(() => this.updateStatus(), 50e3); this.updateStatusInterval = window.setInterval(() => this.updateStatus(), 50e3);
@ -725,7 +725,7 @@ export class AppImManager {
}); });
const onKeyDown = (e: KeyboardEvent) => { const onKeyDown = (e: KeyboardEvent) => {
if($rootScope.overlayIsActive) return; if(rootScope.overlayIsActive) return;
const target = e.target as HTMLElement; const target = e.target as HTMLElement;
@ -1159,8 +1159,8 @@ export class AppImManager {
this.topbar.style.display = this.chatInput.style.display = 'none'; this.topbar.style.display = this.chatInput.style.display = 'none';
this.goDownBtn.classList.add('hide'); this.goDownBtn.classList.add('hide');
this.cleanup(true); this.cleanup(true);
this.peerID = $rootScope.selectedPeerID = 0; this.peerID = rootScope.selectedPeerID = 0;
$rootScope.$broadcast('peer_changed', this.peerID); rootScope.broadcast('peer_changed', this.peerID);
this.selectTab(0); this.selectTab(0);
@ -1218,7 +1218,7 @@ export class AppImManager {
} }
// set new // set new
this.peerID = $rootScope.selectedPeerID = peerID; this.peerID = rootScope.selectedPeerID = peerID;
this.log('setPeer peerID:', this.peerID, dialog, lastMsgID, topMessage); this.log('setPeer peerID:', this.peerID, dialog, lastMsgID, topMessage);
@ -1436,7 +1436,7 @@ export class AppImManager {
appSidebarRight.sharedMediaTab.fillProfileElements(); appSidebarRight.sharedMediaTab.fillProfileElements();
$rootScope.$broadcast('peer_changed', this.peerID); rootScope.broadcast('peer_changed', this.peerID);
} }
public updateUnreadByDialog(dialog: Dialog) { public updateUnreadByDialog(dialog: Dialog) {
@ -2894,7 +2894,7 @@ export class AppImManager {
const dialog = appMessagesManager.getDialogByPeerID(peerID)[0]; const dialog = appMessagesManager.getDialogByPeerID(peerID)[0];
if(dialog) { if(dialog) {
dialog.notify_settings = notify_settings; dialog.notify_settings = notify_settings;
$rootScope.$broadcast('dialog_notify_settings', peerID); rootScope.broadcast('dialog_notify_settings', peerID);
} }
if(peerID == this.peerID) { if(peerID == this.peerID) {

114
src/lib/appManagers/appMessagesManager.ts

@ -16,7 +16,7 @@ import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import referenceDatabase, { ReferenceContext } from "../mtproto/referenceDatabase"; import referenceDatabase, { ReferenceContext } from "../mtproto/referenceDatabase";
import serverTimeManager from "../mtproto/serverTimeManager"; import serverTimeManager from "../mtproto/serverTimeManager";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import searchIndexManager from '../searchIndexManager'; import searchIndexManager from '../searchIndexManager';
import AppStorage from '../storage'; import AppStorage from '../storage';
import DialogsStorage from "../storages/dialogs"; import DialogsStorage from "../storages/dialogs";
@ -137,13 +137,13 @@ export class AppMessagesManager {
constructor() { constructor() {
this.dialogsStorage = new DialogsStorage(this, appMessagesIDsManager, appChatsManager, appPeersManager, serverTimeManager); this.dialogsStorage = new DialogsStorage(this, appMessagesIDsManager, appChatsManager, appPeersManager, serverTimeManager);
this.filtersStorage = new FiltersStorage(appPeersManager, appUsersManager, /* apiManager, */ $rootScope); this.filtersStorage = new FiltersStorage(appPeersManager, appUsersManager, /* apiManager, */ rootScope);
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
this.handleUpdate(e.detail); this.handleUpdate(e.detail);
}); });
$rootScope.$on('webpage_updated', (e) => { rootScope.on('webpage_updated', (e) => {
const eventData = e.detail; const eventData = e.detail;
eventData.msgs.forEach((msgID) => { eventData.msgs.forEach((msgID) => {
const message = this.getMessage(msgID) as Message.message; const message = this.getMessage(msgID) as Message.message;
@ -153,7 +153,7 @@ export class AppMessagesManager {
webpage: appWebPagesManager.getWebPage(eventData.id) webpage: appWebPagesManager.getWebPage(eventData.id)
}; };
$rootScope.$broadcast('message_edit', { rootScope.broadcast('message_edit', {
peerID: this.getMessagePeer(message), peerID: this.getMessagePeer(message),
mid: msgID, mid: msgID,
justMedia: true justMedia: true
@ -161,7 +161,7 @@ export class AppMessagesManager {
}); });
}); });
/* $rootScope.$on('draft_updated', (e) => { /* rootScope.$on('draft_updated', (e) => {
let eventData = e.detail;; let eventData = e.detail;;
var peerID = eventData.peerID; var peerID = eventData.peerID;
var draft = eventData.draft; var draft = eventData.draft;
@ -189,7 +189,7 @@ export class AppMessagesManager {
this.dialogsStorage.pushDialog(dialog); this.dialogsStorage.pushDialog(dialog);
$rootScope.$broadcast('dialog_draft', { rootScope.$broadcast('dialog_draft', {
peerID, peerID,
draft, draft,
index: dialog.index index: dialog.index
@ -459,7 +459,7 @@ export class AppMessagesManager {
} else { } else {
delete message.error; delete message.error;
} }
$rootScope.$broadcast('messages_pending'); rootScope.broadcast('messages_pending');
} }
message.send = () => { message.send = () => {
@ -545,7 +545,7 @@ export class AppMessagesManager {
this.saveMessages([message]); this.saveMessages([message]);
historyStorage.pending.unshift(messageID); historyStorage.pending.unshift(messageID);
$rootScope.$broadcast('history_append', {peerID, messageID, my: true}); rootScope.broadcast('history_append', {peerID, messageID, my: true});
setTimeout(() => message.send(), 0); setTimeout(() => message.send(), 0);
// setTimeout(function () { // setTimeout(function () {
@ -790,7 +790,7 @@ export class AppMessagesManager {
delete message.error; delete message.error;
} }
$rootScope.$broadcast('messages_pending'); rootScope.broadcast('messages_pending');
}; };
let uploaded = false, let uploaded = false,
@ -912,7 +912,7 @@ export class AppMessagesManager {
this.saveMessages([message]); this.saveMessages([message]);
historyStorage.pending.unshift(messageID); historyStorage.pending.unshift(messageID);
$rootScope.$broadcast('history_append', {peerID, messageID, my: true}); rootScope.broadcast('history_append', {peerID, messageID, my: true});
setTimeout(message.send.bind(this), 0); setTimeout(message.send.bind(this), 0);
@ -1060,14 +1060,14 @@ export class AppMessagesManager {
this.saveMessages([message]); this.saveMessages([message]);
historyStorage.pending.unshift(messageID); historyStorage.pending.unshift(messageID);
//$rootScope.$broadcast('history_append', {peerID: peerID, messageID: messageID, my: true}); //rootScope.$broadcast('history_append', {peerID: peerID, messageID: messageID, my: true});
this.pendingByRandomID[randomIDS] = [peerID, messageID]; this.pendingByRandomID[randomIDS] = [peerID, messageID];
return message; return message;
}); });
$rootScope.$broadcast('history_append', {peerID, messageID: messages[messages.length - 1].id, my: true}); rootScope.broadcast('history_append', {peerID, messageID: messages[messages.length - 1].id, my: true});
let toggleError = (message: any, on: boolean) => { let toggleError = (message: any, on: boolean) => {
if(on) { if(on) {
@ -1076,7 +1076,7 @@ export class AppMessagesManager {
delete message.error; delete message.error;
} }
$rootScope.$broadcast('messages_pending'); rootScope.broadcast('messages_pending');
}; };
let uploaded = false, let uploaded = false,
@ -1352,7 +1352,7 @@ export class AppMessagesManager {
delete historyMessage.error delete historyMessage.error
} }
} */ } */
$rootScope.$broadcast('messages_pending'); rootScope.broadcast('messages_pending');
}; };
message.send = () => { message.send = () => {
@ -1404,7 +1404,7 @@ export class AppMessagesManager {
this.saveMessages([message]); this.saveMessages([message]);
historyStorage.pending.unshift(messageID); historyStorage.pending.unshift(messageID);
$rootScope.$broadcast('history_append', {peerID, messageID, my: true}); rootScope.broadcast('history_append', {peerID, messageID, my: true});
setTimeout(message.send, 0); setTimeout(message.send, 0);
@ -1621,10 +1621,10 @@ export class AppMessagesManager {
if(Object.keys(noIDsDialogs).length) { if(Object.keys(noIDsDialogs).length) {
//setTimeout(() => { // test bad situation //setTimeout(() => { // test bad situation
this.reloadConversation(Object.keys(noIDsDialogs).map(id => +id)).then(() => { this.reloadConversation(Object.keys(noIDsDialogs).map(id => +id)).then(() => {
$rootScope.$broadcast('dialogs_multiupdate', noIDsDialogs); rootScope.broadcast('dialogs_multiupdate', noIDsDialogs);
for(let peerID in noIDsDialogs) { for(let peerID in noIDsDialogs) {
$rootScope.$broadcast('dialog_unread', {peerID: +peerID}); rootScope.broadcast('dialog_unread', {peerID: +peerID});
} }
}); });
//}, 10e3); //}, 10e3);
@ -1641,7 +1641,7 @@ export class AppMessagesManager {
if(hasPrepend) { if(hasPrepend) {
this.scheduleHandleNewDialogs(); this.scheduleHandleNewDialogs();
} else { } else {
$rootScope.$broadcast('dialogs_multiupdate', {}); rootScope.broadcast('dialogs_multiupdate', {});
} }
return count; return count;
@ -1788,11 +1788,11 @@ export class AppMessagesManager {
} }
if(justClear) { if(justClear) {
$rootScope.$broadcast('dialog_flush', {peerID}); rootScope.broadcast('dialog_flush', {peerID});
} else { } else {
this.dialogsStorage.dropDialog(peerID); this.dialogsStorage.dropDialog(peerID);
$rootScope.$broadcast('dialog_drop', {peerID}); rootScope.broadcast('dialog_drop', {peerID});
} }
}); });
} }
@ -1805,14 +1805,14 @@ export class AppMessagesManager {
if(!this.messagesStorage.hasOwnProperty(mid)) { if(!this.messagesStorage.hasOwnProperty(mid)) {
this.wrapSingleMessage(mid).then(() => { this.wrapSingleMessage(mid).then(() => {
$rootScope.$broadcast('peer_pinned_message', peerID); rootScope.broadcast('peer_pinned_message', peerID);
}); });
return; return;
} }
} }
$rootScope.$broadcast('peer_pinned_message', peerID); rootScope.broadcast('peer_pinned_message', peerID);
} }
public getPinnedMessage(peerID: number) { public getPinnedMessage(peerID: number) {
@ -2330,10 +2330,10 @@ export class AppMessagesManager {
setTimeout(() => { setTimeout(() => {
const dropped = this.dialogsStorage.dropDialog(migrateFrom); const dropped = this.dialogsStorage.dropDialog(migrateFrom);
if(dropped.length) { if(dropped.length) {
$rootScope.$broadcast('dialog_drop', {peerID: migrateFrom, dialog: dropped[0]}); rootScope.broadcast('dialog_drop', {peerID: migrateFrom, dialog: dropped[0]});
} }
$rootScope.$broadcast('dialog_migrate', {migrateFrom, migrateTo}); rootScope.broadcast('dialog_migrate', {migrateFrom, migrateTo});
}, 100); }, 100);
} }
} }
@ -2394,7 +2394,7 @@ export class AppMessagesManager {
const message = this.messagesStorage[messageID]; const message = this.messagesStorage[messageID];
return message && ( return message && (
message.peerID > 0 message.peerID > 0
|| message.fromID == $rootScope.myID || message.fromID == rootScope.myID
|| appChatsManager.getChat(message.peerID)._ == 'chat' || appChatsManager.getChat(message.peerID)._ == 'chat'
|| appChatsManager.hasRights(message.peerID, 'deleteRevoke') || appChatsManager.hasRights(message.peerID, 'deleteRevoke')
); );
@ -2440,7 +2440,7 @@ export class AppMessagesManager {
this.saveConversation(dialog); this.saveConversation(dialog);
/* if(wasDialogBefore) { /* if(wasDialogBefore) {
$rootScope.$broadcast('dialog_top', dialog); rootScope.$broadcast('dialog_top', dialog);
} else { */ } else { */
updatedDialogs[peerID] = dialog; updatedDialogs[peerID] = dialog;
hasUpdated = true; hasUpdated = true;
@ -2448,7 +2448,7 @@ export class AppMessagesManager {
} else { } else {
const dropped = this.dialogsStorage.dropDialog(peerID); const dropped = this.dialogsStorage.dropDialog(peerID);
if(dropped.length) { if(dropped.length) {
$rootScope.$broadcast('dialog_drop', {peerID: peerID, dialog: dropped[0]}); rootScope.broadcast('dialog_drop', {peerID: peerID, dialog: dropped[0]});
} }
} }
@ -2463,7 +2463,7 @@ export class AppMessagesManager {
}); });
if(hasUpdated) { if(hasUpdated) {
$rootScope.$broadcast('dialogs_multiupdate', updatedDialogs); rootScope.broadcast('dialogs_multiupdate', updatedDialogs);
} }
} }
@ -2548,7 +2548,7 @@ export class AppMessagesManager {
dialog.unread_count++; dialog.unread_count++;
} */ } */
if(this.mergeReplyKeyboard(historyStorage, message)) { if(this.mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID}); rootScope.broadcast('history_reply_markup', {peerID});
} }
} else if(!historyStorage.history.length && !historyStorage.pending.length) { } else if(!historyStorage.history.length && !historyStorage.pending.length) {
historyStorage[mid > 0 ? 'history' : 'pending'].push(mid); historyStorage[mid > 0 ? 'history' : 'pending'].push(mid);
@ -2875,7 +2875,7 @@ export class AppMessagesManager {
clearTimeout(this.newMessagesHandlePromise); clearTimeout(this.newMessagesHandlePromise);
this.newMessagesHandlePromise = 0; this.newMessagesHandlePromise = 0;
$rootScope.$broadcast('history_multiappend', this.newMessagesToHandle); rootScope.broadcast('history_multiappend', this.newMessagesToHandle);
this.newMessagesToHandle = {}; this.newMessagesToHandle = {};
}; };
@ -2903,7 +2903,7 @@ export class AppMessagesManager {
this.incrementMaxSeenID(newMaxSeenID); this.incrementMaxSeenID(newMaxSeenID);
} }
$rootScope.$broadcast('dialogs_multiupdate', this.newDialogsToHandle as any); rootScope.broadcast('dialogs_multiupdate', this.newDialogsToHandle as any);
this.newDialogsToHandle = {}; this.newDialogsToHandle = {};
}; };
@ -3189,7 +3189,7 @@ export class AppMessagesManager {
} }
if(this.mergeReplyKeyboard(historyStorage, message)) { if(this.mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID}); rootScope.broadcast('history_reply_markup', {peerID});
} }
if(!message.pFlags.out && message.from_id) { if(!message.pFlags.out && message.from_id) {
@ -3201,7 +3201,7 @@ export class AppMessagesManager {
if(randomID) { if(randomID) {
if(pendingMessage = this.finalizePendingMessage(randomID, message)) { if(pendingMessage = this.finalizePendingMessage(randomID, message)) {
$rootScope.$broadcast('history_update', {peerID, mid: message.mid}); rootScope.broadcast('history_update', {peerID, mid: message.mid});
} }
delete this.pendingByMessageID[message.mid]; delete this.pendingByMessageID[message.mid];
@ -3251,7 +3251,7 @@ export class AppMessagesManager {
dialog.pFlags.unread_mark = true; dialog.pFlags.unread_mark = true;
} }
$rootScope.$broadcast('dialogs_multiupdate', {peerID: dialog}); rootScope.broadcast('dialogs_multiupdate', {peerID: dialog});
} }
break; break;
@ -3409,10 +3409,10 @@ export class AppMessagesManager {
// @ts-ignore // @ts-ignore
if(message.clear_history) { // that's will never happen if(message.clear_history) { // that's will never happen
if(isTopMessage) { if(isTopMessage) {
$rootScope.$broadcast('dialog_flush', {peerID: peerID}); rootScope.broadcast('dialog_flush', {peerID: peerID});
} }
} else { } else {
$rootScope.$broadcast('message_edit', { rootScope.broadcast('message_edit', {
peerID, peerID,
mid, mid,
justMedia: false justMedia: false
@ -3429,14 +3429,14 @@ export class AppMessagesManager {
} }
if(pinnedMid) { if(pinnedMid) {
$rootScope.$broadcast('peer_pinned_message', peerID); rootScope.broadcast('peer_pinned_message', peerID);
} }
} }
if(isTopMessage || groupID) { if(isTopMessage || groupID) {
const updatedDialogs: {[peerID: number]: Dialog} = {}; const updatedDialogs: {[peerID: number]: Dialog} = {};
updatedDialogs[peerID] = dialog; updatedDialogs[peerID] = dialog;
$rootScope.$broadcast('dialogs_multiupdate', updatedDialogs); rootScope.broadcast('dialogs_multiupdate', updatedDialogs);
} }
} }
break; break;
@ -3507,11 +3507,11 @@ export class AppMessagesManager {
// need be commented for read out messages // need be commented for read out messages
//if(newUnreadCount != 0 || !isOut) { // fix 16.11.2019 (maybe not) //if(newUnreadCount != 0 || !isOut) { // fix 16.11.2019 (maybe not)
//////////this.log.warn(dT(), 'cnt', peerID, newUnreadCount, isOut, foundDialog, update, foundAffected); //////////this.log.warn(dT(), 'cnt', peerID, newUnreadCount, isOut, foundDialog, update, foundAffected);
$rootScope.$broadcast('dialog_unread', {peerID, count: newUnreadCount}); rootScope.broadcast('dialog_unread', {peerID, count: newUnreadCount});
//} //}
if(foundAffected) { if(foundAffected) {
$rootScope.$broadcast('messages_read'); rootScope.broadcast('messages_read');
} }
break; break;
} }
@ -3534,7 +3534,7 @@ export class AppMessagesManager {
} }
} }
$rootScope.$broadcast('messages_media_read', messages); rootScope.broadcast('messages_media_read', messages);
break; break;
} }
@ -3631,11 +3631,11 @@ export class AppMessagesManager {
if(updatedData.albums) { if(updatedData.albums) {
for(const groupID in updatedData.albums) { for(const groupID in updatedData.albums) {
$rootScope.$broadcast('album_edit', {peerID, groupID, deletedMids: [...updatedData.albums[groupID]]}); rootScope.broadcast('album_edit', {peerID, groupID, deletedMids: [...updatedData.albums[groupID]]});
/* const mids = this.getMidsByAlbum(groupID); /* const mids = this.getMidsByAlbum(groupID);
if(mids.length) { if(mids.length) {
const mid = Math.max(...mids); const mid = Math.max(...mids);
$rootScope.$broadcast('message_edit', {peerID, mid, justMedia: false}); rootScope.$broadcast('message_edit', {peerID, mid, justMedia: false});
} */ } */
} }
} }
@ -3656,7 +3656,7 @@ export class AppMessagesManager {
historyStorage.pending = newPending; historyStorage.pending = newPending;
$rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs}); rootScope.broadcast('history_delete', {peerID, msgs: updatedData.msgs});
} }
const foundDialog = this.getDialogByPeerID(peerID)[0]; const foundDialog = this.getDialogByPeerID(peerID)[0];
@ -3664,7 +3664,7 @@ export class AppMessagesManager {
if(updatedData.unread) { if(updatedData.unread) {
foundDialog.unread_count -= updatedData.unread; foundDialog.unread_count -= updatedData.unread;
$rootScope.$broadcast('dialog_unread', { rootScope.broadcast('dialog_unread', {
peerID, peerID,
count: foundDialog.unread_count count: foundDialog.unread_count
}); });
@ -3692,7 +3692,7 @@ export class AppMessagesManager {
if(canViewHistory != hasHistory) { if(canViewHistory != hasHistory) {
delete this.historiesStorage[peerID]; delete this.historiesStorage[peerID];
$rootScope.$broadcast('history_forbidden', peerID); rootScope.broadcast('history_forbidden', peerID);
} }
if(hasDialog != needDialog) { if(hasDialog != needDialog) {
@ -3701,7 +3701,7 @@ export class AppMessagesManager {
} else { } else {
if(foundDialog[0]) { if(foundDialog[0]) {
this.dialogsStorage.dropDialog(peerID); this.dialogsStorage.dropDialog(peerID);
$rootScope.$broadcast('dialog_drop', {peerID: peerID, dialog: foundDialog[0]}); rootScope.broadcast('dialog_drop', {peerID: peerID, dialog: foundDialog[0]});
} }
} }
} }
@ -3719,7 +3719,7 @@ export class AppMessagesManager {
delete this.historiesStorage[peerID]; delete this.historiesStorage[peerID];
this.reloadConversation(-channelID).then(() => { this.reloadConversation(-channelID).then(() => {
$rootScope.$broadcast('history_reload', peerID); rootScope.broadcast('history_reload', peerID);
}); });
break; break;
@ -3731,7 +3731,7 @@ export class AppMessagesManager {
const message = this.getMessage(mid); const message = this.getMessage(mid);
if(message && message.views && message.views < views) { if(message && message.views && message.views < views) {
message.views = views; message.views = views;
$rootScope.$broadcast('message_views', {mid, views}); rootScope.broadcast('message_views', {mid, views});
} }
break; break;
} }
@ -3809,7 +3809,7 @@ export class AppMessagesManager {
delete message.random_id; delete message.random_id;
delete message.send; delete message.send;
$rootScope.$broadcast('messages_pending'); rootScope.broadcast('messages_pending');
} }
delete this.messagesStorage[tempID]; delete this.messagesStorage[tempID];
@ -3835,7 +3835,7 @@ export class AppMessagesManager {
delete this.tempFinalizeCallbacks[tempID]; delete this.tempFinalizeCallbacks[tempID];
} }
$rootScope.$broadcast('message_sent', {tempID, mid}); rootScope.broadcast('message_sent', {tempID, mid});
} }
public incrementMaxSeenID(maxID: number) { public incrementMaxSeenID(maxID: number) {
@ -3989,7 +3989,7 @@ export class AppMessagesManager {
historyStorage.history.splice(offset, historyStorage.history.length - offset); historyStorage.history.splice(offset, historyStorage.history.length - offset);
historyResult.messages.forEach((message: any) => { historyResult.messages.forEach((message: any) => {
if(this.mergeReplyKeyboard(historyStorage, message)) { if(this.mergeReplyKeyboard(historyStorage, message)) {
$rootScope.$broadcast('history_reply_markup', {peerID}); rootScope.broadcast('history_reply_markup', {peerID});
} }
historyStorage.history.push(message.mid); historyStorage.history.push(message.mid);
@ -4047,7 +4047,7 @@ export class AppMessagesManager {
//console.trace('requestHistory', peerID, maxID, limit, offset); //console.trace('requestHistory', peerID, maxID, limit, offset);
$rootScope.$broadcast('history_request'); rootScope.broadcast('history_request');
return apiManager.invokeApi('messages.getHistory', { return apiManager.invokeApi('messages.getHistory', {
peer: appPeersManager.getInputPeerByID(peerID), peer: appPeersManager.getInputPeerByID(peerID),
@ -4187,7 +4187,7 @@ export class AppMessagesManager {
this.saveMessages(getMessagesResult.messages); this.saveMessages(getMessagesResult.messages);
} }
$rootScope.$broadcast('messages_downloaded', splitted.mids[+channelID]); rootScope.broadcast('messages_downloaded', splitted.mids[+channelID]);
})); }));
}); });
@ -4202,7 +4202,7 @@ export class AppMessagesManager {
public wrapSingleMessage(msgID: number, overwrite = false): Promise<void> { public wrapSingleMessage(msgID: number, overwrite = false): Promise<void> {
if(this.messagesStorage[msgID] && !overwrite) { if(this.messagesStorage[msgID] && !overwrite) {
$rootScope.$broadcast('messages_downloaded', [msgID]); rootScope.broadcast('messages_downloaded', [msgID]);
return Promise.resolve(); return Promise.resolve();
} else if(this.needSingleMessages.indexOf(msgID) == -1) { } else if(this.needSingleMessages.indexOf(msgID) == -1) {
this.needSingleMessages.push(msgID); this.needSingleMessages.push(msgID);
@ -4213,7 +4213,7 @@ export class AppMessagesManager {
} }
public setTyping(peerID: number, _action: any): Promise<boolean> { public setTyping(peerID: number, _action: any): Promise<boolean> {
if(!$rootScope.myID) return Promise.resolve(false); if(!rootScope.myID) return Promise.resolve(false);
const action: SendMessageAction = typeof(_action) == 'string' ? {_: _action} : _action; const action: SendMessageAction = typeof(_action) == 'string' ? {_: _action} : _action;
return apiManager.invokeApi('messages.setTyping', { return apiManager.invokeApi('messages.setTyping', {

6
src/lib/appManagers/appPeersManager.ts

@ -2,7 +2,7 @@ import { isObject } from "../../helpers/object";
import { DialogPeer, InputDialogPeer, InputPeer, Peer } from "../../layer"; import { DialogPeer, InputDialogPeer, InputPeer, Peer } from "../../layer";
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import appChatsManager from "./appChatsManager"; import appChatsManager from "./appChatsManager";
import appUsersManager from "./appUsersManager"; import appUsersManager from "./appUsersManager";
@ -29,7 +29,7 @@ export class AppPeersManager {
} */ } */
public canPinMessage(peerID: number) { public canPinMessage(peerID: number) {
return peerID == $rootScope.myID || (peerID < 0 && appChatsManager.hasRights(-peerID, 'pin')); return peerID == rootScope.myID || (peerID < 0 && appChatsManager.hasRights(-peerID, 'pin'));
} }
public getPeerPhoto(peerID: number) { public getPeerPhoto(peerID: number) {
@ -53,7 +53,7 @@ export class AppPeersManager {
public getPeerTitle(peerID: number | any, plainText = false, onlyFirstName = false) { public getPeerTitle(peerID: number | any, plainText = false, onlyFirstName = false) {
if(!peerID) { if(!peerID) {
peerID = $rootScope.myID; peerID = rootScope.myID;
} }
let peer: any = {}; let peer: any = {};

6
src/lib/appManagers/appPollsManager.ts

@ -4,7 +4,7 @@ import { logger, LogLevels } from "../logger";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import apiUpdatesManager from "./apiUpdatesManager"; import apiUpdatesManager from "./apiUpdatesManager";
import appMessagesManager from './appMessagesManager'; import appMessagesManager from './appMessagesManager';
import appPeersManager from './appPeersManager'; import appPeersManager from './appPeersManager';
@ -77,7 +77,7 @@ class AppPollsManager {
private log = logger('POLLS', LogLevels.error); private log = logger('POLLS', LogLevels.error);
constructor() { constructor() {
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
let update = e.detail; let update = e.detail;
this.handleUpdate(update); this.handleUpdate(update);
@ -95,7 +95,7 @@ class AppPollsManager {
} }
poll = this.savePoll(poll, update.results); poll = this.savePoll(poll, update.results);
$rootScope.$broadcast('poll_update', {poll, results: update.results}); rootScope.broadcast('poll_update', {poll, results: update.results});
break; break;
} }

4
src/lib/appManagers/appStateManager.ts

@ -2,7 +2,7 @@ import type { Dialog } from './appMessagesManager';
import type { AppStickersManager } from './appStickersManager'; import type { AppStickersManager } from './appStickersManager';
import { App, MOUNT_CLASS_TO, UserAuth } from '../mtproto/mtproto_config'; import { App, MOUNT_CLASS_TO, UserAuth } from '../mtproto/mtproto_config';
import EventListenerBase from '../../helpers/eventListenerBase'; import EventListenerBase from '../../helpers/eventListenerBase';
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
import AppStorage from '../storage'; import AppStorage from '../storage';
import { logger } from '../logger'; import { logger } from '../logger';
import type { AppUsersManager } from './appUsersManager'; import type { AppUsersManager } from './appUsersManager';
@ -91,7 +91,7 @@ export class AppStateManager extends EventListenerBase<{
if(auth?.id) { if(auth?.id) {
// ! Warning ! DON'T delete this // ! Warning ! DON'T delete this
this.state.authState = {_: 'authStateSignedIn'}; this.state.authState = {_: 'authStateSignedIn'};
$rootScope.$broadcast('user_auth', {id: auth.id}); rootScope.broadcast('user_auth', {id: auth.id});
} else if(!this.state.authState) { } else if(!this.state.authState) {
this.state.authState = {_: 'authStateSignIn'}; this.state.authState = {_: 'authStateSignIn'};
} }

10
src/lib/appManagers/appStickersManager.ts

@ -2,7 +2,7 @@ import { Document, InputFileLocation, InputStickerSet, MessagesRecentStickers, M
import { Modify } from '../../types'; import { Modify } from '../../types';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config'; import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config';
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
import appDocsManager from './appDocsManager'; import appDocsManager from './appDocsManager';
import appStateManager from './appStateManager'; import appStateManager from './appStateManager';
@ -44,13 +44,13 @@ export class AppStickersManager {
//} //}
}); });
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
const update = e.detail; const update = e.detail;
switch(update._) { switch(update._) {
case 'updateNewStickerSet': { case 'updateNewStickerSet': {
this.saveStickerSet(update.stickerset, update.stickerset.set.id); this.saveStickerSet(update.stickerset, update.stickerset.set.id);
$rootScope.$broadcast('stickers_installed', update.stickerset.set); rootScope.broadcast('stickers_installed', update.stickerset.set);
break; break;
} }
} }
@ -210,7 +210,7 @@ export class AppStickersManager {
if(res) { if(res) {
delete set.installed_date; delete set.installed_date;
$rootScope.$broadcast('stickers_deleted', set); rootScope.broadcast('stickers_deleted', set);
return true; return true;
} }
} else { } else {
@ -221,7 +221,7 @@ export class AppStickersManager {
if(res) { if(res) {
set.installed_date = Date.now() / 1000 | 0; set.installed_date = Date.now() / 1000 | 0;
$rootScope.$broadcast('stickers_installed', set); rootScope.broadcast('stickers_installed', set);
return true; return true;
} }
} }

26
src/lib/appManagers/appUsersManager.ts

@ -7,7 +7,7 @@ import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "../mtproto/mtproto_config";
import serverTimeManager from "../mtproto/serverTimeManager"; import serverTimeManager from "../mtproto/serverTimeManager";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import searchIndexManager from "../searchIndexManager"; import searchIndexManager from "../searchIndexManager";
import appChatsManager from "./appChatsManager"; import appChatsManager from "./appChatsManager";
import appPeersManager from "./appPeersManager"; import appPeersManager from "./appPeersManager";
@ -32,9 +32,9 @@ export class AppUsersManager {
constructor() { constructor() {
setInterval(this.updateUsersStatuses, 60000); setInterval(this.updateUsersStatuses, 60000);
$rootScope.$on('stateSynchronized', this.updateUsersStatuses); rootScope.on('stateSynchronized', this.updateUsersStatuses);
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
const update = e.detail as Update; const update = e.detail as Update;
//console.log('on apiUpdate', update); //console.log('on apiUpdate', update);
switch(update._) { switch(update._) {
@ -54,7 +54,7 @@ export class AppUsersManager {
} }
user.sortStatus = this.getUserStatusForSort(user.status); user.sortStatus = this.getUserStatusForSort(user.status);
$rootScope.$broadcast('user_update', userID); rootScope.broadcast('user_update', userID);
} //////else console.warn('No user by id:', userID); } //////else console.warn('No user by id:', userID);
break; break;
@ -74,8 +74,8 @@ export class AppUsersManager {
update.photo : {empty: true}); update.photo : {empty: true});
} }
$rootScope.$broadcast('user_update', userID); rootScope.broadcast('user_update', userID);
$rootScope.$broadcast('avatar_update', userID); rootScope.broadcast('avatar_update', userID);
} else console.warn('No user by id:', userID); } else console.warn('No user by id:', userID);
break; break;
@ -281,7 +281,7 @@ export class AppUsersManager {
safeReplaceObject(result, user); safeReplaceObject(result, user);
} }
$rootScope.$broadcast('user_update', userID); rootScope.broadcast('user_update', userID);
if(this.cachedPhotoLocations[userID] !== undefined) { if(this.cachedPhotoLocations[userID] !== undefined) {
safeReplaceObject(this.cachedPhotoLocations[userID], user && safeReplaceObject(this.cachedPhotoLocations[userID], user &&
@ -323,7 +323,7 @@ export class AppUsersManager {
} }
public getSelf() { public getSelf() {
return this.getUser($rootScope.myID); return this.getUser(rootScope.myID);
} }
public getUserStatusString(userID: number) { public getUserStatusString(userID: number) {
@ -404,7 +404,7 @@ export class AppUsersManager {
} }
public isNonContactUser(id: number) { public isNonContactUser(id: number) {
return this.isRegularUser(id) && !this.isContact(id) && id != $rootScope.myID; return this.isRegularUser(id) && !this.isContact(id) && id != rootScope.myID;
} }
public hasUser(id: number, allowMin?: boolean) { public hasUser(id: number, allowMin?: boolean) {
@ -455,7 +455,7 @@ export class AppUsersManager {
user.status.expires < timestampNow) { user.status.expires < timestampNow) {
user.status = {_: 'userStatusOffline', was_online: user.status.expires}; user.status = {_: 'userStatusOffline', was_online: user.status.expires};
$rootScope.$broadcast('user_update', user.id); rootScope.broadcast('user_update', user.id);
} }
} }
}; };
@ -479,7 +479,7 @@ export class AppUsersManager {
}; };
user.sortStatus = this.getUserStatusForSort(user.status); user.sortStatus = this.getUserStatusForSort(user.status);
$rootScope.$broadcast('user_update', id); rootScope.broadcast('user_update', id);
} }
} }
@ -615,7 +615,7 @@ export class AppUsersManager {
this.contactsList.splice(curPos, 1); this.contactsList.splice(curPos, 1);
} }
$rootScope.$broadcast('contacts_update', userID); rootScope.$broadcast('contacts_update', userID);
} }
} }
} */ } */
@ -637,7 +637,7 @@ export class AppUsersManager {
user.status = status; user.status = status;
user.sortStatus = this.getUserStatusForSort(user.status); user.sortStatus = this.getUserStatusForSort(user.status);
$rootScope.$broadcast('user_update', userID); rootScope.broadcast('user_update', userID);
} }
} }
} }

6
src/lib/appManagers/appWebPagesManager.ts

@ -2,7 +2,7 @@ import appPhotosManager from "./appPhotosManager";
import appDocsManager from "./appDocsManager"; import appDocsManager from "./appDocsManager";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import { ReferenceContext } from "../mtproto/referenceDatabase"; import { ReferenceContext } from "../mtproto/referenceDatabase";
import $rootScope from "../rootScope"; import rootScope from "../rootScope";
import { safeReplaceObject } from "../../helpers/object"; import { safeReplaceObject } from "../../helpers/object";
import { limitSymbols } from "../../helpers/string"; import { limitSymbols } from "../../helpers/string";
@ -11,7 +11,7 @@ class AppWebPagesManager {
pendingWebPages: any = {}; pendingWebPages: any = {};
constructor() { constructor() {
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
const update = e.detail; const update = e.detail;
switch(update._) { switch(update._) {
@ -93,7 +93,7 @@ class AppWebPagesManager {
msgs.push(+msgID); msgs.push(+msgID);
} }
$rootScope.$broadcast('webpage_updated', { rootScope.broadcast('webpage_updated', {
id: apiWebPage.id, id: apiWebPage.id,
msgs: msgs msgs: msgs
}); });

8
src/lib/mtproto/apiManager.ts

@ -14,7 +14,7 @@ import { CancellablePromise, deferredPromise } from '../../helpers/cancellablePr
import { bytesFromHex, bytesToHex } from '../../helpers/bytes'; import { bytesFromHex, bytesToHex } from '../../helpers/bytes';
/// #if !MTPROTO_WORKER /// #if !MTPROTO_WORKER
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
/// #endif /// #endif
/* var networker = apiManager.cachedNetworkers.websocket.upload[2]; /* var networker = apiManager.cachedNetworkers.websocket.upload[2];
@ -90,7 +90,7 @@ export class ApiManager {
this.telegramMeNotify(true); this.telegramMeNotify(true);
/// #if !MTPROTO_WORKER /// #if !MTPROTO_WORKER
$rootScope.$broadcast('user_auth', fullUserAuth); rootScope.broadcast('user_auth', fullUserAuth);
/// #endif /// #endif
} }
@ -207,6 +207,10 @@ export class ApiManager {
} }
} }
/* networker.onConnectionStatusChange = (online) => {
console.log('status:', online);
}; */
delete this.gettingNetworkers[getKey]; delete this.gettingNetworkers[getKey];
return cache[dcID] = networker; return cache[dcID] = networker;
}); });

4
src/lib/mtproto/mtproto.worker.ts

@ -56,6 +56,10 @@ networkerFactory.setUpdatesProcessor((obj, bool) => {
respond({update: {obj, bool}}); respond({update: {obj, bool}});
}); });
networkerFactory.onConnectionStatusChange = (status) => {
respond({type: 'connectionStatusChange', payload: status});
};
ctx.addEventListener('message', async(e) => { ctx.addEventListener('message', async(e) => {
try { try {
const task = e.data; const task = e.data;

8
src/lib/mtproto/mtprotoworker.ts

@ -4,7 +4,7 @@ import type { MethodDeclMap } from '../../layer';
import type { InvokeApiOptions } from '../../types'; import type { InvokeApiOptions } from '../../types';
import CryptoWorkerMethods from '../crypto/crypto_methods'; import CryptoWorkerMethods from '../crypto/crypto_methods';
import { logger } from '../logger'; import { logger } from '../logger';
import $rootScope from '../rootScope'; import rootScope from '../rootScope';
import AppStorage from '../storage'; import AppStorage from '../storage';
import webpWorkerController from '../webp/webpWorkerController'; import webpWorkerController from '../webp/webpWorkerController';
import type { DownloadOptions } from './apiFileManager'; import type { DownloadOptions } from './apiFileManager';
@ -127,7 +127,9 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
this.updatesProcessor(task.update.obj, task.update.bool); this.updatesProcessor(task.update.obj, task.update.bool);
} }
} else if(task.progress) { } else if(task.progress) {
$rootScope.$broadcast('download_progress', task.progress); rootScope.broadcast('download_progress', task.progress);
} else if(task.type == 'connectionStatusChange') {
rootScope.broadcast('connection_status_change', task.payload);
} else if(task.type == 'convertWebp') { } else if(task.type == 'convertWebp') {
webpWorkerController.postMessage(task); webpWorkerController.postMessage(task);
} else if((task as ServiceWorkerTaskResponse).type == 'requestFilePart') { } else if((task as ServiceWorkerTaskResponse).type == 'requestFilePart') {
@ -229,7 +231,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
} }
public setUserAuth(userAuth: {id: number}) { public setUserAuth(userAuth: {id: number}) {
$rootScope.$broadcast('user_auth', userAuth); rootScope.broadcast('user_auth', userAuth);
return this.performTaskWorker('setUserAuth', userAuth); return this.performTaskWorker('setUserAuth', userAuth);
} }

95
src/lib/mtproto/networker.ts

@ -70,7 +70,9 @@ export type MTMessage = InvokeApiOptions & MTMessageOptions & {
export default class MTPNetworker { export default class MTPNetworker {
private authKeyUint8: Uint8Array; private authKeyUint8: Uint8Array;
private upload: boolean; private isFileNetworker: boolean;
private isFileUpload: boolean;
private isFileDownload: boolean;
private lastServerMessages: Array<string> = []; private lastServerMessages: Array<string> = [];
@ -105,19 +107,27 @@ export default class MTPNetworker {
//private transport: MTTransport; //private transport: MTTransport;
private name: string;
private log: ReturnType<typeof logger>; private log: ReturnType<typeof logger>;
constructor(private dcID: number, private authKey: number[], private authKeyID: Uint8Array, private isOnline = false;
private serverSalt: number[], private transport: MTTransport, private options: InvokeApiOptions = {}) { //public onConnectionStatusChange: (online: boolean) => void;
constructor(public dcID: number, private authKey: number[], private authKeyID: Uint8Array,
private serverSalt: number[], private transport: MTTransport, options: InvokeApiOptions = {}) {
this.authKeyUint8 = convertToUint8Array(this.authKey); this.authKeyUint8 = convertToUint8Array(this.authKey);
//this.authKeyID = sha1BytesSync(this.authKey).slice(-8); //this.authKeyID = sha1BytesSync(this.authKey).slice(-8);
//console.trace('Create', dcID, options); //console.trace('Create', dcID, options);
const suffix = this.options.fileUpload ? '-U' : this.options.fileDownload ? '-D' : ''; this.isFileUpload = !!options.fileUpload;
this.upload = this.options.fileUpload || this.options.fileDownload; this.isFileDownload = !!options.fileDownload;
//this.log = logger('NET-' + dcID + suffix, this.upload && this.dcID == 2 ? LogLevels.debug | LogLevels.warn | LogLevels.log | LogLevels.error : LogLevels.error); this.isFileNetworker = this.isFileUpload || this.isFileDownload;
this.log = logger('NET-' + dcID + suffix, LogLevels.log | LogLevels.error);
const suffix = this.isFileUpload ? '-U' : this.isFileDownload ? '-D' : '';
this.name = 'NET-' + dcID + suffix;
//this.log = logger(this.name, this.upload && this.dcID == 2 ? LogLevels.debug | LogLevels.warn | LogLevels.log | LogLevels.error : LogLevels.error);
this.log = logger(this.name, LogLevels.log | LogLevels.error);
this.log('constructor'/* , this.authKey, this.authKeyID, this.serverSalt */); this.log('constructor'/* , this.authKey, this.authKeyID, this.serverSalt */);
// Test resend after bad_server_salt // Test resend after bad_server_salt
@ -130,8 +140,8 @@ export default class MTPNetworker {
// if(!NetworkerFactory.offlineInited) { // if(!NetworkerFactory.offlineInited) {
// NetworkerFactory.offlineInited = true; // NetworkerFactory.offlineInited = true;
// /* $rootScope.offline = true // /* rootScope.offline = true
// $rootScope.offlineConnecting = true */ // rootScope.offlineConnecting = true */
// } // }
/// #if MTPROTO_HTTP_UPLOAD /// #if MTPROTO_HTTP_UPLOAD
@ -198,7 +208,7 @@ export default class MTPNetworker {
return seqNo; return seqNo;
} }
public wrapMtpCall(method: string, params: any = {}, options: MTMessageOptions = {}) { public wrapMtpCall(method: string, params: any, options: MTMessageOptions) {
const serializer = new TLSerialization({mtproto: true}); const serializer = new TLSerialization({mtproto: true});
serializer.storeMethod(method, params); serializer.storeMethod(method, params);
@ -218,7 +228,7 @@ export default class MTPNetworker {
return this.pushMessage(message, options); return this.pushMessage(message, options);
} }
public wrapMtpMessage(object: any = {}, options: MTMessageOptions = {}) { public wrapMtpMessage(object: any, options: MTMessageOptions) {
const serializer = new TLSerialization({mtproto: true}); const serializer = new TLSerialization({mtproto: true});
serializer.storeObject(object, 'Object'); serializer.storeObject(object, 'Object');
@ -321,7 +331,7 @@ export default class MTPNetworker {
AppStorage.get<number>('dc').then((baseDcID: number) => { AppStorage.get<number>('dc').then((baseDcID: number) => {
if(isClean && ( if(isClean && (
baseDcID != this.dcID || baseDcID != this.dcID ||
this.upload || this.isFileNetworker ||
(this.sleepAfter && Date.now() > this.sleepAfter) (this.sleepAfter && Date.now() > this.sleepAfter)
)) { )) {
//console.warn(dT(), 'Send long-poll for DC is delayed', this.dcID, this.sleepAfter); //console.warn(dT(), 'Send long-poll for DC is delayed', this.dcID, this.sleepAfter);
@ -354,7 +364,7 @@ export default class MTPNetworker {
} }
public checkConnection = (event: Event | string) => { public checkConnection = (event: Event | string) => {
/* $rootScope.offlineConnecting = true */ /* rootScope.offlineConnecting = true */
this.log('Check connection', event); this.log('Check connection', event);
clearTimeout(this.checkConnectionTimeout); clearTimeout(this.checkConnectionTimeout);
@ -374,14 +384,14 @@ export default class MTPNetworker {
}; };
this.sendEncryptedRequest(pingMessage).then((result) => { this.sendEncryptedRequest(pingMessage).then((result) => {
/* delete $rootScope.offlineConnecting */ /* delete rootScope.offlineConnecting */
this.toggleOffline(false); this.toggleOffline(false);
}, () => { }, () => {
this.log('Delay ', this.checkConnectionPeriod * 1000); this.log('Delay ', this.checkConnectionPeriod * 1000);
this.checkConnectionTimeout = setTimeout(this.checkConnection, this.checkConnectionPeriod * 1000 | 0); this.checkConnectionTimeout = setTimeout(this.checkConnection, this.checkConnectionPeriod * 1000 | 0);
this.checkConnectionPeriod = Math.min(60, this.checkConnectionPeriod * 1.5); this.checkConnectionPeriod = Math.min(60, this.checkConnectionPeriod * 1.5);
/* setTimeout(function() { /* setTimeout(function() {
delete $rootScope.offlineConnecting delete rootScope.offlineConnecting
}, 1000); */ }, 1000); */
}); });
}; };
@ -393,8 +403,8 @@ export default class MTPNetworker {
} }
this.offline = enabled; this.offline = enabled;
/* $rootScope.offline = enabled; /* rootScope.offline = enabled;
$rootScope.offlineConnecting = false; */ rootScope.offlineConnecting = false; */
if(this.offline) { if(this.offline) {
clearTimeout(this.nextReqTimeout); clearTimeout(this.nextReqTimeout);
@ -481,17 +491,20 @@ export default class MTPNetworker {
seq_no: number, seq_no: number,
body: Uint8Array | number[], body: Uint8Array | number[],
isAPI?: boolean isAPI?: boolean
}, options: MTMessageOptions = {}) { }, options: MTMessageOptions) {
return new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
this.sentMessages[message.msg_id] = Object.assign(message, options, { this.sentMessages[message.msg_id] = Object.assign(message, options, options.notContentRelated
? undefined
: {
deferred: {resolve, reject} deferred: {resolve, reject}
}); }
);
// this.log('Networker pushMessage:', this.sentMessages[message.msg_id]); //this.log.error('Networker pushMessage:', this.sentMessages[message.msg_id]);
this.pendingMessages[message.msg_id] = 0; this.pendingMessages[message.msg_id] = 0;
if(!options || !options.noSchedule) { if(!options.noSchedule) {
this.scheduleRequest(); this.scheduleRequest();
} }
@ -499,6 +512,40 @@ export default class MTPNetworker {
options.messageID = message.msg_id; options.messageID = message.msg_id;
} }
}); });
if(!options.notContentRelated && !options.noResponse) {
const timeout = setTimeout(() => {
this.log.error('timeout', message);
this.setConnectionStatus(false);
}, 5e3);
promise.finally(() => {
clearTimeout(timeout);
this.setConnectionStatus(true);
});
}
return promise;
}
public setConnectionStatus(online: boolean) {
const willChange = this.isOnline != online;
this.isOnline = online;
if(willChange && NetworkerFactory.onConnectionStatusChange) {
NetworkerFactory.onConnectionStatusChange({
_: 'networkerStatus',
online: this.isOnline,
dcID: this.dcID,
name: this.name,
isFileNetworker: this.isFileNetworker,
isFileDownload: this.isFileDownload,
isFileUpload: this.isFileUpload
});
}
/* if(this.onConnectionStatusChange) {
this.onConnectionStatusChange(this.isOnline);
} */
} }
public pushResend(messageID: string, delay = 0) { public pushResend(messageID: string, delay = 0) {
@ -1198,7 +1245,7 @@ export default class MTPNetworker {
this.applyServerSalt(message.server_salt); this.applyServerSalt(message.server_salt);
AppStorage.get<number>('dc').then((baseDcID: number) => { AppStorage.get<number>('dc').then((baseDcID: number) => {
if(baseDcID == this.dcID && !this.upload && NetworkerFactory.updatesProcessor) { if(baseDcID == this.dcID && !this.isFileNetworker && NetworkerFactory.updatesProcessor) {
NetworkerFactory.updatesProcessor(message, true); NetworkerFactory.updatesProcessor(message, true);
} }
}); });

3
src/lib/mtproto/networkerFactory.ts

@ -1,9 +1,10 @@
import MTPNetworker from "./networker"; import MTPNetworker from "./networker";
import { InvokeApiOptions } from "../../types"; import { ConnectionStatusChange, InvokeApiOptions } from "../../types";
import MTTransport from "./transports/transport"; import MTTransport from "./transports/transport";
export class NetworkerFactory { export class NetworkerFactory {
public updatesProcessor: (obj: any, bool: boolean) => void = null; public updatesProcessor: (obj: any, bool: boolean) => void = null;
public onConnectionStatusChange: (info: ConnectionStatusChange) => void = null;
public setUpdatesProcessor(callback: (obj: any, bool: boolean) => void) { public setUpdatesProcessor(callback: (obj: any, bool: boolean) => void) {
this.updatesProcessor = callback; this.updatesProcessor = callback;

14
src/lib/mtproto/transports/websocket.ts

@ -68,10 +68,14 @@ export default class Socket extends MTTransport {
this.releasePending(); this.releasePending();
if(this.networker && this.lastCloseTime) { if(this.networker) {
this.networker.setConnectionStatus(true);
if(this.lastCloseTime) {
this.networker.cleanupSent(); this.networker.cleanupSent();
this.networker.resend(); this.networker.resend();
} }
}
//}, 3e3); //}, 3e3);
}; };
@ -87,6 +91,10 @@ export default class Socket extends MTTransport {
const diff = time - this.lastCloseTime; const diff = time - this.lastCloseTime;
const needTimeout = !isNaN(diff) && diff < CONNECTION_RETRY_TIMEOUT ? CONNECTION_RETRY_TIMEOUT - diff : 0; const needTimeout = !isNaN(diff) && diff < CONNECTION_RETRY_TIMEOUT ? CONNECTION_RETRY_TIMEOUT - diff : 0;
if(this.networker) {
this.networker.setConnectionStatus(false);
}
this.log('will try to reconnect after timeout:', needTimeout / 1000); this.log('will try to reconnect after timeout:', needTimeout / 1000);
setTimeout(() => { setTimeout(() => {
this.log('trying to reconnect...'); this.log('trying to reconnect...');
@ -98,10 +106,6 @@ export default class Socket extends MTTransport {
} }
} }
if(this.networker) {
this.pending
}
this.connect(); this.connect();
}, needTimeout); }, needTimeout);
}; };

54
src/lib/rootScope.ts

@ -3,6 +3,7 @@ import type { MyDocument } from "./appManagers/appDocsManager";
import type { AppMessagesManager, Dialog } from "./appManagers/appMessagesManager"; import type { AppMessagesManager, Dialog } from "./appManagers/appMessagesManager";
import type { Poll, PollResults } from "./appManagers/appPollsManager"; import type { Poll, PollResults } from "./appManagers/appPollsManager";
import type { MyDialogFilter } from "./storages/filters"; import type { MyDialogFilter } from "./storages/filters";
import type { ConnectionStatusChange } from "../types";
import { MOUNT_CLASS_TO } from "./mtproto/mtproto_config"; import { MOUNT_CLASS_TO } from "./mtproto/mtproto_config";
type BroadcastEvents = { type BroadcastEvents = {
@ -61,38 +62,51 @@ type BroadcastEvents = {
'apiUpdate': Update, 'apiUpdate': Update,
'download_progress': any, 'download_progress': any,
'connection_status_change': ConnectionStatusChange
//'draft_updated': any, //'draft_updated': any,
}; };
const $rootScope = { class RootScope {
$broadcast: <T extends keyof BroadcastEvents>(name: T, detail?: BroadcastEvents[T]) => { public overlayIsActive: boolean = false;
public selectedPeerID = 0;
public myID = 0;
public idle = {
isIDLE: false
};
public connectionStatus: {[name: string]: ConnectionStatusChange} = {};
constructor() {
this.on('user_auth', (e) => {
this.myID = e.detail.id;
});
this.on('connection_status_change', (e) => {
const status = e.detail;
this.connectionStatus[e.detail.name] = status;
});
}
public broadcast = <T extends keyof BroadcastEvents>(name: T, detail?: BroadcastEvents[T]) => {
/* if(name != 'user_update') { /* if(name != 'user_update') {
console.debug(dT(), 'Broadcasting ' + name + ' event, with args:', detail); console.debug(dT(), 'Broadcasting ' + name + ' event, with args:', detail);
} */ } */
let myCustomEvent = new CustomEvent(name, {detail}); const myCustomEvent = new CustomEvent(name, {detail});
document.dispatchEvent(myCustomEvent); document.dispatchEvent(myCustomEvent);
}, };
$on: <T extends keyof BroadcastEvents>(name: T, callback: (e: Omit<CustomEvent, 'detail'> & {detail: BroadcastEvents[T]}) => any) => {
public on = <T extends keyof BroadcastEvents>(name: T, callback: (e: Omit<CustomEvent, 'detail'> & {detail: BroadcastEvents[T]}) => any) => {
// @ts-ignore // @ts-ignore
document.addEventListener(name, callback); document.addEventListener(name, callback);
}, };
$off: <T extends keyof BroadcastEvents>(name: T, callback: (e: Omit<CustomEvent, 'detail'> & {detail: BroadcastEvents[T]}) => any) => {
public off = <T extends keyof BroadcastEvents>(name: T, callback: (e: Omit<CustomEvent, 'detail'> & {detail: BroadcastEvents[T]}) => any) => {
// @ts-ignore // @ts-ignore
document.removeEventListener(name, callback); document.removeEventListener(name, callback);
},
overlayIsActive: false,
selectedPeerID: 0,
myID: 0,
idle: {
isIDLE: false
}
}; };
}
$rootScope.$on('user_auth', (e) => { const rootScope = new RootScope();
$rootScope.myID = e.detail.id;
});
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.$rootScope = $rootScope); MOUNT_CLASS_TO && (MOUNT_CLASS_TO.rootScope = rootScope);
export default $rootScope; export default rootScope;

14
src/lib/storages/filters.ts

@ -4,7 +4,7 @@ import type { Modify } from "../../types";
import type { AppPeersManager } from "../appManagers/appPeersManager"; import type { AppPeersManager } from "../appManagers/appPeersManager";
import type { AppUsersManager } from "../appManagers/appUsersManager"; import type { AppUsersManager } from "../appManagers/appUsersManager";
//import type { ApiManagerProxy } from "../mtproto/mtprotoworker"; //import type { ApiManagerProxy } from "../mtproto/mtprotoworker";
import type _$rootScope from "../rootScope"; import type _rootScope from "../rootScope";
import type {Dialog} from '../appManagers/appMessagesManager'; import type {Dialog} from '../appManagers/appMessagesManager';
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
@ -22,8 +22,8 @@ export default class FiltersStorage {
public filters: {[filterID: string]: MyDialogFilter} = {}; public filters: {[filterID: string]: MyDialogFilter} = {};
public orderIndex = START_ORDER_INDEX; public orderIndex = START_ORDER_INDEX;
constructor(private appPeersManager: AppPeersManager, private appUsersManager: AppUsersManager, /* private apiManager: ApiManagerProxy, */ private $rootScope: typeof _$rootScope) { constructor(private appPeersManager: AppPeersManager, private appUsersManager: AppUsersManager, /* private apiManager: ApiManagerProxy, */ private rootScope: typeof _rootScope) {
$rootScope.$on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
this.handleUpdate(e.detail); this.handleUpdate(e.detail);
}); });
} }
@ -37,7 +37,7 @@ export default class FiltersStorage {
this.saveDialogFilter(update.filter as any); this.saveDialogFilter(update.filter as any);
} else if(this.filters[update.id]) { // Папка удалена } else if(this.filters[update.id]) { // Папка удалена
//this.getDialogFilters(true); //this.getDialogFilters(true);
this.$rootScope.$broadcast('filter_delete', this.filters[update.id]); this.rootScope.broadcast('filter_delete', this.filters[update.id]);
delete this.filters[update.id]; delete this.filters[update.id];
} }
@ -73,7 +73,7 @@ export default class FiltersStorage {
this.setOrderIndex(filter); this.setOrderIndex(filter);
}); });
this.$rootScope.$broadcast('filter_order', update.order); this.rootScope.broadcast('filter_order', update.order);
break; break;
} }
@ -179,7 +179,7 @@ export default class FiltersStorage {
this.saveDialogFilter(filter); this.saveDialogFilter(filter);
} }
$rootScope.$broadcast('filter_update', filter); */ rootScope.$broadcast('filter_update', filter); */
this.handleUpdate({ this.handleUpdate({
_: 'updateDialogFilter', _: 'updateDialogFilter',
@ -246,7 +246,7 @@ export default class FiltersStorage {
this.setOrderIndex(filter); this.setOrderIndex(filter);
if(update) { if(update) {
this.$rootScope.$broadcast('filter_update', filter); this.rootScope.broadcast('filter_update', filter);
} }
} }

73
src/scss/partials/_leftSidebar.scss

@ -292,6 +292,79 @@
} }
} }
} }
.connection-status {
width: 100%;
padding: 0 .5rem .5rem;
overflow: hidden;
flex: 0 0 auto;
&:not(.is-not-connected) {
.connection-status-button {
display: none;
}
}
&.is-not-connected {
&.animating {
.connection-status-button, & + .connection-status-bottom {
transition: transform var(--layer-transition);
}
}
&:not(.backwards) {
.connection-status-button {
transform: translateY(0);
}
& + .connection-status-bottom {
transform: translateY(64px);
}
}
&:not(.animating):not(.backwards) {
& + .connection-status-bottom {
height: calc(100% - 64px);
}
}
}
&-button {
color: #2e3939;
align-self: center;
pointer-events: none;
padding-left: 4.5rem;
text-align: left;
height: 3.5rem;
transform: translateY(-100%);
svg {
right: auto;
left: 15px;
height: calc(100% - 30px);
.preloader-path {
stroke: #2e3939;
}
}
}
&-bottom {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
overflow: hidden;
transform: translateY(0);
height: 100%;
/* transform: translateY(64px);
height: calc(100% - 64px); */
}
}
} }
#search-container { #search-container {

4
src/scss/style.scss

@ -313,6 +313,10 @@ input, textarea {
color: $color-error!important; color: $color-error!important;
} }
.bg-warning {
background: #fed85a;
}
#bubble-contextmenu, #dialogs-contextmenu { #bubble-contextmenu, #dialogs-contextmenu {
position: fixed; position: fixed;
right: auto; right: auto;

10
src/types.d.ts vendored

@ -62,3 +62,13 @@ export namespace AuthState {
_: 'authStateSignedIn' _: 'authStateSignedIn'
}; };
} }
export type ConnectionStatusChange = {
_: 'networkerStatus',
online: boolean,
dcID: number,
name: string,
isFileNetworker: boolean,
isFileDownload: boolean,
isFileUpload: boolean
};
Loading…
Cancel
Save