Commit 54dc1958 by Demid Merzlyakov

IOS-163: fix the order of shorts after viewing them.

parent d1ffc16e
......@@ -35,13 +35,13 @@ class ShortsManager {
if let presentShortIndex = (shorts.firstIndex{$0.id == newShort.id}) {
let presentShort = shorts[presentShortIndex]
newShorts[index].isLiked = presentShort.isLiked
newShorts[index].isViewed = presentShort.isViewed
newShorts[index].viewDate = presentShort.viewDate
}
}
}
//MARK: Public
func refreshShorts() {
public func refreshShorts() {
if isUpdating {
return
}
......@@ -72,8 +72,17 @@ class ShortsManager {
}
}
func reordering() {
shorts = shorts.filter{!$0.isViewed} + shorts.filter{$0.isViewed}
public func reordering() {
let unviewedShorts = shorts.filter{$0.viewDate == nil}
let viewedShorts = shorts.filter {
$0.viewDate != nil
}.sorted {
guard let viewDate0 = $0.viewDate, let viewDate1 = $1.viewDate else {
return false
}
return viewDate0 < viewDate1
}
shorts = unviewedShorts + viewedShorts
self.multicastDelegate.invoke { delegate in
delegate.shortsDidChange()
......@@ -93,14 +102,10 @@ class ShortsManager {
}
}
func markAsViewed(item: ShortsItem) {
guard
!item.isViewed,
let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id })
else {
func markAsViewed(index: Int) {
guard index >= 0, index < shorts.count else {
return
}
self.shorts[sourceIndex].markAsViewed()
self.shorts[index].markAsViewed()
}
}
......@@ -50,7 +50,7 @@ class ShortsViewModel: ViewModelProtocol {
if Settings.shared.shortsSwipeUpNudgeShowedCount <= ConfigManager.shared.config.shortsSwipeUpNudgeCount {
Settings.shared.shortsSwipeUpNudgeShowedCount += 1
}
shortsManager.markAsViewed(item: shorts[index])
shortsManager.markAsViewed(index: index)
}
}
......
......@@ -37,7 +37,7 @@ public struct ShortsItem {
public let likeCount: Int
public let shareCount: Int
public var isLiked: Bool = false
public var isViewed: Bool = false
public var viewDate: Date?
public init(id: String, images: [ShortsItemImage], overlayImages: [ShortsItemImage], updatedAtInSecs: TimeInterval, startsAtInSecs: TimeInterval, endsAtInSecs: TimeInterval, shareURL: URL?, title: String, summaryText: String, sourceName: String, heartCount: Int, shortURL: URL?, ctaText: String, ctaURL: URL?, likeCount: Int, shareCount: Int) {
self.id = id
......@@ -97,6 +97,6 @@ public struct ShortsItem {
}
public mutating func markAsViewed() {
isViewed = true
viewDate = Date()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment