better management of user data

This commit is contained in:
Benjamin Reis 2018-01-30 11:58:15 +01:00
parent c661b222b6
commit 274e664c9e
4 changed files with 14 additions and 6 deletions

View file

@ -116,6 +116,18 @@ static UICompositeViewDescription *compositeDescription = nil;
[_tableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
if (_room) {
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_room);
linphone_chat_room_cbs_set_state_changed(cbs, NULL);
linphone_chat_room_cbs_set_subject_changed(cbs, NULL);
linphone_chat_room_cbs_set_participant_added(cbs, NULL);
linphone_chat_room_cbs_set_participant_removed(cbs, NULL);
linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, NULL);
linphone_chat_room_cbs_set_user_data(cbs, NULL);
}
}
#pragma mark - next functions
- (void)onCreate {

View file

@ -68,8 +68,8 @@
#pragma mark -
static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRoom *elem) {
LinphoneChatMessage *last_new_message = linphone_chat_room_get_user_data(to_insert);
LinphoneChatMessage *last_elem_message = linphone_chat_room_get_user_data(elem);
LinphoneChatMessage *last_new_message = linphone_chat_room_get_last_message_in_history(to_insert);
LinphoneChatMessage *last_elem_message = linphone_chat_room_get_last_message_in_history(elem);
if (last_new_message && last_elem_message) {
time_t new = linphone_chat_message_get_time(last_new_message);
@ -90,8 +90,6 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo
while (iter) {
// store last message in user data
LinphoneChatRoom *chat_room = iter->data;
LinphoneChatMessage *last_msg = linphone_chat_room_get_last_message_in_history(chat_room);
linphone_chat_room_set_user_data(chat_room, last_msg);
sorted = bctbx_list_insert_sorted(sorted, chat_room, (bctbx_compare_func)sorted_history_comparison);
iter = iter->next;
}

View file

@ -92,7 +92,6 @@
_chatLatestTimeLabel.text =
[LinphoneUtils timeToString:linphone_chat_message_get_time(last_msg) withFormat:LinphoneDateChatList];
_chatLatestTimeLabel.hidden = NO;
linphone_chat_room_set_user_data(chatRoom, NULL);
} else {
_chatContentLabel.text = nil;
_chatLatestTimeLabel.text = NSLocalizedString(@"Now", nil);

View file

@ -868,7 +868,6 @@ static RootViewManager *rootViewManagerInstance = nil;
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(room);
linphone_chat_room_cbs_set_state_changed(cbs, main_view_chat_room_state_changed);
linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self);
linphone_chat_room_add_participants(room, addresses);
}