Skip to content

Commit

Permalink
Fix skip slow mode capability not handled
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski committed Nov 20, 2023
1 parent 5d81c8b commit af445dc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,8 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
/// Returns the current cooldown time for the channel. Returns 0 in case there is no cooldown active.
public func currentCooldownTime() -> Int {
guard let cooldownDuration = channel?.cooldownDuration, cooldownDuration > 0,
let currentUserLastMessage = channel?.lastMessageFromCurrentUser else {
let currentUserLastMessage = channel?.lastMessageFromCurrentUser,
channel?.ownCapabilities.contains(.skipSlowMode) == false else {
return 0
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/StreamChat/Models/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public struct ChannelCapability: RawRepresentable, ExpressibleByStringLiteral, H
public static var typingEvents: Self = "typing-events"
/// Indicates that channel slow mode is active.
public static var slowMode: Self = "slow-mode"
/// Ability to skip the slow mode when it's active.
public static var skipSlowMode: Self = "skip-slow-mode"
/// Ability to join a call.
public static var joinCall: Self = "join-call"
/// Ability to create a call.
Expand Down
4 changes: 3 additions & 1 deletion Sources/StreamChatUI/Composer/ComposerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ open class ComposerVC: _ViewController,
} else {
createNewMessage(text: text)

if !content.hasCommand, let cooldownDuration = channelController?.channel?.cooldownDuration {
let channel = channelController?.channel
let skipSlowMode = channel?.ownCapabilities.contains(.skipSlowMode) == true
if !content.hasCommand, !skipSlowMode, let cooldownDuration = channel?.cooldownDuration {
cooldownTracker.start(with: cooldownDuration)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public extension ChatChannel {
watcherCount: Int = 0,
memberCount: Int = 0,
reads: [ChatChannelRead] = [],
cooldownDuration: Int = 0,
extraData: [String: RawJSON] = [:],
latestMessages: [ChatMessage] = [],
muteDetails: MuteDetails? = nil,
Expand All @@ -110,6 +111,7 @@ public extension ChatChannel {
watcherCount: watcherCount,
memberCount: memberCount,
reads: reads,
cooldownDuration: cooldownDuration,
extraData: extraData,
latestMessages: { latestMessages },
muteDetails: { muteDetails },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ final class ComposerVC_Tests: XCTestCase {
AssertSnapshot(composerVC)
}

func test_channelWithSlowModeActive_messageIsSent_SkipSlowModeIsOnWithCountdownShown() {
let channel = ChatChannel.mock(cid: .unique, ownCapabilities: [.skipSlowMode, .sendMessage], cooldownDuration: 10)
mockedChatChannelController.channel_mock = channel
composerVC.channelController = mockedChatChannelController
composerVC.appearance = Appearance.default
composerVC.publishMessage(sender: UIButton())
composerVC.content.text = "Test text"
composerVC.composerView.inputMessageView.textView.placeholderLabel.isHidden = true

AssertSnapshot(composerVC, variants: [.defaultLight])
}

func test_didUpdateMessages_startsCooldown() {
let mockedCooldownTracker = CooldownTracker_Mock(timer: ScheduledStreamTimer_Mock())
composerVC.cooldownTracker = mockedCooldownTracker
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af445dc

Please sign in to comment.