Skip to content

Commit

Permalink
Fixing crash on responding to phone call.
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericJacobs committed Jun 19, 2015
1 parent 7acd8ff commit 2fc2070
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
14 changes: 12 additions & 2 deletions Signal/src/contact/ContactsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (Contact *)contactForRecord:(ABRecordRef)record {
}

-(Contact*)latestContactForPhoneNumber:(PhoneNumber *)phoneNumber {
NSArray *allContacts = latestContactsById.allValues;
NSArray *allContacts = [self allContacts];

ContactSearchBlock searchBlock = ^BOOL(Contact *contact, NSUInteger idx, BOOL *stop) {
for (PhoneNumber *number in contact.parsedPhoneNumbers) {
Expand Down Expand Up @@ -336,7 +336,17 @@ -(Contact *)latestContactWithRecordId:(ABRecordID)recordId {
}

- (NSArray*)allContacts {
return [latestContactsById allValues];
NSMutableArray *allContacts = [NSMutableArray array];

for (NSString *key in latestContactsById.allKeys){
Contact *contact = [latestContactsById objectForKey:key];

if ([contact isKindOfClass:[Contact class]]) {
[allContacts addObject:contact];
}
}
return allContacts;

}

- (NSArray*)recordsForContacts:(NSArray*) contacts{
Expand Down
18 changes: 15 additions & 3 deletions Signal/src/phone/signaling/SignalUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ -(bool) isKeepAlive {
}

-(bool) isRingingForSession:(int64_t)targetSessionId {
return [self.method isEqualToString:@"RING"] && [@(targetSessionId) isEqualToNumber:self.tryGetSessionId];
NSNumber *sessionId = self.tryGetSessionId;
BOOL isMethod = [self.method isEqualToString:@"RING"];
BOOL isSession = sessionId?[@(targetSessionId) isEqualToNumber:sessionId]:NO;

return isMethod&&isSession;
}

-(bool) isHangupForSession:(int64_t)targetSessionId {
return [self.method isEqualToString:@"DELETE"] && self.tryGetSessionId?[@(targetSessionId) isEqualToNumber:self.tryGetSessionId]:NO;
NSNumber *sessionId = self.tryGetSessionId;
BOOL isMethod = [self.method isEqualToString:@"DELETE"];
BOOL isSession = sessionId?[@(targetSessionId) isEqualToNumber:sessionId]:NO;

return isMethod&&isSession;
}

-(bool) isBusyForSession:(int64_t)targetSessionId {
return [self.method isEqualToString:@"BUSY"] && [@(targetSessionId) isEqualToNumber:self.tryGetSessionId];
NSNumber *sessionId = self.tryGetSessionId;
BOOL isMethod = [self.method isEqualToString:@"BUSY"];
BOOL isSession = sessionId?[@(targetSessionId) isEqualToNumber:sessionId]:NO;

return isMethod&&isSession;
}

+(HttpRequest*) httpRequestToOpenPortWithSessionId:(int64_t)sessionId {
Expand Down
4 changes: 3 additions & 1 deletion Signal/src/textsecure/Messages/TSMessagesManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ - (void)notifyUserForCall:(TSCall*)call inThread:(TSThread*)thread {
TSContactThread *cThread = (TSContactThread*)thread;

if (call.callType == RPRecentCallTypeMissed) {
[[UIApplication sharedApplication] cancelLocalNotification:notif];
if (notif) {
[[UIApplication sharedApplication] cancelLocalNotification:notif];
}

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.category = Signal_CallBack_Category;
Expand Down
5 changes: 5 additions & 0 deletions Signal/src/view controllers/MessagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,11 @@ -(NSAttributedString*)collectionView:(JSQMessagesCollectionView *)collectionView
if([self.thread isKindOfClass:[TSGroupThread class]]) {
NSString *name = [[Environment getCurrent].contactsManager nameStringForPhoneIdentifier:msg.senderId];
name = name ? name : msg.senderId;

if (!name) {
name = @"";
}

NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:name];
[attrStr appendAttributedString:[NSAttributedString attributedStringWithAttachment:textAttachment]];

Expand Down

1 comment on commit 2fc2070

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $8.07USD for this commit.

Please sign in to comment.