Created
May 19, 2022 16:59
-
-
Save amosgyamfi/e7a32ff93e49aef4bec9fe74af837889 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
import SwiftUI | |
import StreamChat | |
import StreamChatSwiftUI | |
class AppDelegate: NSObject, UIApplicationDelegate { | |
var streamChat: StreamChat? | |
var chatClient: ChatClient = { | |
var config = ChatClientConfig(apiKey: .init("8br4watad788")) | |
config.applicationGroupIdentifier = "group.io.getstream.iOS.ChatDemoAppSwiftUI" | |
let client = ChatClient(config: config) | |
return client | |
}() | |
func application(_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: | |
[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { | |
// Color supplier: Provides the colors used throughout the SDK. | |
// Create instance of the color palette object | |
var colors = ColorPalette() | |
// Text of: Navigation links, chat bubbles, instant commands, context menu, menu icon (swipe to reveal), links in messages, read receipt | |
let nordeaAccentColor = Color(#colorLiteral(red: 0.05098039216, green: 0.5098039216, blue: 0.4078431373, alpha: 1)) // System-wide accent color | |
let cloudBlue = Color(#colorLiteral(red: 0.862745098, green: 0.9294117647, blue: 1, alpha: 1)) // Outgouing chat bubble | |
let darkPink = Color(#colorLiteral(red: 0.9411764706, green: 0.7568627451, blue: 0.6823529412, alpha: 1)) // Incoming chat bubble | |
// Use the tint color to override the default accent color | |
// Change the color of navigation icon, scroll-to button and read indicator | |
colors.tintColor = nordeaAccentColor | |
// Channel list name, chat bubble text, context menu text | |
colors.text = UIColor(nordeaAccentColor) | |
// Backgrounds of: Channel list, chat area, instant commands, and compose area | |
colors.background = UIColor(cloudBlue) | |
// Background of: Searchbar | |
colors.background1 = UIColor(Color(.systemGray4)) | |
// Background of: Outgoing message bubbles | |
colors.background6 = UIColor(cloudBlue) | |
// Backgrounds of: Incoming message bubbles, context menu, reactions | |
colors.background8 = UIColor(darkPink) | |
// Color for giphy label | |
colors.staticColorText = .systemBlue | |
// Create instance of the font object | |
var fonts = Fonts() | |
fonts.body = .largeTitle | |
// Message bubble content fontSize, context menu | |
//fonts.body = .system(size: 45).italic() | |
// Swapping interface icons with SF Symbols | |
// Create instance of the image object | |
let images = Images() | |
// SF Symbols | |
// images.reactionLoveBig = UIImage(systemName: "bolt.heart.fill")! | |
// images.reactionLoveBig = UIImage(systemName: "bolt.heart.fill")! | |
// Google Material Symbols | |
images.reactionLoveBig = UIImage(named: "heart_broke")! | |
images.reactionLoveSmall = UIImage(named: "heart_broke")! | |
// Use the local variables after their declaration | |
//let appearance = Appearance(colors: colors, images: images, fonts: fonts) | |
let appearance = Appearance(colors: colors, images: images, fonts: fonts) | |
/*let channelNamer: ChatChannelNamer = { channel, currentUserId in | |
"This is our custom name: \(channel.name ?? "no name")" | |
}*/ | |
streamChat = StreamChat(chatClient: chatClient, appearance: appearance) | |
connectUser() | |
return true | |
} | |
// The `connectUser` function we need to add. | |
private func connectUser() { | |
// This is a hardcoded token valid on Stream's tutorial environment. | |
let token = try! Token(rawValue: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoibHVrZV9za3l3YWxrZXIifQ.kFSLHRB5X62t0Zlc7nwczWUfsQMwfkpylC6jCUZ6Mc0") | |
// Call `connectUser` on our SDK to get started. | |
chatClient.connectUser( | |
userInfo: .init(id: "luke_skywalker", | |
name: "Luke Skywalker", | |
imageURL: URL(string: "https://vignette.wikia.nocookie.net/starwars/images/2/20/LukeTLJ.jpg")!), | |
token: token | |
) { error in | |
if let error = error { | |
// Some very basic error handling only logging the error. | |
log.error("connecting the user failed \(error)") | |
return | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment