Telegram Web K with changes to work inside I2P
https://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.2 KiB
102 lines
3.2 KiB
4 years ago
|
import appChatsManager from "../../lib/appManagers/appChatsManager";
|
||
|
import appMessagesManager from "../../lib/appManagers/appMessagesManager";
|
||
|
import appPeersManager from "../../lib/appManagers/appPeersManager";
|
||
|
import rootScope from "../../lib/rootScope";
|
||
|
import { PopupButton } from ".";
|
||
|
import PopupPeer from "./peer";
|
||
|
import { ChatType } from "../chat/chat";
|
||
4 years ago
|
|
||
|
export default class PopupDeleteMessages {
|
||
4 years ago
|
constructor(peerId: number, mids: number[], type: ChatType, onConfirm?: () => void) {
|
||
4 years ago
|
const firstName = appPeersManager.getPeerTitle(peerId, false, true);
|
||
4 years ago
|
|
||
|
mids = mids.slice();
|
||
|
const callback = (revoke: boolean) => {
|
||
|
onConfirm && onConfirm();
|
||
4 years ago
|
if(type === 'scheduled') {
|
||
|
appMessagesManager.deleteScheduledMessages(peerId, mids);
|
||
|
} else {
|
||
|
appMessagesManager.deleteMessages(peerId, mids, revoke);
|
||
|
}
|
||
4 years ago
|
};
|
||
|
|
||
|
let title: string, description: string, buttons: PopupButton[];
|
||
4 years ago
|
title = `Delete ${mids.length == 1 ? '' : mids.length + ' '}Message${mids.length == 1 ? '' : 's'}?`;
|
||
4 years ago
|
description = `Are you sure you want to delete ${mids.length == 1 ? 'this message' : 'these messages'}?`;
|
||
|
|
||
4 years ago
|
if(peerId == rootScope.myId || type === 'scheduled') {
|
||
4 years ago
|
buttons = [{
|
||
|
text: 'DELETE',
|
||
|
isDanger: true,
|
||
|
callback: () => callback(false)
|
||
|
}];
|
||
|
} else {
|
||
|
buttons = [{
|
||
|
text: 'DELETE JUST FOR ME',
|
||
|
isDanger: true,
|
||
|
callback: () => callback(false)
|
||
|
}];
|
||
|
|
||
4 years ago
|
if(peerId > 0) {
|
||
4 years ago
|
buttons.push({
|
||
|
text: 'DELETE FOR ME AND ' + firstName,
|
||
|
isDanger: true,
|
||
|
callback: () => callback(true)
|
||
|
});
|
||
4 years ago
|
} else {
|
||
4 years ago
|
const chat = appChatsManager.getChat(-peerId);
|
||
4 years ago
|
|
||
4 years ago
|
const hasRights = appChatsManager.hasRights(-peerId, 'deleteRevoke');
|
||
4 years ago
|
if(chat._ == 'chat') {
|
||
|
const canRevoke = hasRights ? mids.slice() : mids.filter(mid => {
|
||
4 years ago
|
const message = appMessagesManager.getMessageByPeer(peerId, mid);
|
||
4 years ago
|
return message.fromId == rootScope.myId;
|
||
4 years ago
|
});
|
||
|
|
||
|
if(canRevoke.length) {
|
||
|
if(canRevoke.length == mids.length) {
|
||
|
buttons.push({
|
||
|
text: 'DELETE FOR ALL',
|
||
|
isDanger: true,
|
||
|
callback: () => callback(true)
|
||
|
});
|
||
|
} else {
|
||
|
const buttonText = 'Unsend my and delete';
|
||
|
buttons.push({
|
||
|
text: buttonText,
|
||
|
isDanger: true,
|
||
|
callback: () => callback(true)
|
||
|
});
|
||
|
|
||
|
description = `You can also delete the ${canRevoke.length} message${canRevoke.length > 1 ? 's' : ''} you sent from the inboxes of other group members by pressing "${buttonText}".`;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
4 years ago
|
if(!hasRights || appChatsManager.isBroadcast(-peerId)) {
|
||
4 years ago
|
buttons.shift();
|
||
|
}
|
||
|
|
||
|
buttons.push({
|
||
|
text: 'DELETE FOR ALL',
|
||
|
isDanger: true,
|
||
|
callback: () => callback(true)
|
||
|
});
|
||
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
buttons.push({
|
||
|
text: 'CANCEL',
|
||
|
isCancel: true
|
||
|
});
|
||
|
|
||
|
const popup = new PopupPeer('popup-delete-chat', {
|
||
4 years ago
|
peerId,
|
||
4 years ago
|
title,
|
||
|
description,
|
||
|
buttons
|
||
4 years ago
|
});
|
||
|
|
||
|
popup.show();
|
||
|
}
|
||
|
}
|