Created
November 26, 2020 09:14
-
-
Save vpusher/ad060ddbc0d938da752873b86ed15b35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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