add comments and minor refactor back to previous logic

pull/680/head
Ryan Zhao 3 years ago
parent e6e97684b4
commit ed3dcf7634

@ -326,10 +326,18 @@ final class ReactionListSheet: BaseVC {
deleteRowsAnimation: .none, deleteRowsAnimation: .none,
insertRowsAnimation: .none, insertRowsAnimation: .none,
reloadRowsAnimation: .none, reloadRowsAnimation: .none,
interrupt: { interrupt: { [weak self] changeset in
$0.elementInserted.count == 1 && self.selectedReactionUserList.count == 4 || /// This is the case where there were 6 reactors in total and locally we only have 5 including current user,
$0.elementDeleted.count == 1 && self.selectedReactionUserList.count == 6 || /// and current user remove the reaction. There would be 4 reactors locally and we need to show more
$0.changeCount > 100 /// reactors cell at this moment. After update from sogs, we'll get the all 5 reactors and update the table
/// with 5 reactors and not showing the more reactors cell.
changeset.elementInserted.count == 1 && self?.selectedReactionUserList.count == 4 ||
/// This is the case where there were 5 reactors without current user, and current user reacted. Before we got
/// the update from sogs, we'll have 6 reactors locally and not showing the more reactors cell. After the update,
/// we'll need to update the table and show 5 reactors with the more reactors cell.
changeset.elementDeleted.count == 1 && self?.selectedReactionUserList.count == 6 ||
/// To many changes to make
changeset.changeCount > 100
} }
) { [weak self] updatedData in ) { [weak self] updatedData in
self?.selectedReactionUserList = updatedData self?.selectedReactionUserList = updatedData
@ -391,7 +399,8 @@ extension ReactionListSheet: UICollectionViewDataSource, UICollectionViewDelegat
extension ReactionListSheet: UITableViewDelegate, UITableViewDataSource { extension ReactionListSheet: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.selectedReactionUserList.count + 1 let moreReactorCount = self.reactionSummaries[lastSelectedReactionIndex].number - self.selectedReactionUserList.count
return moreReactorCount > 0 ? self.selectedReactionUserList.count + 1 : self.selectedReactionUserList.count
} }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@ -403,7 +412,6 @@ extension ReactionListSheet: UITableViewDelegate, UITableViewDataSource {
emoji: self.reactionSummaries[lastSelectedReactionIndex].emoji.rawValue emoji: self.reactionSummaries[lastSelectedReactionIndex].emoji.rawValue
) )
footerCell.selectionStyle = .none footerCell.selectionStyle = .none
footerCell.isHidden = (moreReactorCount <= 0)
return footerCell return footerCell
} }

Loading…
Cancel
Save