Skip to content

Commit

Permalink
Automatically fetch a page of backlog if the channel doesn't have eno…
Browse files Browse the repository at this point in the history
…ugh events downloaded
  • Loading branch information
c99koder committed Sep 9, 2019
1 parent 663926c commit c679ceb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion IRCCloud/Classes/EventsTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
NSTimeInterval _maxEid, _minEid, _currentCollapsedEid, _earliestEid, _eidToOpen, _lastCollapsedEid;
NSInteger _newMsgs, _newHighlights, _lastSeenEidPos, _bottomRow;
NSString *_lastCollpasedDay;
BOOL _requestingBacklog, _ready;
BOOL _requestingBacklog, _ready, _shouldAutoFetch;
NSTimer *_heartbeatTimer;
NSTimer *_scrollTimer;
NSTimer *_reloadTimer;
Expand Down
7 changes: 6 additions & 1 deletion IRCCloud/Classes/EventsTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,8 @@ - (void)refresh {
__timestampWidth += 8;

NSArray *events = [[EventsDataSource sharedInstance] eventsForBuffer:self->_buffer.bid];
_shouldAutoFetch = !_requestingBacklog && events.count < 50;

if(events.count) {
NSMutableDictionary *uuids = [[NSMutableDictionary alloc] init];
for(int i = 0; i < events.count; i++) {
Expand Down Expand Up @@ -2087,6 +2089,9 @@ - (void)refresh {
self->_tableView.tableHeaderView = nil;
}

if(_earliestEid == _buffer.min_eid)
self->_shouldAutoFetch = NO;

@try {
if(self->_requestingBacklog && backlogEid > 0 && _buffer.scrolledUp) {
int markerPos = -1;
Expand Down Expand Up @@ -2176,7 +2181,7 @@ - (void)refresh {
[self scrollViewDidScroll:self->_tableView];
[self->_tableView flashScrollIndicators];

if(self->_buffer.deferred && self->_conn.state == kIRCCloudStateConnected && self->_conn.ready) {
if((self->_buffer.deferred || (self->_shouldAutoFetch && (rows.count == 0 || [[rows objectAtIndex:0] row] == 0))) && self->_conn.state == kIRCCloudStateConnected && self->_conn.ready) {
[self loadMoreBacklogButtonPressed:nil];
}

Expand Down
2 changes: 1 addition & 1 deletion build-scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
49
50

0 comments on commit c679ceb

Please sign in to comment.