From 46af917c6e7811b60da96509e118a43ca1636f86 Mon Sep 17 00:00:00 2001 From: "benoit.martins" Date: Thu, 6 Apr 2023 18:26:30 +0200 Subject: [PATCH] Add IMDN callback and refresh IMDN icon in UIChatCell --- Classes/ChatsListTableView.h | 1 + Classes/ChatsListTableView.m | 10 ++++++++++ Classes/LinphoneUI/UIChatCell.h | 1 + Classes/LinphoneUI/UIChatCell.m | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/Classes/ChatsListTableView.h b/Classes/ChatsListTableView.h index 3c0593ebc..5a49bf983 100644 --- a/Classes/ChatsListTableView.h +++ b/Classes/ChatsListTableView.h @@ -31,4 +31,5 @@ - (void)loadData; - (void)markCellAsRead:(LinphoneChatRoom *)chatRoom; +- (void)updateEventEntry:(LinphoneChatMessage *)msg; @end diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index d6aa2a69d..4dfcd0888 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -138,6 +138,16 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } } +- (void)updateEventEntry:(LinphoneChatMessage *)msg { + int idx = bctbx_list_index(_data, linphone_chat_message_get_chat_room(msg)); + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; + if (idx < 0) { + LOGW(@"event entry doesn't exist"); + return; + } + [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:FALSE]; +} + - (void)markCellAsRead:(LinphoneChatRoom *)chatRoom { int idx = bctbx_list_index(_data, VIEW(ChatConversationView).chatRoom); NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; diff --git a/Classes/LinphoneUI/UIChatCell.h b/Classes/LinphoneUI/UIChatCell.h index 29343ea40..602c0e247 100644 --- a/Classes/LinphoneUI/UIChatCell.h +++ b/Classes/LinphoneUI/UIChatCell.h @@ -29,6 +29,7 @@ LinphoneChatRoom *chatRoom; } +@property(readonly, nonatomic) LinphoneEventLog *event; @property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage; @property (weak, nonatomic) IBOutlet UIImageView *securityImage; @property(nonatomic, strong) IBOutlet UILabel *addressLabel; diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 96b986595..c5aacd7cd 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -123,6 +123,13 @@ _chatContentLabel.attributedText = boldText; } + if (outgoing){ + linphone_chat_message_set_user_data(last_msg, (void *)CFBridgingRetain(self)); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(last_msg); + linphone_chat_message_cbs_set_msg_state_changed(cbs, message_status); + linphone_chat_message_cbs_set_participant_imdn_state_changed(cbs, participant_imdn_status); + linphone_chat_message_cbs_set_user_data(cbs, (void *)_event); + } LinphoneChatMessageState state = linphone_chat_message_get_state(last_msg); if (outgoing && (state == LinphoneChatMessageStateDeliveredToUser || state == LinphoneChatMessageStateDisplayed || state == LinphoneChatMessageStateNotDelivered || state == LinphoneChatMessageStateFileTransferError)) { @@ -221,4 +228,22 @@ } } +static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState state) { + LOGI(@"State for message [%p] changed to %s", msg, linphone_chat_message_state_to_string(state)); + if (state == LinphoneChatMessageStateFileTransferInProgress) + return; + + if (!linphone_chat_message_is_outgoing(msg) || (state != LinphoneChatMessageStateFileTransferDone && state != LinphoneChatMessageStateFileTransferInProgress)) { + ChatsListView *view = VIEW(ChatsListView); + [view.tableController updateEventEntry:msg]; + } +} + +static void participant_imdn_status(LinphoneChatMessage* msg, const LinphoneParticipantImdnState *state) { + dispatch_async(dispatch_get_main_queue(), ^{ + ChatConversationImdnView *imdnView = VIEW(ChatConversationImdnView); + [imdnView updateImdnList]; + }); +} + @end