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", "message": "No contacts found",
"description": "Label shown when there are no contacts to compose to" "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": { "noConversationsFound": {
"message": "No conversations found", "message": "No conversations found",
"description": "Label shown when there are no conversations to compose to" "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.", "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" "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": { "Stories__settings-toggle--title": {
"message": "Share & View Stories", "message": "Share & View Stories",
"description": "Select box title for the stories on/off toggle" "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 React from 'react';
import type { LocalizerType } from '../types/Util'; import type { LocalizerType } from '../types/Util';
import type { Theme } from '../util/theme';
import { Button } from './Button'; import { Button } from './Button';
import { Modal } from './Modal'; import { Modal } from './Modal';
type PropsType = { type PropsType = {
title?: string;
body: ReactNode; body: ReactNode;
i18n: LocalizerType; i18n: LocalizerType;
onClose: () => void; onClose: () => void;
theme?: Theme;
title?: string;
}; };
export const Alert: FunctionComponent<PropsType> = ({ export const Alert: FunctionComponent<PropsType> = ({
body, body,
i18n, i18n,
onClose, onClose,
theme,
title, title,
}) => ( }) => (
<Modal <Modal
modalName="Alert"
i18n={i18n} i18n={i18n}
onClose={onClose}
title={title}
modalFooter={ modalFooter={
<Button onClick={onClose}>{i18n('Confirmation--confirm')}</Button> <Button onClick={onClose}>{i18n('Confirmation--confirm')}</Button>
} }
modalName="Alert"
onClose={onClose}
theme={theme}
title={title}
> >
{body} {body}
</Modal> </Modal>

View File

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

View File

@ -190,6 +190,14 @@ export async function sendStoryMessage(
return; 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 groupTimestamp = timestamp + index;
const myId = window.ConversationController.getOurConversationIdOrThrow(); const myId = window.ConversationController.getOurConversationIdOrThrow();