Send 1 concrete item from album
Forward: exclude deleted accounts
This commit is contained in:
parent
b8c163f300
commit
ea566a3a1d
@ -1,12 +1,12 @@
|
|||||||
import Scrollable from "./scrollable";
|
|
||||||
import appMessagesManager, { Dialog } from "../lib/appManagers/appMessagesManager";
|
|
||||||
import { cancelEvent, findUpClassName, findUpAttribute } from "../lib/utils";
|
|
||||||
import appDialogsManager from "../lib/appManagers/appDialogsManager";
|
|
||||||
import appChatsManager, { ChatRights } from "../lib/appManagers/appChatsManager";
|
import appChatsManager, { ChatRights } from "../lib/appManagers/appChatsManager";
|
||||||
import appUsersManager from "../lib/appManagers/appUsersManager";
|
import appDialogsManager from "../lib/appManagers/appDialogsManager";
|
||||||
|
import appMessagesManager, { Dialog } from "../lib/appManagers/appMessagesManager";
|
||||||
import appPeersManager from "../lib/appManagers/appPeersManager";
|
import appPeersManager from "../lib/appManagers/appPeersManager";
|
||||||
import appPhotosManager from "../lib/appManagers/appPhotosManager";
|
import appPhotosManager from "../lib/appManagers/appPhotosManager";
|
||||||
|
import appUsersManager from "../lib/appManagers/appUsersManager";
|
||||||
import $rootScope from "../lib/rootScope";
|
import $rootScope from "../lib/rootScope";
|
||||||
|
import { cancelEvent, findUpAttribute, findUpClassName } from "../lib/utils";
|
||||||
|
import Scrollable from "./scrollable";
|
||||||
|
|
||||||
type PeerType = 'contacts' | 'dialogs';
|
type PeerType = 'contacts' | 'dialogs';
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ export class AppSelectPeers {
|
|||||||
|
|
||||||
if(this.chatRightsAction) {
|
if(this.chatRightsAction) {
|
||||||
dialogs = dialogs.filter(d => {
|
dialogs = dialogs.filter(d => {
|
||||||
return d.peerID > 0 || appChatsManager.hasRights(-d.peerID, this.chatRightsAction);
|
return (d.peerID > 0 && (this.chatRightsAction != 'send' || appUsersManager.canSendToUser(d.peerID))) || appChatsManager.hasRights(-d.peerID, this.chatRightsAction);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,11 @@ import { PopupButton, PopupPeer } from "../popup";
|
|||||||
import appSidebarRight from "../sidebarRight";
|
import appSidebarRight from "../sidebarRight";
|
||||||
|
|
||||||
export class ChatContextMenu {
|
export class ChatContextMenu {
|
||||||
private buttons: (ButtonMenuItemOptions & {verify: (peerID: number, msgID: number) => boolean})[];
|
private buttons: (ButtonMenuItemOptions & {verify: (peerID: number, msgID: number, target: HTMLElement) => boolean})[];
|
||||||
private element: HTMLElement;
|
private element: HTMLElement;
|
||||||
|
|
||||||
|
private target: HTMLElement;
|
||||||
|
public peerID: number;
|
||||||
public msgID: number;
|
public msgID: number;
|
||||||
|
|
||||||
constructor(private attachTo: HTMLElement) {
|
constructor(private attachTo: HTMLElement) {
|
||||||
@ -41,17 +44,21 @@ export class ChatContextMenu {
|
|||||||
const msgID = +bubble.dataset.mid;
|
const msgID = +bubble.dataset.mid;
|
||||||
if(!msgID) return;
|
if(!msgID) return;
|
||||||
|
|
||||||
const peerID = $rootScope.selectedPeerID;
|
this.peerID = $rootScope.selectedPeerID;
|
||||||
this.msgID = msgID;
|
this.msgID = msgID;
|
||||||
|
this.target = e.target as HTMLElement;
|
||||||
|
|
||||||
this.buttons.forEach(button => {
|
this.buttons.forEach(button => {
|
||||||
const good = button.verify(peerID, msgID);
|
const good = button.verify(this.peerID, this.msgID, this.target);
|
||||||
button.element.classList.toggle('hide', !good);
|
button.element.classList.toggle('hide', !good);
|
||||||
});
|
});
|
||||||
|
|
||||||
const side: 'left' | 'right' = bubble.classList.contains('is-in') ? 'left' : 'right';
|
const side: 'left' | 'right' = bubble.classList.contains('is-in') ? 'left' : 'right';
|
||||||
positionMenu(e, this.element, side);
|
positionMenu(e, this.element, side);
|
||||||
openBtnMenu(this.element);
|
openBtnMenu(this.element, () => {
|
||||||
|
this.peerID = this.msgID = 0;
|
||||||
|
this.target = null;
|
||||||
|
});
|
||||||
|
|
||||||
/////this.log('contextmenu', e, bubble, msgID, side);
|
/////this.log('contextmenu', e, bubble, msgID, side);
|
||||||
});
|
});
|
||||||
@ -175,7 +182,14 @@ export class ChatContextMenu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private onForwardClick = () => {
|
private onForwardClick = () => {
|
||||||
appSidebarRight.forwardTab.open([this.msgID]);
|
let msgID: number;
|
||||||
|
|
||||||
|
const albumItem = findUpClassName(this.target, 'album-item');
|
||||||
|
if(albumItem) {
|
||||||
|
msgID = +albumItem.dataset.mid;
|
||||||
|
}
|
||||||
|
|
||||||
|
appSidebarRight.forwardTab.open([msgID]);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onDeleteClick = () => {
|
private onDeleteClick = () => {
|
||||||
|
@ -1260,7 +1260,7 @@ export class AppImManager {
|
|||||||
const hasRights = isChannel && appChatsManager.hasRights(-peerID, 'send');
|
const hasRights = isChannel && appChatsManager.hasRights(-peerID, 'send');
|
||||||
this.chatInner.classList.toggle('has-rights', hasRights);
|
this.chatInner.classList.toggle('has-rights', hasRights);
|
||||||
|
|
||||||
const canWrite = (!isChannel || hasRights) && (peerID < 0 || !appUsersManager.getUser(peerID).pFlags.deleted);
|
const canWrite = (!isChannel || hasRights) && (peerID < 0 || appUsersManager.canSendToUser(peerID));
|
||||||
this.chatInput.style.display = canWrite ? '' : 'none';
|
this.chatInput.style.display = canWrite ? '' : 'none';
|
||||||
|
|
||||||
this.chatInner.classList.toggle('is-chat-input-hidden', !canWrite);
|
this.chatInner.classList.toggle('is-chat-input-hidden', !canWrite);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export class AppMessagesIDsManager {
|
export class AppMessagesIDsManager {
|
||||||
public channelLocals = {} as any;
|
public channelLocals: {[channelID: string]: number} = {};
|
||||||
public channelsByLocals = {} as any;
|
public channelsByLocals: {[localStart: string]: number} = {};
|
||||||
public channelCurLocal = 0;
|
public channelCurLocal = 0;
|
||||||
public fullMsgIDModulus = 4294967296;
|
public fullMsgIDModulus = 4294967296;
|
||||||
|
|
||||||
@ -8,8 +8,9 @@ export class AppMessagesIDsManager {
|
|||||||
if(!channelID || msgID <= 0) {
|
if(!channelID || msgID <= 0) {
|
||||||
return msgID;
|
return msgID;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgID = this.getMessageLocalID(msgID);
|
msgID = this.getMessageLocalID(msgID);
|
||||||
var localStart = this.channelLocals[channelID];
|
let localStart = this.channelLocals[channelID];
|
||||||
if(!localStart) {
|
if(!localStart) {
|
||||||
localStart = (++this.channelCurLocal) * this.fullMsgIDModulus;
|
localStart = (++this.channelCurLocal) * this.fullMsgIDModulus;
|
||||||
this.channelsByLocals[localStart] = channelID;
|
this.channelsByLocals[localStart] = channelID;
|
||||||
@ -20,36 +21,32 @@ export class AppMessagesIDsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getMessageIDInfo(fullMsgID: number) {
|
public getMessageIDInfo(fullMsgID: number) {
|
||||||
if (fullMsgID < this.fullMsgIDModulus) {
|
if(fullMsgID < this.fullMsgIDModulus) {
|
||||||
return [fullMsgID, 0];
|
return [fullMsgID, 0];
|
||||||
}
|
}
|
||||||
var msgID = fullMsgID % this.fullMsgIDModulus;
|
|
||||||
var channelID = this.channelsByLocals[fullMsgID - msgID];
|
const msgID = fullMsgID % this.fullMsgIDModulus;
|
||||||
|
const channelID = this.channelsByLocals[fullMsgID - msgID];
|
||||||
|
|
||||||
return [msgID, channelID];
|
return [msgID, channelID];
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMessageLocalID(fullMsgID: number) {
|
public getMessageLocalID(fullMsgID: number) {
|
||||||
if(!fullMsgID) {
|
return fullMsgID ? fullMsgID % this.fullMsgIDModulus : 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return fullMsgID % this.fullMsgIDModulus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public splitMessageIDsByChannels (mids: any[]) {
|
public splitMessageIDsByChannels(mids: number[]) {
|
||||||
var msgIDsByChannels: {[channelID: number]: number[]} = {};
|
const msgIDsByChannels: {[channelID: number]: number[]} = {};
|
||||||
var midsByChannels: {[channelID: number]: number[]} = {};
|
const midsByChannels: {[channelID: number]: number[]} = {};
|
||||||
var i;
|
for(const mid of mids) {
|
||||||
var mid, msgChannel;
|
const msgChannel = this.getMessageIDInfo(mid);
|
||||||
var channelID;
|
const channelID = msgChannel[1];
|
||||||
for(i = 0; i < mids.length; i++) {
|
|
||||||
mid = mids[i];
|
|
||||||
msgChannel = this.getMessageIDInfo(mid);
|
|
||||||
channelID = msgChannel[1];
|
|
||||||
if(msgIDsByChannels[channelID] === undefined) {
|
if(msgIDsByChannels[channelID] === undefined) {
|
||||||
msgIDsByChannels[channelID] = [];
|
msgIDsByChannels[channelID] = [];
|
||||||
midsByChannels[channelID] = [];
|
midsByChannels[channelID] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
msgIDsByChannels[channelID].push(msgChannel[0]);
|
msgIDsByChannels[channelID].push(msgChannel[0]);
|
||||||
midsByChannels[channelID].push(mid);
|
midsByChannels[channelID].push(mid);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import ProgressivePreloader from "../../components/preloader";
|
import ProgressivePreloader from "../../components/preloader";
|
||||||
import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise";
|
import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise";
|
||||||
import { Dialog as MTDialog, DialogFilter, DialogPeer, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize, Update } from "../../layer";
|
import { Dialog as MTDialog, DialogFilter, DialogPeer, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize, Update } from "../../layer";
|
||||||
import { Modify } from "../../types";
|
import { InvokeApiOptions, Modify } from "../../types";
|
||||||
import { bigint, nextRandomInt } from "../bin_utils";
|
import { bigint, nextRandomInt } from "../bin_utils";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import type { ApiFileManager } from '../mtproto/apiFileManager';
|
import type { ApiFileManager } from '../mtproto/apiFileManager';
|
||||||
@ -1997,38 +1997,29 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public forwardMessages(peerID: number, mids: number[], options: Partial<{
|
public forwardMessages(peerID: number, mids: number[], options: Partial<{
|
||||||
withMyScore: boolean
|
withMyScore: true
|
||||||
}> = {}) {
|
}> = {}) {
|
||||||
peerID = appPeersManager.getPeerMigratedTo(peerID) || peerID;
|
peerID = appPeersManager.getPeerMigratedTo(peerID) || peerID;
|
||||||
mids = mids.sort((a, b) => a - b);
|
mids = mids.sort((a, b) => a - b);
|
||||||
|
|
||||||
var flags = 0;
|
const splitted = appMessagesIDsManager.splitMessageIDsByChannels(mids);
|
||||||
if(options.withMyScore) {
|
const promises: Promise<void>[] = [];
|
||||||
flags |= 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
let splitted = appMessagesIDsManager.splitMessageIDsByChannels(mids);
|
for(const channelID in splitted.msgIDs) {
|
||||||
let promises: any[] = [];
|
const msgIDs = splitted.msgIDs[channelID];
|
||||||
|
const randomIDs: [number, number][] = msgIDs.map(() => [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]);
|
||||||
|
|
||||||
for(let channelID in splitted.msgIDs) {
|
const sentRequestOptions: InvokeApiOptions = {};
|
||||||
let msgIDs = splitted.msgIDs[channelID];
|
|
||||||
let len = msgIDs.length;
|
|
||||||
let randomIDs = [];
|
|
||||||
for(let i = 0; i < len; i++) {
|
|
||||||
randomIDs.push([nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let sentRequestOptions: any = {};
|
|
||||||
if(this.pendingAfterMsgs[peerID]) {
|
if(this.pendingAfterMsgs[peerID]) {
|
||||||
sentRequestOptions.afterMessageID = this.pendingAfterMsgs[peerID].messageID;
|
sentRequestOptions.afterMessageID = this.pendingAfterMsgs[peerID].messageID;
|
||||||
}
|
}
|
||||||
|
|
||||||
let promise = apiManager.invokeApi('messages.forwardMessages', {
|
const promise = apiManager.invokeApi('messages.forwardMessages', {
|
||||||
flags: flags,
|
|
||||||
from_peer: appPeersManager.getInputPeerByID(-channelID),
|
from_peer: appPeersManager.getInputPeerByID(-channelID),
|
||||||
id: msgIDs,
|
id: msgIDs,
|
||||||
random_id: randomIDs as any,
|
random_id: randomIDs as any,
|
||||||
to_peer: appPeersManager.getInputPeerByID(peerID)
|
to_peer: appPeersManager.getInputPeerByID(peerID),
|
||||||
|
with_my_score: options.withMyScore
|
||||||
}, sentRequestOptions).then((updates) => {
|
}, sentRequestOptions).then((updates) => {
|
||||||
apiUpdatesManager.processUpdateMessage(updates);
|
apiUpdatesManager.processUpdateMessage(updates);
|
||||||
}, () => {}).then(() => {
|
}, () => {}).then(() => {
|
||||||
|
@ -11,6 +11,8 @@ import appChatsManager from "./appChatsManager";
|
|||||||
import appPeersManager from "./appPeersManager";
|
import appPeersManager from "./appPeersManager";
|
||||||
import appStateManager from "./appStateManager";
|
import appStateManager from "./appStateManager";
|
||||||
|
|
||||||
|
// TODO: updateUserBlocked
|
||||||
|
|
||||||
/* export type User = {
|
/* export type User = {
|
||||||
_: 'user',
|
_: 'user',
|
||||||
access_hash: string,
|
access_hash: string,
|
||||||
@ -110,7 +112,17 @@ export class AppUsersManager {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* // @ts-ignore
|
||||||
|
case 'updateUserBlocked': {
|
||||||
|
const id = (update as any).user_id;
|
||||||
|
const blocked: boolean = (update as any).blocked;
|
||||||
|
|
||||||
|
const user = this.getUser(id);
|
||||||
|
if(user) {
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} */
|
||||||
|
|
||||||
/* case 'updateContactLink':
|
/* case 'updateContactLink':
|
||||||
this.onContactUpdated(update.user_id, update.my_link._ == 'contactLinkContact');
|
this.onContactUpdated(update.user_id, update.my_link._ == 'contactLinkContact');
|
||||||
@ -420,6 +432,11 @@ export class AppUsersManager {
|
|||||||
return isObject(user) && (allowMin || !user.pFlags.min);
|
return isObject(user) && (allowMin || !user.pFlags.min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public canSendToUser(id: number) {
|
||||||
|
const user = this.getUser(id);
|
||||||
|
return !user.pFlags.deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public getUserPhoto(id: number) {
|
public getUserPhoto(id: number) {
|
||||||
var user = this.getUser(id);
|
var user = this.getUser(id);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user