#1898 (Marking story as read/unread right after loading will mark different story)

- Added exta logic to check that a swipe starts and ends on the same row and story, and abandon it if not, to avoid doing the wrong thing.
- It appears that this was caused by reloading a row while loading images, so I also added logic to avoid reloading a row in the middle of a swipe.
This commit is contained in:
David Sinclair 2024-11-11 19:30:11 -07:00
parent d23c4afcbb
commit 1886384209
3 changed files with 18 additions and 6 deletions

View file

@ -55,6 +55,9 @@
@property (nonatomic, strong) id standardInteractivePopGestureDelegate;
//@property (nonatomic, readonly) NSIndexPath *selectedIndexPath;
@property (nonatomic) CGFloat storyHeight;
@property (nonatomic) NSIndexPath *swipingIndexPath;
@property (nonatomic, strong) NSString *swipingStoryHash;
@property (nonatomic, readonly) BOOL canPullToRefresh;
@property (nonatomic, readonly) BOOL isMarkReadOnScroll;
@property (nonatomic, readonly) BOOL isLegacyTable;

View file

@ -59,7 +59,6 @@ typedef NS_ENUM(NSUInteger, FeedSection)
@property (nonatomic) BOOL isFadingTable;
@property (nonatomic, strong) NSString *restoringFolder;
@property (nonatomic, strong) NSString *restoringFeedID;
@property (nonatomic) NSIndexPath *swipingIndexPath;
@end
@ -2245,8 +2244,10 @@ typedef NS_ENUM(NSUInteger, FeedSection)
- (void)swipeTableViewCellDidStartSwiping:(MCSwipeTableViewCell *)cell {
// NSLog(@"Did start swiping the cell!");
NSIndexPath *indexPath = [self.storyTitlesTable indexPathForCell:cell];
FeedDetailTableCell *feedCell = (FeedDetailTableCell *)cell;
self.swipingIndexPath = indexPath;
self.swipingStoryHash = feedCell.storyHash;
}
// When the user is dragging, this method is called and return the dragged percentage from the border
@ -2261,18 +2262,26 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state
NSInteger storyIndex = [storiesCollection indexFromLocation:self.swipingIndexPath.row];
NSDictionary *story = [[storiesCollection activeFeedStories] objectAtIndex:storyIndex];
if (endedOnIndexPath != self.swipingIndexPath) {
NSLog(@"Swipe started at row %@ but ended at %@ for %@", self.swipingIndexPath, endedOnIndexPath, story[@"story_title"]); // log
if (endedOnIndexPath != self.swipingIndexPath || story[@"story_hash"] != self.swipingStoryHash) {
NSLog(@"Swipe started at row %@ (%@) but ended at %@ (%@) for %@", @(self.swipingIndexPath.row), self.swipingStoryHash, @(endedOnIndexPath.row), story[@"story_hash"], story[@"story_title"]); // log
self.swipingIndexPath = nil;
self.swipingStoryHash = nil;
return;
}
self.swipingIndexPath = nil;
self.swipingStoryHash = nil;
if (state == MCSwipeTableViewCellState1) {
// Saved
[storiesCollection toggleStorySaved:story];
[self reloadIndexPath:self.swipingIndexPath withRowAnimation:UITableViewRowAnimationFade];
[self reloadIndexPath:endedOnIndexPath withRowAnimation:UITableViewRowAnimationFade];
} else if (state == MCSwipeTableViewCellState3) {
// Read
[storiesCollection toggleStoryUnread:story];
[self reloadIndexPath:self.swipingIndexPath withRowAnimation:UITableViewRowAnimationFade];
[self reloadIndexPath:endedOnIndexPath withRowAnimation:UITableViewRowAnimationFade];
}
}

View file

@ -197,7 +197,7 @@ class FeedDetailViewController: FeedDetailObjCViewController {
@objc override func reload(_ indexPath: IndexPath, with rowAnimation: UITableView.RowAnimation = .none) {
if !isLegacyTable {
deferredReload()
} else if reloadWorkItem == nil, storyTitlesTable.window != nil {
} else if reloadWorkItem == nil, storyTitlesTable.window != nil, swipingStoryHash == nil {
// Only do this if a deferred reload isn't pending; otherwise no point in doing a partial reload, plus the table may be stale.
storyTitlesTable.reloadRows(at: [indexPath], with: rowAnimation)
}