mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-02 08:13:37 +01:00
Allow all group members to have labels, no permission required
This commit is contained in:
@@ -26,7 +26,6 @@ import {
|
||||
import { ConversationColors } from '../../../types/Colors.std.js';
|
||||
import { WidthBreakpoint } from '../../_util.std.js';
|
||||
import { AxoAlertDialog } from '../../../axo/AxoAlertDialog.dom.js';
|
||||
import { SignalService as Proto } from '../../../protobuf/index.std.js';
|
||||
import { Avatar, AvatarSize } from '../../Avatar.dom.js';
|
||||
import { UserText } from '../../UserText.dom.js';
|
||||
import { GroupMemberLabel } from '../ContactName.dom.js';
|
||||
@@ -105,8 +104,6 @@ export function GroupMemberLabelEditor({
|
||||
}: PropsType): React.JSX.Element {
|
||||
const [isShowingGeneralError, setIsShowingGeneralError] =
|
||||
React.useState(false);
|
||||
const [isShowingPermissionsError, setIsShowingPermissionsError] =
|
||||
React.useState(false);
|
||||
|
||||
const messageContainer = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
@@ -134,17 +131,6 @@ export function GroupMemberLabelEditor({
|
||||
? { labelEmoji, labelString: labelStringForSave }
|
||||
: undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
!group.areWeAdmin &&
|
||||
group.accessControlAttributes ===
|
||||
Proto.AccessControl.AccessRequired.ADMINISTRATOR &&
|
||||
!isShowingPermissionsError
|
||||
) {
|
||||
setIsShowingPermissionsError(true);
|
||||
}
|
||||
}, [group, isShowingPermissionsError, setIsShowingPermissionsError]);
|
||||
|
||||
const tryClose = React.useRef<() => void | undefined>();
|
||||
const [confirmDiscardModal, confirmDiscardIf] = useConfirmDiscard({
|
||||
i18n,
|
||||
@@ -438,38 +424,6 @@ export function GroupMemberLabelEditor({
|
||||
</AxoAlertDialog.Footer>
|
||||
</AxoAlertDialog.Content>
|
||||
</AxoAlertDialog.Root>
|
||||
<AxoAlertDialog.Root
|
||||
open={isShowingPermissionsError}
|
||||
onOpenChange={value => {
|
||||
if (!value) {
|
||||
setIsShowingPermissionsError(false);
|
||||
popPanelForConversation();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<AxoAlertDialog.Content escape="cancel-is-noop">
|
||||
<AxoAlertDialog.Body>
|
||||
<AxoAlertDialog.Title>
|
||||
{i18n('icu:ConversationDetails--member-label--error-title')}
|
||||
</AxoAlertDialog.Title>
|
||||
<AxoAlertDialog.Description>
|
||||
{i18n('icu:ConversationDetails--member-label--error-permissions')}
|
||||
</AxoAlertDialog.Description>
|
||||
</AxoAlertDialog.Body>
|
||||
<AxoAlertDialog.Footer>
|
||||
<AxoAlertDialog.Action
|
||||
variant="primary"
|
||||
arrow={false}
|
||||
onClick={() => {
|
||||
popPanelForConversation();
|
||||
setIsShowingPermissionsError(false);
|
||||
}}
|
||||
>
|
||||
{i18n('icu:ok')}
|
||||
</AxoAlertDialog.Action>
|
||||
</AxoAlertDialog.Footer>
|
||||
</AxoAlertDialog.Content>
|
||||
</AxoAlertDialog.Root>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { SignalService as Proto } from '../../../protobuf/index.std.js';
|
||||
import { PanelRow } from './PanelRow.dom.js';
|
||||
import { PanelSection } from './PanelSection.dom.js';
|
||||
import { Select } from '../../Select.dom.js';
|
||||
import { AxoAlertDialog } from '../../../axo/AxoAlertDialog.dom.js';
|
||||
|
||||
export type PropsDataType = {
|
||||
conversation?: ConversationType;
|
||||
@@ -32,8 +31,6 @@ export function GroupV2Permissions({
|
||||
}: PropsType): React.JSX.Element {
|
||||
const AccessControlEnum = Proto.AccessControl.AccessRequired;
|
||||
|
||||
const [isWarningAboutClearingLabels, setIsWarningAboutClearingLabels] =
|
||||
React.useState(false);
|
||||
const addMembersSelectId = useId();
|
||||
const groupInfoSelectId = useId();
|
||||
const announcementSelectId = useId();
|
||||
@@ -41,17 +38,8 @@ export function GroupV2Permissions({
|
||||
if (conversation === undefined) {
|
||||
throw new Error('GroupV2Permissions rendered without a conversation');
|
||||
}
|
||||
const nonAdminsHaveLabels = conversation.memberships?.some(
|
||||
membership => !membership.isAdmin && membership.labelString
|
||||
);
|
||||
|
||||
const updateAccessControlAttributes = (value: string) => {
|
||||
const newValue = Number(value);
|
||||
if (newValue === AccessControlEnum.ADMINISTRATOR && nonAdminsHaveLabels) {
|
||||
setIsWarningAboutClearingLabels(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setAccessControlAttributesSetting(conversation.id, Number(value));
|
||||
};
|
||||
const updateAccessControlMembers = (value: string) => {
|
||||
@@ -126,51 +114,6 @@ export function GroupV2Permissions({
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<AxoAlertDialog.Root
|
||||
open={isWarningAboutClearingLabels}
|
||||
onOpenChange={value => {
|
||||
if (!value) {
|
||||
setIsWarningAboutClearingLabels(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<AxoAlertDialog.Content escape="cancel-is-noop">
|
||||
<AxoAlertDialog.Body>
|
||||
<AxoAlertDialog.Title>
|
||||
{i18n('icu:ConversationDetails--label-clear-warning--title')}
|
||||
</AxoAlertDialog.Title>
|
||||
<AxoAlertDialog.Description>
|
||||
{i18n(
|
||||
'icu:ConversationDetails--label-clear-warning--description'
|
||||
)}
|
||||
</AxoAlertDialog.Description>
|
||||
</AxoAlertDialog.Body>
|
||||
<AxoAlertDialog.Footer>
|
||||
<AxoAlertDialog.Action
|
||||
variant="secondary"
|
||||
arrow={false}
|
||||
onClick={() => {
|
||||
setIsWarningAboutClearingLabels(false);
|
||||
}}
|
||||
>
|
||||
{i18n('icu:cancel')}
|
||||
</AxoAlertDialog.Action>
|
||||
<AxoAlertDialog.Action
|
||||
variant="primary"
|
||||
arrow={false}
|
||||
onClick={() => {
|
||||
setAccessControlAttributesSetting(
|
||||
conversation.id,
|
||||
AccessControlEnum.ADMINISTRATOR
|
||||
);
|
||||
setIsWarningAboutClearingLabels(false);
|
||||
}}
|
||||
>
|
||||
{i18n('icu:ConversationDetails--label-clear-warning--continue')}
|
||||
</AxoAlertDialog.Action>
|
||||
</AxoAlertDialog.Footer>
|
||||
</AxoAlertDialog.Content>
|
||||
</AxoAlertDialog.Root>
|
||||
</PanelSection>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -857,9 +857,6 @@ export function buildAccessControlAttributesChange(
|
||||
group: ConversationAttributesType,
|
||||
newValue: AccessRequiredEnum
|
||||
): Proto.GroupChange.Actions {
|
||||
const ACCESS_ENUM = Proto.AccessControl.AccessRequired;
|
||||
const ROLE_ENUM = Proto.Member.Role;
|
||||
|
||||
const accessControlAction =
|
||||
new Proto.GroupChange.Actions.ModifyAttributesAccessControlAction();
|
||||
accessControlAction.attributesAccess = newValue;
|
||||
@@ -874,40 +871,6 @@ export function buildAccessControlAttributesChange(
|
||||
actions.version = (group.revision || 0) + 1;
|
||||
actions.modifyAttributesAccess = accessControlAction;
|
||||
|
||||
// Clear out all non-admin labels
|
||||
const previousValue = group.accessControl?.attributes;
|
||||
if (
|
||||
previousValue !== ACCESS_ENUM.ADMINISTRATOR &&
|
||||
newValue === ACCESS_ENUM.ADMINISTRATOR
|
||||
) {
|
||||
const clientZkGroupCipher = getClientZkGroupCipher(group.secretParams);
|
||||
|
||||
const modifyLabelActions = (group.membersV2 || [])
|
||||
.map(member => {
|
||||
if (member.role === ROLE_ENUM.ADMINISTRATOR) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!member.labelString && !member.labelEmoji) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const modifyLabel =
|
||||
new Proto.GroupChange.Actions.ModifyMemberLabelAction();
|
||||
modifyLabel.userId = encryptServiceId(clientZkGroupCipher, member.aci);
|
||||
|
||||
return modifyLabel;
|
||||
})
|
||||
.filter(isNotNil);
|
||||
|
||||
if (modifyLabelActions.length) {
|
||||
log.info(
|
||||
`buildAccessControlAttributesChange: Found ${modifyLabelActions.length} non-admins with labels. Clearing.`
|
||||
);
|
||||
actions.modifyMemberLabels = modifyLabelActions;
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@@ -1271,25 +1234,6 @@ export function buildModifyMemberRoleChange({
|
||||
actions.version = (group.revision || 0) + 1;
|
||||
actions.modifyMemberRoles = [toggleAdmin];
|
||||
|
||||
const membership = group.membersV2?.find(member => member.aci === serviceId);
|
||||
const onlyAdminsCanChangeAttributes =
|
||||
group.accessControl?.attributes ===
|
||||
Proto.AccessControl.AccessRequired.ADMINISTRATOR;
|
||||
const wasPreviouslyAnAdmin =
|
||||
membership?.role === Proto.Member.Role.ADMINISTRATOR;
|
||||
const nowNotAnAdmin = role !== Proto.Member.Role.ADMINISTRATOR;
|
||||
|
||||
if (
|
||||
membership?.labelString &&
|
||||
onlyAdminsCanChangeAttributes &&
|
||||
wasPreviouslyAnAdmin &&
|
||||
nowNotAnAdmin
|
||||
) {
|
||||
const modifyLabel = new Proto.GroupChange.Actions.ModifyMemberLabelAction();
|
||||
modifyLabel.userId = userIdCipherText;
|
||||
actions.modifyMemberLabels = [modifyLabel];
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import type {
|
||||
ConversationType,
|
||||
MembershipType,
|
||||
} from '../state/ducks/conversations.preload.js';
|
||||
import { SignalService as Proto } from '../protobuf/index.std.js';
|
||||
|
||||
export const missingEmojiPlaceholder = '⍰';
|
||||
|
||||
@@ -26,11 +25,5 @@ export function getCanAddLabel(
|
||||
conversation: ConversationType,
|
||||
membership: MembershipType | undefined
|
||||
): boolean {
|
||||
return Boolean(
|
||||
membership &&
|
||||
conversation.type === 'group' &&
|
||||
(membership.isAdmin ||
|
||||
conversation.accessControlAttributes ===
|
||||
Proto.AccessControl.AccessRequired.MEMBER)
|
||||
);
|
||||
return Boolean(membership && conversation.type === 'group');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user