From 41caff1ebbafa66cd620cd0546be7ff82b23c19e Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 20 May 2016 14:44:18 +0200 Subject: [PATCH] Handle missing VoIP better (#323): Do not show expired call invites when resuming the app --- Vector/AppDelegate.m | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index 033026b84..d4311fb71 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -1837,6 +1837,14 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt [noCallSupportAlert dismiss:NO]; } + MXCallInviteEventContent *callInviteEventContent = [MXCallInviteEventContent modelFromJSON:event.content]; + + // Sanity and invite expiration checks + if (!callInviteEventContent || event.age >= callInviteEventContent.lifetime) + { + return; + } + MXUser *caller = [mxSession userWithUserId:event.sender]; NSString *callerDisplayname = caller.displayname; if (!callerDisplayname.length) @@ -1862,18 +1870,14 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt [noCallSupportAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"reject_call"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { // Reject the call by sending the hangup event - MXCallInviteEventContent *callInviteEventContent = [MXCallInviteEventContent modelFromJSON:event.content]; - if (callInviteEventContent) - { - NSDictionary *content = @{ - @"call_id": callInviteEventContent.callId, - @"version": @(0) - }; + NSDictionary *content = @{ + @"call_id": callInviteEventContent.callId, + @"version": @(0) + }; - [mxSession.matrixRestClient sendEventToRoom:event.roomId eventType:kMXEventTypeStringCallHangup content:content success:nil failure:^(NSError *error) { - NSLog(@"[AppDelegate] enableNoVoIPOnMatrixSession: ERROR: Cannot send m.call.hangup event. Error: %@", error); - }]; - } + [mxSession.matrixRestClient sendEventToRoom:event.roomId eventType:kMXEventTypeStringCallHangup content:content success:nil failure:^(NSError *error) { + NSLog(@"[AppDelegate] enableNoVoIPOnMatrixSession: ERROR: Cannot send m.call.hangup event. Error: %@", error); + }]; __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf->noCallSupportAlert = nil;