mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Sort chatrooms by most recent message
This commit is contained in:
parent
75980c4e09
commit
7eb4d18432
1 changed files with 28 additions and 1 deletions
|
|
@ -49,8 +49,35 @@
|
|||
|
||||
#pragma mark -
|
||||
|
||||
static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRoom *elem){
|
||||
MSList* new_history = linphone_chat_room_get_history(to_insert, 1);
|
||||
LinphoneChatMessage* last_new_message = new_history? new_history->data : NULL;
|
||||
MSList* elem_history = linphone_chat_room_get_history(elem, 1);
|
||||
LinphoneChatMessage* last_elem_message = elem_history?elem_history->data:NULL;
|
||||
|
||||
if( last_new_message && last_elem_message ){
|
||||
time_t new = linphone_chat_message_get_time(last_new_message);
|
||||
time_t old = linphone_chat_message_get_time(last_elem_message);
|
||||
if ( new < old ) return 1;
|
||||
else if ( new > old) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (MSList*)sortChatRooms {
|
||||
MSList* sorted = nil;
|
||||
MSList* unsorted = linphone_core_get_chat_rooms([LinphoneManager getLc]);
|
||||
MSList* iter = unsorted;
|
||||
|
||||
while (iter) {
|
||||
sorted = ms_list_insert_sorted(sorted, iter->data, (MSCompareFunc)sorted_history_comparison);
|
||||
iter = iter->next;
|
||||
}
|
||||
return sorted;
|
||||
}
|
||||
|
||||
- (void)loadData {
|
||||
data = linphone_core_get_chat_rooms([LinphoneManager getLc]);
|
||||
data = [self sortChatRooms];
|
||||
[[self tableView] reloadData];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue