Skip to content

Commit 8aad73c

Browse files
Update XMPP server list
1 parent bf7657c commit 8aad73c

File tree

13 files changed

+140
-6
lines changed

13 files changed

+140
-6
lines changed

ChatSecure/Classes/Model/OTRXMPPServerInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ NS_ASSUME_NONNULL_BEGIN
4848
/** Defaults to 5222 */
4949
@property (nonatomic, readonly) in_port_t portNumber;
5050
@property (nonatomic, strong, readonly, nullable) NSString *certificate;
51+
/** If the server has a CAPTCHA challenge when registering. We currently don't support CAPTCHAs, so those results will be filtered out of . */
52+
@property (nonatomic, readonly) BOOL requiresCaptcha;
5153

5254
/** Return image if loaded from local resource bundle */
5355
- (nullable UIImage*) logoImage;
@@ -58,8 +60,11 @@ NS_ASSUME_NONNULL_BEGIN
5860
/** loaded from bundle */
5961
@property (class, readonly, nullable) NSArray<OTRXMPPServerInfo*> *defaultServerList;
6062

61-
//+ (nullable NSArray<OTRXMPPServerInfo*> *)defaultServerList;
63+
/** Returns all servers (that don't require CAPTCHAs) */
6264
+ (nullable NSArray<OTRXMPPServerInfo*> *)serverListFromJSONData:(NSData*)jsonData;
6365

66+
/** Returns servers with optional CAPTCHA filtering. filterRequiresCaptcha=YES will remove results. */
67+
+ (nullable NSArray<OTRXMPPServerInfo*> *)serverListFromJSONData:(NSData*)jsonData filterRequiresCaptcha:(BOOL)filterRequiresCaptcha;
68+
6469
@end
6570
NS_ASSUME_NONNULL_END

ChatSecure/Classes/Model/OTRXMPPServerInfo.m

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
@implementation OTRXMPPServerInfo
3232
@synthesize portNumber = _portNumber;
33+
@synthesize websiteURL = _websiteURL;
34+
@synthesize twitterURL = _twitterURL;
35+
@synthesize privacyPolicyURL = _privacyPolicyURL;
3336

3437
- (instancetype) initWithDomain:(NSString*)domain {
3538
if (self = [super init]) {
@@ -51,7 +54,8 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
5154
@"server": @"server",
5255
@"onion": @"onion",
5356
@"portNumber": @"port",
54-
@"certificate": @"certificate"
57+
@"certificate": @"certificate",
58+
@"requiresCaptcha": @"captcha"
5559
};
5660
}
5761

@@ -68,16 +72,21 @@ + (NSValueTransformer *)privacyPolicyURLJSONTransformer {
6872
}
6973

7074
- (UIImage*) logoImage {
75+
UIImage *defaultImage = [UIImage imageNamed:@"xmpp" inBundle:[OTRAssets resourcesBundle] compatibleWithTraitCollection:nil]; // load default image
76+
NSParameterAssert(defaultImage);
7177
NSBundle *bundle = [[self class] serverBundle];
7278
NSArray *pathComponents = [self.logo pathComponents];
79+
if (pathComponents.count < 2) {
80+
return defaultImage;
81+
}
7382
NSString *folder = pathComponents[0];
7483
NSString *fileName = pathComponents[1];
7584
NSString *extension = [fileName pathExtension];
7685
NSString *resource = [fileName stringByDeletingPathExtension];
7786
NSString *path = [bundle pathForResource:resource ofType:extension inDirectory:folder];
7887
UIImage *image = [UIImage imageWithContentsOfFile:path];
7988
if (!image) {
80-
image = [UIImage imageNamed:@"xmpp" inBundle:[OTRAssets resourcesBundle] compatibleWithTraitCollection:nil];
89+
image = defaultImage;
8190
}
8291
NSParameterAssert(image);
8392
return image;
@@ -90,6 +99,27 @@ - (in_port_t) portNumber {
9099
return 5222;
91100
}
92101

102+
- (NSURL*) websiteURL {
103+
if (_websiteURL.absoluteString.length == 0) {
104+
return nil;
105+
}
106+
return _websiteURL;
107+
}
108+
109+
- (NSURL*) twitterURL {
110+
if (_twitterURL.absoluteString.length == 0) {
111+
return nil;
112+
}
113+
return _twitterURL;
114+
}
115+
116+
- (NSURL*) privacyPolicyURL {
117+
if (_privacyPolicyURL.absoluteString.length == 0) {
118+
return nil;
119+
}
120+
return _privacyPolicyURL;
121+
}
122+
93123
+ (NSBundle*)serverBundle {
94124
NSString *folderName = @"xmpp-server-list";
95125
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:folderName];
@@ -112,7 +142,11 @@ + (NSArray *)defaultServerList
112142
return _defaultServerList;
113143
}
114144

115-
+ (NSArray *)serverListFromJSONData:(NSData*)jsonData {
145+
+ (nullable NSArray<OTRXMPPServerInfo*> *)serverListFromJSONData:(NSData*)jsonData {
146+
return [self serverListFromJSONData:jsonData filterRequiresCaptcha:YES];
147+
}
148+
149+
+ (nullable NSArray<OTRXMPPServerInfo*> *)serverListFromJSONData:(NSData*)jsonData filterRequiresCaptcha:(BOOL)filterRequiresCaptcha {
116150
NSParameterAssert(jsonData != nil);
117151
NSError *error = nil;
118152
NSDictionary *root = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
@@ -128,6 +162,10 @@ + (NSArray *)serverListFromJSONData:(NSData*)jsonData {
128162
NSLog(@"Error parsing server list JSON: %@", error);
129163
return nil;
130164
}
165+
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(OTRXMPPServerInfo *evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
166+
return evaluatedObject.requiresCaptcha != filterRequiresCaptcha;
167+
}];
168+
servers = [servers filteredArrayUsingPredicate:predicate];
131169
return servers;
132170
}
133171

ChatSecure/Classes/Views/Cells/XMPPServerInfoCell.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ - (void) setServerInfo:(OTRXMPPServerInfo*)serverInfo parentViewController:(UIVi
5959
[serverInfo.privacyPolicyURL promptToShowURLFromViewController:parentViewController sender:sender];
6060
}];
6161
[self setOnionAction:^(XMPPServerInfoCell * _Nonnull cell, id _Nonnull sender) {
62-
// TODO: show Tor info
62+
NSURL *url = [NSURL URLWithString:@"https://en.wikipedia.org/wiki/.onion"];
63+
[url promptToShowURLFromViewController:parentViewController sender:sender];
6364
}];
6465
[self setTwitterAction:^(XMPPServerInfoCell * _Nonnull cell, id _Nonnull sender) {
6566
[serverInfo.twitterURL promptToShowURLFromViewController:parentViewController sender:sender];
1.41 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "BE.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "DE.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
1.4 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "FR.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
1.53 KB
Loading

0 commit comments

Comments
 (0)