2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../../../state/ducks/conversations';
|
|
|
|
import type { LocalizerType } from '../../../types/Util';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { getAccessControlOptions } from '../../../util/getAccessControlOptions';
|
2021-07-20 20:18:35 +00:00
|
|
|
import { SignalService as Proto } from '../../../protobuf';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { PanelRow } from './PanelRow';
|
|
|
|
import { PanelSection } from './PanelSection';
|
2021-06-03 22:12:23 +00:00
|
|
|
import { Select } from '../../Select';
|
2022-04-07 21:40:57 +00:00
|
|
|
import { useUniqueId } from '../../../hooks/useUniqueId';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
export type PropsDataType = {
|
2021-01-29 21:19:24 +00:00
|
|
|
conversation?: ConversationType;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
};
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
type PropsActionType = {
|
|
|
|
setAccessControlAttributesSetting: (id: string, value: number) => void;
|
|
|
|
setAccessControlMembersSetting: (id: string, value: number) => void;
|
|
|
|
setAnnouncementsOnly: (id: string, value: boolean) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsType = PropsDataType & PropsActionType;
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function GroupV2Permissions({
|
2021-01-29 21:19:24 +00:00
|
|
|
conversation,
|
|
|
|
i18n,
|
|
|
|
setAccessControlAttributesSetting,
|
|
|
|
setAccessControlMembersSetting,
|
2021-07-20 20:18:35 +00:00
|
|
|
setAnnouncementsOnly,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2022-04-07 21:40:57 +00:00
|
|
|
const addMembersSelectId = useUniqueId();
|
|
|
|
const groupInfoSelectId = useUniqueId();
|
|
|
|
const announcementSelectId = useUniqueId();
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
if (conversation === undefined) {
|
|
|
|
throw new Error('GroupV2Permissions rendered without a conversation');
|
|
|
|
}
|
|
|
|
|
2021-06-03 22:12:23 +00:00
|
|
|
const updateAccessControlAttributes = (value: string) => {
|
2022-12-05 22:56:23 +00:00
|
|
|
setAccessControlAttributesSetting(conversation.id, Number(value));
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
2021-06-03 22:12:23 +00:00
|
|
|
const updateAccessControlMembers = (value: string) => {
|
2022-12-05 22:56:23 +00:00
|
|
|
setAccessControlMembersSetting(conversation.id, Number(value));
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
2021-07-20 20:18:35 +00:00
|
|
|
const AccessControlEnum = Proto.AccessControl.AccessRequired;
|
|
|
|
const updateAnnouncementsOnly = (value: string) => {
|
2022-12-05 22:56:23 +00:00
|
|
|
setAnnouncementsOnly(
|
|
|
|
conversation.id,
|
|
|
|
Number(value) === AccessControlEnum.ADMINISTRATOR
|
|
|
|
);
|
2021-07-20 20:18:35 +00:00
|
|
|
};
|
2021-07-09 19:36:10 +00:00
|
|
|
const accessControlOptions = getAccessControlOptions(i18n);
|
2021-07-20 20:18:35 +00:00
|
|
|
const announcementsOnlyValue = String(
|
|
|
|
conversation.announcementsOnly
|
|
|
|
? AccessControlEnum.ADMINISTRATOR
|
|
|
|
: AccessControlEnum.MEMBER
|
|
|
|
);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-08-05 17:23:50 +00:00
|
|
|
const showAnnouncementsOnlyPermission =
|
|
|
|
conversation.areWeAdmin &&
|
|
|
|
(conversation.announcementsOnly || conversation.announcementsOnlyReady);
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
return (
|
|
|
|
<PanelSection>
|
|
|
|
<PanelRow
|
2022-04-07 21:40:57 +00:00
|
|
|
label={
|
|
|
|
<label htmlFor={addMembersSelectId}>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:ConversationDetails--add-members-label')}
|
2022-04-07 21:40:57 +00:00
|
|
|
</label>
|
|
|
|
}
|
2023-03-30 00:03:25 +00:00
|
|
|
info={i18n('icu:ConversationDetails--add-members-info')}
|
2021-01-29 21:19:24 +00:00
|
|
|
right={
|
2021-06-03 22:12:23 +00:00
|
|
|
<Select
|
2022-04-07 21:40:57 +00:00
|
|
|
id={addMembersSelectId}
|
2021-06-03 22:12:23 +00:00
|
|
|
onChange={updateAccessControlMembers}
|
|
|
|
options={accessControlOptions}
|
|
|
|
value={String(conversation.accessControlMembers)}
|
|
|
|
/>
|
2021-01-29 21:19:24 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<PanelRow
|
2022-04-07 21:40:57 +00:00
|
|
|
label={
|
|
|
|
<label htmlFor={groupInfoSelectId}>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:ConversationDetails--group-info-label')}
|
2022-04-07 21:40:57 +00:00
|
|
|
</label>
|
|
|
|
}
|
2023-03-30 00:03:25 +00:00
|
|
|
info={i18n('icu:ConversationDetails--group-info-info')}
|
2021-01-29 21:19:24 +00:00
|
|
|
right={
|
2021-06-03 22:12:23 +00:00
|
|
|
<Select
|
2022-04-07 21:40:57 +00:00
|
|
|
id={groupInfoSelectId}
|
2021-06-03 22:12:23 +00:00
|
|
|
onChange={updateAccessControlAttributes}
|
|
|
|
options={accessControlOptions}
|
|
|
|
value={String(conversation.accessControlAttributes)}
|
|
|
|
/>
|
2021-01-29 21:19:24 +00:00
|
|
|
}
|
|
|
|
/>
|
2021-08-05 17:23:50 +00:00
|
|
|
{showAnnouncementsOnlyPermission && (
|
2021-07-20 20:18:35 +00:00
|
|
|
<PanelRow
|
2022-04-07 21:40:57 +00:00
|
|
|
label={
|
|
|
|
<label htmlFor={announcementSelectId}>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:ConversationDetails--announcement-label')}
|
2022-04-07 21:40:57 +00:00
|
|
|
</label>
|
|
|
|
}
|
2023-03-30 00:03:25 +00:00
|
|
|
info={i18n('icu:ConversationDetails--announcement-info')}
|
2021-07-20 20:18:35 +00:00
|
|
|
right={
|
|
|
|
<Select
|
2022-04-07 21:40:57 +00:00
|
|
|
id={announcementSelectId}
|
2021-07-20 20:18:35 +00:00
|
|
|
onChange={updateAnnouncementsOnly}
|
|
|
|
options={accessControlOptions}
|
|
|
|
value={announcementsOnlyValue}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2021-01-29 21:19:24 +00:00
|
|
|
</PanelSection>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|