fix sort of chat room

This commit is contained in:
Benjamin Reis 2018-02-13 14:02:53 +01:00
parent 0582bf13ae
commit f85932b7f1
2 changed files with 15 additions and 9 deletions

View file

@ -84,18 +84,21 @@
#pragma mark -
static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRoom *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);
LinphoneEventLog *last_new_event = (LinphoneEventLog *)linphone_chat_room_get_history_events(to_insert, 1) ? linphone_chat_room_get_history_events(to_insert, 1)->data : NULL;
LinphoneEventLog *last_elem_event = (LinphoneEventLog *)linphone_chat_room_get_history_events(elem, 1) ? linphone_chat_room_get_history_events(elem, 1)->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 (last_new_event && last_elem_event) {
time_t new = linphone_event_log_get_creation_time(last_new_event);
time_t old = linphone_event_log_get_creation_time(last_elem_event);
if (new < old)
return 1;
else if (new > old)
return -1;
}
return 0;
if (last_new_event)
return 1;
return -1;
}
- (MSList *)sortChatRooms {

View file

@ -81,6 +81,12 @@
[_avatarImage setImage:[UIImage imageNamed:@"chat_group_avatar.png"] bordered:NO withRoundedRadius:YES];
}
LinphoneEventLog *last_event = (LinphoneEventLog *)linphone_chat_room_get_history_events(chatRoom, 1) ? linphone_chat_room_get_history_events(chatRoom, 1)->data : NULL;
if (last_event) {
_chatLatestTimeLabel.text =
[LinphoneUtils timeToString:linphone_event_log_get_creation_time(last_event) withFormat:LinphoneDateChatList];
_chatLatestTimeLabel.hidden = NO;
}
LinphoneChatMessage *last_msg = linphone_chat_room_get_last_message_in_history(chatRoom);
if (last_msg) {
NSString *message = [UIChatBubbleTextCell TextMessageForChat:last_msg];
@ -89,9 +95,6 @@
message = [[message substringToIndex:50] stringByAppendingString:@"[...]"];
}
_chatContentLabel.text = message;
_chatLatestTimeLabel.text =
[LinphoneUtils timeToString:linphone_chat_message_get_time(last_msg) withFormat:LinphoneDateChatList];
_chatLatestTimeLabel.hidden = NO;
} else {
_chatContentLabel.text = nil;
_chatLatestTimeLabel.text = NSLocalizedString(@"Now", nil);