Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active February 23, 2021 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardoso/36cb3a539951c94e208b248316574ff4 to your computer and use it in GitHub Desktop.
Save cardoso/36cb3a539951c94e208b248316574ff4 to your computer and use it in GitHub Desktop.
struct ChannelsView: View {
...
@State
var createChannelName = ""
var createChannelView: some View {
if(createTrigger) {
return AnyView(HStack {
TextField("Channel name", text: $createChannelName)
Button(action: { try? self.createChannel() }) {
Text(self.createChannelName.isEmpty ? "Cancel" : "Submit")
}
}.padding())
}
return AnyView(EmptyView()) // TODO: Add Channel
}
func createChannel() throws {
self.createTrigger = false
if !self.createChannelName.isEmpty {
let cid = ChannelId(type: .messaging, id: createChannelName)
let controller = try ChatClient.shared.channelController(
createChannelWithId: cid,
name: nil,
imageURL: nil,
isCurrentUserMember: true,
extraData: .defaultValue
)
controller.synchronize { error in
if let error = error {
print(error)
} else if let channel = controller.channel {
channels.append(channel)
}
}
}
self.createChannelName = ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment