Skip to content

Commit b5d59a8

Browse files
authored
Merge pull request #2652 from GetStream/develop
Next Release
2 parents d8d52f5 + 327aeac commit b5d59a8

File tree

63 files changed

+1404
-462
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1404
-462
lines changed

.github/workflows/sample-distribution.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
paths:
1010
- '.github/workflows/sample-distribution.yml'
1111
- 'package/**'
12-
- 'packages/examples/SampleApp/**'
12+
- 'examples/SampleApp/**'
1313

1414
jobs:
1515
build_and_deploy_ios_testflight_qa:
36.7 KB
Loading
689 KB
Loading
572 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Function called when the _Ban User_ action is invoked from message actions list.
2+
This function does not override the default behavior of the _Ban User_ action.
3+
Please refer to [the guide on customizing message actions](../../../../guides/custom-message-actions.mdx) for details.
4+
5+
| Type |
6+
| -------- |
7+
| function |
8+
9+
| Parameter | Description |
10+
| --------- | ------------------------------- |
11+
| message | message the action is called on |
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
:::note
2+
This is deprecated. Please use `handleBan` instead.
3+
:::
4+
15
Function called when the _Block User_ action is invoked from message actions list.
26
This function does not override the default behavior of the _Block User_ action.
37
Please refer to [the guide on customizing message actions](../../../../guides/custom-message-actions.mdx) for details.
48

5-
| Type |
6-
| -------- |
7-
| function |
8-
9+
| Type |
10+
| --------- | ------------------------------- |
11+
| function |
912
| Parameter | Description |
1013
| --------- | ------------------------------- |
1114
| message | message the action is called on |

docusaurus/docs/reactnative/contexts/messages-context.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import FormatDate from '../common-content/ui-components/channel/props/format_dat
2525
import Gallery from '../common-content/ui-components/channel/props/gallery.mdx';
2626
import Giphy from '../common-content/ui-components/channel/props/giphy.mdx';
2727
import GiphyVersion from '../common-content/ui-components/channel/props/giphy_version.mdx';
28+
import HandleBan from '../common-content/ui-components/channel/props/handle_ban.mdx';
2829
import HandleBlock from '../common-content/ui-components/channel/props/handle_block.mdx';
2930
import HandleCopy from '../common-content/ui-components/channel/props/handle_copy.mdx';
3031
import HandleDelete from '../common-content/ui-components/channel/props/handle_delete.mdx';
@@ -110,6 +111,10 @@ Id of current channel.
110111

111112
<FormatDate />
112113

114+
### <div class="label description">_forwarded from [Channel](../../core-components/channel#handleban)_ props</div> `handleBan` {#handleban}
115+
116+
<HandleBan />
117+
113118
### <div class="label description">_forwarded from [Channel](../../core-components/channel#handleblock)_ props</div> `handleBlock` {#handleblock}
114119

115120
<HandleBlock />

docusaurus/docs/reactnative/core-components/channel.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import Giphy from '../common-content/ui-components/channel/props/giphy.mdx';
6464
import GiphyEnabled from '../common-content/ui-components/channel/props/giphy_enabled.mdx';
6565
import GiphyVersion from '../common-content/ui-components/channel/props/giphy_version.mdx';
6666
import HandleAttachButtonPress from '../common-content/ui-components/channel/props/handle_attach_button_press.mdx';
67+
import HandleBan from '../common-content/ui-components/channel/props/handle_ban.mdx';
6768
import HandleBlock from '../common-content/ui-components/channel/props/handle_block.mdx';
6869
import HandleCopy from '../common-content/ui-components/channel/props/handle_copy.mdx';
6970
import HandleDelete from '../common-content/ui-components/channel/props/handle_delete.mdx';
@@ -486,6 +487,10 @@ The max allowable is 255, which when reached displays as `255+`.
486487

487488
<HandleAttachButtonPress />
488489

490+
### `handleBan`
491+
492+
<HandleBan />
493+
489494
### `handleBlock`
490495

