get last message from chatroom + update linphone

This commit is contained in:
Benjamin Reis 2017-11-27 13:39:25 +01:00
parent fda16165ce
commit 0b5b0915eb
3 changed files with 11 additions and 21 deletions

View file

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

View file

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

@ -1 +1 @@
Subproject commit 60915d8a159424576ad3db515a91cf49d7aad286
Subproject commit 5069a4a5085792e6303b1e0208ba24cd64408a6d