Skip to content

Commit c925b55

Browse files
Implemented channel config for commands
1 parent ce4dad2 commit c925b55

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerTypeView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ public struct AttachmentPickerTypeView: View {
4545
)
4646
}
4747

48-
PickerTypeButton(
49-
pickerTypeState: $pickerTypeState,
50-
pickerType: .instantCommands,
51-
selected: attachmentPickerType
52-
)
48+
if channelConfig?.commands.count ?? 0 > 0 {
49+
PickerTypeButton(
50+
pickerTypeState: $pickerTypeState,
51+
pickerType: .instantCommands,
52+
selected: attachmentPickerType
53+
)
54+
}
5355
case .collapsed:
5456
Button {
5557
withAnimation {

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
140140
}
141141
}
142142
.overlay(
143-
viewModel.composerCommand != nil ?
143+
viewModel.showCommandsOverlay ?
144144
factory.makeCommandsContainerView(
145145
suggestions: viewModel.suggestions,
146146
handleCommand: { commandInfo in

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ open class MessageComposerViewModel: ObservableObject {
239239
channelController.channel?.isDirectMessageChannel ?? false
240240
}
241241

242+
public var showCommandsOverlay: Bool {
243+
composerCommand != nil && channelController.channel?.config.commands.count ?? 0 > 0
244+
}
245+
242246
public func change(pickerState: AttachmentPickerState) {
243247
if pickerState != self.pickerState {
244248
self.pickerState = pickerState

Sources/StreamChatSwiftUI/ChatChannel/Composer/Suggestions/CommandsConfig.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ public class DefaultCommandsConfig: CommandsConfig {
4141

4242
var instantCommands = [CommandHandler]()
4343

44-
let giphyCommand = GiphyCommandHandler(commandSymbol: "/giphy")
45-
instantCommands.append(giphyCommand)
44+
let channelConfig = channelController.channel?.config
4645

47-
if channelController.channel?.config.mutesEnabled == true {
46+
let giphyEnabled = channelConfig?.commands.first(where: { command in
47+
command.name == "giphy"
48+
}) != nil
49+
50+
if giphyEnabled {
51+
let giphyCommand = GiphyCommandHandler(commandSymbol: "/giphy")
52+
instantCommands.append(giphyCommand)
53+
}
54+
55+
if channelConfig?.mutesEnabled == true {
4856
let muteCommand = MuteCommandHandler(
4957
channelController: channelController,
5058
commandSymbol: "/mute"

0 commit comments

Comments
 (0)