8000 Expose canSendPoll capability and handle it in the Composer (#3635) · GetStream/stream-chat-swift@c573af5 · GitHub
[go: up one dir, main page]

Skip to content

Commit c573af5

Browse files
authored
Expose canSendPoll capability and handle it in the Composer (#3635)
* Expose canSendPoll and canCastPollVote capabilities * Only show Create Poll action in the composer if it has the capability * Update CHANGELOG.md
1 parent fd26748 commit c573af5

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
## StreamChat
77
### ✅ Added
88
- Add `ChatChannelController.deletePoll()` for deleting polls [#3632](https://github.com/GetStream/stream-chat-swift/pull/3632)
9+
- Add `ChatChannel.canSendPoll` capability [#3635](https://github.com/GetStream/stream-chat-swift/pull/3635)
10+
- Add `ChatChannel.canCastPollVote` capability [#3635](https://github.com/GetStream/stream-chat-swift/pull/3635)
11+
12+
## StreamChatUI
13+
### 🐞 Fixed
14+
- Fix showing Create Poll action in the composer if the user does not have the capability [#3635](https://github.com/GetStream/stream-chat-swift/pull/3635)
915

1016
# [4.76.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.76.0)
1117
_March 31, 2025_

Sources/StreamChat/Models/Channel.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ public struct ChannelCapability: RawRepresentable, ExpressibleByStringLiteral, H
426426
public static let joinCall: Self = "join-call"
427427
/// Ability to create a call.
428428
public static let createCall: Self = "create-call"
429+
/// Ability to send a poll.
430+
public static let sendPoll: Self = "send-poll"
431+
/// Ability to cast a poll vote.
432+
public static let castPollVote: Self = "cast-poll-vote"
429433
}
430434

431435
public extension ChatChannel {
@@ -573,4 +577,14 @@ public extension ChatChannel {
573577
var isSlowMode: Bool {
574578
ownCapabilities.contains(.slowMode)
575579
}
580+
581+
/// Can the current user send a poll in this channel.
582+
var canSendPoll: Bool {
583+
ownCapabilities.contains(.sendPoll)
584+
}
585+
586+
/// Can the current user cast a poll vote in this channel.
587+
var canCastPollVote: Bool {
588+
ownCapabilities.contains(.castPollVote)
589+
}
576590
}

Sources/StreamChatUI/Composer/ComposerVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ open class ComposerVC: _ViewController,
876876
/// Returns actions for attachments picker.
877877
open var attachmentsPickerActions: [UIAlertAction] {
878878
let isCameraAvailable = UIImagePickerController.isSourceTypeAvailable(.camera)
879-
let isPollCreationEnabled = channelConfig?.pollsEnabled == true
879+
let isPollCreationEnabled = channelConfig?.pollsEnabled == true && channelController?.channel?.canSendPoll == true
880880

881881
let showFilePickerAction = UIAlertAction(
882882
title: L10n.Composer.Picker.file,

Tests/StreamChatTests/Models/ChatChannel_Tests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ final class ChatChannel_Tests: XCTestCase {
285285
XCTAssertEqual(channelWithoutCapability.isSlowMode, false)
286286
}
287287

288+
func test_canSendPoll() throws {
289+
let channel = setupChannel(withCapabilities: [.sendPoll])
290+
XCTAssertEqual(channel.canSendPoll, true)
291+
292+
let channelWithoutCapability = setupChannel(withCapabilities: [])
293+
XCTAssertEqual(channelWithoutCapability.canSendPoll, false)
294+
}
295+
296+
func test_canCastPollVote() throws {
297+
let channel = setupChannel(withCapabilities: [.castPollVote])
298+
XCTAssertEqual(channel.canCastPollVote, true)
299+
300+
let channelWithoutCapability = setupChannel(withCapabilities: [])
301+
XCTAssertEqual(channelWithoutCapability.canCastPollVote, false)
302+
}
303+
288304
func test_lastReadMessageId_readsDontContainUser() {
289305
let userId: UserId = "current"
290306
let channel = ChatChannel.mock(cid: .unique, reads: [

0 commit comments

Comments
 (0)
0