Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #3026: Add support for brave partner cards (#3052)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson authored and iccub committed Nov 19, 2020
1 parent f819b55 commit 3716ef1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Client/Frontend/Brave Today/Composer/FeedDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class FeedDataSource {
})?.enabled ?? item.source.isDefault
}
var sponsors = feedsFromEnabledSources.filter { $0.content.contentType == .sponsor }
var partners = feedsFromEnabledSources.filter { $0.content.contentType == .partner }
var deals = feedsFromEnabledSources.filter { $0.content.contentType == .deals }
var articles = feedsFromEnabledSources.filter { $0.content.contentType == .article }

Expand All @@ -460,6 +461,7 @@ class FeedDataSource {
.repeating([
.repeating([.headline(paired: false)], times: 2),
.repeating([.headline(paired: true)], times: 2),
.partner,
.fillUsing(
CategoryFillStrategy(
categories: Set(articles.map(\.source.category)),
Expand Down Expand Up @@ -496,6 +498,13 @@ class FeedDataSource {
let title = $0.first?.content.offersCategory
return [.deals($0, title: title ?? Strings.BraveToday.deals)]
}
case .partner:
let imageExists = { (item: FeedItem) -> Bool in
item.content.imageURL != nil
}
return fillStrategy.next(from: &partners, where: imageExists).map {
[.headline($0)]
}
case .headline(let paired):
if articles.isEmpty { return nil }
let imageExists = { (item: FeedItem) -> Bool in
Expand Down Expand Up @@ -581,6 +590,8 @@ extension FeedDataSource {
private enum FeedSequenceElement {
/// Display a sponsored image with the content type of `product`
case sponsor
/// Display a headline from a list of partnered items
case partner
/// Displays a horizontal list of deals with the content type of `brave_offers`
case deals
/// Displays an `article` type item in a headline card. Can also be displayed as two (smaller) paired
Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Brave Today/Composer/FeedItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension FeedItem {
static let article = FeedContentType(rawValue: "article")
static let deals = FeedContentType(rawValue: "product")
static let sponsor = FeedContentType(rawValue: "brave_offers")
static let partner = FeedContentType(rawValue: "brave_partner")
}

struct Content: Equatable, Decodable {
Expand Down

0 comments on commit 3716ef1

Please sign in to comment.