Skip to content

Commit 667260a

Browse files
authored
fix: non-admin user group add/remove permissions (#1079)
1 parent 3e8325f commit 667260a

21 files changed

+75
-74
lines changed

examples/SampleApp/src/components/ChatScreenHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useContext } from 'react';
1+
import React from 'react';
22
import { Image, StyleSheet, TouchableOpacity } from 'react-native';
33
import { CompositeNavigationProp, useNavigation } from '@react-navigation/native';
44
import { useChatContext, useTheme } from 'stream-chat-react-native';
55

66
import { RoundButton } from './RoundButton';
77
import { ScreenHeader } from './ScreenHeader';
88

9-
import { AppContext } from '../context/AppContext';
9+
import { useAppContext } from '../context/AppContext';
1010
import { NewDirectMessageIcon } from '../icons/NewDirectMessageIcon';
1111

1212
import type { DrawerNavigationProp } from '@react-navigation/drawer';
@@ -36,7 +36,7 @@ export const ChatScreenHeader: React.FC<{ title?: string }> = ({ title = 'Stream
3636
} = useTheme();
3737

3838
const navigation = useNavigation<ChatScreenHeaderNavigationProp>();
39-
const { chatClient } = useContext(AppContext);
39+
const { chatClient } = useAppContext();
4040
const { isOnline } = useChatContext();
4141

4242
return (

examples/SampleApp/src/components/UnreadCountBadge.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { useContext, useEffect, useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
33
import { isOwnUser } from 'stream-chat';
44
import { useTheme } from 'stream-chat-react-native';
55

6-
import { AppContext } from '../context/AppContext';
6+
import { useAppContext } from '../context/AppContext';
77

88
const styles = StyleSheet.create({
99
unreadContainer: {
@@ -27,7 +27,7 @@ export const UnreadCountBadge: React.FC = () => {
2727
},
2828
} = useTheme();
2929

30-
const { chatClient } = useContext(AppContext);
30+
const { chatClient } = useAppContext();
3131
const [count, setCount] = useState<number>();
3232

3333
useEffect(() => {

examples/SampleApp/src/components/UserInfoOverlay.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ import type {
4444
LocalReactionType,
4545
LocalUserType,
4646
} from '../types';
47+
import { useAppContext } from '../context/AppContext';
48+
import { UserResponse } from 'stream-chat';
4749

4850
dayjs.extend(relativeTime);
4951

5052
const avatarSize = 64;
5153

52-
const permissions = ['admin', 'moderator'];
53-
5454
const styles = StyleSheet.create({
5555
avatarPresenceIndicator: {
5656
right: 5,
@@ -114,7 +114,7 @@ export type UserInfoOverlayProps = {
114114

115115
export const UserInfoOverlay = (props: UserInfoOverlayProps) => {
116116
const { overlayOpacity, visible } = props;
117-
117+
const { chatClient } = useAppContext();
118118
const { overlay, setOverlay } = useAppOverlayContext();
119119
const { client } = useChatContext<
120120
LocalAttachmentType,
@@ -242,13 +242,10 @@ export const UserInfoOverlay = (props: UserInfoOverlayProps) => {
242242
return null;
243243
}
244244

245-
const memberModifiable = permissions.every(
246-
(permission) => (member.role || '').toLowerCase() !== permission,
247-
);
248-
const modifyingPermissions =
249-
(permissions.some((permission) => (self.role || '').toLowerCase() === permission) &&
250-
memberModifiable) ||
251-
memberModifiable;
245+
if (!channel) return null;
246+
247+
const channelCreatorId =
248+
channel.data && (channel.data.created_by_id || (channel.data.created_by as UserResponse)?.id);
252249

253250
return (
254251
<Animated.View pointerEvents={visible ? 'auto' : 'none'} style={StyleSheet.absoluteFill}>
@@ -388,7 +385,7 @@ export const UserInfoOverlay = (props: UserInfoOverlayProps) => {
388385
<Text style={[styles.rowText, { color: black }]}>Message</Text>
389386
</View>
390387
</TapGestureHandler>
391-
{modifyingPermissions ? (
388+
{channelCreatorId === chatClient?.user?.id ? (
392389
<TapGestureHandler
393390
onHandlerStateChange={({ nativeEvent: { state } }) => {
394391
if (state === State.END) {

examples/SampleApp/src/context/AppContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ type AppContextType = {
2929
};
3030

3131
export const AppContext = React.createContext({} as AppContextType);
32+
33+
export const useAppContext = () => React.useContext(AppContext);

examples/SampleApp/src/hooks/useChannelMembersStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useContext, useEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22

3-
import { AppContext } from '../context/AppContext';
3+
import { useAppContext } from '../context/AppContext';
44
import { getUserActivityStatus } from '../utils/getUserActivityStatus';
55

66
import type { Channel } from 'stream-chat';
@@ -50,7 +50,7 @@ export const useChannelMembersStatus = (
5050
};
5151

5252
const [status, setStatus] = useState(getStatus());
53-
const { chatClient } = useContext(AppContext);
53+
const { chatClient } = useAppContext();
5454

5555
useEffect(() => {
5656
setStatus(getStatus());

examples/SampleApp/src/hooks/usePaginatedAttachments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useContext, useEffect, useRef, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

3-
import { AppContext } from '../context/AppContext';
3+
import { useAppContext } from '../context/AppContext';
44

55
import type { Channel, MessageResponse } from 'stream-chat';
66

@@ -26,7 +26,7 @@ export const usePaginatedAttachments = (
2626
>,
2727
attachmentType: string,
2828
) => {
29-
const { chatClient } = useContext(AppContext);
29+
const { chatClient } = useAppContext();
3030
const offset = useRef(0);
3131
const hasMoreResults = useRef(true);
3232
const queryInProgress = useRef(false);

examples/SampleApp/src/hooks/usePaginatedPinnedMessages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useContext, useEffect, useRef, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

3-
import { AppContext } from '../context/AppContext';
3+
import { useAppContext } from '../context/AppContext';
44

55
import type { Channel, MessageResponse } from 'stream-chat';
66

@@ -26,7 +26,7 @@ export const usePaginatedPinnedMessages = (
2626
LocalUserType
2727
>,
2828
) => {
29-
const { chatClient } = useContext(AppContext);
29+
const { chatClient } = useAppContext();
3030
const offset = useRef(0);
3131
const hasMoreResults = useRef(true);
3232
const queryInProgress = useRef(false);

examples/SampleApp/src/hooks/usePaginatedSearchedMessages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useContext, useEffect, useRef, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

3-
import { AppContext } from '../context/AppContext';
3+
import { useAppContext } from '../context/AppContext';
44

55
import type { MessageFilters, MessageResponse } from 'stream-chat';
66

@@ -43,7 +43,7 @@ export const usePaginatedSearchedMessages = (
4343
const offset = useRef(0);
4444
const hasMoreResults = useRef(true);
4545
const queryInProgress = useRef(false);
46-
const { chatClient } = useContext(AppContext);
46+
const { chatClient } = useAppContext();
4747

4848
const done = () => {
4949
queryInProgress.current = false;

examples/SampleApp/src/hooks/usePaginatedUsers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useContext, useEffect, useRef, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

3-
import { AppContext } from '../context/AppContext';
3+
import { useAppContext } from '../context/AppContext';
44

55
import type { UserFilters, UserResponse } from 'stream-chat';
66

@@ -27,7 +27,7 @@ export type PaginatedUsers = {
2727
};
2828

2929
export const usePaginatedUsers = (): PaginatedUsers => {
30-
const { chatClient } = useContext(AppContext);
30+
const { chatClient } = useAppContext();
3131

3232
const [initialResults, setInitialResults] = useState<UserResponse<LocalUserType>[] | null>(null);
3333
const [loading, setLoading] = useState(true);

examples/SampleApp/src/screens/AdvancedUserSelectorScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { useContext, useState } from 'react';
1+
import React, { useState } from 'react';
22
import { Alert, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44
import { KeyboardCompatibleView, useTheme, version } from 'stream-chat-react-native';
55

66
import { ScreenHeader } from '../components/ScreenHeader';
7-
import { AppContext } from '../context/AppContext';
7+
import { useAppContext } from '../context/AppContext';
88

99
const styles = StyleSheet.create({
1010
bottomContainer: {
@@ -143,7 +143,7 @@ export const AdvancedUserSelectorScreen: React.FC = () => {
143143
},
144144
} = useTheme();
145145

146-
const { loginUser } = useContext(AppContext);
146+
const { loginUser } = useAppContext();
147147
const [apiKey, setApiKey] = useState('');
148148
const [apiKeyError, setApiKeyError] = useState(false);
149149
const [userId, setUserId] = useState('');

0 commit comments

Comments
 (0)