491496
<HandleBlock />
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
id: blocking-users
3+
title: Blocking Users
4+
---
5+
6+
## Introduction
7+
8+
Blocking users is an essential feature in a chat app because it enhances user safety and experience. It allows individuals to protect themselves from harassment, spam, and unwanted interactions. By giving users control over their interactions, it helps maintain privacy, reduces the risk of cyberbullying, and promotes a respectful community atmosphere.
9+
10+
As a result, some app stores require this functionality as part of their review process.
11+
12+
## Stream Chat
13+
14+
The Stream Chat SDK provides a way for blocking and unblocking users, as well as listing all of the blocked users.
15+
16+
When you block a user, you won’t receive any direct messages from that user anymore. However, if you share a group with other participants, you will still receive messages from the blocked user.
17+
18+
In this cookbook, we will see how to implement this feature in your chat apps, using the Stream Chat SDK.
19+
20+
## Low Level Client support
21+
22+
The low-level client provides the following methods related to user blocking.
23+
24+
### Blocking a user
25+
26+
In order to block a user, you need to use the `blockUser` method of the client instance. This method takes the user id of the user you wish to block.
27+
28+
```tsx
29+
import { StreamChat } from 'stream-chat';
30+
const chatClient = StreamChat.getInstance('your api key');
31+
32+
// Note this has to be done after the client connection(`client.connectUser`) is established.
33+
const blockUser = async (userId: string) => {
34+
try {
35+
await chatClient.blockUser(userId);
36+
} catch (err) {
37+
console.log('Error blocking user:', err);
38+
}
39+
};
40+
```
41+
42+
### Unblocking a user
43+
44+
Similarly, to unblock a blocked user, you need to use the `unBlockUser` method of the client instance. This method takes the user id of the user you wish to unblock.
45+
46+
```tsx
47+
import { StreamChat } from 'stream-chat';
48+
const chatClient = StreamChat.getInstance('your api key');
49+
50+
// Note this has to be done after the client connection(`client.connectUser`) is established.
51+
const unBlockUser = async (userId: string) => {
52+
try {
53+
await chatClient.unBlockUser(userId);
54+
} catch (err) {
55+
console.log('Error UnBlocking user:', err);
56+
}
57+
};
58+
```
59+
60+
### Listing Blocked Users
61+
62+
To list all the blocked users, you can use the `getBlockedUsers` method of the client instance.
63+
64+
```tsx
65+
const chatClient = StreamChat.getInstance('your api key');
66+
67+
// Note this has to be done after the client connection(`client.connectUser`) is established.
68+
const getBlockedUsers = async () => {
69+
try {
70+
const users = await chatClient.getBlockedUsers();
71+
setBlockedUsers(users.blocks);
72+
} catch (error) {
73+
console.log('Error getting blocked users:', error);
74+
}
75+
};
76+
```
77+
78+
## Message Actions
79+
80+
You can use the logic above to create your own custom message actions that will involve user blocking.
81+
82+
This can be done by using the `messageActions` prop of the `Channel` component. You can follow the guide [here](../guides/custom-message-actions.mdx).
83+
84+
```tsx
85+
import { Channel, messageActions } from 'stream-chat-react-native';
86+
87+
const App = () => {
88+
return (
89+
<Channel
90+
channel={channel}
91+
messageActions={params => {
92+
const { dismissOverlay, message } = params;
93+
const actions = messageActions({ ...params });
94+
if (actions) {
95+
actions.push({
96+
action: async () => {
97+
try {
98+
await chatClient.blockUser(message.user?.id || '');
99+
dismissOverlay();
100+
} catch (error) {
101+
console.log('Error blocking user:', error);
102+
}
103+
},
104+
actionType: 'block-user',
105+
title: 'Block User',
106+
});
107+
return actions;
108+
} else {
109+
return [];
110+
}
111+
}}
112+
>
113+
{/* Other components here */}
114+
</Channel>
115+
);
116+
};
117+
```
118+
119+
## Displaying Blocked users
120+
121+
Next, let’s see how we can build a custom UI that will show the list of blocked users. This will allow easier overview for the users about who they blocked, as well as provide an easy way to unblock them if needed.
122+
123+
![Blocked Users](../assets/guides/blocking-users/blocked-users-list.png)
124+
125+
```tsx
126+
import { useEffect, useState } from 'react';
127+
import { Image, StyleSheet, Text, View } from 'react-native';
128+
import { BlockedUserDetails, StreamChat } from 'stream-chat';
129+
130+
const chatClient = StreamChat.getInstance('your api key');
131+
132+
const BlockedUsers = () => {
133+
const [blockedUsers, setBlockedUsers] = useState<BlockedUserDetails[]>([]);
134+
135+
useEffect(() => {
136+
const getBlockedUsers = async () => {
137+
try {
138+
const users = await chatClient.getBlockedUsers();
139+
setBlockedUsers(users.blocks);
140+
} catch (error) {
141+
console.log('Error getting blocked users:', error);
142+
}
143+
};
144+
145+
getBlockedUsers();
146+
}, []);
147+
148+
const unBlockUser = async (userId: string) => {
149+
try {
150+
await chatClient.unBlockUser(userId);
151+
const filteredUsers = blockedUsers.filter(user => user.blocked_user_id !== userId);
152+
setBlockedUsers(filteredUsers);
153+
} catch (err) {
154+
console.log('Error UnBlocking user:', err);
155+
}
156+
};
157+
158+
return (
159+
<View>
160+
{blockedUsers.map((blockedUser: BlockedUserDetails) => (
161+
<Pressable
162+
key={blockedUser.blocked_user_id}
163+
onPress={() => {
164+
unBlockUser(blockedUser.blocked_user_id);
165+
}}
166+
style={styles.container}
167+
>
168+
<Image source={{ uri: blockedUser.blocked_user.image as string }} style={styles.image} />
169+
<Text style={styles.name}>{blockedUser.blocked_user.name}</Text>
170+
</Pressable>
171+
))}
172+
</View>
173+
);
174+
};
175+
176+
const styles = StyleSheet.create({
177+
container: {
178+
flexDirection: 'row',
179+
padding: 16,
180+
alignItems: 'center',
181+
},
182+
image: {
183+
height: 80,
184+
width: 80,
185+
borderRadius: 40,
186+
},
187+
name: {
188+
fontSize: 16,
189+
fontWeight: 'bold',
190+
marginLeft: 16,
191+
},
192+
});
193+
```
194+
195+
There’s nothing special in this view, it just shows the blocked users in a list, and exposes a delete action, which will remove the blocked user from the list.
196+
197+
## Summary
198+
199+
In this cookbook we have seen the capabilities of the Stream Chat SDK for blocking users. We have also seen how to add message actions to block and unblock users, as well as a custom UI for displaying the blocked users.
200+
201+
It is recommended to use these actions, in order to avoid issues during app store reviews, especially on the Apple platforms.

docusaurus/docs/reactnative/guides/custom-message-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ These functions will be called right before the underlying default handlers.
390390
Please note that these intercepts will neither change the standard functions nor block them.
391391
:::
392392
393-
- `handleBlock`
393+
- `handleBan`
394+
- `handleBlock`(deprecated)
394395
- `handleCopy`
395396
- `handleDelete`
396397
- `handleEdit`

0 commit comments

Comments
 (0)