Browse Source

Support adding chats to privacy exception

master
morethanwords 3 years ago
parent
commit
beebb77bce
  1. 38
      src/components/appSelectPeers.ts
  2. 2
      src/components/chat/input.ts
  3. 2
      src/components/chat/mentionsHelper.ts
  4. 8
      src/components/chat/selection.ts
  5. 2
      src/components/popups/forward.ts
  6. 7
      src/components/privacySection.ts
  7. 7
      src/components/sidebarLeft/tabs/addMembers.ts
  8. 2
      src/lib/appManagers/appPeersManager.ts
  9. 2
      src/lib/appManagers/appUsersManager.ts

38
src/components/appSelectPeers.ts

@ -23,8 +23,9 @@ import replaceContent from "../helpers/dom/replaceContent"; @@ -23,8 +23,9 @@ import replaceContent from "../helpers/dom/replaceContent";
import { filterUnique, indexOfAndSplice } from "../helpers/array";
import debounce from "../helpers/schedulers/debounce";
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', потому что там идут сначала контакты - потом неконтакты, а должно всё сортироваться по имени
@ -59,12 +60,14 @@ export default class AppSelectPeers { @@ -59,12 +60,14 @@ export default class AppSelectPeers {
private appendTo: HTMLElement;
private onChange: (length: number) => void;
private peerType: PeerType[] = ['dialogs'];
private peerType: SelectSearchPeerType[] = ['dialogs'];
private renderResultsFunc: (peerIds: PeerId[]) => void;
private chatRightsAction: ChatRights;
private multiSelect = true;
private rippleEnabled = true;
private avatarSize = 48;
private exceptSelf = false;
private filterPeerTypeBy: IsPeerType[];
private tempIds: {[k in keyof AppSelectPeers['loadedWhat']]: number} = {};
private peerId: PeerId;
@ -79,22 +82,24 @@ export default class AppSelectPeers { @@ -79,22 +82,24 @@ export default class AppSelectPeers {
appendTo: AppSelectPeers['appendTo'],
onChange?: AppSelectPeers['onChange'],
peerType?: AppSelectPeers['peerType'],
peerId?: number,
peerId?: AppSelectPeers['peerId'],
onFirstRender?: () => void,
renderResultsFunc?: AppSelectPeers['renderResultsFunc'],
chatRightsAction?: AppSelectPeers['chatRightsAction'],
multiSelect?: AppSelectPeers['multiSelect'],
rippleEnabled?: boolean,
rippleEnabled?: AppSelectPeers['rippleEnabled'],
avatarSize?: AppSelectPeers['avatarSize'],
placeholder?: LangPackKey,
selfPresence?: LangPackKey
placeholder?: AppSelectPeers['placeholder'],
selfPresence?: AppSelectPeers['selfPresence'],
exceptSelf?: AppSelectPeers['exceptSelf'],
filterPeerTypeBy?: AppSelectPeers['filterPeerTypeBy']
}) {
safeAssign(this, options);
this.container.classList.add('selector');
const f = (this.renderResultsFunc || this.renderResults).bind(this);
this.renderResultsFunc = (peerIds: PeerId[]) => {
this.renderResultsFunc = (peerIds) => {
if(this.needSwitchList) {
this.scrollable.splitUp.replaceWith(this.list);
this.scrollable.setVirtualContainer(this.list);
@ -107,6 +112,19 @@ export default class AppSelectPeers { @@ -107,6 +112,19 @@ export default class AppSelectPeers {
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);
};
@ -235,7 +253,11 @@ export default class AppSelectPeers { @@ -235,7 +253,11 @@ export default class AppSelectPeers {
};
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]);
}
}

2
src/components/chat/input.ts

@ -124,7 +124,7 @@ export default class ChatInput { @@ -124,7 +124,7 @@ export default class ChatInput {
private getWebPagePromise: Promise<void>;
private willSendWebPage: WebPage = null;
private forwarding: {[frompeerId: PeerId]: number[]};
private forwarding: {[fromPeerId: PeerId]: number[]};
public replyToMsgId: number;
public editMsgId: number;
public editMessage: Message.message;

2
src/components/chat/mentionsHelper.ts

@ -21,7 +21,7 @@ export default class MentionsHelper extends AutocompletePeerHelper { @@ -21,7 +21,7 @@ export default class MentionsHelper extends AutocompletePeerHelper {
controller,
'mentions-helper',
(target) => {
const user = appUsersManager.getUser((target as HTMLElement).dataset.peerId);
const user = appUsersManager.getUser((target as HTMLElement).dataset.peerId.toUserId());
let str = '', entity: MessageEntity;
if(user.username) {
str = '@' + user.username;

8
src/components/chat/selection.ts

@ -175,8 +175,8 @@ class AppSelection { @@ -175,8 +175,8 @@ class AppSelection {
const processElement = (element: HTMLElement, checkBetween = true) => {
const mid = +element.dataset.mid;
const peerId = (element.dataset.peerId || '').toPeerId();
if(!mid || !peerId) return;
if(!mid || !element.dataset.peerId) return;
const peerId = element.dataset.peerId.toPeerId();
if(!isInDOM(firstTarget)) {
firstTarget = element;
@ -620,7 +620,7 @@ export class SearchSelection extends AppSelection { @@ -620,7 +620,7 @@ export class SearchSelection extends AppSelection {
this.selectionForwardBtn = ButtonIcon(`forward ${BASE_CLASS}-forward`);
attachClickEvent(this.selectionForwardBtn, () => {
const obj: {[frompeerId: PeerId]: number[]} = {};
const obj: {[fromPeerId: PeerId]: number[]} = {};
for(const [fromPeerId, mids] of this.selectedMids) {
obj[fromPeerId] = Array.from(mids);
}
@ -895,7 +895,7 @@ export default class ChatSelection extends AppSelection { @@ -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.append(i18n('Forward'));
attachClickEvent(this.selectionForwardBtn, () => {
const obj: {[frompeerId: PeerId]: number[]} = {};
const obj: {[fromPeerId: PeerId]: number[]} = {};
for(const [fromPeerId, mids] of this.selectedMids) {
obj[fromPeerId] = Array.from(mids);
}

2
src/components/popups/forward.ts

@ -9,7 +9,7 @@ import PopupPickUser from "./pickUser"; @@ -9,7 +9,7 @@ import PopupPickUser from "./pickUser";
export default class PopupForward extends PopupPickUser {
constructor(
peerIdMids: {[frompeerId: PeerId]: number[]},
peerIdMids: {[fromPeerId: PeerId]: number[]},
onSelect?: (peerId: PeerId) => Promise<void> | void,
onClose?: () => void,
overrideOnSelect = false

7
src/components/privacySection.ts

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
import { randomLong } from "../helpers/random";
import { InputPrivacyKey, InputPrivacyRule } from "../layer";
import appChatsManager from "../lib/appManagers/appChatsManager";
import appPrivacyManager, { PrivacyType } from "../lib/appManagers/appPrivacyManager";
import appUsersManager from "../lib/appManagers/appUsersManager";
import { i18n, join, LangPackKey, _i18n } from "../lib/langPack";
@ -150,11 +149,11 @@ export default class PrivacySection { @@ -150,11 +149,11 @@ export default class PrivacySection {
if(this.exceptions) {
this.peerIds = {};
(['allow', 'disallow'] as ('allow' | 'disallow')[]).forEach(k => {
['allow' as const, 'disallow' as const].forEach(k => {
const arr = [];
const from = k === 'allow' ? details.allowPeers : details.disallowPeers;
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;
const s = this.exceptions.get(k).row.subtitle;
s.innerHTML = '';
@ -194,7 +193,7 @@ export default class PrivacySection { @@ -194,7 +193,7 @@ export default class PrivacySection {
if(_peerIds) {
const splitted = this.splitPeersByType(_peerIds);
if(splitted.chats.length) {
rules.push({_: chatKey, chats: splitted.chats.map(peerId => peerId.toChatId())});
rules.push({_: chatKey, chats: splitted.chats});
}
if(splitted.users.length) {

7
src/components/sidebarLeft/tabs/addMembers.ts

@ -65,13 +65,16 @@ export default class AppAddMembersTab extends SliderSuperTab { @@ -65,13 +65,16 @@ export default class AppAddMembersTab extends SliderSuperTab {
this.takeOut = options.takeOut;
this.skippable = options.skippable;
const isPrivacy = this.peerType === 'privacy';
this.selector = new AppSelectPeers({
appendTo: this.content,
onChange: this.skippable ? null : (length) => {
this.nextBtn.classList.toggle('is-visible', !!length);
},
peerType: ['contacts'],
placeholder: options.placeholder
peerType: [isPrivacy ? 'dialogs' : 'contacts'],
placeholder: options.placeholder,
exceptSelf: isPrivacy,
filterPeerTypeBy: isPrivacy ? ['isAnyGroup', 'isUser'] : undefined
});
if(options.selectedPeerIds) {

2
src/lib/appManagers/appPeersManager.ts

@ -308,6 +308,8 @@ export class AppPeersManager { @@ -308,6 +308,8 @@ export class AppPeersManager {
}
}
export type IsPeerType = 'isChannel' | 'isMegagroup' | 'isAnyGroup' | 'isBroadcast' | 'isBot' | 'isContact' | 'isUser' | 'isAnyChat';
[
'isChannel',
'isMegagroup',

2
src/lib/appManagers/appUsersManager.ts

@ -515,7 +515,7 @@ export class AppUsersManager { @@ -515,7 +515,7 @@ export class AppUsersManager {
return 0;
}
public getUser(id: any) {
public getUser(id: User | UserId) {
if(isObject<User>(id)) {
return id;
}

Loading…
Cancel
Save