time optimization to enter a chatroom

This commit is contained in:
Danmei Chen 2018-12-11 10:40:21 +01:00
parent b9d7c07fda
commit bc90383cd4
4 changed files with 44 additions and 4 deletions

View file

@ -38,9 +38,11 @@
@interface ChatConversationTableView : UICheckBoxTableView {
@private
NSMutableArray *eventList;
NSMutableArray *totalEventList;
}
@property(nonatomic) LinphoneChatRoom *chatRoom;
@property(nonatomic) NSInteger currentIndex;
@property(nonatomic, strong) id<ChatConversationDelegate> chatRoomDelegate;
@property NSMutableDictionary<NSString *, UIImage *> *imagesInChatroom;
@ -48,5 +50,6 @@
- (void)scrollToBottom:(BOOL)animated;
- (void)scrollToLastUnread:(BOOL)animated;
- (void)updateEventEntry:(LinphoneEventLog *)event;
- (void)refreshData;
@end

View file

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

View file

@ -39,6 +39,7 @@
BOOL scrollOnGrowingEnabled;
BOOL composingVisible;
UIConfirmationDialog *securityDialog;
UIRefreshControl *refreshControl;
}
@property(nonatomic) LinphoneChatRoom *chatRoom;

View file

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