2020-10-21 01:25:36 +02:00
import appChatsManager from "../lib/appManagers/appChatsManager" ;
import appMessagesManager from "../lib/appManagers/appMessagesManager" ;
import appPeersManager from "../lib/appManagers/appPeersManager" ;
2020-11-15 04:33:47 +01:00
import rootScope from "../lib/rootScope" ;
2020-10-21 01:25:36 +02:00
import { PopupButton } from "./popup" ;
import PopupPeer from "./popupPeer" ;
export default class PopupDeleteMessages {
constructor ( mids : number [ ] , onConfirm ? : ( ) = > void ) {
2020-12-01 16:38:36 +01:00
const peerID = appMessagesManager . getMessage ( mids [ 0 ] ) . peerID ;
2020-10-21 01:25:36 +02:00
const firstName = appPeersManager . getPeerTitle ( peerID , false , true ) ;
mids = mids . slice ( ) ;
const callback = ( revoke : boolean ) = > {
onConfirm && onConfirm ( ) ;
appMessagesManager . deleteMessages ( mids , revoke ) ;
} ;
let title : string , description : string , buttons : PopupButton [ ] ;
2020-11-12 03:11:43 +01:00
title = ` Delete ${ mids . length == 1 ? '' : mids . length + ' ' } Message ${ mids . length == 1 ? '' : 's' } ? ` ;
2020-10-21 01:25:36 +02:00
description = ` Are you sure you want to delete ${ mids . length == 1 ? 'this message' : 'these messages' } ? ` ;
2020-11-15 04:33:47 +01:00
if ( peerID == rootScope . myID ) {
2020-10-21 01:25:36 +02:00
buttons = [ {
text : 'DELETE' ,
isDanger : true ,
callback : ( ) = > callback ( false )
} ] ;
} else {
buttons = [ {
text : 'DELETE JUST FOR ME' ,
isDanger : true ,
callback : ( ) = > callback ( false )
} ] ;
if ( peerID > 0 ) {
buttons . push ( {
text : 'DELETE FOR ME AND ' + firstName ,
isDanger : true ,
callback : ( ) = > callback ( true )
} ) ;
2020-11-12 03:11:43 +01:00
} else {
const chat = appChatsManager . getChat ( - peerID ) ;
const hasRights = appChatsManager . hasRights ( - peerID , 'deleteRevoke' ) ;
if ( chat . _ == 'chat' ) {
const canRevoke = hasRights ? mids . slice ( ) : mids . filter ( mid = > {
const message = appMessagesManager . getMessage ( mid ) ;
2020-11-15 04:33:47 +01:00
return message . fromID == rootScope . myID ;
2020-11-12 03:11:43 +01:00
} ) ;
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 {
if ( ! hasRights || appChatsManager . isBroadcast ( - peerID ) ) {
buttons . shift ( ) ;
}
buttons . push ( {
text : 'DELETE FOR ALL' ,
isDanger : true ,
callback : ( ) = > callback ( true )
} ) ;
}
2020-10-21 01:25:36 +02:00
}
}
buttons . push ( {
text : 'CANCEL' ,
isCancel : true
} ) ;
const popup = new PopupPeer ( 'popup-delete-chat' , {
2020-10-23 03:01:26 +02:00
peerID ,
title ,
description ,
buttons
2020-10-21 01:25:36 +02:00
} ) ;
popup . show ( ) ;
}
}