Browse Source

Some popup fixes

master
Eduard Kuzmenko 3 years ago
parent
commit
36022a478b
  1. 37
      src/components/popups/deleteMessages.ts
  2. 7
      src/components/popups/sendNow.ts
  3. 33
      src/components/popups/unpinMessage.ts
  4. 1
      src/lang.ts
  5. 6
      src/lib/appManagers/appMessagesManager.ts

37
src/components/popups/deleteMessages.ts

@ -7,8 +7,8 @@
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 rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { addCancelButton, PopupButton } from "."; import { addCancelButton } from ".";
import PopupPeer from "./peer"; import PopupPeer, { PopupPeerButtonCallbackCheckboxes, PopupPeerOptions } from "./peer";
import { ChatType } from "../chat/chat"; import { ChatType } from "../chat/chat";
import { i18n, LangPackKey } from "../../lib/langPack"; import { i18n, LangPackKey } from "../../lib/langPack";
import PeerTitle from "../peerTitle"; import PeerTitle from "../peerTitle";
@ -21,16 +21,16 @@ export default class PopupDeleteMessages {
}).element; }).element;
mids = mids.slice(); mids = mids.slice();
const callback = (revoke?: true) => { const callback = (checked: PopupPeerButtonCallbackCheckboxes, revoke?: boolean) => {
onConfirm && onConfirm(); onConfirm && onConfirm();
if(type === 'scheduled') { if(type === 'scheduled') {
appMessagesManager.deleteScheduledMessages(peerId, mids); appMessagesManager.deleteScheduledMessages(peerId, mids);
} else { } else {
appMessagesManager.deleteMessages(peerId, mids, revoke); appMessagesManager.deleteMessages(peerId, mids, !!checked.size || revoke);
} }
}; };
let title: LangPackKey, titleArgs: any[], description: LangPackKey, descriptionArgs: any[], buttons: PopupButton[]; let title: LangPackKey, titleArgs: any[], description: LangPackKey, descriptionArgs: any[], buttons: PopupPeerOptions['buttons'], checkboxes: PopupPeerOptions['checkboxes'] = [];
if(mids.length === 1) { if(mids.length === 1) {
title = 'DeleteSingleMessagesTitle'; title = 'DeleteSingleMessagesTitle';
} else { } else {
@ -43,18 +43,16 @@ export default class PopupDeleteMessages {
buttons = [{ buttons = [{
langKey: 'Delete', langKey: 'Delete',
isDanger: true, isDanger: true,
callback: () => callback() callback
}]; }];
if(peerId === rootScope.myId || type === 'scheduled') { if(peerId === rootScope.myId || type === 'scheduled') {
} else { } else {
if(peerId > 0) { if(peerId > 0) {
buttons.push({ checkboxes.push({
langKey: 'DeleteMessagesOptionAlso', text: 'DeleteMessagesOptionAlso',
langArgs: [peerTitleElement], textArgs: [peerTitleElement]
isDanger: true,
callback: () => callback(true)
}); });
} else { } else {
const chat = appChatsManager.getChat(-peerId); const chat = appChatsManager.getChat(-peerId);
@ -68,16 +66,12 @@ export default class PopupDeleteMessages {
if(canRevoke.length) { if(canRevoke.length) {
if(canRevoke.length === mids.length) { if(canRevoke.length === mids.length) {
buttons.push({ checkboxes.push({
langKey: 'DeleteForAll', text: 'DeleteForAll'
isDanger: true,
callback: () => callback(true)
}); });
} else { } else {
buttons.push({ checkboxes.push({
langKey: 'DeleteMessagesOption', text: 'DeleteMessagesOption'
isDanger: true,
callback: () => callback(true)
}); });
description = 'DeleteMessagesTextGroup'; description = 'DeleteMessagesTextGroup';
@ -86,7 +80,7 @@ export default class PopupDeleteMessages {
} }
} }
} else { } else {
buttons[0].callback = () => callback(true); buttons[0].callback = (checked) => callback(checked, true);
} }
} }
} }
@ -99,7 +93,8 @@ export default class PopupDeleteMessages {
titleLangArgs: titleArgs, titleLangArgs: titleArgs,
descriptionLangKey: description, descriptionLangKey: description,
descriptionLangArgs: descriptionArgs, descriptionLangArgs: descriptionArgs,
buttons buttons,
checkboxes
}); });
popup.show(); popup.show();

7
src/components/popups/sendNow.ts

