2014-07-10 16:11:09 +02:00
|
|
|
#import "TGApplication.h"
|
|
|
|
|
|
|
|
#import "TGAppDelegate.h"
|
|
|
|
#import "TGViewController.h"
|
|
|
|
|
|
|
|
#import "TGHacks.h"
|
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
#import "TGStringUtils.h"
|
|
|
|
|
|
|
|
#import <SafariServices/SafariServices.h>
|
|
|
|
|
2014-07-10 16:11:09 +02:00
|
|
|
@interface TGApplication ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TGApplication
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
- (NSString *)telegramMeLinkFromText:(NSString *)text startPrivatePayload:(__autoreleasing NSString **)startPrivatePayload startGroupPayload:(__autoreleasing NSString **)startGroupPayload
|
|
|
|
{
|
|
|
|
NSString *pattern = @"https?:\\/\\/telegram\\.me\\/([a-zA-Z0-9_]+)(\\?.*)?";
|
|
|
|
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:NULL];
|
|
|
|
NSTextCheckingResult *match = [regex firstMatchInString:text options:0 range:NSMakeRange(0, [text length])];
|
|
|
|
if (match != nil)
|
|
|
|
{
|
|
|
|
NSString *arguments = ([match numberOfRanges] >= 2 && [match rangeAtIndex:2].location != NSNotFound) ? [[text substringWithRange:[match rangeAtIndex:2]] substringFromIndex:1] : nil;
|
|
|
|
if (arguments.length != 0)
|
|
|
|
{
|
|
|
|
NSDictionary *dict = [TGStringUtils argumentDictionaryInUrlString:arguments];
|
|
|
|
if (dict.count == 1 && (dict[@"start"] != nil || dict[@"startgroup"]))
|
|
|
|
{
|
|
|
|
if (startPrivatePayload)
|
|
|
|
*startPrivatePayload = dict[@"start"];
|
|
|
|
if (startGroupPayload)
|
|
|
|
*startGroupPayload = dict[@"startgroup"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return [text substringWithRange:[match rangeAtIndex:1]];
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)openURL:(NSURL *)url forceNative:(BOOL)__unused forceNative
|
2014-07-10 16:11:09 +02:00
|
|
|
{
|
2015-10-01 18:19:52 +02:00
|
|
|
NSString *rawAbsoluteString = url.absoluteString;
|
|
|
|
NSString *absolutePrefixString = [url.absoluteString lowercaseString];
|
|
|
|
if ([absolutePrefixString hasPrefix:@"tel:"] || [absolutePrefixString hasPrefix:@"facetime:"])
|
2014-07-10 16:11:09 +02:00
|
|
|
{
|
|
|
|
[TGAppDelegateInstance performPhoneCall:url];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
if ([absolutePrefixString hasPrefix:@"http://telegram.me/addstickers/"])
|
|
|
|
{
|
|
|
|
NSString *stickerPackHash = [rawAbsoluteString substringFromIndex:@"http://telegram.me/addstickers/".length];
|
|
|
|
NSString *internalUrl = [[NSString alloc] initWithFormat:@"tg://addstickers?set=%@", stickerPackHash];
|
|
|
|
[(TGAppDelegate *)self.delegate handleOpenDocument:[NSURL URLWithString:internalUrl] animated:true];
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-10 16:11:09 +02:00
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
if ([absolutePrefixString hasPrefix:@"https://telegram.me/addstickers/"])
|
|
|
|
{
|
|
|
|
NSString *stickerPackHash = [rawAbsoluteString substringFromIndex:@"https://telegram.me/addstickers/".length];
|
|
|
|
NSString *internalUrl = [[NSString alloc] initWithFormat:@"tg://addstickers?set=%@", stickerPackHash];
|
|
|
|
[(TGAppDelegate *)self.delegate handleOpenDocument:[NSURL URLWithString:internalUrl] animated:true];
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-10 16:11:09 +02:00
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
if ([absolutePrefixString hasPrefix:@"http://telegram.me/joinchat/"])
|
|
|
|
{
|
|
|
|
NSString *groupHash = [rawAbsoluteString substringFromIndex:@"http://telegram.me/joinchat/".length];
|
|
|
|
NSString *internalUrl = [[NSString alloc] initWithFormat:@"tg://join?invite=%@", groupHash];
|
|
|
|
[(TGAppDelegate *)self.delegate handleOpenDocument:[NSURL URLWithString:internalUrl] animated:true];
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-10 16:11:09 +02:00
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
if ([absolutePrefixString hasPrefix:@"https://telegram.me/joinchat/"])
|
2014-07-10 16:11:09 +02:00
|
|
|
{
|
2015-10-01 18:19:52 +02:00
|
|
|
NSString *groupHash = [rawAbsoluteString substringFromIndex:@"https://telegram.me/joinchat/".length];
|
|
|
|
NSString *internalUrl = [[NSString alloc] initWithFormat:@"tg://join?invite=%@", groupHash];
|
|
|
|
[(TGAppDelegate *)self.delegate handleOpenDocument:[NSURL URLWithString:internalUrl] animated:true];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *startPrivatePayload = nil;
|
|
|
|
NSString *startGroupPayload = nil;
|
|
|
|
NSString *telegramMeLink = [self telegramMeLinkFromText:rawAbsoluteString startPrivatePayload:&startPrivatePayload startGroupPayload:&startGroupPayload];
|
|
|
|
if (telegramMeLink.length != 0)
|
|
|
|
{
|
|
|
|
NSMutableString *internalUrl = [[NSMutableString alloc] initWithFormat:@"tg://resolve?domain=%@", telegramMeLink];
|
|
|
|
if (startPrivatePayload.length != 0 || startGroupPayload.length != 0)
|
|
|
|
{
|
|
|
|
if (startPrivatePayload.length != 0)
|
|
|
|
[internalUrl appendFormat:@"&start=%@", startPrivatePayload];
|
|
|
|
if (startGroupPayload.length != 0)
|
|
|
|
[internalUrl appendFormat:@"&startgroup=%@", startGroupPayload];
|
|
|
|
}
|
|
|
|
[(TGAppDelegate *)self.delegate handleOpenDocument:[NSURL URLWithString:internalUrl] animated:true];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iosMajorVersion() >= 9 && ([url.scheme isEqual:@"http"] || [url.scheme isEqual:@"https"])) {
|
|
|
|
SFSafariViewController *controller = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:false];
|
|
|
|
[TGAppDelegateInstance.window.rootViewController presentViewController:controller animated:true completion:nil];
|
2014-07-10 16:11:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-01 18:19:52 +02:00
|
|
|
return [super openURL:url];
|
2014-07-10 16:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)openURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
return [self openURL:url forceNative:false];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle
|
|
|
|
{
|
|
|
|
[self setStatusBarStyle:statusBarStyle animated:false];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStatusBarStyle:(UIStatusBarStyle)__unused statusBarStyle animated:(BOOL)__unused animated
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStatusBarHidden:(BOOL)statusBarHidden
|
|
|
|
{
|
|
|
|
[self setStatusBarHidden:statusBarHidden withAnimation:UIStatusBarAnimationNone];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
|
|
|
|
{
|
|
|
|
if (_processStatusBarHiddenRequests)
|
|
|
|
{
|
|
|
|
/*if (animation != UIStatusBarAnimationNone)
|
|
|
|
{
|
|
|
|
[TGHacks animateApplicationStatusBarAppearance:hidden ? TGStatusBarAppearanceAnimationSlideUp : TGStatusBarAppearanceAnimationSlideUp duration:0.3 completion:^
|
|
|
|
{
|
|
|
|
if (hidden)
|
|
|
|
[TGHacks setApplicationStatusBarAlpha:0.0f];
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (!hidden)
|
|
|
|
[TGHacks setApplicationStatusBarAlpha:1.0f];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[TGHacks setApplicationStatusBarAlpha:hidden ? 0.0f : 1.0f];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
[self forceSetStatusBarHidden:hidden withAnimation:animation];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)forceSetStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super setStatusBarStyle:statusBarStyle animated:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)forceSetStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
|
|
|
|
{
|
|
|
|
[super setStatusBarHidden:hidden withAnimation:animation];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|