Browse Source

Hide select messages button if chat is empty

Delete button in chat topbar menu
master
Eduard Kuzmenko 4 years ago
parent
commit
4de230e114
  1. 2
      src/components/chat/bubbles.ts
  2. 6
      src/components/chat/messageRender.ts
  3. 14
      src/components/chat/topbar.ts
  4. 113
      src/components/dialogsContextMenu.ts
  5. 100
      src/components/popups/deleteDialog.ts
  6. 3
      src/lib/appManagers/appDialogsManager.ts
  7. 24
      src/lib/appManagers/appPeersManager.ts
  8. 5
      src/pages/pagePassword.ts

2
src/components/chat/bubbles.ts

@ -1559,7 +1559,7 @@ export default class ChatBubbles { @@ -1559,7 +1559,7 @@ export default class ChatBubbles {
messageDiv.innerHTML = richText;
}
const timeSpan = MessageRender.setTime(message, bubble, bubbleContainer, messageDiv);
const timeSpan = MessageRender.setTime(this.chat, message, bubble, bubbleContainer, messageDiv);
bubbleContainer.prepend(messageDiv);
//bubble.prepend(timeSpan, messageDiv); // that's bad

6
src/components/chat/messageRender.ts

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import { getFullDate } from "../../helpers/date";
import { formatNumber } from "../../helpers/number";
import appImManager from "../../lib/appManagers/appImManager";
import RichTextProcessor from "../../lib/richtextprocessor";
import Chat from "./chat";
type Message = any;
@ -10,7 +10,7 @@ export namespace MessageRender { @@ -10,7 +10,7 @@ export namespace MessageRender {
}; */
export const setTime = (message: Message, bubble: HTMLElement, bubbleContainer: HTMLElement, messageDiv: HTMLElement) => {
export const setTime = (chat: Chat, message: Message, bubble: HTMLElement, bubbleContainer: HTMLElement, messageDiv: HTMLElement) => {
const date = new Date(message.date * 1000);
let time = ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2);
@ -40,7 +40,7 @@ export namespace MessageRender { @@ -40,7 +40,7 @@ export namespace MessageRender {
time = '<i class="edited">edited</i> ' + time;
}
if(appImManager.chat.type != 'pinned' && message.pFlags.pinned) {
if(chat.type != 'pinned' && message.pFlags.pinned) {
bubble.classList.add('is-pinned');
time = '<i class="tgico tgico-pinnedchat"></i>' + time;
}

14
src/components/chat/topbar.ts

@ -17,6 +17,7 @@ import ChatSearch from "./search"; @@ -17,6 +17,7 @@ import ChatSearch from "./search";
import { ButtonMenuItemOptions } from "../buttonMenu";
import ListenerSetter from "../../helpers/listenerSetter";
import appStateManager from "../../lib/appManagers/appStateManager";
import PopupDeleteDialog from "../popups/deleteDialog";
export default class ChatTopbar {
container: HTMLDivElement;
@ -100,6 +101,9 @@ export default class ChatTopbar { @@ -100,6 +101,9 @@ export default class ChatTopbar {
this.menuButtons.forEach(button => {
button.element.classList.toggle('hide', !button.verify());
});
// delete button
this.menuButtons[this.menuButtons.length - 1].element.firstChild.nodeValue = this.appPeersManager.getDeleteButtonText(this.peerId);
});
}
@ -185,7 +189,7 @@ export default class ChatTopbar { @@ -185,7 +189,7 @@ export default class ChatTopbar {
onClick: () => {
this.chat.selection.toggleSelection(true, true);
},
verify: () => !this.chat.selection.isSelecting
verify: () => !this.chat.selection.isSelecting && !!Object.keys(this.chat.bubbles.bubbles).length
}, {
icon: 'select',
text: 'Clear Selection',
@ -195,9 +199,11 @@ export default class ChatTopbar { @@ -195,9 +199,11 @@ export default class ChatTopbar {
verify: () => this.chat.selection.isSelecting
}, {
icon: 'delete danger',
text: 'Delete and Leave',
onClick: () => {},
verify: () => true
text: 'Delete',
onClick: () => {
new PopupDeleteDialog(this.peerId);
},
verify: () => !!this.appMessagesManager.getDialogByPeerId(this.peerId)[0]
}];
this.btnPinned = ButtonIcon('pinlist');

113
src/components/dialogsContextMenu.ts

@ -8,13 +8,13 @@ import { positionMenu, openBtnMenu } from "./misc"; @@ -8,13 +8,13 @@ import { positionMenu, openBtnMenu } from "./misc";
import { PopupButton } from "./popups";
import PopupPeer from "./popups/peer";
import ButtonMenu, { ButtonMenuItemOptions } from "./buttonMenu";
import PopupDeleteDialog from "./popups/deleteDialog";
export default class DialogsContextMenu {
private element: HTMLElement;
private buttons: (ButtonMenuItemOptions & {verify: () => boolean})[];
private selectedId: number;
private peerType: 'channel' | 'chat' | 'megagroup' | 'group' | 'saved';
private filterId: number;
private dialog: Dialog;
@ -117,96 +117,7 @@ export default class DialogsContextMenu { @@ -117,96 +117,7 @@ export default class DialogsContextMenu {
};
private onDeleteClick = () => {
let firstName = appPeersManager.getPeerTitle(this.selectedId, false, true);
let callbackFlush = (justClear?: true) => {
appMessagesManager.flushHistory(this.selectedId, justClear);
};
let callbackLeave = () => {
appChatsManager.leave(-this.selectedId);
};
let title: string, description: string, buttons: PopupButton[];
switch(this.peerType) {
case 'channel': {
title = 'Leave Channel?';
description = `Are you sure you want to leave this channel?`;
buttons = [{
text: 'LEAVE ' + firstName,
isDanger: true,
callback: callbackLeave
}];
break;
}
case 'megagroup': {
title = 'Leave Group?';
description = `Are you sure you want to leave this group?`;
buttons = [{
text: 'LEAVE ' + firstName,
isDanger: true,
callback: callbackLeave
}];
break;
}
case 'chat': {
title = 'Delete Chat?';
description = `Are you sure you want to delete chat with <b>${firstName}</b>?`;
buttons = [{
text: 'DELETE FOR ME AND ' + firstName,
isDanger: true,
callback: () => callbackFlush()
}, {
text: 'DELETE JUST FOR ME',
isDanger: true,
callback: () => callbackFlush(true)
}];
break;
}
case 'saved': {
title = 'Delete Saved Messages?';
description = `Are you sure you want to delete all your saved messages?`;
buttons = [{
text: 'DELETE SAVED MESSAGES',
isDanger: true,
callback: () => callbackFlush()
}];
break;
}
case 'group': {
title = 'Delete and leave Group?';
description = `Are you sure you want to delete all message history and leave <b>${firstName}</b>?`;
buttons = [{
text: 'DELETE AND LEAVE ' + firstName,
isDanger: true,
callback: () => callbackLeave()
}];
break;
}
}
buttons.push({
text: 'CANCEL',
isCancel: true
});
let popup = new PopupPeer('popup-delete-chat', {
peerId: this.selectedId,
title: title,
description: description,
buttons: buttons
});
popup.show();
new PopupDeleteDialog(this.selectedId);
};
onContextMenu = (e: MouseEvent | Touch) => {
@ -241,25 +152,7 @@ export default class DialogsContextMenu { @@ -241,25 +152,7 @@ export default class DialogsContextMenu {
});
// delete button
let deleteButtonText = '';
if(appPeersManager.isMegagroup(this.selectedId)) {
deleteButtonText = 'Leave';
//deleteButtonText = 'Leave group';
this.peerType = 'megagroup';
} else if(appPeersManager.isChannel(this.selectedId)) {
deleteButtonText = 'Leave';
//deleteButtonText = 'Leave channel';
this.peerType = 'channel';
} else if(this.selectedId < 0) {
deleteButtonText = 'Delete';
//deleteButtonText = 'Delete and leave';
this.peerType = 'group';
} else {
deleteButtonText = 'Delete';
//deleteButtonText = 'Delete chat';
this.peerType = this.selectedId == rootScope.myId ? 'saved' : 'chat';
}
this.buttons[this.buttons.length - 1].element.firstChild.nodeValue = deleteButtonText;
this.buttons[this.buttons.length - 1].element.firstChild.nodeValue = appPeersManager.getDeleteButtonText(this.selectedId);
li.classList.add('menu-open');
positionMenu(e, this.element);

100
src/components/popups/deleteDialog.ts

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
import { PopupButton } from ".";
import appChatsManager from "../../lib/appManagers/appChatsManager";
import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import appPeersManager, { PeerType } from "../../lib/appManagers/appPeersManager";
import PopupPeer from "./peer";
export default class PopupDeleteDialog {
constructor(peerId: number, peerType: PeerType = appPeersManager.getDialogType(peerId)) {
let firstName = appPeersManager.getPeerTitle(peerId, false, true);
let callbackFlush = (justClear?: true) => {
appMessagesManager.flushHistory(peerId, justClear);
};
let callbackLeave = () => {
appChatsManager.leave(-peerId);
};
let title: string, description: string, buttons: PopupButton[];
switch(peerType) {
case 'channel': {
title = 'Leave Channel?';
description = `Are you sure you want to leave this channel?`;
buttons = [{
text: 'LEAVE ' + firstName,
isDanger: true,
callback: callbackLeave
}];
break;
}
case 'megagroup': {
title = 'Leave Group?';
description = `Are you sure you want to leave this group?`;
buttons = [{
text: 'LEAVE ' + firstName,
isDanger: true,
callback: callbackLeave
}];
break;
}
case 'chat': {
title = 'Delete Chat?';
description = `Are you sure you want to delete chat with <b>${firstName}</b>?`;
buttons = [{
text: 'DELETE FOR ME AND ' + firstName,
isDanger: true,
callback: () => callbackFlush()
}, {
text: 'DELETE JUST FOR ME',
isDanger: true,
callback: () => callbackFlush(true)
}];
break;
}
case 'saved': {
title = 'Delete Saved Messages?';
description = `Are you sure you want to delete all your saved messages?`;
buttons = [{
text: 'DELETE SAVED MESSAGES',
isDanger: true,
callback: () => callbackFlush()
}];
break;
}
case 'group': {
title = 'Delete and leave Group?';
description = `Are you sure you want to delete all message history and leave <b>${firstName}</b>?`;
buttons = [{
text: 'DELETE AND LEAVE ' + firstName,
isDanger: true,
callback: () => callbackLeave()
}];
break;
}
}
buttons.push({
text: 'CANCEL',
isCancel: true
});
let popup = new PopupPeer('popup-delete-chat', {
peerId,
title,
description,
buttons
});
popup.show();
}
}

3
src/lib/appManagers/appDialogsManager.ts

@ -8,7 +8,6 @@ import Scrollable, { ScrollableX, SliceSides, SliceSidesContainer } from "../../ @@ -8,7 +8,6 @@ import Scrollable, { ScrollableX, SliceSides, SliceSidesContainer } from "../../
import appSidebarLeft from "../../components/sidebarLeft";
import { formatDateAccordingToToday } from "../../helpers/date";
import { escapeRegExp } from "../../helpers/string";
import { isTouchSupported } from "../../helpers/touchSupport";
import { isApple, isSafari } from "../../helpers/userAgent";
import { logger, LogLevels } from "../logger";
import { RichTextProcessor } from "../richtextprocessor";
@ -621,7 +620,7 @@ export class AppDialogsManager { @@ -621,7 +620,7 @@ export class AppDialogsManager {
if(this.loadDialogsPromise/* || 1 == 1 */) return this.loadDialogsPromise;
const promise = new Promise(async(resolve, reject) => {
const promise = new Promise<void>(async(resolve, reject) => {
if(!this.chatList.childElementCount) {
const container = this.chatList.parentElement;
container.append(this.chatsPreloader);

24
src/lib/appManagers/appPeersManager.ts

@ -22,6 +22,7 @@ const DialogColorsFg = ['#c03d33', '#4fad2d', '#d09306', '#168acd', '#8544d6', ' @@ -22,6 +22,7 @@ const DialogColorsFg = ['#c03d33', '#4fad2d', '#d09306', '#168acd', '#8544d6', '
const DialogColors = ['#e17076', '#7bc862', '#e5ca77', '#65AADD', '#a695e7', '#ee7aae', '#6ec9cb', '#faa774'];
const DialogColorsMap = [0, 7, 4, 1, 6, 3, 5];
export type PeerType = 'channel' | 'chat' | 'megagroup' | 'group' | 'saved';
export class AppPeersManager {
/* public savePeerInstance(peerId: number, instance: any) {
if(peerId < 0) appChatsManager.saveApiChat(instance);
@ -228,6 +229,29 @@ export class AppPeersManager { @@ -228,6 +229,29 @@ export class AppPeersManager {
}
return text;
}
public getDialogType(peerId: number): PeerType {
if(appPeersManager.isMegagroup(peerId)) {
return 'megagroup';
} else if(appPeersManager.isChannel(peerId)) {
return 'channel';
} else if(peerId < 0) {
return 'group';
} else {
return peerId == rootScope.myId ? 'saved' : 'chat';
}
}
public getDeleteButtonText(peerId: number) {
switch(this.getDialogType(peerId)) {
case 'megagroup':
case 'channel':
return 'Leave';
default:
return 'Delete';
}
}
}
const appPeersManager = new AppPeersManager();

5
src/pages/pagePassword.ts

@ -43,10 +43,12 @@ let onFirstMount = (): Promise<any> => { @@ -43,10 +43,12 @@ let onFirstMount = (): Promise<any> => {
let handleError = (err: any) => {
btnNext.removeAttribute('disabled');
passwordInput.classList.add('error');
switch(err.type) {
default:
btnNext.innerText = err.type;
//btnNext.innerText = err.type;
btnNext.innerText = 'INVALID PASSWORD';
break;
}
@ -111,6 +113,7 @@ let onFirstMount = (): Promise<any> => { @@ -111,6 +113,7 @@ let onFirstMount = (): Promise<any> => {
passwordInput.addEventListener('keypress', function(this, e) {
this.classList.remove('error');
btnNext.innerText = 'NEXT';
if(e.key == 'Enter') {
return btnNext.click();

Loading…
Cancel
Save