-
-
Save cardoso/36cb3a539951c94e208b248316574ff4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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