diff --git a/packages/stream_chat/lib/src/permission_type.dart b/packages/stream_chat/lib/src/permission_type.dart new file mode 100644 index 00000000..2e6eef64 --- /dev/null +++ b/packages/stream_chat/lib/src/permission_type.dart @@ -0,0 +1,37 @@ +class PermissionType { + static const String sendMessage = "send-message"; + + static const String sendReaction = "send-reaction"; + + static const String sendLinks = "send-links"; + + static const String sendReply = "send-reply"; + + static const String freezeChannel = "freeze-channel"; + + static const String setChannelCooldown = "set-channel-cooldown"; + + static const String leaveChannel = "leave-channel"; + + static const String pinMessage = "pin-message"; + + static const String deleteAnyMessage = "delete-any-message"; + + static const String deleteOwnMessage = "delete-own-message"; + + static const String updateAnyMessage = "update-any-message"; + + static const String updateOwnMessage = "update-own-message"; + + static const String searchMessages = "search-messages"; + + static const String sendTypingEvents = "send-typing-events"; + + static const String uploadFile = "upload-file"; + + static const String deleteChannel = "delete-channel"; + + static const String updateChannel = "update-channel"; + + static const String updateChannelMembers = "update-channel-members"; +} diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index 571d78f5..d196b675 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -36,6 +36,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'; diff --git a/packages/stream_chat_flutter/lib/src/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view.dart index 5424a1c2..12902030 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view.dart @@ -164,7 +164,6 @@ class MessageListView extends StatefulWidget { this.messageFilter, this.onMessageTap, this.onSystemMessageTap, - this.pinPermissions = const [], this.showFloatingDateDivider = true, this.threadSeparatorBuilder, this.messageListController, @@ -276,9 +275,6 @@ class MessageListView extends StatefulWidget { /// Called when system message is tapped final OnMessageTap? onSystemMessageTap; - /// A List of user types that have permission to pin messages - final List pinPermissions; - /// Builder used to build the thread separator in case it's a thread view final WidgetBuilder? threadSeparatorBuilder; @@ -301,6 +297,7 @@ class _MessageListViewState extends State { int? _messageListLength; StreamChannelState? streamChannel; late StreamChatThemeData _streamTheme; + late List _userPermissions; int get _initialIndex { final initialScrollIndex = widget.initialScrollIndex; @@ -960,7 +957,7 @@ class _MessageListViewState extends State { FocusScope.of(context).unfocus(); }, showPinButton: currentUserMember != null && - widget.pinPermissions.contains(currentUserMember.role), + _userPermissions.contains(PermissionType.pinMessage), ); if (widget.parentMessageBuilder != null) { @@ -1159,7 +1156,7 @@ class _MessageListViewState extends State { FocusScope.of(context).unfocus(); }, showPinButton: currentUserMember != null && - widget.pinPermissions.contains(currentUserMember.role), + _userPermissions.contains(PermissionType.pinMessage), ); if (widget.messageBuilder != null) { @@ -1239,6 +1236,9 @@ class _MessageListViewState extends State { void didChangeDependencies() { final newStreamChannel = StreamChannel.of(context); _streamTheme = StreamChatTheme.of(context); + _userPermissions = + newStreamChannel.channel.state?.channelState.channel?.ownCapabilities ?? + []; if (newStreamChannel != streamChannel) { streamChannel = newStreamChannel;