Skip to content

Commit

Permalink
feat(llc): added user blocking (#2033)
Browse files Browse the repository at this point in the history
Co-authored-by: Sahil Kumar <sahil@getstream.io>
  • Loading branch information
deven98 and xsahil03x authored Oct 22, 2024
1 parent 7373a49 commit ac87693
Show file tree
Hide file tree
Showing 27 changed files with 1,087 additions and 426 deletions.
5 changes: 5 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Upcoming

✅ Added
- Added user blocking to the client.

## 8.1.0

✅ Added
Expand Down
12 changes: 12 additions & 0 deletions packages/stream_chat/lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,18 @@ class StreamChatClient {
Future<EmptyResponse> unmuteUser(String userId) =>
_chatApi.moderation.unmuteUser(userId);

/// Blocks a user
Future<UserBlockResponse> blockUser(String userId) =>
_chatApi.user.blockUser(userId);

/// Unblocks a user
Future<EmptyResponse> unblockUser(String userId) =>
_chatApi.user.unblockUser(userId);

/// Requests users with a given query.
Future<BlockedUsersResponse> queryBlockedUsers() =>
_chatApi.user.queryBlockedUsers();

/// Flag a message
Future<EmptyResponse> flagMessage(String messageId) =>
_chatApi.moderation.flagMessage(messageId);
Expand Down
6 changes: 3 additions & 3 deletions packages/stream_chat/lib/src/core/api/requests.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions packages/stream_chat/lib/src/core/api/responses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:stream_chat/src/core/models/message.dart';
import 'package:stream_chat/src/core/models/reaction.dart';
import 'package:stream_chat/src/core/models/read.dart';
import 'package:stream_chat/src/core/models/user.dart';
import 'package:stream_chat/src/core/models/user_block.dart';

part 'responses.g.dart';

Expand Down Expand Up @@ -530,3 +531,34 @@ class CreateCallPayload extends _BaseResponse {
/// The call object.
CallPayload? call;
}

/// Contains information about a [User] that was banned from a [Channel] or App.
@JsonSerializable()
class UserBlockResponse extends _BaseResponse {
/// User that banned the [user].
@JsonKey(defaultValue: '')
late String blockedByUserId;

/// Reason for the ban.
@JsonKey(defaultValue: '')
late String blockedUserId;

/// Timestamp when the [user] was banned.
late DateTime createdAt;

/// Create a new instance from a json
static UserBlockResponse fromJson(Map<String, dynamic> json) =>
_$UserBlockResponseFromJson(json);
}

/// Model response for [StreamChatClient.queryBlockedUsers] api call
@JsonSerializable(createToJson: false)
class BlockedUsersResponse extends _BaseResponse {
/// Updated users
@JsonKey(defaultValue: [])
late List<UserBlock> blocks;

/// Create a new instance from a json
static BlockedUsersResponse fromJson(Map<String, dynamic> json) =>
_$BlockedUsersResponseFromJson(json);
}
32 changes: 28 additions & 4 deletions packages/stream_chat/lib/src/core/api/responses.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions packages/stream_chat/lib/src/core/api/user_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,32 @@ class UserApi {
);
return UpdateUsersResponse.fromJson(response.data);
}

/// Blocks a user
Future<UserBlockResponse> blockUser(String userId) async {
final response = await _client.post(
'/users/block',
data: {'blocked_user_id': userId},
);

return UserBlockResponse.fromJson(response.data);
}

/// Unblocks a user
Future<EmptyResponse> unblockUser(String userId) async {
final response = await _client.post(
'/users/unblock',
data: {'blocked_user_id': userId},
);
return EmptyResponse.fromJson(response.data);
}

/// Requests blocked users.
Future<BlockedUsersResponse> queryBlockedUsers() async {
final response = await _client.get(
'/users/block',
);

return BlockedUsersResponse.fromJson(response.data);
}
}
4 changes: 2 additions & 2 deletions packages/stream_chat/lib/src/core/models/attachment.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ac87693

Please sign in to comment.