Skip to content

Commit ac87693

Browse files
d3xvnxsahil03x
andauthored
feat(llc): added user blocking (#2033)
Co-authored-by: Sahil Kumar <[email protected]>
1 parent 7373a49 commit ac87693

27 files changed

+1087
-426
lines changed

packages/stream_chat/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Upcoming
2+
3+
✅ Added
4+
- Added user blocking to the client.
5+
16
## 8.1.0
27

38
✅ Added

packages/stream_chat/lib/src/client/client.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,18 @@ class StreamChatClient {
12771277
Future<EmptyResponse> unmuteUser(String userId) =>
12781278
_chatApi.moderation.unmuteUser(userId);
12791279

1280+
/// Blocks a user
1281+
Future<UserBlockResponse> blockUser(String userId) =>
1282+
_chatApi.user.blockUser(userId);
1283+
1284+
/// Unblocks a user
1285+
Future<EmptyResponse> unblockUser(String userId) =>
1286+
_chatApi.user.unblockUser(userId);
1287+
1288+
/// Requests users with a given query.
1289+
Future<BlockedUsersResponse> queryBlockedUsers() =>
1290+
_chatApi.user.queryBlockedUsers();
1291+
12801292
/// Flag a message
12811293
Future<EmptyResponse> flagMessage(String messageId) =>
12821294
_chatApi.moderation.flagMessage(messageId);

packages/stream_chat/lib/src/core/api/requests.g.dart

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_chat/lib/src/core/api/responses.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:stream_chat/src/core/models/message.dart';
1313
import 'package:stream_chat/src/core/models/reaction.dart';
1414
import 'package:stream_chat/src/core/models/read.dart';
1515
import 'package:stream_chat/src/core/models/user.dart';
16+
import 'package:stream_chat/src/core/models/user_block.dart';
1617

1718
part 'responses.g.dart';
1819

@@ -530,3 +531,34 @@ class CreateCallPayload extends _BaseResponse {
530531
/// The call object.
531532
CallPayload? call;
532533
}
534+
535+
/// Contains information about a [User] that was banned from a [Channel] or App.
536+
@JsonSerializable()
537+
class UserBlockResponse extends _BaseResponse {
538+
/// User that banned the [user].
539+
@JsonKey(defaultValue: '')
540+
late String blockedByUserId;
541+
542+
/// Reason for the ban.
543+
@JsonKey(defaultValue: '')
544+
late String blockedUserId;
545+
546+
/// Timestamp when the [user] was banned.
547+
late DateTime createdAt;
548+
549+
/// Create a new instance from a json
550+
static UserBlockResponse fromJson(Map<String, dynamic> json) =>
551+
_$UserBlockResponseFromJson(json);
552+
}
553+
554+
/// Model response for [StreamChatClient.queryBlockedUsers] api call
555+
@JsonSerializable(createToJson: false)
556+
class BlockedUsersResponse extends _BaseResponse {
557+
/// Updated users
558+
@JsonKey(defaultValue: [])
559+
late List<UserBlock> blocks;
560+
561+
/// Create a new instance from a json
562+
static BlockedUsersResponse fromJson(Map<String, dynamic> json) =>
563+
_$BlockedUsersResponseFromJson(json);
564+
}

packages/stream_chat/lib/src/core/api/responses.g.dart

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_chat/lib/src/core/api/user_api.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,32 @@ class UserApi {
5959
);
6060
return UpdateUsersResponse.fromJson(response.data);
6161
}
62+
63+
/// Blocks a user
64+
Future<UserBlockResponse> blockUser(String userId) async {
65+
final response = await _client.post(
66+
'/users/block',
67+
data: {'blocked_user_id': userId},
68+
);
69+
70+
return UserBlockResponse.fromJson(response.data);
71+
}
72+
73+
/// Unblocks a user
74+
Future<EmptyResponse> unblockUser(String userId) async {
75+
final response = await _client.post(
76+
'/users/unblock',
77+
data: {'blocked_user_id': userId},
78+
);
79+
return EmptyResponse.fromJson(response.data);
80+
}
81+
82+
/// Requests blocked users.
83+
Future<BlockedUsersResponse> queryBlockedUsers() async {
84+
final response = await _client.get(
85+
'/users/block',
86+
);
87+
88+
return BlockedUsersResponse.fromJson(response.data);
89+
}
6290
}

packages/stream_chat/lib/src/core/models/attachment.g.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)