Skip to content

Commit

Permalink
use api_host from login/signup/set_shard
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Feb 3, 2021
1 parent c32ecd9 commit a9829ec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
2 changes: 0 additions & 2 deletions IRCCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@
2223C6A71768D7150032544B /* ImageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageViewController.h; sourceTree = "<group>"; };
2223C6A81768D7150032544B /* ImageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageViewController.m; sourceTree = "<group>"; };
2223C6B51768F4500032544B /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
222AA74725C351EF00E678DE /* IRCCloud copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "IRCCloud copy-Info.plist"; path = "/Users/sam/Projects/irccloud-ios/IRCCloud copy-Info.plist"; sourceTree = "<absolute>"; };
222C80B41E48ABB200A243E7 /* ImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCache.h; sourceTree = "<group>"; };
222C80B51E48ABB200A243E7 /* ImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCache.m; sourceTree = "<group>"; };
222C80BA1E4A0BB600A243E7 /* SBJson5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJson5.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1962,7 +1961,6 @@
228A056E16D3DABA0029769C /* Frameworks */,
228A056D16D3DABA0029769C /* Products */,
7CF0BE4739CE6912111DBBD1 /* Pods */,
222AA74725C351EF00E678DE /* IRCCloud copy-Info.plist */,
);
sourceTree = "<group>";
};
Expand Down
13 changes: 5 additions & 8 deletions IRCCloud/Classes/LoginSplashViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ -(void)_loginWithAccessLink {
if([result objectForKey:@"websocket_path"])
IRCCLOUD_PATH = [result objectForKey:@"websocket_path"];
[NetworkConnection sharedInstance].session = [result objectForKey:@"session"];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_PATH forKey:@"path"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([result objectForKey:@"api_host"])
[[NetworkConnection sharedInstance] updateAPIHost:[result objectForKey:@"api_host"]];
#ifdef ENTERPRISE
NSUserDefaults *d = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.irccloud.enterprise.share"];
#else
Expand Down Expand Up @@ -742,22 +742,19 @@ -(IBAction)loginButtonPressed:(id)sender {
});
return;
}
IRCCLOUD_HOST = [config objectForKey:@"api_host"];
[self _stripIRCCloudHost];
[[NetworkConnection sharedInstance] updateAPIHost:[config objectForKey:@"api_host"]];

[[NetworkConnection sharedInstance] requestAuthTokenWithHandler:^(IRCCloudJSONObject *result) {
if([[result objectForKey:@"success"] intValue] == 1) {
IRCCloudAPIResultHandler handler = ^(IRCCloudJSONObject *result) {
if([[result objectForKey:@"success"] intValue] == 1) {
if([result objectForKey:@"websocket_host"])
IRCCLOUD_HOST = [result objectForKey:@"websocket_host"];
if([result objectForKey:@"websocket_path"])
IRCCLOUD_PATH = [result objectForKey:@"websocket_path"];
[NetworkConnection sharedInstance].session = [result objectForKey:@"session"];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_PATH forKey:@"path"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([result objectForKey:@"api_host"])
[[NetworkConnection sharedInstance] updateAPIHost:[result objectForKey:@"api_host"]];
#ifdef ENTERPRISE
NSUserDefaults *d = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.irccloud.enterprise.share"];
#else
Expand Down
1 change: 1 addition & 0 deletions IRCCloud/Classes/NetworkConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ typedef void (^IRCCloudAPIResultHandler)(IRCCloudJSONObject *result);
-(void)setLastSelectedBID:(int)bid;
-(void)parse:(NSDictionary *)object backlog:(BOOL)backlog;
-(void)sendFeedbackReport:(UIViewController *)delegate;
-(void)updateAPIHost:(NSString *)host;

//WebSocket
-(int)say:(NSString *)message to:(NSString *)to cid:(int)cid handler:(IRCCloudAPIResultHandler)handler;
Expand Down
38 changes: 20 additions & 18 deletions IRCCloud/Classes/NetworkConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ -(id)init {
CLS_LOG(@"oob_include, invalidating BIDs");
[self->_buffers invalidate];
[self->_channels invalidate];
[self fetchOOB:[NSString stringWithFormat:@"https://%@%@", IRCCLOUD_HOST, [object objectForKey:@"url"]]];
[self fetchOOB:[NSString stringWithFormat:@"%@%@", [object objectForKey:@"api_host"], [object objectForKey:@"url"]]];
},
@"oob_timeout": ^(IRCCloudJSONObject *object, BOOL backlog) {
CLS_LOG(@"OOB timed out");
Expand Down Expand Up @@ -631,22 +631,18 @@ -(id)init {
if([p objectForKey:@"time-left"]) {
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"time-left"])
[[NSUserDefaults standardUserDefaults] setObject:[p objectForKey:@"time-left"] forKey:@"time-left"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
}
if([p objectForKey:@"avatars-off"]) {
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"avatars-off"])
[[NSUserDefaults standardUserDefaults] setObject:[p objectForKey:@"avatars-off"] forKey:@"avatars-off"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
}
if([p objectForKey:@"chat-oneline"]) {
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"chat-oneline"])
[[NSUserDefaults standardUserDefaults] setObject:[p objectForKey:@"chat-oneline"] forKey:@"chat-oneline"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
}
if([p objectForKey:@"chat-norealname"]) {
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"chat-norealname"])
[[NSUserDefaults standardUserDefaults] setObject:[p objectForKey:@"chat-norealname"] forKey:@"chat-norealname"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
}
if([[p objectForKey:@"labs"] objectForKey:@"avatars"]) {
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"avatarImages"])
Expand Down Expand Up @@ -1408,6 +1404,21 @@ -(void)requestConfigurationWithHandler:(IRCCloudAPIResultHandler)handler {
}];
}

