Handle missing VoIP better (#323): Do not show expired call invites when resuming the app

This commit is contained in:
manuroe
2016-05-20 14:44:18 +02:00
parent 0fd7b9e104
commit 41caff1ebb
+15 -11
View File
@@ -1837,6 +1837,14 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt
[noCallSupportAlert dismiss:NO]; [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]; MXUser *caller = [mxSession userWithUserId:event.sender];
NSString *callerDisplayname = caller.displayname; NSString *callerDisplayname = caller.displayname;
if (!callerDisplayname.length) if (!callerDisplayname.length)
@@ -1862,18 +1870,14 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt
[noCallSupportAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"reject_call"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { [noCallSupportAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"reject_call"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
// Reject the call by sending the hangup event // Reject the call by sending the hangup event
MXCallInviteEventContent *callInviteEventContent = [MXCallInviteEventContent modelFromJSON:event.content]; NSDictionary *content = @{
if (callInviteEventContent) @"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) { [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); NSLog(@"[AppDelegate] enableNoVoIPOnMatrixSession: ERROR: Cannot send m.call.hangup event. Error: %@", error);
}]; }];
}
__strong __typeof(weakSelf)strongSelf = weakSelf; __strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->noCallSupportAlert = nil; strongSelf->noCallSupportAlert = nil;