update user defaults when app becomes active and after message is sent or received

This commit is contained in:
David Idmansour 2018-06-19 15:39:55 +02:00
parent 50000e66e5
commit 1d27eabdd4
4 changed files with 12 additions and 11 deletions

View file

@ -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];

View file

@ -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;
}

View file

@ -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) {

View file

@ -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