@@ -270,7 +270,7 @@ class Channel {
270270 final userLastMessageAt = currentUserLastMessageAt;
271271 if (userLastMessageAt == null ) return 0 ;
272272
273- if (ownCapabilities. contains ( PermissionType .skipSlowMode) ) return 0 ;
273+ if (canSkipSlowMode ) return 0 ;
274274
275275 final currentTime = DateTime .timestamp ();
276276 final elapsedTime = currentTime.difference (userLastMessageAt).inSeconds;
@@ -413,11 +413,11 @@ class Channel {
413413 }
414414
415415 /// List of user permissions on this channel
416- List <String > get ownCapabilities =>
416+ List <ChannelCapability > get ownCapabilities =>
417417 state? ._channelState.channel? .ownCapabilities ?? [];
418418
419419 /// List of user permissions on this channel
420- Stream <List <String >> get ownCapabilitiesStream {
420+ Stream <List <ChannelCapability >> get ownCapabilitiesStream {
421421 _checkInitialized ();
422422 return state! .channelStateStream
423423 .map ((cs) => cs.channel? .ownCapabilities ?? [])
@@ -2899,9 +2899,7 @@ class ChannelClientState {
28992899 if (_channel.isMuted) return false ;
29002900
29012901 // Don't count if the channel doesn't allow read events.
2902- if (! _channel.ownCapabilities.contains (PermissionType .readEvents)) {
2903- return false ;
2904- }
2902+ if (! _channel.canReceiveReadEvents) return false ;
29052903
29062904 // Don't count thread replies which are not shown in the channel as unread.
29072905 if (message.parentId != null && message.showInChannel == false ) {
@@ -3215,3 +3213,187 @@ extension on Iterable<Message> {
32153213 return messageMap.values;
32163214 }
32173215}
3216+
3217+ /// Extension methods for checking channel capabilities on a Channel instance.
3218+ ///
3219+ /// These methods provide a convenient way to check if the current user has
3220+ /// specific capabilities in a channel.
3221+ extension ChannelCapabilityCheck on Channel {
3222+ /// True, if the current user can send a message to this channel.
3223+ bool get canSendMessage {
3224+ return ownCapabilities.contains (ChannelCapability .sendMessage);
3225+ }
3226+
3227+ /// True, if the current user can send a reply to this channel.
3228+ bool get canSendReply {
3229+ return ownCapabilities.contains (ChannelCapability .sendReply);
3230+ }
3231+
3232+ /// True, if the current user can send a message with restricted visibility.
3233+ bool get canSendRestrictedVisibilityMessage {
3234+ return ownCapabilities.contains (
3235+ ChannelCapability .sendRestrictedVisibilityMessage,
3236+ );
3237+ }
3238+
3239+ /// True, if the current user can send reactions.
3240+ bool get canSendReaction {
3241+ return ownCapabilities.contains (ChannelCapability .sendReaction);
3242+ }
3243+
3244+ /// True, if the current user can attach links to messages.
3245+ bool get canSendLinks {
3246+ return ownCapabilities.contains (ChannelCapability .sendLinks);
3247+ }
3248+
3249+ /// True, if the current user can attach files to messages.
3250+ bool get canCreateAttachment {
3251+ return ownCapabilities.contains (ChannelCapability .createAttachment);
3252+ }
3253+
3254+ /// True, if the current user can freeze or unfreeze channel.
3255+ bool get canFreezeChannel {
3256+ return ownCapabilities.contains (ChannelCapability .freezeChannel);
3257+ }
3258+
3259+ /// True, if the current user can enable or disable slow mode.
3260+ bool get canSetChannelCooldown {
3261+ return ownCapabilities.contains (ChannelCapability .setChannelCooldown);
3262+ }
3263+
3264+ /// True, if the current user can leave channel (remove own membership).
3265+ bool get canLeaveChannel {
3266+ return ownCapabilities.contains (ChannelCapability .leaveChannel);
3267+ }
3268+
3269+ /// True, if the current user can join channel (add own membership).
3270+ bool get canJoinChannel {
3271+ return ownCapabilities.contains (ChannelCapability .joinChannel);
3272+ }
3273+
3274+ /// True, if the current user can pin a message.
3275+ bool get canPinMessage {
3276+ return ownCapabilities.contains (ChannelCapability .pinMessage);
3277+ }
3278+
3279+ /// True, if the current user can delete any message from the channel.
3280+ bool get canDeleteAnyMessage {
3281+ return ownCapabilities.contains (ChannelCapability .deleteAnyMessage);
3282+ }
3283+
3284+ /// True, if the current user can delete own messages from the channel.
3285+ bool get canDeleteOwnMessage {
3286+ return ownCapabilities.contains (ChannelCapability .deleteOwnMessage);
3287+ }
3288+
3289+ /// True, if the current user can update any message in the channel.
3290+ bool get canUpdateAnyMessage {
3291+ return ownCapabilities.contains (ChannelCapability .updateAnyMessage);
3292+ }
3293+
3294+ /// True, if the current user can update own messages in the channel.
3295+ bool get canUpdateOwnMessage {
3296+ return ownCapabilities.contains (ChannelCapability .updateOwnMessage);
3297+ }
3298+
3299+ /// True, if the current user can use message search.
3300+ bool get canSearchMessages {
3301+ return ownCapabilities.contains (ChannelCapability .searchMessages);
3302+ }
3303+
3304+ /// True, if the current user can send typing events.
3305+ bool get canSendTypingEvents {
3306+ return ownCapabilities.contains (ChannelCapability .sendTypingEvents);
3307+ }
3308+
3309+ /// True, if the current user can upload message attachments.
3310+ bool get canUploadFile {
3311+ return ownCapabilities.contains (ChannelCapability .uploadFile);
3312+ }
3313+
3314+ /// True, if the current user can delete channel.
3315+ bool get canDeleteChannel {
3316+ return ownCapabilities.contains (ChannelCapability .deleteChannel);
3317+ }
3318+
3319+ /// True, if the current user can update channel data.
3320+ bool get canUpdateChannel {
3321+ return ownCapabilities.contains (ChannelCapability .updateChannel);
3322+ }
3323+
3324+ /// True, if the current user can update channel members.
3325+ bool get canUpdateChannelMembers {
3326+ return ownCapabilities.contains (ChannelCapability .updateChannelMembers);
3327+ }
3328+
3329+ /// True, if the current user can update thread data.
3330+ bool get canUpdateThread {
3331+ return ownCapabilities.contains (ChannelCapability .updateThread);
3332+ }
3333+
3334+ /// True, if the current user can quote a message.
3335+ bool get canQuoteMessage {
3336+ return ownCapabilities.contains (ChannelCapability .quoteMessage);
3337+ }
3338+
3339+ /// True, if the current user can ban channel members.
3340+ bool get canBanChannelMembers {
3341+ return ownCapabilities.contains (ChannelCapability .banChannelMembers);
3342+ }
3343+
3344+ /// True, if the current user can flag a message.
3345+ bool get canFlagMessage {
3346+ return ownCapabilities.contains (ChannelCapability .flagMessage);
3347+ }
3348+
3349+ /// True, if the current user can mute a channel.
3350+ bool get canMuteChannel {
3351+ return ownCapabilities.contains (ChannelCapability .muteChannel);
3352+ }
3353+
3354+ /// True, if the current user can send custom events.
3355+ bool get canSendCustomEvents {
3356+ return ownCapabilities.contains (ChannelCapability .sendCustomEvents);
3357+ }
3358+
3359+ /// True, if the current user has read events capability.
3360+ bool get canReceiveReadEvents {
3361+ return ownCapabilities.contains (ChannelCapability .readEvents);
3362+ }
3363+
3364+ /// True, if the current user has connect events capability.
3365+ bool get canReceiveConnectEvents {
3366+ return ownCapabilities.contains (ChannelCapability .connectEvents);
3367+ }
3368+
3369+ /// True, if the current user can send and receive typing events.
3370+ bool get canUseTypingEvents {
3371+ return ownCapabilities.contains (ChannelCapability .typingEvents);
3372+ }
3373+
3374+ /// True, if channel slow mode is active.
3375+ bool get isInSlowMode {
3376+ return ownCapabilities.contains (ChannelCapability .slowMode);
3377+ }
3378+
3379+ /// True, if the current user is allowed to post messages as usual even if the
3380+ /// channel is in slow mode.
3381+ bool get canSkipSlowMode {
3382+ return ownCapabilities.contains (ChannelCapability .skipSlowMode);
3383+ }
3384+
3385+ /// True, if the current user can create a poll.
3386+ bool get canSendPoll {
3387+ return ownCapabilities.contains (ChannelCapability .sendPoll);
3388+ }
3389+
3390+ /// True, if the current user can vote in a poll.
3391+ bool get canCastPollVote {
3392+ return ownCapabilities.contains (ChannelCapability .castPollVote);
3393+ }
3394+
3395+ /// True, if the current user can query poll votes.
3396+ bool get canQueryPollVotes {
3397+ return ownCapabilities.contains (ChannelCapability .queryPollVotes);
3398+ }
3399+ }
0 commit comments