Merge pull request #762 from GetStream/feat/capabilities
feat(llc, ui): user capabilities
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
✅ Added
|
||||
|
||||
- Added `client.enrichUrl` endpoint for enriching URLs with metadata.
|
||||
- Fixed `unreadCount` after removing user from a channel.
|
||||
- `ChannelModel` now supplies individual user capabilities.
|
||||
|
||||
## 3.3.1
|
||||
|
||||
|
||||
@@ -300,6 +300,18 @@ class Channel {
|
||||
return data;
|
||||
}
|
||||
|
||||
/// List of user permissions on this channel
|
||||
List<String> get ownCapabilities =>
|
||||
state?._channelState.channel?.ownCapabilities ?? [];
|
||||
|
||||
/// List of user permissions on this channel
|
||||
Stream<List<String>> get ownCapabilitiesStream {
|
||||
_checkInitialized();
|
||||
return state!.channelStateStream
|
||||
.map((cs) => cs.channel?.ownCapabilities ?? [])
|
||||
.distinct();
|
||||
}
|
||||
|
||||
/// Channel extra data as a stream.
|
||||
Stream<Map<String, Object?>> get extraDataStream {
|
||||
_checkInitialized();
|
||||
@@ -1548,6 +1560,7 @@ class ChannelClientState {
|
||||
members: List.from(
|
||||
channelState.members..removeWhere((m) => m.userId == user!.id),
|
||||
),
|
||||
read: channelState.read..removeWhere((r) => r.user.id == user!.id),
|
||||
));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class ChannelModel {
|
||||
String? id,
|
||||
String? type,
|
||||
String? cid,
|
||||
this.ownCapabilities = const [],
|
||||
ChannelConfig? config,
|
||||
this.createdBy,
|
||||
this.frozen = false,
|
||||
@@ -51,6 +52,10 @@ class ChannelModel {
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final String cid;
|
||||
|
||||
/// List of user permissions on this channel
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final List<String> ownCapabilities;
|
||||
|
||||
/// The channel configuration data
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final ChannelConfig config;
|
||||
@@ -101,6 +106,7 @@ class ChannelModel {
|
||||
'id',
|
||||
'type',
|
||||
'cid',
|
||||
'own_capabilities',
|
||||
'config',
|
||||
'created_by',
|
||||
'frozen',
|
||||
@@ -127,6 +133,7 @@ class ChannelModel {
|
||||
String? id,
|
||||
String? type,
|
||||
String? cid,
|
||||
List<String>? ownCapabilities,
|
||||
ChannelConfig? config,
|
||||
User? createdBy,
|
||||
bool? frozen,
|
||||
@@ -143,6 +150,7 @@ class ChannelModel {
|
||||
id: id ?? this.id,
|
||||
type: type ?? this.type,
|
||||
cid: cid ?? this.cid,
|
||||
ownCapabilities: ownCapabilities ?? this.ownCapabilities,
|
||||
config: config ?? this.config,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
frozen: frozen ?? this.frozen,
|
||||
@@ -164,6 +172,7 @@ class ChannelModel {
|
||||
id: other.id,
|
||||
type: other.type,
|
||||
cid: other.cid,
|
||||
ownCapabilities: other.ownCapabilities,
|
||||
config: other.config,
|
||||
createdBy: other.createdBy,
|
||||
frozen: other.frozen,
|
||||
|
||||
@@ -10,6 +10,10 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) => ChannelModel(
|
||||
id: json['id'] as String?,
|
||||
type: json['type'] as String?,
|
||||
cid: json['cid'] as String?,
|
||||
ownCapabilities: (json['own_capabilities'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
config: json['config'] == null
|
||||
? null
|
||||
: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
|
||||
@@ -48,6 +52,7 @@ Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) {
|
||||
}
|
||||
|
||||
writeNotNull('cid', readonly(instance.cid));
|
||||
writeNotNull('own_capabilities', readonly(instance.ownCapabilities));
|
||||
writeNotNull('config', readonly(instance.config));
|
||||
writeNotNull('created_by', readonly(instance.createdBy));
|
||||
val['frozen'] = instance.frozen;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/// Describes capabilities of a user vis-a-vis a channel
|
||||
class PermissionType {
|
||||
/// Capability required to send a message in the channel
|
||||
/// Channel is not frozen (or user has UseFrozenChannel permission)
|
||||
/// and user has CreateMessage permission.
|
||||
static const String sendMessage = 'send-message';
|
||||
|
||||
/// Capability required to receive connect events in the channel
|
||||
static const String connectEvents = 'connect-events';
|
||||
|
||||
/// Capability required to send a message
|
||||
/// Reactions are enabled for the channel, channel is not frozen
|
||||
/// (or user has UseFrozenChannel permission) and user has
|
||||
/// CreateReaction permission
|
||||
static const String sendReaction = 'send-reaction';
|
||||
|
||||
/// Capability required to send links in a channel
|
||||
/// send-message + user has AddLinks permission
|
||||
static const String sendLinks = 'send-links';
|
||||
|
||||
/// Capability required to send thread reply
|
||||
/// send-message + channel has replies enabled
|
||||
static const String sendReply = 'send-reply';
|
||||
|
||||
/// Capability to freeze a channel
|
||||
/// User has UpdateChannelFrozen permission.
|
||||
/// The name implies freezing,
|
||||
/// but unfreezing is also allowed when this capability is present
|
||||
static const String freezeChannel = 'freeze-channel';
|
||||
|
||||
/// User has UpdateChannelCooldown permission.
|
||||
/// Allows to enable/disable slow mode in the channel
|
||||
static const String setChannelCooldown = 'set-channel-cooldown';
|
||||
|
||||
/// User has RemoveOwnChannelMembership or UpdateChannelMembers permission
|
||||
static const String leaveChannel = 'leave-channel';
|
||||
|
||||
/// User can mute channel
|
||||
static const String muteChannel = 'mute-channel';
|
||||
|
||||
/// Ability to receive read events
|
||||
static const String readEvents = 'read-events';
|
||||
|
||||
/// Capability required to pin a message in a channel
|
||||
/// Corresponds to PinMessage permission
|
||||
static const String pinMessage = 'pin-message';
|
||||
|
||||
/// Capability required to quote a message in a channel
|
||||
static const String quoteMessage = 'quote-message';
|
||||
|
||||
/// Capability required to flag a message in a channel
|
||||
static const String flagMessage = 'flag-message';
|
||||
|
||||
/// User has ability to delete any message in the channel
|
||||
/// User has DeleteMessage permission
|
||||
/// which applies to any message in the channel
|
||||
static const String deleteAnyMessage = 'delete-any-message';
|
||||
|
||||
/// User has ability to delete their own message in the channel
|
||||
/// User has DeleteMessage permission which applies only to owned messages
|
||||
static const String deleteOwnMessage = 'delete-own-message';
|
||||
|
||||
/// User has ability to update/edit any message in the channel
|
||||
/// User has UpdateMessage permission which
|
||||
/// applies to any message in the channel
|
||||
static const String updateAnyMessage = 'update-any-message';
|
||||
|
||||
/// User has ability to update/edit their own message in the channel
|
||||
/// User has UpdateMessage permission which applies only to owned messages
|
||||
static const String updateOwnMessage = 'update-own-message';
|
||||
|
||||
/// User can search for message in a channel
|
||||
/// Search feature is enabled (it will also have
|
||||
/// permission check in the future)
|
||||
static const String searchMessages = 'search-messages';
|
||||
|
||||
/// Capability required to send typing events in a channel
|
||||
/// (Typing events are enabled)
|
||||
static const String sendTypingEvents = 'send-typing-events';
|
||||
|
||||
/// Capability required to upload a file in a channel
|
||||
/// Uploads are enabled and user has UploadAttachment
|
||||
static const String uploadFile = 'upload-file';
|
||||
|
||||
/// Capability required to delete channel
|
||||
/// User has DeleteChannel permission
|
||||
static const String deleteChannel = 'delete-channel';
|
||||
|
||||
/// Capability required update/edit channel info
|
||||
/// User has UpdateChannel permission
|
||||
static const String updateChannel = 'update-channel';
|
||||
|
||||
/// Capability required to update/edit channel members
|
||||
/// Channel is not distinct and user has UpdateChannelMembers permission
|
||||
static const String updateChannelMembers = 'update-channel-members';
|
||||
}
|
||||
@@ -37,6 +37,7 @@ export './src/core/util/extension.dart';
|
||||
export './src/db/chat_persistence_client.dart';
|
||||
export './src/event_type.dart';
|
||||
export './src/location.dart';
|
||||
export './src/permission_type.dart';
|
||||
export './src/ws/connection_status.dart';
|
||||
export 'src/client/channel.dart';
|
||||
export 'src/client/client.dart';
|
||||
|
||||
Reference in New Issue
Block a user