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 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 appPhotosManager from "../lib/appManagers/appPhotosManager";
|
||||
import appUsersManager from "../lib/appManagers/appUsersManager";
|
||||
import $rootScope from "../lib/rootScope";
|
||||
import { cancelEvent, findUpAttribute, findUpClassName } from "../lib/utils";
|
||||
import Scrollable from "./scrollable";
|
||||
|
||||
type PeerType = 'contacts' | 'dialogs';
|
||||
|
||||
@ -172,7 +172,7 @@ export class AppSelectPeers {
|
||||
|
||||
if(this.chatRightsAction) {
|
||||
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";
|
||||
|
||||
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 target: HTMLElement;
|
||||
public peerID: number;
|
||||
public msgID: number;
|
||||
|
||||
constructor(private attachTo: HTMLElement) {
|
||||
@ -41,17 +44,21 @@ export class ChatContextMenu {
|
||||
const msgID = +bubble.dataset.mid;
|
||||
if(!msgID) return;
|
||||
|
||||
const peerID = $rootScope.selectedPeerID;
|
||||
this.peerID = $rootScope.selectedPeerID;
|
||||
this.msgID = msgID;
|
||||
this.target = e.target as HTMLElement;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
const side: 'left' | 'right' = bubble.classList.contains('is-in') ? 'left' : 'right';
|
||||
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);
|
||||
});
|
||||
@ -175,7 +182,14 @@ export class ChatContextMenu {
|
||||
};
|
||||
|
||||
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 = () => {
|
||||
|
@ -1260,7 +1260,7 @@ export class AppImManager {
|
||||
const hasRights = isChannel && appChatsManager.hasRights(-peerID, 'send');
|
||||
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.chatInner.classList.toggle('is-chat-input-hidden', !canWrite);
|
||||
|
@ -1,6 +1,6 @@
|
||||
export class AppMessagesIDsManager {
|
||||
public channelLocals = {} as any;
|
||||
public channelsByLocals = {} as any;
|
||||
public channelLocals: {[channelID: string]: number} = {};
|
||||
public channelsByLocals: {[localStart: string]: number} = {};
|
||||
public channelCurLocal = 0;
|
||||
public fullMsgIDModulus = 4294967296;
|
||||
|
||||
@ -8,8 +8,9 @@ export class AppMessagesIDsManager {
|
||||
if(!channelID || msgID <= 0) {
|
||||
return msgID;
|
||||
}
|
||||
|
||||
msgID = this.getMessageLocalID(msgID);
|
||||
var localStart = this.channelLocals[channelID];
|
||||
let localStart = this.channelLocals[channelID];
|
||||
if(!localStart) {
|
||||
localStart = (++this.channelCurLocal) * this.fullMsgIDModulus;
|
||||
this.channelsByLocals[localStart] = channelID;
|
||||
@ -20,36 +21,32 @@ export class AppMessagesIDsManager {
|
||||
}
|
||||
|
||||
public getMessageIDInfo(fullMsgID: number) {
|
||||
if (fullMsgID < this.fullMsgIDModulus) {
|
||||
if(fullMsgID < this.fullMsgIDModulus) {
|
||||
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];
|
||||
}
|
||||
|
||||
public getMessageLocalID(fullMsgID: number) {
|
||||
if(!fullMsgID) {
|
||||
return 0;
|
||||
}
|
||||
return fullMsgID % this.fullMsgIDModulus;
|
||||
return fullMsgID ? fullMsgID % this.fullMsgIDModulus : 0;
|
||||
}
|
||||
|
||||
public splitMessageIDsByChannels (mids: any[]) {
|
||||
var msgIDsByChannels: {[channelID: number]: number[]} = {};
|
||||
var midsByChannels: {[channelID: number]: number[]} = {};
|
||||
var i;
|
||||
var mid, msgChannel;
|
||||
var channelID;
|
||||
for(i = 0; i < mids.length; i++) {
|
||||
mid = mids[i];
|
||||
msgChannel = this.getMessageIDInfo(mid);
|
||||
channelID = msgChannel[1];
|
||||
public splitMessageIDsByChannels(mids: number[]) {
|
||||
const msgIDsByChannels: {[channelID: number]: number[]} = {};
|
||||
const midsByChannels: {[channelID: number]: number[]} = {};
|
||||
for(const mid of mids) {
|
||||
const msgChannel = this.getMessageIDInfo(mid);
|
||||
const channelID = msgChannel[1];
|
||||
|
||||
if(msgIDsByChannels[channelID] === undefined) {
|
||||
msgIDsByChannels[channelID] = [];
|
||||
midsByChannels[channelID] = [];
|
||||
}
|
||||
|
||||
msgIDsByChannels[channelID].push(msgChannel[0]);
|
||||
midsByChannels[channelID].push(mid);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import ProgressivePreloader from "../../components/preloader";
|
||||
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 { Modify } from "../../types";
|
||||
import { InvokeApiOptions, Modify } from "../../types";
|
||||
import { bigint, nextRandomInt } from "../bin_utils";
|
||||
import { logger } from "../logger";
|
||||
import type { ApiFileManager } from '../mtproto/apiFileManager';
|
||||
@ -1997,38 +1997,29 @@ export class AppMessagesManager {
|
||||
}
|
||||
|
||||
public forwardMessages(peerID: number, mids: number[], options: Partial<{
|
||||
withMyScore: boolean
|
||||
withMyScore: true
|
||||
}> = {}) {
|
||||
peerID = appPeersManager.getPeerMigratedTo(peerID) || peerID;
|
||||
mids = mids.sort((a, b) => a - b);
|
||||
|
||||
var flags = 0;
|
||||
if(options.withMyScore) {
|
||||
flags |= 256;
|
||||
}
|
||||
const splitted = appMessagesIDsManager.splitMessageIDsByChannels(mids);
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
let splitted = appMessagesIDsManager.splitMessageIDsByChannels(mids);
|
||||
let promises: any[] = [];
|
||||
for(const channelID in splitted.msgIDs) {
|
||||
const msgIDs = splitted.msgIDs[channelID];
|
||||
const randomIDs: [number, number][] = msgIDs.map(() => [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]);
|
||||
|
||||
for(let channelID in splitted.msgIDs) {
|
||||
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 = {};
|
||||
const sentRequestOptions: InvokeApiOptions = {};
|
||||
if(this.pendingAfterMsgs[peerID]) {
|
||||
sentRequestOptions.afterMessageID = this.pendingAfterMsgs[peerID].messageID;
|
||||
}
|
||||
|
||||
let promise = apiManager.invokeApi('messages.forwardMessages', {
|
||||
flags: flags,
|
||||
const promise = apiManager.invokeApi('messages.forwardMessages', {
|
||||
from_peer: appPeersManager.getInputPeerByID(-channelID),
|
||||
id: msgIDs,
|
||||
random_id: randomIDs as any,
|
||||
to_peer: appPeersManager.getInputPeerByID(peerID)
|
||||
to_peer: appPeersManager.getInputPeerByID(peerID),
|
||||
with_my_score: options.withMyScore
|
||||
}, sentRequestOptions).then((updates) => {
|
||||
apiUpdatesManager.processUpdateMessage(updates);
|
||||
}, () => {}).then(() => {
|
||||
|
@ -11,6 +11,8 @@ import appChatsManager from "./appChatsManager";
|
||||
import appPeersManager from "./appPeersManager";
|
||||
import appStateManager from "./appStateManager";
|
||||
|
||||
// TODO: updateUserBlocked
|
||||
|
||||
/* export type User = {
|
||||
_: 'user',
|
||||
access_hash: string,
|
||||
@ -110,7 +112,17 @@ export class AppUsersManager {
|
||||
|
||||
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':
|
||||
this.onContactUpdated(update.user_id, update.my_link._ == 'contactLinkContact');
|
||||
@ -420,6 +432,11 @@ export class AppUsersManager {
|
||||
return isObject(user) && (allowMin || !user.pFlags.min);
|
||||
}
|
||||
|
||||
public canSendToUser(id: number) {
|
||||
const user = this.getUser(id);
|
||||
return !user.pFlags.deleted;
|
||||
}
|
||||
|
||||
public getUserPhoto(id: number) {
|
||||
var user = this.getUser(id);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user