From 92defb9ca327c7a9e8f8bfa0f1bf2525ca3dd819 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Fri, 4 Jul 2014 10:59:49 +0200 Subject: [PATCH] Null check --- Classes/LinphoneUI/UIChatCell.m | 2 +- Classes/LinphoneUI/UIChatRoomCell.m | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 7fe696aef..55521d1af 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -114,7 +114,7 @@ // Message if(url) { [chatContentLabel setText:@""]; - } else { + } else if (text) { NSString *message = [NSString stringWithUTF8String:text]; // shorten long messages if([message length] > 50) diff --git a/Classes/LinphoneUI/UIChatRoomCell.m b/Classes/LinphoneUI/UIChatRoomCell.m index f2d3f4b74..eea11e183 100644 --- a/Classes/LinphoneUI/UIChatRoomCell.m +++ b/Classes/LinphoneUI/UIChatRoomCell.m @@ -110,9 +110,9 @@ static UIFont *CELL_FONT = nil; [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update chat room cell: null chat"]; return; } - const char*url = linphone_chat_message_get_external_body_url(chat); - const char*text = linphone_chat_message_get_text(chat); - BOOL is_external = url && (strstr(url, "http") == url); + const char* url = linphone_chat_message_get_external_body_url(chat); + const char* text = linphone_chat_message_get_text(chat); + BOOL is_external = url && (strstr(url, "http") == url); NSString* localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat]; @@ -151,14 +151,18 @@ static UIFont *CELL_FONT = nil; } else { // simple text message [messageText setHidden:FALSE]; - /* We need to use an attributed string here so that data detector don't mess - * with the text style. See http://stackoverflow.com/a/20669356 */ - NSAttributedString* attr_text = [[NSAttributedString alloc] - initWithString:[NSString stringWithUTF8String:text] - attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0], - NSForegroundColorAttributeName:[UIColor darkGrayColor]}]; - messageText.attributedText = attr_text; - [attr_text release]; + if (text ){ + /* We need to use an attributed string here so that data detector don't mess + * with the text style. See http://stackoverflow.com/a/20669356 */ + NSAttributedString* attr_text = [[NSAttributedString alloc] + initWithString:[NSString stringWithUTF8String:text] + attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0], + NSForegroundColorAttributeName:[UIColor darkGrayColor]}]; + messageText.attributedText = attr_text; + [attr_text release]; + } else { + messageText.text = @""; + } [messageImageView setImage:nil]; [messageImageView setHidden:TRUE];