From 0b5b0915eb315a313dd6233c937afa288fe87161 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 27 Nov 2017 13:39:25 +0100 Subject: [PATCH] get last message from chatroom + update linphone --- Classes/ChatsListTableView.m | 20 ++++---------------- Classes/LinphoneUI/UIChatCell.m | 10 ++++++---- submodules/linphone | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 60612b073..16ed81712 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -96,19 +96,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo while (iter) { // store last message in user data LinphoneChatRoom *chat_room = iter->data; - bctbx_list_t *history = linphone_chat_room_get_history_events(iter->data, 1); - LinphoneChatMessage *last_msg = NULL; - // TODO [2017/11/07]: get_last_message directly via chat room API - while (history) { - LinphoneEventLog *event = history->data; - if (linphone_event_log_get_type(event) != LinphoneEventLogTypeConferenceChatMessage) { - history = history->next; - continue; - } - last_msg = linphone_chat_message_ref(linphone_event_log_get_chat_message(event)); - bctbx_list_free(history); - break; - } + 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, linphone_chat_room_ref(chat_room), (bctbx_compare_func)sorted_history_comparison); @@ -118,9 +106,9 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } static void chatTable_free_chatrooms(void *data) { - LinphoneChatMessage *lastMsg = linphone_chat_room_get_user_data(data); - if (lastMsg) { - linphone_chat_message_unref(lastMsg); + LinphoneChatMessage *last_msg = linphone_chat_room_get_user_data(data); + if (last_msg) { + linphone_chat_message_unref(last_msg); linphone_chat_room_set_user_data(data, NULL); } linphone_chat_room_unref(data); diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index be588936e..683882195 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -81,17 +81,19 @@ } } - LinphoneChatMessage *last_message = linphone_chat_room_get_user_data(chatRoom); - if (last_message) { - NSString *message = [UIChatBubbleTextCell TextMessageForChat:last_message]; + LinphoneChatMessage *last_msg = linphone_chat_room_get_user_data(chatRoom); + if (last_msg) { + NSString *message = [UIChatBubbleTextCell TextMessageForChat:last_msg]; // shorten long messages if ([message length] > 50) { message = [[message substringToIndex:50] stringByAppendingString:@"[...]"]; } _chatContentLabel.text = message; _chatLatestTimeLabel.text = - [LinphoneUtils timeToString:linphone_chat_message_get_time(last_message) withFormat:LinphoneDateChatList]; + [LinphoneUtils timeToString:linphone_chat_message_get_time(last_msg) withFormat:LinphoneDateChatList]; _chatLatestTimeLabel.hidden = NO; + linphone_chat_message_unref(last_msg); + linphone_chat_room_set_user_data(chatRoom, NULL); } else { _chatContentLabel.text = nil; _chatLatestTimeLabel.text = NSLocalizedString(@"Now", nil); diff --git a/submodules/linphone b/submodules/linphone index 60915d8a1..5069a4a50 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 60915d8a159424576ad3db515a91cf49d7aad286 +Subproject commit 5069a4a5085792e6303b1e0208ba24cd64408a6d