-(void)updateAPIHost:(NSString *)host {
IRCCLOUD_HOST = host;
if([IRCCLOUD_HOST hasPrefix:@"http://"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringFromIndex:7];
if([IRCCLOUD_HOST hasPrefix:@"https://"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringFromIndex:8];
if([IRCCLOUD_HOST hasSuffix:@"/"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringToIndex:IRCCLOUD_HOST.length - 1];

[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"];
[[NSUserDefaults standardUserDefaults] synchronize];

CLS_LOG(@"API Host: %@", IRCCLOUD_HOST);
}

-(void)_configLoaded {
#ifdef ENTERPRISE
if(![[self->_config objectForKey:@"enterprise"] isKindOfClass:[NSDictionary class]])
Expand All @@ -1419,20 +1430,9 @@ -(void)_configLoaded {
self.pasteURITemplate = [CSURITemplate URITemplateWithString:[self->_config objectForKey:@"pastebin_uri_template"] error:nil];
self.avatarURITemplate = [CSURITemplate URITemplateWithString:[self->_config objectForKey:@"avatar_uri_template"] error:nil];
self.avatarRedirectURITemplate = [CSURITemplate URITemplateWithString:[self->_config objectForKey:@"avatar_redirect_uri_template"] error:nil];

IRCCLOUD_HOST = [self->_config objectForKey:@"api_host"];
if([IRCCLOUD_HOST hasPrefix:@"http://"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringFromIndex:7];
if([IRCCLOUD_HOST hasPrefix:@"https://"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringFromIndex:8];
if([IRCCLOUD_HOST hasSuffix:@"/"])
IRCCLOUD_HOST = [IRCCLOUD_HOST substringToIndex:IRCCLOUD_HOST.length - 1];

[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"];
[[NSUserDefaults standardUserDefaults] synchronize];

[self updateAPIHost:[self->_config objectForKey:@"api_host"]];
}

CLS_LOG(@"API Host: %@", IRCCLOUD_HOST);
}

-(void)propertiesForFile:(NSString *)fileID handler:(IRCCloudAPIResultHandler)handler {
Expand Down Expand Up @@ -2242,6 +2242,8 @@ -(void)parse:(NSDictionary *)dict backlog:(BOOL)backlog {
} else if([[object objectForKey:@"message"] isEqualToString:@"set_shard"]) {
if([object objectForKey:@"websocket_path"])
IRCCLOUD_PATH = [object objectForKey:@"websocket_path"];
if([object objectForKey:@"api_host"])
[self updateAPIHost:[object objectForKey:@"api_host"]];
[self setSession:[object objectForKey:@"cookie"]];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_PATH forKey:@"path"];
[[NSUserDefaults standardUserDefaults] synchronize];
Expand Down
1 change: 0 additions & 1 deletion IRCCloud/Classes/SamlLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ -(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigatio
[NetworkConnection sharedInstance].session = cookie.value;
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"];
[[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_PATH forKey:@"path"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"greeting_3.0"];
[[NSUserDefaults standardUserDefaults] synchronize];
#ifdef ENTERPRISE
NSUserDefaults *d = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.irccloud.enterprise.share"];
Expand Down

0 comments on commit a9829ec

Please sign in to comment.