Remove push functions from OCTTox
This commit is contained in:
parent
42f9650515
commit
1f1963d135
@ -69,169 +69,6 @@
|
|||||||
[self.dataSource.managerGetNotificationCenter postNotificationName:kOCTScheduleFileTransferCleanupNotification object:nil];
|
[self.dataSource.managerGetNotificationCenter postNotificationName:kOCTScheduleFileTransferCleanupNotification object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendOwnPush
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendMessagePushToChat:(OCTChat *)chat
|
|
||||||
{
|
|
||||||
NSParameterAssert(chat);
|
|
||||||
NSLog(@"PUSH:sendMessagePushToChat");
|
|
||||||
__weak OCTSubmanagerChatsImpl *weakSelf = self;
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
__strong OCTSubmanagerChatsImpl *strongSelf = weakSelf;
|
|
||||||
OCTRealmManager *realmManager = [strongSelf.dataSource managerGetRealmManager];
|
|
||||||
|
|
||||||
OCTFriend *friend = [chat.friends firstObject];
|
|
||||||
__block NSString *friend_pushToken = friend.pushToken;
|
|
||||||
|
|
||||||
if (friend_pushToken == nil)
|
|
||||||
{
|
|
||||||
NSLog(@"sendMessagePushToChat:Friend has No Pushtoken");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// HINT: only select outgoing messages (senderUniqueIdentifier == NULL)
|
|
||||||
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chatUniqueIdentifier == %@ AND messageText.isDelivered == 0 AND messageText.sentPush == 0 AND senderUniqueIdentifier == nil", chat.uniqueIdentifier];
|
|
||||||
|
|
||||||
RLMResults *results = [realmManager objectsWithClass:[OCTMessageAbstract class] predicate:predicate];
|
|
||||||
OCTMessageAbstract *message_found = [results firstObject];
|
|
||||||
if (message_found) {
|
|
||||||
|
|
||||||
[realmManager updateObject:message_found withBlock:^(OCTMessageAbstract *theMessage) {
|
|
||||||
theMessage.messageText.sentPush = YES;
|
|
||||||
}];
|
|
||||||
triggerPush(friend_pushToken, message_found.messageText.msgv3HashHex, strongSelf, chat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerPush(NSString *used_pushToken,
|
|
||||||
NSString *msgv3HashHex,
|
|
||||||
OCTSubmanagerChatsImpl *strongSelf,
|
|
||||||
OCTChat *chat)
|
|
||||||
{
|
|
||||||
// HINT: call push token (URL) here
|
|
||||||
// best in a background thread
|
|
||||||
//
|
|
||||||
NSLog(@"PUSH:triggerPush");
|
|
||||||
if ((used_pushToken != nil) && (used_pushToken.length > 5)) {
|
|
||||||
|
|
||||||
// check push url starts with allowed values
|
|
||||||
if (
|
|
||||||
([used_pushToken hasPrefix:@"https://tox.zoff.xyz/toxfcm/fcm.php?id="])
|
|
||||||
||
|
|
||||||
([used_pushToken hasPrefix:@"https://gotify1.unifiedpush.org/UP?token="])
|
|
||||||
||
|
|
||||||
([used_pushToken hasPrefix:@"https://ntfy.sh/"])
|
|
||||||
) {
|
|
||||||
|
|
||||||
NSString *strong_pushToken = used_pushToken;
|
|
||||||
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
||||||
// NSString *strong_pushToken = weak_pushToken;
|
|
||||||
int PUSH_URL_TRIGGER_AGAIN_MAX_COUNT = 8;
|
|
||||||
int PUSH_URL_TRIGGER_AGAIN_SECONDS = 21;
|
|
||||||
|
|
||||||
for (int i=0; i<(PUSH_URL_TRIGGER_AGAIN_MAX_COUNT + 1); i++)
|
|
||||||
{
|
|
||||||
if (chat == nil) {
|
|
||||||
__block UIApplicationState as = UIApplicationStateBackground;
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
||||||
as =[[UIApplication sharedApplication] applicationState];
|
|
||||||
});
|
|
||||||
|
|
||||||
if (as == UIApplicationStateActive) {
|
|
||||||
NSLog(@"PUSH:fg->break:1");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:strong_pushToken]];
|
|
||||||
NSString *userUpdate = [NSString stringWithFormat:@"&text=1", nil];
|
|
||||||
[urlRequest setHTTPMethod:@"POST"];
|
|
||||||
|
|
||||||
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
|
|
||||||
[urlRequest setHTTPBody:data1];
|
|
||||||
[urlRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
|
|
||||||
[urlRequest setTimeoutInterval:10]; // HINT: 10 seconds
|
|
||||||
NSString *userAgent = @"Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0";
|
|
||||||
[urlRequest setValue:userAgent forHTTPHeaderField:@"User-Agent"];
|
|
||||||
[urlRequest setValue:@"no-cache, no-store, must-revalidate" forHTTPHeaderField:@"Cache-Control"];
|
|
||||||
[urlRequest setValue:@"no-cache" forHTTPHeaderField:@"Pragma"];
|
|
||||||
[urlRequest setValue:@"0" forHTTPHeaderField:@"Expires"];
|
|
||||||
|
|
||||||
// NSLog(@"PUSH:for msgv3HashHex=%@", msgv3HashHex);
|
|
||||||
// NSLog(@"PUSH:for friend.pushToken=%@", strong_pushToken);
|
|
||||||
|
|
||||||
NSURLSession *session = [NSURLSession sharedSession];
|
|
||||||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
||||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
|
||||||
if ((httpResponse.statusCode < 300) && (httpResponse.statusCode > 199)) {
|
|
||||||
NSLog(@"calling PUSH URL:CALL:SUCCESS");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"calling PUSH URL:-ERROR:01-");
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
NSLog(@"calling PUSH URL:CALL:start");
|
|
||||||
[dataTask resume];
|
|
||||||
if (i < PUSH_URL_TRIGGER_AGAIN_MAX_COUNT)
|
|
||||||
{
|
|
||||||
NSLog(@"calling PUSH URL:WAIT:start");
|
|
||||||
[NSThread sleepForTimeInterval:PUSH_URL_TRIGGER_AGAIN_SECONDS];
|
|
||||||
NSLog(@"calling PUSH URL:WAIT:done");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chat == nil) {
|
|
||||||
__block UIApplicationState as = UIApplicationStateBackground;
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
||||||
as =[[UIApplication sharedApplication] applicationState];
|
|
||||||
});
|
|
||||||
|
|
||||||
if (as == UIApplicationStateActive) {
|
|
||||||
NSLog(@"PUSH:fg->break:2");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgv3HashHex != nil)
|
|
||||||
{
|
|
||||||
OCTRealmManager *realmManager = [strongSelf.dataSource managerGetRealmManager];
|
|
||||||
__block BOOL msgIsDelivered = NO;
|
|
||||||
|
|
||||||
NSLog(@"calling PUSH URL:DB check:start");
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
||||||
// HINT: only select outgoing messages (senderUniqueIdentifier == NULL)
|
|
||||||
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chatUniqueIdentifier == %@ AND messageText.msgv3HashHex == %@ AND senderUniqueIdentifier == nil",
|
|
||||||
chat.uniqueIdentifier, msgv3HashHex];
|
|
||||||
RLMResults *results = [realmManager objectsWithClass:[OCTMessageAbstract class] predicate:predicate];
|
|
||||||
OCTMessageAbstract *message_found = [results firstObject];
|
|
||||||
if (message_found) {
|
|
||||||
if (message_found.messageText) {
|
|
||||||
msgIsDelivered = message_found.messageText.isDelivered;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NSLog(@"calling PUSH URL:DB check:end_real");
|
|
||||||
});
|
|
||||||
NSLog(@"calling PUSH URL:DB check:end");
|
|
||||||
|
|
||||||
if (msgIsDelivered == YES) {
|
|
||||||
// OCTLogInfo(@"PUSH:for msgv3HashHex isDelivered=YES");
|
|
||||||
NSLog(@"PUSH:for msgv3HashHex isDelivered=YES");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"unsafe PUSH URL not allowed:-ERROR:02-");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendMessageToChat:(OCTChat *)chat
|
- (void)sendMessageToChat:(OCTChat *)chat
|
||||||
text:(NSString *)text
|
text:(NSString *)text
|
||||||
type:(OCTToxMessageType)type
|
type:(OCTToxMessageType)type
|
||||||
@ -298,8 +135,6 @@ triggerPush(NSString *used_pushToken,
|
|||||||
|
|
||||||
if ((error.code == OCTToxErrorFriendSendMessageFriendNotConnected) &&
|
if ((error.code == OCTToxErrorFriendSendMessageFriendNotConnected) &&
|
||||||
[strongSelf.dataSource managerUseFauxOfflineMessaging]) {
|
[strongSelf.dataSource managerUseFauxOfflineMessaging]) {
|
||||||
NSString *friend_pushToken = friend.pushToken;
|
|
||||||
triggerPush(friend_pushToken, msgv3HashHex, strongSelf, chat);
|
|
||||||
successBlock(-1);
|
successBlock(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -57,18 +57,6 @@
|
|||||||
successBlock:(void (^)(OCTMessageAbstract *message))userSuccessBlock
|
successBlock:(void (^)(OCTMessageAbstract *message))userSuccessBlock
|
||||||
failureBlock:(void (^)(NSError *error))userFailureBlock;
|
failureBlock:(void (^)(NSError *error))userFailureBlock;
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger PUSH Message to yourself
|
|
||||||
*/
|
|
||||||
- (void)sendOwnPush;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger PUSH Message to Friend if the Text Message was sent in a period where the friend
|
|
||||||
* was online to us, but the friend was in fact already offline.
|
|
||||||
* so no message was sent AND not PUSH was triggered.
|
|
||||||
*/
|
|
||||||
- (void)sendMessagePushToChat:(OCTChat *)chat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set our typing status for a chat. You are responsible for turning it on or off.
|
* Set our typing status for a chat. You are responsible for turning it on or off.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user