Browse Source

Fix navigation

Fix stickers playback on page start
master
morethanwords 3 years ago
parent
commit
65cfebb5ea
  1. 26
      src/components/appNavigationController.ts
  2. 8
      src/components/chat/bubbleGroups.ts
  3. 2
      src/components/chat/chat.ts
  4. 31
      src/components/chat/topbar.ts
  5. 2
      src/components/sidebarLeft/index.ts
  6. 4
      src/components/sidebarRight/index.ts
  7. 2
      src/components/sidebarRight/tabs/gifs.ts
  8. 2
      src/components/sidebarRight/tabs/pollResults.ts
  9. 2
      src/components/sidebarRight/tabs/sharedMedia.ts
  10. 14
      src/components/slider.ts
  11. 19
      src/lib/appManagers/appImManager.ts

26
src/components/appNavigationController.ts

@ -106,23 +106,23 @@ export class AppNavigationController {
this.manual = false; this.manual = false;
} }
public back(type?: NavigationItem['type']) { public findItemByType(type: NavigationItem['type']) {
if(type) { for(let i = this.navigations.length - 1; i >= 0; --i) {
let item: NavigationItem; const item = this.navigations[i];
let i = this.navigations.length - 1; if(item.type === type) {
for(; i >= 0; --i) { return {item, index: i};
const _item = this.navigations[i]; }
if(_item.type === type) {
item = _item;
break;
} }
} }
if(item) { public back(type?: NavigationItem['type']) {
if(type) {
const ret = this.findItemByType(type);
if(ret) {
this.manual = true; this.manual = true;
if(i !== (this.navigations.length - 1)) { if(ret.index !== (this.navigations.length - 1)) {
this.navigations.splice(i, 1); this.navigations.splice(ret.index, 1);
this.handleItem(item); this.handleItem(ret.item);
return; return;
} }
} }

8
src/components/chat/bubbleGroups.ts

@ -1,7 +1,7 @@
import rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
//import { generatePathData } from "../../helpers/dom"; //import { generatePathData } from "../../helpers/dom";
import { MyMessage } from "../../lib/appManagers/appMessagesManager"; import { MyMessage } from "../../lib/appManagers/appMessagesManager";
import Chat from "./chat"; import type Chat from "./chat";
type Group = {bubble: HTMLElement, mid: number, timestamp: number}[]; type Group = {bubble: HTMLElement, mid: number, timestamp: number}[];
type BubbleGroup = {timestamp: number, fromId: number, mid: number, group: Group}; type BubbleGroup = {timestamp: number, fromId: number, mid: number, group: Group};
@ -18,7 +18,8 @@ export default class BubbleGroups {
removeBubble(bubble: HTMLElement) { removeBubble(bubble: HTMLElement) {
const details = this.detailsMap.get(bubble); const details = this.detailsMap.get(bubble);
if(details && details.group.length) { if(details) {
if(details.group.length) {
details.group.findAndSplice(d => d.bubble === bubble); details.group.findAndSplice(d => d.bubble === bubble);
if(!details.group.length) { if(!details.group.length) {
this.groups.findAndSplice(g => g === details.group); this.groups.findAndSplice(g => g === details.group);
@ -26,6 +27,9 @@ export default class BubbleGroups {
this.updateGroup(details.group); this.updateGroup(details.group);
} }
} }
this.detailsMap.delete(bubble);
}
} }
addBubble(bubble: HTMLElement, message: MyMessage, reverse: boolean) { addBubble(bubble: HTMLElement, message: MyMessage, reverse: boolean) {

2
src/components/chat/chat.ts

@ -201,7 +201,7 @@ export default class Chat extends EventListenerBase<{
// set new // set new
if(!samePeer) { if(!samePeer) {
if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) { if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) {
appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.search); appSidebarRight.onCloseBtnClick();
} }
appSidebarRight.sharedMediaTab.setPeer(peerId, this.threadId); appSidebarRight.sharedMediaTab.setPeer(peerId, this.threadId);

31
src/components/chat/topbar.ts

@ -19,6 +19,7 @@ import ListenerSetter from "../../helpers/listenerSetter";
import appStateManager from "../../lib/appManagers/appStateManager"; import appStateManager from "../../lib/appManagers/appStateManager";
import PopupDeleteDialog from "../popups/deleteDialog"; import PopupDeleteDialog from "../popups/deleteDialog";
import appNavigationController from "../appNavigationController"; import appNavigationController from "../appNavigationController";
import { LEFT_COLUMN_ACTIVE_CLASSNAME } from "../sidebarLeft";
export default class ChatTopbar { export default class ChatTopbar {
container: HTMLDivElement; container: HTMLDivElement;
@ -135,17 +136,39 @@ export default class ChatTopbar {
} else { } else {
this.chat.appImManager.setInnerPeer(peerId, mid); this.chat.appImManager.setInnerPeer(peerId, mid);
} }
} else {
if(mediaSizes.activeScreen === ScreenSize.medium && document.body.classList.contains(LEFT_COLUMN_ACTIVE_CLASSNAME)) {
onBtnBackClick();
} else { } else {
this.appSidebarRight.toggleSidebar(true); this.appSidebarRight.toggleSidebar(true);
} }
}
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
attachClickEvent(this.btnBack, (e) => { const onBtnBackClick = (e?: Event) => {
if(e) {
cancelEvent(e); cancelEvent(e);
/* this.chat.appImManager.setPeer(0); }
blurActiveElement(); */
//const item = appNavigationController.findItemByType('chat');
// * return manually to chat by arrow, since can't get back to
if(mediaSizes.activeScreen === ScreenSize.medium && document.body.classList.contains(LEFT_COLUMN_ACTIVE_CLASSNAME)) {
this.chat.appImManager.setPeer(this.peerId);
} else {
const isFirstChat = this.chat.appImManager.chats.indexOf(this.chat) === 0;
appNavigationController.back(isFirstChat ? 'im' : 'chat');
return;
if(mediaSizes.activeScreen === ScreenSize.medium && !appNavigationController.findItemByType('chat')) {
this.chat.appImManager.setPeer(0);
blurActiveElement();
} else {
appNavigationController.back('chat'); appNavigationController.back('chat');
}, {listenerSetter: this.listenerSetter}); }
}
};
attachClickEvent(this.btnBack, onBtnBackClick, {listenerSetter: this.listenerSetter});
} }
public constructUtils() { public constructUtils() {

2
src/components/sidebarLeft/index.ts

@ -24,6 +24,8 @@ import AppContactsTab from "./tabs/contacts";
import AppArchivedTab from "./tabs/archivedTab"; import AppArchivedTab from "./tabs/archivedTab";
import AppAddMembersTab from "./tabs/addMembers"; import AppAddMembersTab from "./tabs/addMembers";
export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown';
export class AppSidebarLeft extends SidebarSlider { export class AppSidebarLeft extends SidebarSlider {
private toolsBtn: HTMLButtonElement; private toolsBtn: HTMLButtonElement;
private backBtn: HTMLButtonElement; private backBtn: HTMLButtonElement;

4
src/components/sidebarRight/index.ts

@ -58,12 +58,12 @@ export class AppSidebarRight extends SidebarSlider {
}); });
} }
public onCloseTab(id: number, animate: boolean) { public onCloseTab(id: number, animate: boolean, isNavigation?: boolean) {
if(!this.historyTabIds.length) { if(!this.historyTabIds.length) {
this.toggleSidebar(false, animate); this.toggleSidebar(false, animate);
} }
super.onCloseTab(id, animate); super.onCloseTab(id, animate, isNavigation);
} }
/* public selectTab(id: number) { /* public selectTab(id: number) {

2
src/components/sidebarRight/tabs/gifs.ts

@ -52,7 +52,7 @@ export default class AppGifsTab implements SliderTab {
const fileId = target.dataset.docId; const fileId = target.dataset.docId;
if(appImManager.chat.input.sendMessageWithDocument(fileId)) { if(appImManager.chat.input.sendMessageWithDocument(fileId)) {
if(mediaSizes.isMobile) { if(mediaSizes.isMobile) {
appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.gifs); appSidebarRight.onCloseBtnClick();
} }
} else { } else {
console.warn('got no doc by id:', fileId); console.warn('got no doc by id:', fileId);

2
src/components/sidebarRight/tabs/pollResults.ts

@ -71,7 +71,7 @@ export default class AppPollResultsTab implements SliderTab {
list.classList.add('poll-results-voters'); list.classList.add('poll-results-voters');
appDialogsManager.setListClickListener(list, () => { appDialogsManager.setListClickListener(list, () => {
appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.pollResults); appSidebarRight.onCloseBtnClick();
}, undefined, true); }, undefined, true);
list.style.minHeight = Math.min(result.voters, 4) * 50 + 'px'; list.style.minHeight = Math.min(result.voters, 4) * 50 + 'px';

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

@ -115,7 +115,7 @@ export default class AppSharedMediaTab implements SliderTab {
transition(0); transition(0);
closeIcon.classList.remove('state-back'); closeIcon.classList.remove('state-back');
} else if(!this.scroll.isHeavyAnimationInProgress) { } else if(!this.scroll.isHeavyAnimationInProgress) {
appSidebarRight.closeTab(); appSidebarRight.onCloseBtnClick();
} }
}); });

14
src/components/slider.ts

@ -44,19 +44,19 @@ export default class SidebarSlider {
}); });
} }
private onCloseBtnClick = () => { public onCloseBtnClick = () => {
appNavigationController.back(this.navigationType); appNavigationController.back(this.navigationType);
// this.closeTab(); // this.closeTab();
}; };
public closeTab = (id?: number | SliderSuperTab, animate?: boolean) => { public closeTab = (id?: number | SliderSuperTab, animate?: boolean, isNavigation?: boolean) => {
if(id !== undefined && this.historyTabIds[this.historyTabIds.length - 1] !== id) { if(id !== undefined && this.historyTabIds[this.historyTabIds.length - 1] !== id) {
return false; return false;
} }
//console.log('sidebar-close-button click:', this.historyTabIDs); //console.log('sidebar-close-button click:', this.historyTabIDs);
const closingId = this.historyTabIds.pop(); // pop current const closingId = this.historyTabIds.pop(); // pop current
this.onCloseTab(closingId, animate); this.onCloseTab(closingId, animate, isNavigation);
const tab = this.historyTabIds[this.historyTabIds.length - 1]; const tab = this.historyTabIds[this.historyTabIds.length - 1];
this._selectTab(tab !== undefined ? (tab instanceof SliderSuperTab ? tab.container : tab) : (this.canHideFirst ? -1 : 0), animate); this._selectTab(tab !== undefined ? (tab instanceof SliderSuperTab ? tab.container : tab) : (this.canHideFirst ? -1 : 0), animate);
@ -89,7 +89,7 @@ export default class SidebarSlider {
appNavigationController.pushItem({ appNavigationController.pushItem({
type: this.navigationType, type: this.navigationType,
onPop: (canAnimate) => { onPop: (canAnimate) => {
this.closeTab(undefined, canAnimate); this.closeTab(undefined, canAnimate, true);
return true; return true;
} }
}); });
@ -117,7 +117,11 @@ export default class SidebarSlider {
} }
} }
public onCloseTab(id: number | SliderSuperTab, animate: boolean) { protected onCloseTab(id: number | SliderSuperTab, animate: boolean, isNavigation?: boolean) {
if(!isNavigation) {
appNavigationController.removeByType(this.navigationType, true);
}
const tab: SliderTab = id instanceof SliderSuperTab ? id : this.tabs.get(id); const tab: SliderTab = id instanceof SliderSuperTab ? id : this.tabs.get(id);
if(tab) { if(tab) {
if(tab.onClose) { if(tab.onClose) {

19
src/lib/appManagers/appImManager.ts

@ -1,6 +1,6 @@
//import apiManager from '../mtproto/apiManager'; //import apiManager from '../mtproto/apiManager';
import animationIntersector from '../../components/animationIntersector'; import animationIntersector from '../../components/animationIntersector';
import appSidebarLeft from "../../components/sidebarLeft"; import appSidebarLeft, { LEFT_COLUMN_ACTIVE_CLASSNAME } from "../../components/sidebarLeft";
import appSidebarRight, { AppSidebarRight, RIGHT_COLUMN_ACTIVE_CLASSNAME } from '../../components/sidebarRight'; import appSidebarRight, { AppSidebarRight, RIGHT_COLUMN_ACTIVE_CLASSNAME } from '../../components/sidebarRight';
import mediaSizes, { ScreenSize } from '../../helpers/mediaSizes'; import mediaSizes, { ScreenSize } from '../../helpers/mediaSizes';
import { logger, LogLevels } from "../logger"; import { logger, LogLevels } from "../logger";
@ -41,8 +41,6 @@ import appNavigationController from '../../components/appNavigationController';
appSidebarLeft; // just to include appSidebarLeft; // just to include
const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown';
export const CHAT_ANIMATION_GROUP = 'chat'; export const CHAT_ANIMATION_GROUP = 'chat';
const FOCUS_EVENT_NAME = isTouchSupported ? 'touchstart' : 'mousemove'; const FOCUS_EVENT_NAME = isTouchSupported ? 'touchstart' : 'mousemove';
@ -59,7 +57,7 @@ export class AppImManager {
public tabId = -1; public tabId = -1;
private chats: Chat[] = []; public chats: Chat[] = [];
private prevTab: HTMLElement; private prevTab: HTMLElement;
private chatsSelectTabDebounced: () => void; private chatsSelectTabDebounced: () => void;
@ -86,7 +84,7 @@ export class AppImManager {
this.offline = rootScope.idle.isIDLE = true; this.offline = rootScope.idle.isIDLE = true;
this.updateStatus(); this.updateStatus();
clearInterval(this.updateStatusInterval); clearInterval(this.updateStatusInterval);
rootScope.broadcast('idle', true); rootScope.broadcast('idle', rootScope.idle.isIDLE);
window.addEventListener('focus', () => { window.addEventListener('focus', () => {
this.offline = rootScope.idle.isIDLE = false; this.offline = rootScope.idle.isIDLE = false;
@ -96,7 +94,7 @@ export class AppImManager {
// в обратном порядке // в обратном порядке
animationIntersector.checkAnimations(false); animationIntersector.checkAnimations(false);
rootScope.broadcast('idle', false); rootScope.broadcast('idle', rootScope.idle.isIDLE);
}, {once: true}); }, {once: true});
}); });
@ -105,7 +103,8 @@ export class AppImManager {
this.updateStatusInterval = window.setInterval(() => this.updateStatus(), 50e3); this.updateStatusInterval = window.setInterval(() => this.updateStatus(), 50e3);
this.updateStatus(); this.updateStatus();
rootScope.broadcast('idle', false); this.offline = rootScope.idle.isIDLE = false;
rootScope.broadcast('idle', rootScope.idle.isIDLE);
}, {once: true, passive: true}); }, {once: true, passive: true});
this.chatsContainer = document.createElement('div'); this.chatsContainer = document.createElement('div');
@ -566,7 +565,8 @@ export class AppImManager {
document.body.classList.remove(RIGHT_COLUMN_ACTIVE_CLASSNAME); document.body.classList.remove(RIGHT_COLUMN_ACTIVE_CLASSNAME);
} }
if(prevTabId !== -1 && id > prevTabId && id < 2) { if(prevTabId !== -1 && id > prevTabId) {
if(id < 2 || !appNavigationController.findItemByType('im')) {
appNavigationController.pushItem({ appNavigationController.pushItem({
type: 'im', type: 'im',
onPop: (canAnimate) => { onPop: (canAnimate) => {
@ -575,6 +575,7 @@ export class AppImManager {
} }
}); });
} }
}
rootScope.broadcast('im_tab_change', id); rootScope.broadcast('im_tab_change', id);
@ -623,7 +624,7 @@ export class AppImManager {
rootScope.broadcast('peer_changed', this.chat.peerId); rootScope.broadcast('peer_changed', this.chat.peerId);
if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) { if(appSidebarRight.historyTabIds[appSidebarRight.historyTabIds.length - 1] === AppSidebarRight.SLIDERITEMSIDS.search) {
appSidebarRight.closeTab(AppSidebarRight.SLIDERITEMSIDS.search); appSidebarRight.onCloseBtnClick();
} }
appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId, this.chat.threadId); appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId, this.chat.threadId);

Loading…
Cancel
Save