2019-08-24 21:57:51 +02:00
|
|
|
//
|
|
|
|
// ActivityFactory.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 8/23/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreSpotlight
|
|
|
|
import CoreServices
|
|
|
|
import Articles
|
|
|
|
|
|
|
|
class ActivityFactory {
|
|
|
|
|
|
|
|
static func make(_ article: Article) -> NSUserActivity {
|
2019-08-25 02:31:29 +02:00
|
|
|
let activity = NSUserActivity(activityType: ActivityType.readArticle.rawValue)
|
2019-08-24 21:57:51 +02:00
|
|
|
|
|
|
|
activity.title = article.title
|
|
|
|
|
|
|
|
let feedNameKeywords = article.feed?.nameForDisplay.components(separatedBy: " ").filter { $0.count > 2 } ?? []
|
|
|
|
let articleTitleKeywords = article.title?.components(separatedBy: " ").filter { $0.count > 2 } ?? []
|
|
|
|
let keywords = feedNameKeywords + articleTitleKeywords
|
|
|
|
activity.keywords = Set(keywords)
|
|
|
|
|
|
|
|
activity.userInfo = [
|
|
|
|
ActivityID.accountID.rawValue: article.accountID,
|
2019-08-25 02:31:29 +02:00
|
|
|
ActivityID.accountName.rawValue: article.account?.name ?? "",
|
2019-08-24 21:57:51 +02:00
|
|
|
ActivityID.feedID.rawValue: article.feedID,
|
|
|
|
ActivityID.articleID.rawValue: article.articleID
|
|
|
|
]
|
|
|
|
activity.isEligibleForSearch = true
|
|
|
|
activity.isEligibleForPrediction = false
|
|
|
|
activity.isEligibleForHandoff = true
|
|
|
|
|
|
|
|
// CoreSpotlight
|
|
|
|
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeCompositeContent as String)
|
|
|
|
attributeSet.title = article.title
|
|
|
|
attributeSet.contentDescription = article.summary
|
|
|
|
attributeSet.keywords = keywords
|
|
|
|
|
|
|
|
if let image = article.avatarImage() {
|
|
|
|
attributeSet.thumbnailData = image.pngData()
|
|
|
|
}
|
|
|
|
|
|
|
|
activity.contentAttributeSet = attributeSet
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|