Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassan Shahbazi committed Mar 15, 2020
2 parents a6adb99 + 88f4939 commit f0ef68c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
10 changes: 8 additions & 2 deletions NinchatSDK/NINChatSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
* The return value indicates if the SDK should initiate a new chat session or not.
*/
@optional
-(BOOL) ninchatDidFailToResumeSession:(NINChatSession*_Nonnull)session;

/**
Expand Down Expand Up @@ -134,15 +135,20 @@
/**
* Starts the API engine using given credentials. Must be called before other API methods.
* If callback returns the error indicating invalidated credentials, the caller is responsible to decide
* for using `-startWithCallback:` and startign a new chat session.
* for using `-startWithCallback:` and starting a new chat session.
*/
-(void)startWithCredentials:(nonnull NINSessionCredentials*)credentials andCallback:(nonnull startCallbackBlock)callbackBlock;

/**
* Starts the API engine. Must be called before other API methods. The method creates
* a new user and a new session. The caller must wait for the callback block to be called without errors.
*/
-(void) startWithCallback:(nonnull startCallbackBlock)callbackBlock;
-(void) startWithCredentialCallback:(nonnull startCallbackBlock)callbackBlock;

/**
* Add backward compatibility for applications to omit credentials and session resumption features.
* */
-(void) startWithCallback:(nonnull void(^)(NSError* _Nullable))callbackBlock;

/**
* Returns the view controller for the Ninchat UI.
Expand Down
10 changes: 8 additions & 2 deletions NinchatSDK/NINChatSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ -(void) startWithCredentials:(nonnull NINSessionCredentials*)credentials andCall
* 1. Using that configuration, starts a new chat session
* 2. Retrieves the queues available for this realm (realm id from site configuration)
*/
-(void) startWithCallback:(nonnull startCallbackBlock)callbackBlock {
-(void) startWithCredentialCallback:(nonnull startCallbackBlock)callbackBlock {
__weak typeof(self) weakSelf = self;
[self sdklog:@"Starting a new chat session"];

Expand All @@ -237,6 +237,12 @@ -(void) startWithCallback:(nonnull startCallbackBlock)callbackBlock {
self.resumeSession = NO;
}

-(void)startWithCallback:(nonnull void (^)(NSError *_Nullable))callbackBlock {
[self startWithCredentialCallback:^(NINSessionCredentials *credentials, NSError *error) {
callbackBlock(error);
}];
}

/** Fetching site configurations usable by both approaches to opening sessions */
-(void) fetchSiteConfigurations:(nonnull void (^)(NSError* _Nullable))callbackBlock {
__weak typeof(self) weakSelf = self;
Expand Down Expand Up @@ -297,7 +303,7 @@ -(void) continueSessionWithCredentials:(nonnull NINSessionCredentials*)credentia
// [weakSelf.sessionManager closeOldSession:credentials.sessionID];
if ((error != nil && [error.userInfo[@"message"] isEqualToString:@"user_not_found"]) || !canContinueSession) {
if ([weakSelf.delegate respondsToSelector:@selector(ninchatDidFailToResumeSession:)] && [weakSelf.delegate ninchatDidFailToResumeSession:weakSelf]) {}
[weakSelf startWithCallback:callbackBlock];
[weakSelf startWithCredentialCallback:callbackBlock];
return;
}

Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,20 @@ ninchatSession.start { (credentials: NINSessionCredentials?, error: Error?) in
}
```

**Note: You still can initiate the session using the legacy interface without any credentials involved:**

```swift
ninchatSession.start { (error: Error?) in
if let error = error {
/// Some errors in starting a new session.
}
/// Show the SDK UI.
}
```

#### Resuming a session

Starting **version 0.0.42**, the SDK provides support to resume a session. In case of any issues in resuming the session using provided credentials, the corresponded delegate is called to ask if a new session should be started or not.
Starting **version 0.0.42**, the SDK provides support to resume a session. In case of any issues in resuming the session using provided credentials, the corresponded optional delegate is called to ask if a new session should be started or not.

```swift
ninchatSession.start(with: credentials) { (credentials: NINSessionCredentials?, error: Error?) in
Expand All @@ -104,6 +115,7 @@ ninchatSession.start(with: credentials) { (credentials: NINSessionCredentials?,
/// Update saved/cached `credentials` with the new one.
}

/// Optional
/// Called when credentials are not valid.
func ninchatDidFail(toResumeSession session: NINChatSession) -> Bool {
/// Return `true` if the SDK should start a new session.
Expand Down Expand Up @@ -175,6 +187,7 @@ func ninchat(_ session: NINChatSession, didOutputSDKLog message: String) {
log.debug("** NINCHAT SDK **: \(message)")
}

/// Optional
/// This method is called when the SDK was unable to resume a session using provided credentials.
/// The return value determines if the SDK should initiate a new session or not.
func ninchatDidFail(toResumeSession session: NINChatSession) -> Bool {
Expand Down

0 comments on commit f0ef68c

Please sign in to comment.