From 1d27eabdd4254979c6e3c65706ea08327aca1d43 Mon Sep 17 00:00:00 2001 From: David Idmansour Date: Tue, 19 Jun 2018 15:39:55 +0200 Subject: [PATCH] update user defaults when app becomes active and after message is sent or received --- Classes/ChatConversationView.m | 1 + Classes/ChatsListTableView.m | 4 ++-- Classes/LinphoneManager.m | 1 + latestChatroomsWidget/TodayViewController.m | 17 ++++++++--------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 60fccdfd9..f8f854fb3 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -760,6 +760,7 @@ void on_chat_room_chat_message_sent(LinphoneChatRoom *cr, const LinphoneEventLog ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); [view.tableController addEventEntry:(LinphoneEventLog *)event_log]; [view.tableController scrollToBottom:true]; + [ChatsListTableView saveDataToUserDefaults]; if (IPAD) [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:view]; diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 290777a12..687e9b6ae 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -144,12 +144,12 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo const LinphoneAddress *address = linphone_chat_room_get_peer_address(cr); NSString *display; [dict setObject:[[NSString stringWithUTF8String:linphone_address_as_string_uri_only(address)] substringFromIndex:4] forKey:@"address"]; - if (linphone_chat_room_get_nb_participants(cr) > 1) + if (linphone_chat_room_get_conference_address(cr)) display = [NSString stringWithUTF8String:linphone_chat_room_get_subject(cr)]; else display = [NSString stringWithUTF8String:linphone_address_get_display_name(address)?:linphone_address_get_username(address)]; [dict setObject:display forKey:@"display"]; - [dict setObject:[NSNumber numberWithInt:linphone_chat_room_get_nb_participants(cr)] forKey:@"nbParticipants"]; + [dict setObject:[NSNumber numberWithBool:linphone_chat_room_get_conference_address(cr)] forKey:@"nbParticipants"]; [addresses addObject:dict]; sorted = sorted->next; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 5d43ea304..c4362e2f1 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1242,6 +1242,7 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut } }]; } + [ChatsListTableView saveDataToUserDefaults]; } static void linphone_iphone_message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message) { diff --git a/latestChatroomsWidget/TodayViewController.m b/latestChatroomsWidget/TodayViewController.m index fdf636b92..accfa310d 100644 --- a/latestChatroomsWidget/TodayViewController.m +++ b/latestChatroomsWidget/TodayViewController.m @@ -27,7 +27,7 @@ for (NSDictionary *dict in _chatrooms) { [_addresses addObject:[dict objectForKey:@"address"]]; [_displayNames addObject:[dict objectForKey:@"display"]]; - [_isConf addObject:[NSNumber numberWithBool:(((NSNumber *)[dict objectForKey:@"nbParticipants"]).intValue > 1)]]; + [_isConf addObject:(NSNumber *)[dict objectForKey:@"nbParticipants"]]; } } @@ -37,11 +37,9 @@ UIStackView *stack = _stackViews[i]; UIButton *button = stack.subviews[0]; UILabel *name = stack.subviews[1]; - printf("%s\n", ((NSString *)_addresses[i]).UTF8String); if ([self.imgs.allKeys containsObject:_addresses[i]]) { NSData *imgData = [_imgs objectForKey:_addresses[i]]; [button setImage:[UIImage imageWithData:imgData] forState:UIControlStateNormal]; - NSLog(@"Size of Image(bytes):%d", (int)[imgData length]); } else if (((NSNumber *)_isConf[i]).boolValue) { [button setImage:[UIImage imageNamed:@"chat_group_avatar.png"] forState:UIControlStateNormal]; } @@ -81,6 +79,7 @@ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. [_imgs removeAllObjects]; + [_chatrooms removeAllObjects]; } - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler { @@ -100,23 +99,23 @@ completionHandler:nil]; } -- (void)launchOnChatConversationViewWithId:(NSString *)chatId { - [self launchAppWithURL:[NSURL URLWithString:[@"linphone-widget://chatroom/show?" stringByAppendingString:chatId]]]; +- (void)launchOnChatConversationViewWithAddress:(NSString *)chatAddress { + [self launchAppWithURL:[NSURL URLWithString:[@"linphone-widget://chatroom/show?" stringByAppendingString:chatAddress]]]; } - (IBAction)firstButtonTapped { - [self launchOnChatConversationViewWithId:_addresses[0]]; + [self launchOnChatConversationViewWithAddress:_addresses[0]]; } - (IBAction)secondButtonTapped { - [self launchOnChatConversationViewWithId:_addresses[1]]; + [self launchOnChatConversationViewWithAddress:_addresses[1]]; } - (IBAction)thirdButtonTapped { - [self launchOnChatConversationViewWithId:_addresses[2]]; + [self launchOnChatConversationViewWithAddress:_addresses[2]]; } - (IBAction)fourthButtonTapped { - [self launchOnChatConversationViewWithId:_addresses[3]]; + [self launchOnChatConversationViewWithAddress:_addresses[3]]; } @end