Commit 54dc1958 by Demid Merzlyakov

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

parent d1ffc16e
...@@ -35,13 +35,13 @@ class ShortsManager { ...@@ -35,13 +35,13 @@ class ShortsManager {
if let presentShortIndex = (shorts.firstIndex{$0.id == newShort.id}) { if let presentShortIndex = (shorts.firstIndex{$0.id == newShort.id}) {
let presentShort = shorts[presentShortIndex] let presentShort = shorts[presentShortIndex]
newShorts[index].isLiked = presentShort.isLiked newShorts[index].isLiked = presentShort.isLiked
newShorts[index].isViewed = presentShort.isViewed newShorts[index].viewDate = presentShort.viewDate
} }
} }
} }
//MARK: Public //MARK: Public
func refreshShorts() { public func refreshShorts() {
if isUpdating { if isUpdating {
return return
} }
...@@ -72,8 +72,17 @@ class ShortsManager { ...@@ -72,8 +72,17 @@ class ShortsManager {
} }
} }
func reordering() { public func reordering() {
shorts = shorts.filter{!$0.isViewed} + shorts.filter{$0.isViewed} 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 self.multicastDelegate.invoke { delegate in
delegate.shortsDidChange() delegate.shortsDidChange()
...@@ -93,14 +102,10 @@ class ShortsManager { ...@@ -93,14 +102,10 @@ class ShortsManager {
} }
} }
func markAsViewed(item: ShortsItem) { func markAsViewed(index: Int) {
guard guard index >= 0, index < shorts.count else {
!item.isViewed,
let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id })
else {
return return
} }
self.shorts[index].markAsViewed()
self.shorts[sourceIndex].markAsViewed()
} }
} }
...@@ -50,7 +50,7 @@ class ShortsViewModel: ViewModelProtocol { ...@@ -50,7 +50,7 @@ class ShortsViewModel: ViewModelProtocol {
if Settings.shared.shortsSwipeUpNudgeShowedCount <= ConfigManager.shared.config.shortsSwipeUpNudgeCount { if Settings.shared.shortsSwipeUpNudgeShowedCount <= ConfigManager.shared.config.shortsSwipeUpNudgeCount {
Settings.shared.shortsSwipeUpNudgeShowedCount += 1 Settings.shared.shortsSwipeUpNudgeShowedCount += 1
} }
shortsManager.markAsViewed(item: shorts[index]) shortsManager.markAsViewed(index: index)
} }
} }
......
...@@ -37,7 +37,7 @@ public struct ShortsItem { ...@@ -37,7 +37,7 @@ public struct ShortsItem {
public let likeCount: Int public let likeCount: Int
public let shareCount: Int public let shareCount: Int
public var isLiked: Bool = false 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) { 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 self.id = id
...@@ -97,6 +97,6 @@ public struct ShortsItem { ...@@ -97,6 +97,6 @@ public struct ShortsItem {
} }
public mutating func markAsViewed() { 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