Do not allow send to announcement only groups

This commit is contained in:
Josh Perez 2022-10-05 15:43:37 -04:00 committed by GitHub
parent 5219cdf2c9
commit b0203e8909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 5 deletions

View File

@ -1915,6 +1915,10 @@
"message": "No contacts found",
"description": "Label shown when there are no contacts to compose to"
},
"noGroupsFound": {
"message": "No groups found",
"description": "Label shown when there are no groups to compose to"
},
"noConversationsFound": {
"message": "No conversations found",
"description": "Label shown when there are no conversations to compose to"
@ -5623,6 +5627,10 @@
"message": "Remove story? This will remove the story from your list, but you will still be able to view stories from this group.",
"description": "Confirmation body for removing a group story"
},
"SendStoryModal__announcements-only": {
"message": "Only admins can send stories to this group.",
"description": "Alert body for groups that non-admins cannot send stories to"
},
"Stories__settings-toggle--title": {
"message": "Share & View Stories",
"description": "Select box title for the stories on/off toggle"

View File

@ -5,30 +5,34 @@ import type { FunctionComponent, ReactNode } from 'react';
import React from 'react';
import type { LocalizerType } from '../types/Util';
import type { Theme } from '../util/theme';
import { Button } from './Button';
import { Modal } from './Modal';
type PropsType = {
title?: string;
body: ReactNode;
i18n: LocalizerType;
onClose: () => void;
theme?: Theme;
title?: string;
};
export const Alert: FunctionComponent<PropsType> = ({
body,
i18n,
onClose,
theme,
title,
}) => (
<Modal
modalName="Alert"
i18n={i18n}
onClose={onClose}
title={title}
modalFooter={
<Button onClick={onClose}>{i18n('Confirmation--confirm')}</Button>
}
modalName="Alert"
onClose={onClose}
theme={theme}
title={title}
>
{body}
</Modal>

View File

@ -13,6 +13,7 @@ import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
import type { PropsType as StoriesSettingsModalPropsType } from './StoriesSettingsModal';
import type { StoryDistributionListWithMembersDataType } from '../types/Stories';
import type { UUIDStringType } from '../types/UUID';
import { Alert } from './Alert';
import { Avatar, AvatarSize } from './Avatar';
import { Button, ButtonVariant } from './Button';
import { Checkbox } from './Checkbox';
@ -199,6 +200,8 @@ export const SendStoryModal = ({
Array<ConversationType>
>([]);
const [hasAnnouncementsOnlyAlert, setHasAnnouncementsOnlyAlert] =
useState(false);
const [confirmRemoveGroupId, setConfirmRemoveGroupId] = useState<
string | undefined
>();
@ -481,6 +484,11 @@ export const SendStoryModal = ({
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
if (group.announcementsOnly && !group.areWeAdmin) {
setHasAnnouncementsOnlyAlert(true);
return;
}
setChosenGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
@ -531,7 +539,7 @@ export const SendStoryModal = ({
))
) : (
<div className="module-ForwardMessageModal__no-candidate-contacts">
{i18n('noContactsFound')}
{i18n('noGroupsFound')}
</div>
)}
</ModalPage>
@ -708,6 +716,11 @@ export const SendStoryModal = ({
return;
}
if (group.announcementsOnly && !group.areWeAdmin) {
setHasAnnouncementsOnlyAlert(true);
return;
}
setSelectedGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
@ -788,6 +801,14 @@ export const SendStoryModal = ({
>
{modal}
</PagedModal>
{hasAnnouncementsOnlyAlert && (
<Alert
body={i18n('SendStoryModal__announcements-only')}
i18n={i18n}
onClose={() => setHasAnnouncementsOnlyAlert(false)}
theme={Theme.Dark}
/>
)}
{confirmRemoveGroupId && (
<ConfirmationDialog
dialogName="SendStoryModal.confirmRemoveGroupId"

View File

@ -190,6 +190,14 @@ export async function sendStoryMessage(
return;
}
if (group.get('announcementsOnly') && !group.areWeAdmin()) {
log.warn(
'stories.sendStoryMessage: cannot send to an announcement only group as a non-admin',
conversationId
);
return;
}
const groupTimestamp = timestamp + index;
const myId = window.ConversationController.getOurConversationIdOrThrow();