@ -21,15 +21,10 @@ export default class PopupSendNow {
}; };
buttons.push({ buttons.push({
text: 'SEND', langKey: 'Send',
callback callback
}); });
buttons.push({
text: 'CANCEL',
isCancel: true
});
const popup = new PopupPeer('popup-delete-chat', { const popup = new PopupPeer('popup-delete-chat', {
peerId, peerId,
title, title,

33
src/components/popups/unpinMessage.ts

@ -5,8 +5,8 @@
*/ */
import appMessagesManager from "../../lib/appManagers/appMessagesManager"; import appMessagesManager from "../../lib/appManagers/appMessagesManager";
import { addCancelButton, PopupButton } from "."; import { addCancelButton } from ".";
import PopupPeer from "./peer"; import PopupPeer, { PopupPeerButtonCallbackCheckboxes, PopupPeerOptions } from "./peer";
import appPeersManager from "../../lib/appManagers/appPeersManager"; import appPeersManager from "../../lib/appManagers/appPeersManager";
import rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
import { LangPackKey } from "../../lib/langPack"; import { LangPackKey } from "../../lib/langPack";
@ -15,11 +15,11 @@ import PeerTitle from "../peerTitle";
export default class PopupPinMessage { export default class PopupPinMessage {
constructor(peerId: number, mid: number, unpin?: true, onConfirm?: () => void) { constructor(peerId: number, mid: number, unpin?: true, onConfirm?: () => void) {
let title: LangPackKey, description: LangPackKey, buttons: PopupButton[] = []; let title: LangPackKey, description: LangPackKey, buttons: PopupPeerOptions['buttons'] = [], checkboxes: PopupPeerOptions['checkboxes'] = [];
const canUnpin = appPeersManager.canPinMessage(peerId); const canUnpin = appPeersManager.canPinMessage(peerId);
const callback = (oneSide?: true, silent?: true) => { const callback = (checked: PopupPeerButtonCallbackCheckboxes, oneSide?: boolean, silent?: boolean) => {
setTimeout(() => { // * костыль, потому что document.elementFromPoint вернёт popup-peer пока он будет закрываться setTimeout(() => { // * костыль, потому что document.elementFromPoint вернёт popup-peer пока он будет закрываться
let promise: Promise<any>; let promise: Promise<any>;
if(unpin && !mid) { if(unpin && !mid) {
@ -57,7 +57,7 @@ export default class PopupPinMessage {
buttons.push({ buttons.push({
langKey: buttonText, langKey: buttonText,
isDanger: true, isDanger: true,
callback: () => callback() callback
}); });
} else { } else {
title = 'PinMessageAlertTitle'; title = 'PinMessageAlertTitle';
@ -66,7 +66,7 @@ export default class PopupPinMessage {
if(peerId < 0) { if(peerId < 0) {
buttons.push({ buttons.push({
langKey: pinButtonText, langKey: pinButtonText,
callback: () => callback() callback: (checked) => callback(checked, false, !checked.size)
}); });
if(appChatsManager.isBroadcast(-peerId)) { if(appChatsManager.isBroadcast(-peerId)) {
@ -74,9 +74,9 @@ export default class PopupPinMessage {
} else { } else {
description = 'PinMessageAlert'; description = 'PinMessageAlert';
buttons.push({ checkboxes.push({
langKey: 'PinNotify', text: 'PinNotify',
callback: () => callback(undefined, true) checked: true
}); });
} }
} else { } else {
@ -85,18 +85,18 @@ export default class PopupPinMessage {
if(peerId === rootScope.myId) { if(peerId === rootScope.myId) {
buttons.push({ buttons.push({
langKey: pinButtonText, langKey: pinButtonText,
callback: () => callback() callback
}); });
} else { } else {
buttons.push({ buttons.push({
langKey: pinButtonText, langKey: pinButtonText,
callback: () => callback(true) callback: (checked) => callback(checked, !checked.size)
}); });
buttons.push({ checkboxes.push({
langKey: 'PinAlsoFor', text: 'PinAlsoFor',
langArgs: [new PeerTitle({peerId, onlyFirstName: true}).element], textArgs: [new PeerTitle({peerId, onlyFirstName: true}).element],
callback: () => callback() checked: true
}); });
} }
} }
@ -108,7 +108,8 @@ export default class PopupPinMessage {
peerId, peerId,
titleLangKey: title, titleLangKey: title,
descriptionLangKey: description, descriptionLangKey: description,
buttons buttons,
checkboxes
}); });
popup.show(); popup.show();

1
src/lang.ts

@ -523,6 +523,7 @@ const lang = {
"AppName": "Telegram", "AppName": "Telegram",
"OK": "OK", "OK": "OK",
"PinFolderLimitReached": "Sorry, you can\'t pin any more chats to the top.", "PinFolderLimitReached": "Sorry, you can\'t pin any more chats to the top.",
"Send": "Send",
// * macos // * macos
"AccountSettings.Filters": "Chat Folders", "AccountSettings.Filters": "Chat Folders",

6
src/lib/appManagers/appMessagesManager.ts

@ -2077,12 +2077,12 @@ export class AppMessagesManager {
}); });
} }
public updatePinnedMessage(peerId: number, mid: number, unpin?: true, silent?: true, oneSide?: true) { public updatePinnedMessage(peerId: number, mid: number, unpin?: boolean, silent?: boolean, pm_oneside?: boolean) {
return apiManager.invokeApi('messages.updatePinnedMessage', { return apiManager.invokeApi('messages.updatePinnedMessage', {
peer: appPeersManager.getInputPeerById(peerId), peer: appPeersManager.getInputPeerById(peerId),
unpin, unpin,
silent, silent,
pm_oneside: oneSide, pm_oneside,
id: this.getServerMessageId(mid) id: this.getServerMessageId(mid)
}).then(updates => { }).then(updates => {
//this.log('pinned updates:', updates); //this.log('pinned updates:', updates);
@ -3540,7 +3540,7 @@ export class AppMessagesManager {
}); });
} }
public deleteMessages(peerId: number, mids: number[], revoke?: true) { public deleteMessages(peerId: number, mids: number[], revoke?: boolean) {
let promise: Promise<any>; let promise: Promise<any>;
const localMessageIds = mids.map(mid => this.getServerMessageId(mid)); const localMessageIds = mids.map(mid => this.getServerMessageId(mid));

Loading…
Cancel
Save