Support adding chats to privacy exception
This commit is contained in:
parent
98d3c8d73d
commit
beebb77bce
@ -23,8 +23,9 @@ import replaceContent from "../helpers/dom/replaceContent";
|
|||||||
import { filterUnique, indexOfAndSplice } from "../helpers/array";
|
import { filterUnique, indexOfAndSplice } from "../helpers/array";
|
||||||
import debounce from "../helpers/schedulers/debounce";
|
import debounce from "../helpers/schedulers/debounce";
|
||||||
import windowSize from "../helpers/windowSize";
|
import windowSize from "../helpers/windowSize";
|
||||||
|
import appPeersManager, { IsPeerType } from "../lib/appManagers/appPeersManager";
|
||||||
|
|
||||||
type PeerType = 'contacts' | 'dialogs' | 'channelParticipants';
|
type SelectSearchPeerType = 'contacts' | 'dialogs' | 'channelParticipants';
|
||||||
|
|
||||||
// TODO: правильная сортировка для addMembers, т.е. для peerType: 'contacts', потому что там идут сначала контакты - потом неконтакты, а должно всё сортироваться по имени
|
// TODO: правильная сортировка для addMembers, т.е. для peerType: 'contacts', потому что там идут сначала контакты - потом неконтакты, а должно всё сортироваться по имени
|
||||||
|
|
||||||
@ -59,12 +60,14 @@ export default class AppSelectPeers {
|
|||||||
|
|
||||||
private appendTo: HTMLElement;
|
private appendTo: HTMLElement;
|
||||||
private onChange: (length: number) => void;
|
private onChange: (length: number) => void;
|
||||||
private peerType: PeerType[] = ['dialogs'];
|
private peerType: SelectSearchPeerType[] = ['dialogs'];
|
||||||
private renderResultsFunc: (peerIds: PeerId[]) => void;
|
private renderResultsFunc: (peerIds: PeerId[]) => void;
|
||||||
private chatRightsAction: ChatRights;
|
private chatRightsAction: ChatRights;
|
||||||
private multiSelect = true;
|
private multiSelect = true;
|
||||||
private rippleEnabled = true;
|
private rippleEnabled = true;
|
||||||
private avatarSize = 48;
|
private avatarSize = 48;
|
||||||
|
private exceptSelf = false;
|
||||||
|
private filterPeerTypeBy: IsPeerType[];
|
||||||
|
|
||||||
private tempIds: {[k in keyof AppSelectPeers['loadedWhat']]: number} = {};
|
private tempIds: {[k in keyof AppSelectPeers['loadedWhat']]: number} = {};
|
||||||
private peerId: PeerId;
|
private peerId: PeerId;
|
||||||
@ -79,22 +82,24 @@ export default class AppSelectPeers {
|
|||||||
appendTo: AppSelectPeers['appendTo'],
|
appendTo: AppSelectPeers['appendTo'],
|
||||||
onChange?: AppSelectPeers['onChange'],
|
onChange?: AppSelectPeers['onChange'],
|
||||||
peerType?: AppSelectPeers['peerType'],
|
peerType?: AppSelectPeers['peerType'],
|
||||||
peerId?: number,
|
peerId?: AppSelectPeers['peerId'],
|
||||||
onFirstRender?: () => void,
|
onFirstRender?: () => void,
|
||||||
renderResultsFunc?: AppSelectPeers['renderResultsFunc'],
|
renderResultsFunc?: AppSelectPeers['renderResultsFunc'],
|
||||||
chatRightsAction?: AppSelectPeers['chatRightsAction'],
|
chatRightsAction?: AppSelectPeers['chatRightsAction'],
|
||||||
multiSelect?: AppSelectPeers['multiSelect'],
|
multiSelect?: AppSelectPeers['multiSelect'],
|
||||||
rippleEnabled?: boolean,
|
rippleEnabled?: AppSelectPeers['rippleEnabled'],
|
||||||
avatarSize?: AppSelectPeers['avatarSize'],
|
avatarSize?: AppSelectPeers['avatarSize'],
|
||||||
placeholder?: LangPackKey,
|
placeholder?: AppSelectPeers['placeholder'],
|
||||||
selfPresence?: LangPackKey
|
selfPresence?: AppSelectPeers['selfPresence'],
|
||||||
|
exceptSelf?: AppSelectPeers['exceptSelf'],
|
||||||
|
filterPeerTypeBy?: AppSelectPeers['filterPeerTypeBy']
|
||||||
}) {
|
}) {
|
||||||
safeAssign(this, options);
|
safeAssign(this, options);
|
||||||
|
|
||||||
this.container.classList.add('selector');
|
this.container.classList.add('selector');
|
||||||
|
|
||||||
const f = (this.renderResultsFunc || this.renderResults).bind(this);
|
const f = (this.renderResultsFunc || this.renderResults).bind(this);
|
||||||
this.renderResultsFunc = (peerIds: PeerId[]) => {
|
this.renderResultsFunc = (peerIds) => {
|
||||||
if(this.needSwitchList) {
|
if(this.needSwitchList) {
|
||||||
this.scrollable.splitUp.replaceWith(this.list);
|
this.scrollable.splitUp.replaceWith(this.list);
|
||||||
this.scrollable.setVirtualContainer(this.list);
|
this.scrollable.setVirtualContainer(this.list);
|
||||||
@ -107,6 +112,19 @@ export default class AppSelectPeers {
|
|||||||
return notRendered;
|
return notRendered;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(this.filterPeerTypeBy) {
|
||||||
|
peerIds = peerIds.filter(peerId => {
|
||||||
|
if(peerId.isPeerId()) {
|
||||||
|
const peer = appPeersManager.getPeer(peerId);
|
||||||
|
if(!peer.deleted) {
|
||||||
|
return this.filterPeerTypeBy.find(method => appPeersManager[method](peerId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return f(peerIds);
|
return f(peerIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -235,7 +253,11 @@ export default class AppSelectPeers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private renderSaved() {
|
private renderSaved() {
|
||||||
if(!this.offsetIndex && this.folderId === 0 && this.peerType.includes('dialogs') && (!this.query || appUsersManager.testSelfSearch(this.query))) {
|
if(!this.exceptSelf &&
|
||||||
|
!this.offsetIndex &&
|
||||||
|
this.folderId === 0 &&
|
||||||
|
this.peerType.includes('dialogs') &&
|
||||||
|
(!this.query || appUsersManager.testSelfSearch(this.query))) {
|
||||||
this.renderResultsFunc([rootScope.myId]);
|
this.renderResultsFunc([rootScope.myId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ export default class ChatInput {
|
|||||||
|
|
||||||
private getWebPagePromise: Promise<void>;
|
private getWebPagePromise: Promise<void>;
|
||||||
private willSendWebPage: WebPage = null;
|
private willSendWebPage: WebPage = null;
|
||||||
private forwarding: {[frompeerId: PeerId]: number[]};
|
private forwarding: {[fromPeerId: PeerId]: number[]};
|
||||||
public replyToMsgId: number;
|
public replyToMsgId: number;
|
||||||
public editMsgId: number;
|
public editMsgId: number;
|
||||||
public editMessage: Message.message;
|
public editMessage: Message.message;
|
||||||
|
@ -21,7 +21,7 @@ export default class MentionsHelper extends AutocompletePeerHelper {
|
|||||||
controller,
|
controller,
|
||||||
'mentions-helper',
|
'mentions-helper',
|
||||||
(target) => {
|
(target) => {
|
||||||
const user = appUsersManager.getUser((target as HTMLElement).dataset.peerId);
|
const user = appUsersManager.getUser((target as HTMLElement).dataset.peerId.toUserId());
|
||||||
let str = '', entity: MessageEntity;
|
let str = '', entity: MessageEntity;
|
||||||
if(user.username) {
|
if(user.username) {
|
||||||
str = '@' + user.username;
|
str = '@' + user.username;
|
||||||
|
@ -175,8 +175,8 @@ class AppSelection {
|
|||||||
|
|
||||||
const processElement = (element: HTMLElement, checkBetween = true) => {
|
const processElement = (element: HTMLElement, checkBetween = true) => {
|
||||||
const mid = +element.dataset.mid;
|
const mid = +element.dataset.mid;
|
||||||
const peerId = (element.dataset.peerId || '').toPeerId();
|
if(!mid || !element.dataset.peerId) return;
|
||||||
if(!mid || !peerId) return;
|
const peerId = element.dataset.peerId.toPeerId();
|
||||||
|
|
||||||
if(!isInDOM(firstTarget)) {
|
if(!isInDOM(firstTarget)) {
|
||||||
firstTarget = element;
|
firstTarget = element;
|
||||||
@ -620,7 +620,7 @@ export class SearchSelection extends AppSelection {
|
|||||||
|
|
||||||
this.selectionForwardBtn = ButtonIcon(`forward ${BASE_CLASS}-forward`);
|
this.selectionForwardBtn = ButtonIcon(`forward ${BASE_CLASS}-forward`);
|
||||||
attachClickEvent(this.selectionForwardBtn, () => {
|
attachClickEvent(this.selectionForwardBtn, () => {
|
||||||
const obj: {[frompeerId: PeerId]: number[]} = {};
|
const obj: {[fromPeerId: PeerId]: number[]} = {};
|
||||||
for(const [fromPeerId, mids] of this.selectedMids) {
|
for(const [fromPeerId, mids] of this.selectedMids) {
|
||||||
obj[fromPeerId] = Array.from(mids);
|
obj[fromPeerId] = Array.from(mids);
|
||||||
}
|
}
|
||||||
@ -895,7 +895,7 @@ export default class ChatSelection extends AppSelection {
|
|||||||
this.selectionForwardBtn = Button('btn-primary btn-transparent text-bold selection-container-forward', {icon: 'forward'});
|
this.selectionForwardBtn = Button('btn-primary btn-transparent text-bold selection-container-forward', {icon: 'forward'});
|
||||||
this.selectionForwardBtn.append(i18n('Forward'));
|
this.selectionForwardBtn.append(i18n('Forward'));
|
||||||
attachClickEvent(this.selectionForwardBtn, () => {
|
attachClickEvent(this.selectionForwardBtn, () => {
|
||||||
const obj: {[frompeerId: PeerId]: number[]} = {};
|
const obj: {[fromPeerId: PeerId]: number[]} = {};
|
||||||
for(const [fromPeerId, mids] of this.selectedMids) {
|
for(const [fromPeerId, mids] of this.selectedMids) {
|
||||||
obj[fromPeerId] = Array.from(mids);
|
obj[fromPeerId] = Array.from(mids);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import PopupPickUser from "./pickUser";
|
|||||||
|
|
||||||
export default class PopupForward extends PopupPickUser {
|
export default class PopupForward extends PopupPickUser {
|
||||||
constructor(
|
constructor(
|
||||||
peerIdMids: {[frompeerId: PeerId]: number[]},
|
peerIdMids: {[fromPeerId: PeerId]: number[]},
|
||||||
onSelect?: (peerId: PeerId) => Promise<void> | void,
|
onSelect?: (peerId: PeerId) => Promise<void> | void,
|
||||||
onClose?: () => void,
|
onClose?: () => void,
|
||||||
overrideOnSelect = false
|
overrideOnSelect = false
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
import { randomLong } from "../helpers/random";
|
import { randomLong } from "../helpers/random";
|
||||||
import { InputPrivacyKey, InputPrivacyRule } from "../layer";
|
import { InputPrivacyKey, InputPrivacyRule } from "../layer";
|
||||||
import appChatsManager from "../lib/appManagers/appChatsManager";
|
|
||||||
import appPrivacyManager, { PrivacyType } from "../lib/appManagers/appPrivacyManager";
|
import appPrivacyManager, { PrivacyType } from "../lib/appManagers/appPrivacyManager";
|
||||||
import appUsersManager from "../lib/appManagers/appUsersManager";
|
import appUsersManager from "../lib/appManagers/appUsersManager";
|
||||||
import { i18n, join, LangPackKey, _i18n } from "../lib/langPack";
|
import { i18n, join, LangPackKey, _i18n } from "../lib/langPack";
|
||||||
@ -150,11 +149,11 @@ export default class PrivacySection {
|
|||||||
|
|
||||||
if(this.exceptions) {
|
if(this.exceptions) {
|
||||||
this.peerIds = {};
|
this.peerIds = {};
|
||||||
(['allow', 'disallow'] as ('allow' | 'disallow')[]).forEach(k => {
|
['allow' as const, 'disallow' as const].forEach(k => {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
const from = k === 'allow' ? details.allowPeers : details.disallowPeers;
|
const from = k === 'allow' ? details.allowPeers : details.disallowPeers;
|
||||||
arr.push(...from.users.map(id => id.toPeerId()));
|
arr.push(...from.users.map(id => id.toPeerId()));
|
||||||
arr.push(...from.chats.map(id => id.toPeerId(false)));
|
arr.push(...from.chats.map(id => id.toPeerId(true)));
|
||||||
this.peerIds[k] = arr;
|
this.peerIds[k] = arr;
|
||||||
const s = this.exceptions.get(k).row.subtitle;
|
const s = this.exceptions.get(k).row.subtitle;
|
||||||
s.innerHTML = '';
|
s.innerHTML = '';
|
||||||
@ -194,7 +193,7 @@ export default class PrivacySection {
|
|||||||
if(_peerIds) {
|
if(_peerIds) {
|
||||||
const splitted = this.splitPeersByType(_peerIds);
|
const splitted = this.splitPeersByType(_peerIds);
|
||||||
if(splitted.chats.length) {
|
if(splitted.chats.length) {
|
||||||
rules.push({_: chatKey, chats: splitted.chats.map(peerId => peerId.toChatId())});
|
rules.push({_: chatKey, chats: splitted.chats});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(splitted.users.length) {
|
if(splitted.users.length) {
|
||||||
|
@ -65,13 +65,16 @@ export default class AppAddMembersTab extends SliderSuperTab {
|
|||||||
this.takeOut = options.takeOut;
|
this.takeOut = options.takeOut;
|
||||||
this.skippable = options.skippable;
|
this.skippable = options.skippable;
|
||||||
|
|
||||||
|
const isPrivacy = this.peerType === 'privacy';
|
||||||
this.selector = new AppSelectPeers({
|
this.selector = new AppSelectPeers({
|
||||||
appendTo: this.content,
|
appendTo: this.content,
|
||||||
onChange: this.skippable ? null : (length) => {
|
onChange: this.skippable ? null : (length) => {
|
||||||
this.nextBtn.classList.toggle('is-visible', !!length);
|
this.nextBtn.classList.toggle('is-visible', !!length);
|
||||||
},
|
},
|
||||||
peerType: ['contacts'],
|
peerType: [isPrivacy ? 'dialogs' : 'contacts'],
|
||||||
placeholder: options.placeholder
|
placeholder: options.placeholder,
|
||||||
|
exceptSelf: isPrivacy,
|
||||||
|
filterPeerTypeBy: isPrivacy ? ['isAnyGroup', 'isUser'] : undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
if(options.selectedPeerIds) {
|
if(options.selectedPeerIds) {
|
||||||
|
@ -308,6 +308,8 @@ export class AppPeersManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IsPeerType = 'isChannel' | 'isMegagroup' | 'isAnyGroup' | 'isBroadcast' | 'isBot' | 'isContact' | 'isUser' | 'isAnyChat';
|
||||||
|
|
||||||
[
|
[
|
||||||
'isChannel',
|
'isChannel',
|
||||||
'isMegagroup',
|
'isMegagroup',
|
||||||
|
@ -515,7 +515,7 @@ export class AppUsersManager {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUser(id: any) {
|
public getUser(id: User | UserId) {
|
||||||
if(isObject<User>(id)) {
|
if(isObject<User>(id)) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user