Skip to content

Commit

Permalink
Fix some small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bensmiley committed Dec 3, 2020
1 parent 7f022a7 commit 52e58a1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
10 changes: 7 additions & 3 deletions ChatSDKCore/Classes/Handlers/Abstract/BAbstractCoreHandler.m
Expand Up @@ -59,7 +59,7 @@ -(RXPromise *) pushUser: (BOOL) uploadAvatar {
*/
-(id<PUser>) currentUserModel {
NSString * currentUserID = BChatSDK.auth.currentUserID;
if (currentUserID && !_currentUser) {
if (currentUserID && (!_currentUser || !_currentUser.entityID)) {
_currentUser = [BChatSDK.db fetchEntityWithID:currentUserID withType:bUserEntity];
}
return _currentUser;
Expand All @@ -68,10 +68,14 @@ -(RXPromise *) pushUser: (BOOL) uploadAvatar {
-(RXPromise *) currentUserModelAsync {
NSString * currentUserID = BChatSDK.auth.currentUserID;
if (currentUserID.length && !_currentUser) {
return [BChatSDK.db performOnMain:^id {
RXPromise * promise = [RXPromise new];

[BChatSDK.db performOnMain:^{
_currentUser = [BChatSDK.db fetchEntityWithID:currentUserID withType:bUserEntity];
return _currentUser;
[promise resolveWithResult:_currentUser];
}];

return promise;
} else {
return [RXPromise resolveWithResult:_currentUser];
}
Expand Down
2 changes: 1 addition & 1 deletion ChatSDKCore/Classes/Interfaces/PStorageAdapter.h
Expand Up @@ -81,7 +81,7 @@ typedef enum {
-(NSArray<PMessage> *) loadMessagesForThread: (id<PThread>) thread oldest: (int) count;

//-(RXPromise *) performOnPrivate: (id (^)(void)) block;
-(RXPromise *) performOnMain: (id (^)(void)) block;
-(void) performOnMain: (void(^)(void)) block;
-(void) performOnMainAndWait:(void(^)(void)) block;

//-(RXPromise *) performOnPrivateAndSave:(id (^)(void))block;
Expand Down
28 changes: 18 additions & 10 deletions ChatSDKCoreData/Classes/BCoreDataStorageAdapter.m
Expand Up @@ -309,10 +309,18 @@ -(id) fetchEntityWithID: (NSString *) entityID withType: (NSString *) type {
// return [self performOn:self.backgroundManagedObjectContext withBlock:block];
//}

-(RXPromise *) performOnMain:(id(^)(void)) block {
return [self performOn:_mainMoc withBlock:block];
-(void) performOnMain: (void(^)(void)) block {
[_mainMoc performBlock:^{
if (block != nil) {
block();
}
}];
}

//-(RXPromise *) performOnMain:(id(^)(void)) block {
// return [self performOn:_mainMoc withBlock:block];
//}

-(void) performOnMainAndWait:(void(^)(void)) block {
[_mainMoc performBlockAndWait:^{
block();
Expand Down Expand Up @@ -343,14 +351,14 @@ -(RXPromise *) performOnAndSave: (NSManagedObjectContext *) context withBlock: (
return promise;
}

-(RXPromise *) performOn: (NSManagedObjectContext *) context withBlock: (id(^)(void)) block {
RXPromise * promise = [RXPromise new];
[context performBlock:^{
id result = block();
[promise resolveWithResult:result];
}];
return promise;
}
//-(RXPromise *) performOn: (NSManagedObjectContext *) context withBlock: (void(^)(void)) block {
// RXPromise * promise = [RXPromise new];
// [context performBlock:^{
// block();
// [promise resolveWithResult:result];
// }];
// return promise;
//}

-(id) fetchOrCreateEntityWithID: (NSString *) entityID withType: (NSString *) type {

Expand Down
Expand Up @@ -151,10 +151,13 @@ -(RXPromise *) loginWithFirebaseUser: (FIRUser *) firebaseUser {
-(RXPromise *) loginWithFirebaseUser: (FIRUser *) firebaseUser accountDetails: (BAccountDetails *) details {

// If the user isn't authenticated they'll need to login
if (!firebaseUser) {
if (!firebaseUser || !firebaseUser.uid) {
return [RXPromise resolveWithResult:Nil];
}

// Save the authentication ID for the current user
[self setCurrentUserID:firebaseUser.uid];

// Get the user
id<PUser> cachedUser = [BChatSDK.db fetchEntityWithID:firebaseUser.uid withType:bUserEntity];

Expand Down Expand Up @@ -205,10 +208,7 @@ -(RXPromise *) loginWithFirebaseUser: (FIRUser *) firebaseUser accountDetails: (
-(RXPromise *) completeAuthentication: (BAccountDetails *) details withUser: (id<PUser>) user {

_isAuthenticatedThisSession = YES;

// Save the authentication ID for the current user
[self setCurrentUserID:user.entityID];


// If the user was authenticated automatically
if (!details) {
[BHookNotification notificationDidAuthenticate:user type:bHook_AuthenticationTypeCached];
Expand Down
Expand Up @@ -13,8 +13,12 @@
@implementation BFirebaseEventHandler

-(void) currentUserOn: (NSString *) entityID {

id<PUser> user = [BChatSDK.db fetchEntityWithID:entityID withType:bUserEntity];

if (!user.entityID) {
NSLog(@"");
}

[BHookNotification notificationUserOn:user];

Expand Down
3 changes: 2 additions & 1 deletion ChatSDKUI/Classes/Components/Chat View/BTextInputView.m
Expand Up @@ -182,7 +182,8 @@ -(void) updateInterfaceForReachabilityStateChange {
_optionsButton.enabled = connected;

if (BChatSDK.config.disableSendButtonWhenDisconnected) {
connected = BChatSDK.core.connectionStatus == bConnectionStatusConnected;
bConnectionStatus status = BChatSDK.core.connectionStatus;
connected = status == bConnectionStatusConnected || status == bConnectionStatusNone;
_sendButton.enabled = connected;
_optionsButton.enabled = connected;
}
Expand Down
4 changes: 4 additions & 0 deletions ChatSDKUI/Classes/Swift/Views/ReconnectingView.swift
Expand Up @@ -88,6 +88,7 @@ import KeepLayout
// self.isHidden = status == bConnectionStatusConnected

self?.label?.isHidden = connStatus == bConnectionStatusNone
self?.imageView?.isHidden = connStatus == bConnectionStatusNone

if connStatus == bConnectionStatusConnecting {
// self.label?.text = Bundle.t(bConnecting)
Expand All @@ -104,7 +105,10 @@ import KeepLayout
self?.label?.text = Bundle.t(bOnline)
self?.stopBlink()
self?.imageView?.image = Bundle.uiImageNamed("icn_20_connected")
} else {
self?.stopBlink()
}

self?.label?.keepWidth.equal = self?.label?.intrinsicContentSize.width ?? 130
} else {
self?.isHidden = true
Expand Down

0 comments on commit 52e58a1

Please sign in to comment.