added docs and reactions modal

This commit is contained in:
Deven Joshi
2021-11-09 16:16:11 +05:30
parent 3460164b75
commit 13b0fa0a4c
2 changed files with 75 additions and 21 deletions
@@ -1,37 +1,81 @@
/// Describes capabilities of a user vis-a-vis a channel
class PermissionType {
static const String sendMessage = "send-message";
/// 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';
static const String sendReaction = "send-reaction";
/// 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';
static const String sendLinks = "send-links";
/// Capability required to send links in a channel
/// send-message + user has AddLinks permission
static const String sendLinks = 'send-links';
static const String sendReply = "send-reply";
/// Capability required to send thread reply
/// send-message + channel has replies enabled
static const String sendReply = 'send-reply';
static const String freezeChannel = "freeze-channel";
/// 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';
static const String setChannelCooldown = "set-channel-cooldown";
/// User has UpdateChannelCooldown permission.
/// Allows to enable/disable slow mode in the channel
static const String setChannelCooldown = 'set-channel-cooldown';
static const String leaveChannel = "leave-channel";
/// User has RemoveOwnChannelMembership or UpdateChannelMembers permission
static const String leaveChannel = 'leave-channel';
static const String pinMessage = "pin-message";
/// Capability required to pin a message in a channel
/// Corresponds to PinMessage permission
static const String pinMessage = 'pin-message';
static const String deleteAnyMessage = "delete-any-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';
static const String deleteOwnMessage = "delete-own-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';
static const String updateAnyMessage = "update-any-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';
static const String updateOwnMessage = "update-own-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';
static const String searchMessages = "search-messages";
/// 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';
static const String sendTypingEvents = "send-typing-events";
/// Capability required to send typing events in a channel
/// (Typing events are enabled)
static const String sendTypingEvents = 'send-typing-events';
static const String uploadFile = "upload-file";
/// Capability required to upload a file in a channel
/// Uploads are enabled and user has UploadAttachment
static const String uploadFile = 'upload-file';
static const String deleteChannel = "delete-channel";
/// Capability required to delete channel
/// User has DeleteChannel permission
static const String deleteChannel = 'delete-channel';
static const String updateChannel = "update-channel";
/// Capability required update/edit channel info
/// User has UpdateChannel permission
static const String updateChannel = 'update-channel';
static const String updateChannelMembers = "update-channel-members";
/// Capability required to update/edit channel members
/// Channel is not distinct and user has UpdateChannelMembers permission
static const String updateChannelMembers = 'update-channel-members';
}
@@ -18,7 +18,7 @@ class MessageReactionsModal extends StatelessWidget {
required this.message,
required this.messageWidget,
required this.messageTheme,
this.showReactions = true,
this.showReactions,
this.reverse = false,
this.onUserAvatarTap,
}) : super(key: key);
@@ -36,7 +36,7 @@ class MessageReactionsModal extends StatelessWidget {
final bool reverse;
/// Flag to show reactions on message
final bool showReactions;
final bool? showReactions;
/// Callback when user avatar is tapped
final void Function(User)? onUserAvatarTap;
@@ -45,6 +45,16 @@ class MessageReactionsModal extends StatelessWidget {
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final user = StreamChat.of(context).currentUser;
final _userPermissions = StreamChannel.of(context)
.channel
.state
?.channelState
.channel
?.ownCapabilities ??
[];
final hasReactionPermission =
_userPermissions.contains(PermissionType.sendReaction);
final roughMaxSize = size.width * 2 / 3;
var messageTextLength = message.text!.length;
@@ -76,7 +86,7 @@ class MessageReactionsModal extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (showReactions &&
if ((showReactions ?? hasReactionPermission) &&
(message.status == MessageSendingStatus.sent))
Align(
alignment: Alignment(