Update for PR feedback.

URLPreviewManager becomes URLPreviewService.
addVerticalWhitespaceToString used instead of heightForCellData multiple times.
All newline characters removed.
This commit is contained in:
Doug
2021-09-08 15:10:13 +01:00
parent 0f88e8e851
commit 1963f35d30
13 changed files with 105 additions and 150 deletions
+42 -37
View File
@@ -444,43 +444,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05;
[self userInterfaceThemeDidChange];
// Observe URL preview updates.
URLPreviewDidUpdateNotificationObserver = [NSNotificationCenter.defaultCenter addObserverForName:URLPreviewDidUpdateNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) {
// Ensure this is the correct room
if (![(NSString*)notification.userInfo[@"roomId"] isEqualToString:self.roomDataSource.roomId])
{
return;
}
// Get the indexPath for the updated cell.
NSString *updatedEventId = notification.userInfo[@"eventId"];
NSInteger updatedEventIndex = [self.roomDataSource indexOfCellDataWithEventId:updatedEventId];
NSIndexPath *updatedIndexPath = [NSIndexPath indexPathForRow:updatedEventIndex inSection:0];
// Store the content size and offset before reloading the cell
CGFloat originalContentSize = self.bubblesTableView.contentSize.height;
CGPoint contentOffset = self.bubblesTableView.contentOffset;
// Only update the content offset if the cell is visible or above the current visible cells.
BOOL shouldUpdateContentOffset = NO;
NSIndexPath *lastVisibleIndexPath = [self.bubblesTableView indexPathsForVisibleRows].lastObject;
if (lastVisibleIndexPath && updatedIndexPath.row < lastVisibleIndexPath.row)
{
shouldUpdateContentOffset = YES;
}
// Note: Despite passing in the index path, this reloads the whole table.
[self dataSource:self.roomDataSource didCellChange:updatedIndexPath];
// Update the content offset to include any changes to the scroll view's height.
if (shouldUpdateContentOffset)
{
CGFloat delta = self.bubblesTableView.contentSize.height - originalContentSize;
contentOffset.y += delta;
self.bubblesTableView.contentOffset = contentOffset;
}
}];
[self registerURLPreviewNotifications];
[self setupActions];
}
@@ -1556,6 +1520,47 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05;
return myPower >= requiredPower;
}
- (void)registerURLPreviewNotifications
{
URLPreviewDidUpdateNotificationObserver = [NSNotificationCenter.defaultCenter addObserverForName:URLPreviewDidUpdateNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) {
// Ensure this is the correct room
if (![(NSString*)notification.userInfo[@"roomId"] isEqualToString:self.roomDataSource.roomId])
{
return;
}
// Get the indexPath for the updated cell.
NSString *updatedEventId = notification.userInfo[@"eventId"];
NSInteger updatedEventIndex = [self.roomDataSource indexOfCellDataWithEventId:updatedEventId];
NSIndexPath *updatedIndexPath = [NSIndexPath indexPathForRow:updatedEventIndex inSection:0];
// Store the content size and offset before reloading the cell
CGFloat originalContentSize = self.bubblesTableView.contentSize.height;
CGPoint contentOffset = self.bubblesTableView.contentOffset;
// Only update the content offset if the cell is visible or above the current visible cells.
BOOL shouldUpdateContentOffset = NO;
NSIndexPath *lastVisibleIndexPath = [self.bubblesTableView indexPathsForVisibleRows].lastObject;
if (lastVisibleIndexPath && updatedIndexPath.row < lastVisibleIndexPath.row)
{
shouldUpdateContentOffset = YES;
}
// Note: Despite passing in the index path, this reloads the whole table.
[self dataSource:self.roomDataSource didCellChange:updatedIndexPath];
// Update the content offset to include any changes to the scroll view's height.
if (shouldUpdateContentOffset)
{
CGFloat delta = self.bubblesTableView.contentSize.height - originalContentSize;
contentOffset.y += delta;
self.bubblesTableView.contentOffset = contentOffset;
}
}];
}
- (void)refreshRoomTitle
{
NSMutableArray *rightBarButtonItems = nil;