SBDGroupChannel.createChannel creates a channel with a nil nickame

  • SendBirdUIKit (2.0.9):
    • SendBirdSDK (~> 3.0.205)

Hi,
I have a problem with the creation of a 1-1 chat using SBDGroupChannel.createChannel.

func openChat(userId: String) {
    SBDGroupChannel.createChannel(withUserIds: [userId], isDistinct: true, completionHandler: { [weak self] (groupChannel, error) in
        guard error == nil else {
            Alert.i.alertOnTopViewController(message: error.debugDescription, style: .alert)
            return
        }
        if let channelUrl = groupChannel?.channelUrl {
            // Open the chat
            self?.showChannel(channelUrl: channelUrl)
        }
    })
}
func showChannel(channelUrl: String) {
    SendBirdUtils.i.setCustomTheme() // Changes the theme
    let channelVC = MySBUChannelViewController(channelUrl: channelUrl)
    let naviVC = NavBarWithLightStatusBarStyle(rootViewController: channelVC)
    naviVC.modalPresentationStyle = .fullScreen
    (self.parent as? JobsVC)?.present(naviVC, animated: true)
}

When the chat doesn’t exist and I call the func openChat(…) the chat is created but the user nickname groupChannel?.getMember(userId)?.nickname is nil even if a send a message to him.


The nickname acquires value when the other user responds to me and after I close and reopen the app. I don’t understand what I’m doing wrong, if you have any advice please tell me.
Thanks AP

I found a workaround executing two query to found the 2 users nickname :

func searchSBDUser(userId: String?, onUserFound: @escaping ((String) -> ())) {
        if let id = userId {
            let listQuery = SBDMain.createApplicationUserListQuery()
            listQuery?.userIdsFilter = [id]
            listQuery?.loadNextPage(completionHandler: { (users, error) in
                guard error == nil else {
                    Alert.i.alertOnTopViewController(message: error.debugDescription, style: .alert)
                    return
                }
                if let userNick = users?[0].nickname {
                    onUserFound(userNick)
                }
            })
        }
}

And set it to the member of the 1-1 channel:
groupChannel?.getMember(userId)?.nickname = foundedNickName.
But that mean 2 query every time I click on the button open chat.
If you have any advice please tell me, thanks.

Hey @Andrea_Procucci,

I’m sorry it took so long for me to reply to this. Let me take a look and see if I can recreate this behavior.

1 Like

Hi @Andrea_Procucci,

I’m trying to reproduce this and am not having much luck. If you were to print out the channel members prior to opening the the channel, do they contain the nickname? I tested this in a dirty way, but provides me the information I needed:

SBDGroupChannel.createChannel(with: params) { (channel, error) in
            self.hideLoadingIndicatorView()
            
            guard let user = channel?.members?[0] as? SBDUser else {return}
            print(user.nickname)
}
1 Like

Hello,
I don’t know exactly why, but I tried to do a “fresh start” of SendBird and now I have the 2 nicknames. Thank you for your time.