Chat: optimize conversation loading time and replace deprecated functions

This commit is contained in:
Gautier Pelloux-Prayer 2015-11-20 14:35:08 +01:00
parent 6cea81b103
commit 4f4adc81db
28 changed files with 73 additions and 81 deletions

View file

@ -393,7 +393,7 @@
</label>
<textField opaque="NO" clipsSubviews="YES" tag="100" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" adjustsFontSizeToFit="NO" minimumFontSize="10" id="YRW-ex-VZy" userLabel="usernameField" customClass="UIAssistantTextField">
<rect key="frame" x="38" y="187" width="299" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<animations/>
<color key="backgroundColor" red="0.88235294119999996" green="0.88235294119999996" blue="0.88235294119999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" label="Username"/>

View file

@ -51,7 +51,7 @@
const MSList *calls = linphone_core_get_calls([LinphoneManager getLc]);
int i = -1;
while (calls) {
if (linphone_call_is_in_conference(calls->data)) {
if (linphone_call_params_get_local_conference_mode(calls->data)) {
i++;
if (i == row)
break;
@ -77,7 +77,7 @@
const MSList *calls = linphone_core_get_calls([LinphoneManager getLc]);
int count = 0;
while (calls) {
if (linphone_call_is_in_conference(calls->data)) {
if (linphone_call_params_get_local_conference_mode(calls->data)) {
count++;
}
calls = calls->next;

View file

@ -89,7 +89,8 @@
if (linphone_call_get_state(call) == LinphoneCallPaused) {
count++;
}
if (linphone_call_is_in_conference(call) && !linphone_core_is_in_conference([LinphoneManager getLc])) {
if (linphone_call_params_get_local_conference_mode(linphone_call_get_current_params(call)) &&
!linphone_core_is_in_conference([LinphoneManager getLc])) {
conference_in_pause = 1;
}
calls = calls->next;

View file

@ -666,7 +666,7 @@ static void hideSpinner(LinphoneCall *call, void *user_data) {
const LinphoneCallParams *remote = linphone_call_get_remote_params(call);
/* remote wants to add video */
if (linphone_core_video_enabled(lc) && !linphone_call_params_video_enabled(current) &&
if (linphone_core_video_display_enabled(lc) && !linphone_call_params_video_enabled(current) &&
linphone_call_params_video_enabled(remote) &&
!linphone_core_get_video_policy(lc)->automatically_accept) {
linphone_core_defer_call_update(lc, call);

View file

@ -44,7 +44,7 @@
}];
// also add current entry, if not listed
NSString *nsuri = filter.lowercaseString;
LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], nsuri.UTF8String);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(NULL, nsuri.UTF8String);
if (addr) {
char *uri = linphone_address_as_string(addr);
nsuri = [NSString stringWithUTF8String:uri];

View file

@ -209,7 +209,7 @@
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]);
return [UIChatBubbleTextCell ViewSizeForMessage:chat withWidth:self.view.frame.size.width].height;
return [UIChatBubbleTextCell ViewHeightForMessage:chat withWidth:self.view.frame.size.width].height;
}

View file

@ -164,7 +164,7 @@ static void chatTable_free_chatrooms(void *data) {
}
[ftdToDelete cancel];
linphone_core_delete_chat_room(linphone_chat_room_get_lc(chatRoom), chatRoom);
linphone_core_delete_chat_room(linphone_chat_room_get_core(chatRoom), chatRoom);
data = ms_list_remove(data, chatRoom);
// will force a call to [self loadData]

View file

@ -271,7 +271,7 @@
if ([lDict objectForKey:(__bridge NSString *)kABPersonInstantMessageServiceKey] == nil) {
/*too bad probably a gtalk number, storing uri*/
NSString *username = [lDict objectForKey:(NSString *)kABPersonInstantMessageUsernameKey];
LinphoneAddress *address = linphone_core_interpret_url([LinphoneManager getLc], [username UTF8String]);
LinphoneAddress *address = linphone_proxy_config_normalize_sip_uri(NULL, [username UTF8String]);
if (address) {
char *uri = linphone_address_as_string_uri_only(address);
NSDictionary *dict2 = @{

View file

@ -124,7 +124,7 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
}
- (void)addCurrentContactContactField:(NSString *)address {
LinphoneAddress *linphoneAddress = linphone_core_interpret_url([LinphoneManager getLc], address.UTF8String);
LinphoneAddress *linphoneAddress = linphone_proxy_config_normalize_sip_uri(NULL, address.UTF8String);
NSString *username =
linphoneAddress ? [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)] : address;

View file

@ -119,7 +119,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[self callUpdate:call state:state];
if (LinphoneManager.runningOnIpad) {
BOOL videoEnabled = linphone_core_video_enabled(lc);
BOOL videoEnabled = linphone_core_video_display_enabled(lc);
BOOL previewPref = [mgr lpConfigBoolForKey:@"preview_preference"];
if (videoEnabled && previewPref) {
@ -222,7 +222,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)coreUpdateEvent:(NSNotification *)notif {
if (LinphoneManager.runningOnIpad) {
LinphoneCore *lc = [LinphoneManager getLc];
if (linphone_core_video_enabled(lc) && linphone_core_video_preview_enabled(lc)) {
if (linphone_core_video_display_enabled(lc) && linphone_core_video_preview_enabled(lc)) {
linphone_core_set_native_preview_window_id(lc, (__bridge void *)(videoPreview));
[backgroundView setHidden:FALSE];
[videoCameraSwitch setHidden:FALSE];

View file

@ -195,7 +195,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
forKey:key];
}
[self setBool:linphone_core_video_enabled(lc) forKey:@"enable_video_preference"];
[self setBool:linphone_core_video_display_enabled(lc) forKey:@"enable_video_preference"];
[self setBool:[LinphoneManager.instance lpConfigBoolForKey:@"auto_answer"]
forKey:@"enable_auto_answer_preference"];
[self setBool:[lm lpConfigBoolForKey:@"advanced_account_preference"] forKey:@"advanced_account_preference"];
@ -588,7 +588,8 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
[self synchronizeAccounts];
bool enableVideo = [self boolForKey:@"enable_video_preference"];
linphone_core_enable_video(lc, enableVideo, enableVideo);
linphone_core_enable_video_capture(lc, enableVideo);
linphone_core_enable_video_display(lc, enableVideo);
bool enableAutoAnswer = [self boolForKey:@"enable_auto_answer_preference"];
[LinphoneManager.instance lpConfigSetBool:enableAutoAnswer forKey:@"auto_answer"];

View file

@ -1282,17 +1282,11 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
#pragma mark - VTable
static LinphoneCoreVTable linphonec_vtable = {
.show = NULL,
.call_state_changed = (LinphoneCoreCallStateChangedCb)linphone_iphone_call_state,
.registration_state_changed = linphone_iphone_registration_state,
.notify_presence_received = NULL,
.new_subscription_requested = NULL,
.auth_info_requested = linphone_iphone_popup_password_request,
.display_status = linphone_iphone_display_status,
.display_message = linphone_iphone_log_user_info,
.display_warning = linphone_iphone_log_user_warning,
.display_url = NULL,
.text_received = NULL,
.message_received = linphone_iphone_message_received,
.dtmf_received = NULL,
.transfer_state_changed = linphone_iphone_transfer_state_changed,
@ -1383,7 +1377,8 @@ static LinphoneCoreVTable linphonec_vtable = {
linphone_core_enable_payload_type(theLinphoneCore, pt, FALSE);
LOGW(@"SILK/24000 and video disabled on old iPhone 3G");
}
linphone_core_enable_video(theLinphoneCore, FALSE, FALSE);
linphone_core_enable_video_display(theLinphoneCore, FALSE);
linphone_core_enable_video_capture(theLinphoneCore, FALSE);
}
LOGI(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model UTF8String]);
@ -1715,7 +1710,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) {
linphone_core_start_dtmf_stream(theLinphoneCore);
/*start the video preview in case we are in the main view*/
if (LinphoneManager.runningOnIpad && linphone_core_video_enabled(theLinphoneCore) &&
if (LinphoneManager.runningOnIpad && linphone_core_video_display_enabled(theLinphoneCore) &&
[self lpConfigBoolForKey:@"preview_preference"]) {
linphone_core_enable_video_preview(theLinphoneCore, TRUE);
}
@ -1931,7 +1926,7 @@ static void audioRouteChangeListenerCallback(void *inUserData, // 1
// Continue by checking that the provided address is a valid SIP address, abort otherwise.
if ([address length] == 0) {
// no address provided... nothing to do
} else if ((addr = linphone_core_interpret_url(theLinphoneCore, address.UTF8String)) == NULL) {
} else if ((addr = linphone_proxy_config_normalize_sip_uri(NULL, address.UTF8String)) == NULL) {
UIAlertView *error = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Invalid SIP address", nil)
message:NSLocalizedString(@"Either configure a SIP proxy server from settings prior to place a "

View file

@ -29,7 +29,7 @@
- (void)setCall:(LinphoneCall *)call {
_call = call;
if (!call || !linphone_call_is_in_conference(call)) {
if (!call || !linphone_call_params_get_local_conference_mode(linphone_call_get_current_params(call))) {
LOGF(@"Invalid call: either NULL or not in conference.");
return;
}

View file

@ -45,6 +45,7 @@
- (IBAction)onResendClick:(id)event;
- (void)update;
+ (CGSize)ViewHeightForMessage:(LinphoneChatMessage *)chat withWidth:(int)width;
+ (NSString *)TextMessageForChat:(LinphoneChatMessage *)message;
+ (CGSize)computeBoundingBox:(NSString *)text size:(CGSize)size font:(UIFont *)font;

View file

@ -223,7 +223,8 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7) {
return [text boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading)
attributes:@{
NSFontAttributeName : font
}
@ -241,54 +242,45 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 32;
static const CGFloat CELL_IMAGE_HEIGHT = 100.0f;
static const CGFloat CELL_IMAGE_WIDTH = 100.0f;
+ (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width {
static UIFont *messageFont = nil;
static UIFont *dateFont = nil;
static CGSize dateViewSize;
CGSize messageSize;
const char *url = linphone_chat_message_get_external_body_url(chat);
+ (CGSize)ViewHeightForMessage:(LinphoneChatMessage *)chat withWidth:(int)width {
NSString *messageText = [UIChatBubbleTextCell TextMessageForChat:chat];
UITableView *tableView = VIEW(ChatConversationView).tableController.tableView;
if (tableView.isEditing)
width -= 40; /*checkbox */
static UIFont *messageFont = nil;
if (!messageFont) {
UIChatBubbleTextCell *cell =
[[UIChatBubbleTextCell alloc] initWithIdentifier:NSStringFromClass(UIChatBubbleTextCell.class)];
messageFont = cell.messageText.font;
}
if (tableView.isEditing)
width -= 40; /*checkbox */
CGSize size;
const char *url = linphone_chat_message_get_external_body_url(chat);
if (url == nil && linphone_chat_message_get_file_transfer_information(chat) == NULL) {
size = [self computeBoundingBox:messageText
size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN, CGFLOAT_MAX)
font:messageFont];
} else {
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat];
size = (localImage != nil) ? CGSizeMake(CELL_IMAGE_WIDTH, CELL_IMAGE_HEIGHT) : CGSizeMake(50, 50);
}
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
return size;
}
+ (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width {
static UIFont *dateFont = nil;
static CGSize dateViewSize;
if (!dateFont) {
UIChatBubbleTextCell *cell =
[[UIChatBubbleTextCell alloc] initWithIdentifier:NSStringFromClass(UIChatBubbleTextCell.class)];
dateFont = cell.contactDateLabel.font;
dateViewSize = cell.contactDateLabel.frame.size;
}
if (url == nil && linphone_chat_message_get_file_transfer_information(chat) == NULL) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7) {
messageSize = [messageText boundingRectWithSize:CGSizeMake(width - CELL_MESSAGE_X_MARGIN, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesFontLeading)
attributes:@{
NSFontAttributeName : messageFont
}
context:nil]
.size;
} else
#endif
{
messageSize = [messageText sizeWithFont:messageFont
constrainedToSize:CGSizeMake(width - CELL_MESSAGE_X_MARGIN, 10000.0f)
lineBreakMode:NSLineBreakByTruncatingTail];
}
} else {
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat];
messageSize = (localImage != nil) ? CGSizeMake(CELL_IMAGE_WIDTH, CELL_IMAGE_HEIGHT) : CGSizeMake(50, 50);
}
CGSize messageSize = [self ViewHeightForMessage:chat withWidth:width];
CGSize dateSize = [self computeBoundingBox:[self ContactDateForChat:chat] size:dateViewSize font:dateFont];
messageSize.width = MAX(messageSize.width, dateSize.width);
messageSize.width = MAX(messageSize.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
messageSize.height = MAX(messageSize.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
messageSize.width = MAX(MAX(messageSize.width, dateSize.width), CELL_MIN_WIDTH);
return messageSize;
}

View file

@ -43,7 +43,7 @@
- (void)setAddress:(NSString *)address {
_addressLabel.text = _editTextfield.text = address;
LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], _addressLabel.text.UTF8String);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(NULL, _addressLabel.text.UTF8String);
_chatButton.enabled = _callButton.enabled = (addr != NULL);
_chatButton.accessibilityLabel =
@ -75,7 +75,7 @@
}
- (IBAction)onCallClick:(id)event {
LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], _addressLabel.text.UTF8String);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(NULL, _addressLabel.text.UTF8String);
if (addr == NULL)
return;
char *lAddress = linphone_address_as_string_uri_only(addr);
@ -89,7 +89,7 @@
}
- (IBAction)onChatClick:(id)event {
LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], _addressLabel.text.UTF8String);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(NULL, _addressLabel.text.UTF8String);
if (addr == NULL)
return;
[PhoneMainView.instance changeCurrentView:ChatsListView.compositeViewDescription];

View file

@ -69,7 +69,7 @@
[addressField setText:newAddress];
linphone_core_play_dtmf([LinphoneManager getLc], digit, -1);
} else {
linphone_core_send_dtmf([LinphoneManager getLc], digit);
linphone_call_send_dtmf(linphone_core_get_current_call([LinphoneManager getLc]), digit);
linphone_core_play_dtmf([LinphoneManager getLc], digit, 100);
}
}

View file

@ -27,7 +27,7 @@
+ (bool)isInConference:(LinphoneCall *)call {
if (!call)
return false;
return linphone_call_is_in_conference(call);
return linphone_call_params_get_local_conference_mode(linphone_call_get_current_params(call));
}
+ (int)callCount:(LinphoneCore *)lc {

View file

@ -24,15 +24,15 @@
@implementation UIMicroButton
- (void)onOn {
linphone_core_mute_mic([LinphoneManager getLc], false);
linphone_core_enable_mic([LinphoneManager getLc], false);
}
- (void)onOff {
linphone_core_mute_mic([LinphoneManager getLc], true);
linphone_core_enable_mic([LinphoneManager getLc], true);
}
- (bool)onUpdate {
return linphone_core_is_mic_muted([LinphoneManager getLc]);
return linphone_core_mic_enabled([LinphoneManager getLc]);
}
@end

View file

@ -58,7 +58,7 @@
+ (bool)isInConference:(LinphoneCall *)call {
if (!call)
return false;
return linphone_call_is_in_conference(call);
return linphone_call_params_get_local_conference_mode(linphone_call_get_current_params(call));
}
+ (int)notInConferenceCallCount:(LinphoneCore *)lc {

View file

@ -58,7 +58,7 @@
- (void)onOn {
LinphoneCore *lc = [LinphoneManager getLc];
if (!linphone_core_video_enabled(lc))
if (!linphone_core_video_display_enabled(lc))
return;
[self setEnabled:FALSE];
@ -81,7 +81,7 @@
- (void)onOff {
LinphoneCore *lc = [LinphoneManager getLc];
if (!linphone_core_video_enabled(lc))
if (!linphone_core_video_display_enabled(lc))
return;
[self setEnabled:FALSE];
@ -103,7 +103,7 @@
LinphoneCore *lc = [LinphoneManager getLc];
LinphoneCall *currentCall = linphone_core_get_current_call(lc);
if (linphone_core_video_supported(lc)) {
if (linphone_core_video_enabled(lc) && currentCall && !linphone_call_media_in_progress(currentCall) &&
if (linphone_core_video_display_enabled(lc) && currentCall && !linphone_call_media_in_progress(currentCall) &&
linphone_call_get_state(currentCall) == LinphoneCallStreamsRunning) {
video_enabled = TRUE;
}

View file

@ -586,7 +586,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[hiddenKeys addObject:@"enable_video_preference"];
}
if (!linphone_core_video_enabled([LinphoneManager getLc])) {
if (!linphone_core_video_display_enabled([LinphoneManager getLc])) {
[hiddenKeys addObject:@"video_menu"];
}

View file

@ -90,7 +90,7 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
address = [[address componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
componentsJoinedByString:@" "];
NSString *normalizedSipAddress = nil;
LinphoneAddress *linphoneAddress = linphone_core_interpret_url([LinphoneManager getLc], [address UTF8String]);
LinphoneAddress *linphoneAddress = linphone_proxy_config_normalize_sip_uri(NULL, [address UTF8String]);
if (linphoneAddress != NULL) {
char *tmp = linphone_address_as_string_uri_only(linphoneAddress);
if (tmp != NULL) {

View file

@ -142,7 +142,7 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom {
[LinphoneManager.instance.fileTransferDelegates addObject:self];
LinphoneContent *content = linphone_core_create_content(linphone_chat_room_get_lc(chatRoom));
LinphoneContent *content = linphone_core_create_content(linphone_chat_room_get_core(chatRoom));
_data = [NSMutableData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
linphone_content_set_type(content, "image");
linphone_content_set_subtype(content, "jpeg");

View file

@ -179,7 +179,9 @@
LinphoneChatRoom *room = linphone_core_get_chat_room_from_uri(lc, [[self me] UTF8String]);
// generate lots of messages...
for (; count < 50; count++) {
linphone_chat_room_send_message(room, [[NSString stringWithFormat:@"Message %d", count + 1] UTF8String]);
LinphoneChatMessage *msg =
linphone_chat_room_create_message(room, [[NSString stringWithFormat:@"Message %d", count + 1] UTF8String]);
linphone_chat_room_send_chat_message(room, msg);
}
for (int i = 0; i < 25; i++) {

View file

@ -79,7 +79,7 @@
LinphoneProxyConfig *cfg = (LinphoneProxyConfig *)proxies->data;
const char *domain = linphone_proxy_config_get_domain(cfg);
const char *identity = linphone_proxy_config_get_identity(cfg);
LinphoneAddress *addr = linphone_core_interpret_url(lc, identity);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(NULL, identity);
const char *username = linphone_address_get_username(addr);
if (addr && (username && strcmp(username, [[self me] UTF8String]) == 0) &&

@ -1 +1 @@
Subproject commit 6b32795f7e97729884eaa537c921d477c10a874b
Subproject commit 535ffb9d91b071f9272cb3bf71e4e4dacc57371a

@ -1 +1 @@
Subproject commit 91352ffccd1edba32f56794194b0cc2695acd387
Subproject commit 7228158af0d723d642dbaa7e1c556dddb9cf78d7