Open vijay21021993 opened 4 years ago
I am having the same issue.
Hi, I found a way to create thread
_ = BChatSDK.auth()?.authenticate().thenOnMain({ success -> Any? in
/// Create Thread Here
}, nil)
@vijay21021993
I am trying to create a thread with the two user to make one to one chat. The thread is creating on my controller where I link them and start a chat.
you need something like this
`
let indexes: [Any] = [bUserEmailKey]
let promise = BChatSDK.search()?.users(forIndexes: indexes, withValue: "myContact@example.com", limit: 1, userAdded: {
result in
if let user = result {
let users: [Any] = [user]
let thread = BChatSDK.core()?.fetchOrCreateThread(withUsers: users, name: user.name())
if let vc = BChatSDK.ui()?.chatViewController(with: thread) {
controller.navigationController?.pushViewController(vc, animated: true)
} else {
let error = ... // define custom error
_ = self.handleError(error)
}
} else {
let error = ... // define custom error
_ = self.handleError(error)
}
})
_ = promise?.thenOnMain({ result in
return result
}, { error in
return self.handleError(error)
})
`
and for this to work your target user must be already in firebase database
The above looks good but every user doesn't have email they may be signIn with their social account or mobile no.All the user have firebaseID can we use that instead of email?
The above looks good but every user doesn't have email they may be signIn with their social account or mobile no.All the user have firebaseID can we use that instead of email?
explore indexes and search api.
If you want to get a user for a given ID, you can use something like this:
-(id<PUser>) getUserForEntityID: (NSString *) entityID {
id<PUser> user = [BChatSDK.db fetchOrCreateEntityWithID:entityID withType:bUserEntity];
[BChatSDK.core observeUser:user];
return user;
}
The first line gets the user object from the database or creates it if it doesn't exist. The second line adds the Firebase listeners to that user.
The crash is getting on creating and fetching the thread throw the users. ( BChatSDK.core()?.createThread(withUsers: userArray as [Any],) Getting the user was not the problem the thread creation method is the problem.
It looks like one of the users you're trying to add is Nil. Are you sure that you have let authentication finish before trying to make the thread?
_ = BChatSDK.auth()?.authenticate().thenOnMain({ success -> Any? in
/// Create Thread Here
}, nil)
If you try to make a thread before this, the current user will be Nil.
sorry about the previous example (i'm new to this framework) fetchOrCreateThread
does not seem to sync with firebase try this approach
let indexes: [Any] = [bUserEmailKey]
let promUsers = BChatSDK.search()?.users(forIndexes: indexes, withValue: userInfo.email(), limit: 1, userAdded: {
result in
if let user = result {
let users: [Any] = [user]
let promThread = BChatSDK.core()?.createThread(withUsers: users, threadCreated: { (error, thread) in
if let thread = thread {
if let vc = BChatSDK.ui()?.chatViewController(with: thread) {
controller.navigationController?.pushViewController(vc, animated: true)
} else {
let error = ... // define custom error
_ = self.handleError(error)
}
} else if let error = error {
_ = self.handleError(error)
}
})
_ = promThread?.thenOnMain({ result in
return result
}, { error in
return self.handleError(error)
})
} else {
let error = ... // define custom error
_ = self.handleError(error)
}
})
_ = promUsers?.thenOnMain({ result in
return result
}, { error in
return self.handleError(error)
})
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.