diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index a29288367..b603ab3f4 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -38,9 +38,11 @@ @interface ChatConversationTableView : UICheckBoxTableView { @private NSMutableArray *eventList; + NSMutableArray *totalEventList; } @property(nonatomic) LinphoneChatRoom *chatRoom; +@property(nonatomic) NSInteger currentIndex; @property(nonatomic, strong) id chatRoomDelegate; @property NSMutableDictionary *imagesInChatroom; @@ -48,5 +50,6 @@ - (void)scrollToBottom:(BOOL)animated; - (void)scrollToLastUnread:(BOOL)animated; - (void)updateEventEntry:(LinphoneEventLog *)event; +- (void)refreshData; @end diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 573801ba0..322af9273 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -62,11 +62,17 @@ ? linphone_chat_room_get_history_message_events(_chatRoom, 0) : linphone_chat_room_get_history_events(_chatRoom, 0); bctbx_list_t *head = chatRoomEvents; - eventList = [[NSMutableArray alloc] initWithCapacity:bctbx_list_size(chatRoomEvents)]; + size_t listSize = bctbx_list_size(chatRoomEvents); + totalEventList = [[NSMutableArray alloc] initWithCapacity:listSize]; + eventList = [[NSMutableArray alloc] initWithCapacity:MIN(listSize, BASIC_EVENT_LIST)]; while (chatRoomEvents) { - LinphoneEventLog *event = (LinphoneEventLog *)chatRoomEvents->data; - [eventList addObject:[NSValue valueWithPointer:linphone_event_log_ref(event)]]; + LinphoneEventLog *event = (LinphoneEventLog *)chatRoomEvents->data; + [totalEventList addObject:[NSValue valueWithPointer:linphone_event_log_ref(event)]]; + if (listSize <= BASIC_EVENT_LIST) { + [eventList addObject:[NSValue valueWithPointer:linphone_event_log_ref(event)]]; + } chatRoomEvents = chatRoomEvents->next; + listSize -= 1; } bctbx_list_free_with_data(head, (bctbx_list_free_func)linphone_event_log_unref); @@ -81,6 +87,22 @@ } } +- (void)refreshData { + if (totalEventList.count <= eventList.count) { + _currentIndex = 0; + return; + } + + NSUInteger num = MIN(totalEventList.count-eventList.count, BASIC_EVENT_LIST); + _currentIndex = num - 1; + while (num) { + NSInteger index = totalEventList.count - eventList.count - 1; + [eventList insertObject:[totalEventList objectAtIndex:index] atIndex:0]; + index -= 1; + num -= 1; + } +} + - (void)reloadData { [self updateData]; [self.tableView reloadData]; @@ -167,6 +189,7 @@ } static const int MAX_AGGLOMERATED_TIME=300; +static const int BASIC_EVENT_LIST=20; - (BOOL)isFirstIndexInTableView:(NSIndexPath *)indexPath chat:(LinphoneChatMessage *)chat { LinphoneEventLog *previousEvent = nil; diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 6d6cd4834..32fd99ecd 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -39,6 +39,7 @@ BOOL scrollOnGrowingEnabled; BOOL composingVisible; UIConfirmationDialog *securityDialog; + UIRefreshControl *refreshControl; } @property(nonatomic) LinphoneChatRoom *chatRoom; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index db914e6f5..20f8c5fde 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -95,7 +95,11 @@ static UICompositeViewDescription *compositeDescription = nil; _backButton.hidden = YES; _backButton.alpha = 0; } - + + refreshControl = [[UIRefreshControl alloc]init]; + [refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; + _tableController.refreshControl = refreshControl; + _messageField.minNumberOfLines = 1; _messageField.maxNumberOfLines = IPAD ? 10 : 3; _messageField.delegate = self; @@ -107,6 +111,15 @@ static UICompositeViewDescription *compositeDescription = nil; [_imagesCollectionView setDataSource:self]; } +- (void)refreshData { + [_tableController refreshData]; + [refreshControl endRefreshing]; + [_tableController loadData]; + [_tableController.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_tableController.currentIndex inSection:0] + atScrollPosition:UITableViewScrollPositionTop + animated:false]; +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [NSNotificationCenter.defaultCenter addObserver:self