mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Filter out the current viewer in the recommended by list
This commit is contained in:
parent
1b2c3db90c
commit
615bebc610
3 changed files with 22 additions and 12 deletions
|
|
@ -28,7 +28,7 @@ struct MacFeedCardNavigationLink: View {
|
|||
.onAppear {
|
||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: audioController) }
|
||||
}
|
||||
FeedCard(item: item) {
|
||||
FeedCard(item: item, viewer: dataService.currentViewer) {
|
||||
viewModel.selectedLinkItem = item.objectID
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ struct FeedCardNavigationLink: View {
|
|||
.onAppear {
|
||||
Task { await viewModel.itemAppeared(item: item, dataService: dataService, audioController: audioController) }
|
||||
}
|
||||
FeedCard(item: item)
|
||||
FeedCard(item: item, viewer: dataService.currentViewer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,17 @@ import CoreData
|
|||
import Foundation
|
||||
|
||||
public extension Recommendation {
|
||||
static func byline(_ set: NSSet) -> String {
|
||||
Array(set).reduce("") { str, item in
|
||||
if let recommendation = item as? Recommendation, let userName = recommendation.user?.name {
|
||||
// Returns the recommendations from other users, filtering out the viewer
|
||||
// if they have also recommended the page.
|
||||
static func notViewers(viewer: Viewer?, _ set: NSSet?) -> [Recommendation] {
|
||||
Array(set ?? [])
|
||||
.compactMap { $0 as? Recommendation }
|
||||
.filter { $0.user?.userID != viewer?.userID }
|
||||
}
|
||||
|
||||
static func byline(_ recommendations: [Recommendation]) -> String {
|
||||
recommendations.reduce("") { str, recommendation in
|
||||
if let userName = recommendation.user?.name {
|
||||
if str.isEmpty {
|
||||
return userName
|
||||
} else {
|
||||
|
|
@ -15,9 +23,9 @@ public extension Recommendation {
|
|||
}
|
||||
}
|
||||
|
||||
static func groupsLine(_ set: NSSet) -> String {
|
||||
Array(set).reduce("") { str, item in
|
||||
if let recommendation = item as? Recommendation, let name = recommendation.name {
|
||||
static func groupsLine(_ recommendations: [Recommendation]) -> String {
|
||||
recommendations.reduce("") { str, recommendation in
|
||||
if let name = recommendation.name {
|
||||
if str.isEmpty {
|
||||
return name
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ import SwiftUI
|
|||
import Utils
|
||||
|
||||
public struct FeedCard: View {
|
||||
let viewer: Viewer?
|
||||
let tapHandler: () -> Void
|
||||
@ObservedObject var item: LinkedItem
|
||||
|
||||
public init(item: LinkedItem, tapHandler: @escaping () -> Void = {}) {
|
||||
public init(item: LinkedItem, viewer: Viewer?, tapHandler: @escaping () -> Void = {}) {
|
||||
self.item = item
|
||||
self.viewer = viewer
|
||||
self.tapHandler = tapHandler
|
||||
}
|
||||
|
||||
|
|
@ -87,9 +89,9 @@ public struct FeedCard: View {
|
|||
#endif
|
||||
}
|
||||
|
||||
if let recommendations = item.recommendations, recommendations.count > 0 {
|
||||
let byStr = Recommendation.byline(recommendations)
|
||||
let inStr = Recommendation.groupsLine(recommendations)
|
||||
if let recs = Recommendation.notViewers(viewer: viewer, item.recommendations), recs.count > 0 {
|
||||
let byStr = Recommendation.byline(recs)
|
||||
let inStr = Recommendation.groupsLine(recs)
|
||||
HStack {
|
||||
Image(systemName: "sparkles")
|
||||
Text("Recommended by \(byStr) in \(inStr)")
|
||||
|
|
|
|||
Loading…
Reference in a new issue