Skip to content

Commit

Permalink
Merge pull request #388 from 64characters/call-ended-notifications
Browse files Browse the repository at this point in the history
‘Call ended’ notifications
  • Loading branch information
eofster committed Oct 6, 2017
2 parents 06fff48 + 9a8143b commit 58fa5d7
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions Telephone/CallController.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,33 @@ - (BOOL)shouldShowViewController:(NSViewController *)viewController {
return ![self.callInfoView isEqual:viewController.view];
}

- (void)showUserNotification {
NSString *notificationTitle;
if ([[self nameFromAddressBook] length] > 0) {
notificationTitle = [self nameFromAddressBook];
} else if ([[self enteredCallDestination] length] > 0) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
AKTelephoneNumberFormatter *telephoneNumberFormatter = [[AKTelephoneNumberFormatter alloc] init];
if ([[self enteredCallDestination] ak_isTelephoneNumber] && [defaults boolForKey:kFormatTelephoneNumbers]) {
notificationTitle = [telephoneNumberFormatter stringForObjectValue:[self enteredCallDestination]];
} else {
notificationTitle = [self enteredCallDestination];
}
} else {
AKSIPURIFormatter *SIPURIFormatter = [[AKSIPURIFormatter alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[SIPURIFormatter setFormatsTelephoneNumbers:[defaults boolForKey:kFormatTelephoneNumbers]];
[SIPURIFormatter setTelephoneNumberFormatterSplitsLastFourDigits:
[defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
notificationTitle = [SIPURIFormatter stringForObjectValue:[[self call] remoteURI]];
}
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
userNotification.title = notificationTitle;
userNotification.informativeText = self.status;
userNotification.userInfo = @{kUserNotificationCallControllerIdentifierKey: self.identifier};
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
}


#pragma mark -
#pragma mark NSWindow delegate methods
Expand Down Expand Up @@ -511,37 +538,8 @@ - (void)SIPCallDidDisconnect:(NSNotification *)notification {

[self.musicPlayer resume];

// Show user notification.

NSString *notificationTitle;

if ([[self nameFromAddressBook] length] > 0) {
notificationTitle = [self nameFromAddressBook];

} else if ([[self enteredCallDestination] length] > 0) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
AKTelephoneNumberFormatter *telephoneNumberFormatter = [[AKTelephoneNumberFormatter alloc] init];

if ([[self enteredCallDestination] ak_isTelephoneNumber] && [defaults boolForKey:kFormatTelephoneNumbers]) {
notificationTitle = [telephoneNumberFormatter stringForObjectValue:[self enteredCallDestination]];
} else {
notificationTitle = [self enteredCallDestination];
}
} else {
AKSIPURIFormatter *SIPURIFormatter = [[AKSIPURIFormatter alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[SIPURIFormatter setFormatsTelephoneNumbers:[defaults boolForKey:kFormatTelephoneNumbers]];
[SIPURIFormatter setTelephoneNumberFormatterSplitsLastFourDigits:
[defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
notificationTitle = [SIPURIFormatter stringForObjectValue:[[self call] remoteURI]];
}

if (![NSApp isActive]) {
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
userNotification.title = notificationTitle;
userNotification.informativeText = self.status;
userNotification.userInfo = @{kUserNotificationCallControllerIdentifierKey: self.identifier};
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
if (![NSApp isActive] && ![self isCallUnhandled]) {
[self showUserNotification];
}

// Optionally close disconnected call window.
Expand Down

0 comments on commit 58fa5d7

Please sign in to comment.