Skip to content

Instantly share code, notes, and snippets.

@vpusher
Created November 26, 2020 09:14
Show Gist options
  • Save vpusher/ad060ddbc0d938da752873b86ed15b35 to your computer and use it in GitHub Desktop.
Save vpusher/ad060ddbc0d938da752873b86ed15b35 to your computer and use it in GitHub Desktop.
// Gather unread messages since the last date.
var unreads = models.filter { message in
return message.model.createdDate?.isAfterDate(date, granularity: .second) ?? false
}
// Among unread messages, drops those sent by me since they are known by the current user.
unreads = Array(unreads.drop(while: { message in
return message.model.isMe
}))
// If unread message is found, scroll to that message.
if let firstUnread = unreads.first, let indexPath = list.indexPath(of: firstUnread) {
self.scrollToRow(at: indexPath, at: .top, animated: false)
// If none, scroll to last one.
} else if let last = indexPathes.last {
self.scrollToRow(at: last, at: .top, animated: false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment