Skip to content

Commit 1b32694

Browse files
committed
fix: only allow poll creation when capability is there
1 parent a6a7ef7 commit 1b32694

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

package/src/components/AttachmentPicker/components/AttachmentPickerSelectionBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { StyleSheet, TouchableOpacity, View } from 'react-native';
33

4-
import { useChannelContext } from '../../../contexts';
4+
import { useChannelContext, useOwnCapabilitiesContext } from '../../../contexts';
55
import { useAttachmentPickerContext } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
66
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
77
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
@@ -38,7 +38,8 @@ export const AttachmentPickerSelectionBar = () => {
3838
sendMessage,
3939
takeAndUploadImage,
4040
} = useMessageInputContext();
41-
const { threadList } = useChannelContext();
41+
const { hasCreatePoll, threadList } = useChannelContext();
42+
const ownCapabilities = useOwnCapabilitiesContext();
4243

4344
const {
4445
theme: {
@@ -109,7 +110,7 @@ export const AttachmentPickerSelectionBar = () => {
109110
</View>
110111
</TouchableOpacity>
111112
) : null}
112-
{!threadList ? ( // do not allow poll creation in threads
113+
{!threadList && hasCreatePoll && ownCapabilities.sendPoll ? ( // do not allow poll creation in threads
113114
<TouchableOpacity
114115
hitSlop={{ bottom: 15, top: 15 }}
115116
onPress={openPollCreationModal}

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export type ChannelPropsWithContext<
233233
| 'Poll'
234234
| 'PollButtons'
235235
| 'PollHeader'
236+
| 'hasCreatePoll'
236237
>
237238
> &
238239
Pick<ChatContextValue<StreamChatGenerics>, 'client' | 'enableOfflineSupport'> &
@@ -505,6 +506,7 @@ const ChannelWithContext = <
505506
hasCameraPicker = isImagePickerAvailable(),
506507
// If pickDocument isn't available, default to hiding the file picker
507508
hasCommands = true,
509+
hasCreatePoll,
508510
hasFilePicker = pickDocument !== null,
509511
hasImagePicker = true,
510512
hideDateSeparators = false,
@@ -2238,6 +2240,7 @@ const ChannelWithContext = <
22382240
giphyEnabled:
22392241
giphyEnabled ??
22402242
!!(clientChannelConfig?.commands || [])?.some((command) => command.name === 'giphy'),
2243+
hasCreatePoll: hasCreatePoll === undefined ? true : hasCreatePoll,
22412244
hideDateSeparators,
22422245
hideStickyDateHeader,
22432246
isAdmin,

package/src/components/Channel/hooks/useCreateChannelContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const useCreateChannelContext = <
1313
enforceUniqueReaction,
1414
error,
1515
giphyEnabled,
16+
hasCreatePoll,
1617
hideDateSeparators,
1718
hideStickyDateHeader,
1819
isAdmin,
@@ -60,6 +61,7 @@ export const useCreateChannelContext = <
6061
enforceUniqueReaction,
6162
error,
6263
giphyEnabled,
64+
hasCreatePoll,
6365
hideDateSeparators,
6466
hideStickyDateHeader,
6567
isAdmin,
@@ -104,6 +106,7 @@ export const useCreateChannelContext = <
104106
targetedMessage,
105107
threadList,
106108
watcherCount,
109+
hasCreatePoll,
107110
],
108111
);
109112

package/src/components/MessageInput/components/NativeAttachmentPicker.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useRef } from 'react';
22
import { Animated, Easing, LayoutRectangle, Pressable, StyleSheet } from 'react-native';
33

4-
import { useChannelContext } from '../../../contexts';
4+
import { useChannelContext, useOwnCapabilitiesContext } from '../../../contexts';
55
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
66
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
77

@@ -46,7 +46,8 @@ export const NativeAttachmentPicker = ({
4646
sendMessage,
4747
takeAndUploadImage,
4848
} = useMessageInputContext();
49-
const { threadList } = useChannelContext();
49+
const { hasCreatePoll, threadList } = useChannelContext();
50+
const ownCapabilities = useOwnCapabilitiesContext();
5051

5152
const popupHeight =
5253
// the top padding
@@ -113,17 +114,18 @@ export const NativeAttachmentPicker = ({
113114
};
114115

115116
// do not allow poll creation in threads
116-
const buttons = threadList
117-
? []
118-
: [
119-
{
120-
icon: <CreatePollIcon />,
121-
id: 'Poll',
122-
onPressHandler: () => {
123-
openPollCreationDialog?.({ sendMessage });
117+
const buttons =
118+
threadList && hasCreatePoll && ownCapabilities.sendPoll
119+
? []
120+
: [
121+
{
122+
icon: <CreatePollIcon />,
123+
id: 'Poll',
124+
onPressHandler: () => {
125+
openPollCreationDialog?.({ sendMessage });
126+
},
124127
},
125-
},
126-
];
128+
];
127129

128130
if (hasImagePicker) {
129131
buttons.push({

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type ChannelContextValue<
5555
* When set to false, it will disable giphy command on MessageInput component.
5656
*/
5757
giphyEnabled: boolean;
58+
hasCreatePoll: boolean;
5859
/**
5960
* Hide inline date separators on channel
6061
*/

package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import { isTestEnvironment } from '../utils/isTestEnvironment';
66

77
export const allOwnCapabilities = {
88
banChannelMembers: 'ban-channel-members',
9+
castPollVote: 'cast-poll-vote',
910
deleteAnyMessage: 'delete-any-message',
1011
deleteOwnMessage: 'delete-own-message',
1112
flagMessage: 'flag-message',
1213
pinMessage: 'pin-message',
14+
queryPollVotes: 'query-poll-votes',
1315
quoteMessage: 'quote-message',
1416
readEvents: 'read-events',
1517
sendLinks: 'send-links',
1618
sendMessage: 'send-message',
19+
sendPoll: 'send-poll',
1720
sendReaction: 'send-reaction',
1821
sendReply: 'send-reply',
1922
sendTypingEvents: 'send-typing-events',

0 commit comments

Comments
 (0)