Fixed a feed detail swipe starting on one row and ending on another causing the wrong row being marked unread

This commit is contained in:
David Sinclair 2024-08-21 21:28:23 -07:00
parent 5f0f2ed8e1
commit a23bb24bfe

View file

@ -59,6 +59,7 @@ typedef NS_ENUM(NSUInteger, FeedSection)
@property (nonatomic) BOOL isFadingTable; @property (nonatomic) BOOL isFadingTable;
@property (nonatomic, strong) NSString *restoringFolder; @property (nonatomic, strong) NSString *restoringFolder;
@property (nonatomic, strong) NSString *restoringFeedID; @property (nonatomic, strong) NSString *restoringFeedID;
@property (nonatomic) NSIndexPath *swipingIndexPath;
@end @end
@ -2238,6 +2239,9 @@ typedef NS_ENUM(NSUInteger, FeedSection)
// When the user starts swiping the cell this method is called // When the user starts swiping the cell this method is called
- (void)swipeTableViewCellDidStartSwiping:(MCSwipeTableViewCell *)cell { - (void)swipeTableViewCellDidStartSwiping:(MCSwipeTableViewCell *)cell {
// NSLog(@"Did start swiping the cell!"); // NSLog(@"Did start swiping the cell!");
NSIndexPath *indexPath = [self.storyTitlesTable indexPathForCell:cell];
self.swipingIndexPath = indexPath;
} }
// When the user is dragging, this method is called and return the dragged percentage from the border // When the user is dragging, this method is called and return the dragged percentage from the border
@ -2248,23 +2252,22 @@ typedef NS_ENUM(NSUInteger, FeedSection)
- (void)swipeTableViewCell:(MCSwipeTableViewCell *)cell - (void)swipeTableViewCell:(MCSwipeTableViewCell *)cell
didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state
mode:(MCSwipeTableViewCellMode)mode { mode:(MCSwipeTableViewCellMode)mode {
NSIndexPath *indexPath = [self.storyTitlesTable indexPathForCell:cell]; NSIndexPath *endedOnIndexPath = [self.storyTitlesTable indexPathForCell:cell];
if (!indexPath) { NSInteger storyIndex = [storiesCollection indexFromLocation:self.swipingIndexPath.row];
// This can happen if the user swipes on a cell that is being refreshed.
return;
}
NSInteger storyIndex = [storiesCollection indexFromLocation:indexPath.row];
NSDictionary *story = [[storiesCollection activeFeedStories] objectAtIndex:storyIndex]; 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 (state == MCSwipeTableViewCellState1) { if (state == MCSwipeTableViewCellState1) {
// Saved // Saved
[storiesCollection toggleStorySaved:story]; [storiesCollection toggleStorySaved:story];
[self reloadIndexPath:indexPath withRowAnimation:UITableViewRowAnimationFade]; [self reloadIndexPath:self.swipingIndexPath withRowAnimation:UITableViewRowAnimationFade];
} else if (state == MCSwipeTableViewCellState3) { } else if (state == MCSwipeTableViewCellState3) {
// Read // Read
[storiesCollection toggleStoryUnread:story]; [storiesCollection toggleStoryUnread:story];
[self reloadIndexPath:indexPath withRowAnimation:UITableViewRowAnimationFade]; [self reloadIndexPath:self.swipingIndexPath withRowAnimation:UITableViewRowAnimationFade];
} }
} }