forked from zelo72/mastodon-ios
fix: decode error
This commit is contained in:
parent
fde5baad2e
commit
ada6d542f3
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D80" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D75" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Application" representedClassName=".Application" syncable="YES">
|
||||
<attribute name="identifier" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
|
@ -35,11 +35,11 @@
|
|||
<relationship name="toot" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Toot" inverseName="emojis" inverseEntity="Toot"/>
|
||||
</entity>
|
||||
<entity name="History" representedClassName=".History" syncable="YES">
|
||||
<attribute name="accounts" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="accounts" optional="YES" attributeType="String"/>
|
||||
<attribute name="createAt" attributeType="Date" defaultDateTimeInterval="631123200" usesScalarValueType="NO"/>
|
||||
<attribute name="day" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="identifier" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="uses" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="uses" optional="YES" attributeType="String"/>
|
||||
<relationship name="tag" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Tag" inverseName="histories" inverseEntity="Tag"/>
|
||||
</entity>
|
||||
<entity name="HomeTimelineIndex" representedClassName=".HomeTimelineIndex" syncable="YES">
|
||||
|
|
|
@ -14,8 +14,8 @@ public final class History: NSManagedObject {
|
|||
@NSManaged public private(set) var createAt: Date
|
||||
|
||||
@NSManaged public private(set) var day: Date
|
||||
@NSManaged public private(set) var uses: Int
|
||||
@NSManaged public private(set) var accounts: Int
|
||||
@NSManaged public private(set) var uses: String
|
||||
@NSManaged public private(set) var accounts: String
|
||||
|
||||
// many-to-one relationship
|
||||
@NSManaged public private(set) var tag: Tag
|
||||
|
@ -43,10 +43,10 @@ public extension History {
|
|||
public extension History {
|
||||
struct Property {
|
||||
public let day: Date
|
||||
public let uses: Int
|
||||
public let accounts: Int
|
||||
public let uses: String
|
||||
public let accounts: String
|
||||
|
||||
public init(day: Date, uses: Int, accounts: Int) {
|
||||
public init(day: Date, uses: String, accounts: String) {
|
||||
self.day = day
|
||||
self.uses = uses
|
||||
self.accounts = accounts
|
||||
|
|
|
@ -47,6 +47,7 @@ extension SearchViewController {
|
|||
searchBar.delegate = self
|
||||
navigationItem.titleView = searchBar
|
||||
navigationItem.hidesBackButton = true
|
||||
viewModel.requestRecommendData()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,39 +26,56 @@ final class SearchViewModel {
|
|||
|
||||
init(context: AppContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
func requestRecommendData() {
|
||||
guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else {
|
||||
return
|
||||
}
|
||||
context.apiService.recommendTrends(domain: activeMastodonAuthenticationBox.domain, query: Mastodon.API.Trends.Query(limit: 5))
|
||||
let trendsAPI = context.apiService.recommendTrends(domain: activeMastodonAuthenticationBox.domain, query: Mastodon.API.Trends.Query(limit: 5))
|
||||
// .sink { completion in
|
||||
// switch completion {
|
||||
// case .failure(let error):
|
||||
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendTrends fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||
// case .finished:
|
||||
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendTrends success", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// } receiveValue: { [weak self] tags in
|
||||
// guard let self = self else { return }
|
||||
// self.recommendHashTags = tags.value
|
||||
// }
|
||||
// .store(in: &disposeBag)
|
||||
|
||||
let accountsAPI = context.apiService.recommendAccount(domain: activeMastodonAuthenticationBox.domain, query: nil, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
|
||||
// .sink { completion in
|
||||
// switch completion {
|
||||
// case .failure(let error):
|
||||
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendAccount fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||
// case .finished:
|
||||
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendAccount success", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
// break
|
||||
// }
|
||||
// } receiveValue: { [weak self] accounts in
|
||||
// guard let self = self else { return }
|
||||
// self.recommendAccounts = accounts.value
|
||||
// }
|
||||
// .store(in: &disposeBag)
|
||||
Publishers.Zip(trendsAPI,accountsAPI)
|
||||
.sink { completion in
|
||||
switch completion {
|
||||
case .failure(let error):
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendTrends fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: zip request fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||
case .finished:
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendTrends success", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: zip request success", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
break
|
||||
}
|
||||
|
||||
} receiveValue: { [weak self] tags in
|
||||
} receiveValue: { [weak self] (tags, accounts) in
|
||||
guard let self = self else { return }
|
||||
self.recommendAccounts = accounts.value
|
||||
self.recommendHashTags = tags.value
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
context.apiService.recommendAccount(domain: activeMastodonAuthenticationBox.domain, query: nil, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
|
||||
.sink { completion in
|
||||
switch completion {
|
||||
case .failure(let error):
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendAccount fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||
case .finished:
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: recommendAccount success", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
break
|
||||
}
|
||||
} receiveValue: { [weak self] accounts in
|
||||
guard let self = self else { return }
|
||||
self.recommendAccounts = accounts.value
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,27 +8,27 @@
|
|||
import Combine
|
||||
import Foundation
|
||||
|
||||
/// Search results
|
||||
///
|
||||
/// Search for content in accounts, statuses and hashtags.
|
||||
///
|
||||
/// Version history:
|
||||
/// 2.4.1 - added, limit hardcoded to 5
|
||||
/// 2.8.0 - add type, limit, offset, min_id, max_id, account_id
|
||||
/// 3.0.0 - add exclude_unreviewed param
|
||||
/// # Reference
|
||||
/// [Document](https://docs.joinmastodon.org/methods/search/)
|
||||
/// - Parameters:
|
||||
/// - session: `URLSession`
|
||||
/// - domain: Mastodon instance domain. e.g. "example.com"
|
||||
/// - query: search query
|
||||
/// - Returns: `AnyPublisher` contains `Accounts,Hashtags,Status` nested in the response
|
||||
|
||||
extension Mastodon.API.Search {
|
||||
static func searchURL(domain: String) -> URL {
|
||||
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("api/v2/search")
|
||||
Mastodon.API.endpointV2URL(domain: domain).appendingPathComponent("search")
|
||||
}
|
||||
|
||||
/// Search results
|
||||
///
|
||||
/// Search for content in accounts, statuses and hashtags.
|
||||
///
|
||||
/// Version history:
|
||||
/// 2.4.1 - added, limit hardcoded to 5
|
||||
/// 2.8.0 - add type, limit, offset, min_id, max_id, account_id
|
||||
/// 3.0.0 - add exclude_unreviewed param
|
||||
/// # Reference
|
||||
/// [Document](https://docs.joinmastodon.org/methods/search/)
|
||||
/// - Parameters:
|
||||
/// - session: `URLSession`
|
||||
/// - domain: Mastodon instance domain. e.g. "example.com"
|
||||
/// - query: search query
|
||||
/// - authorization: User token
|
||||
/// - Returns: `AnyPublisher` contains `Accounts,Hashtags,Status` nested in the response
|
||||
public static func search(
|
||||
session: URLSession,
|
||||
domain: String,
|
||||
|
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
|
||||
extension Mastodon.API.Suggestions {
|
||||
static func suggestionsURL(domain: String) -> URL {
|
||||
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("api/v1/suggestions")
|
||||
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("suggestions")
|
||||
}
|
||||
|
||||
/// Follow suggestions
|
||||
|
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
|
||||
extension Mastodon.API.Trends {
|
||||
static func trendsURL(domain: String) -> URL {
|
||||
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("api/v1/trends")
|
||||
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("trends")
|
||||
}
|
||||
|
||||
/// Trending tags
|
||||
|
|
|
@ -50,6 +50,9 @@ extension Mastodon.API {
|
|||
if let date = fullDatePreciseISO8601Formatter.date(from: string) {
|
||||
return date
|
||||
}
|
||||
if let timestamp = TimeInterval(string) {
|
||||
return Date(timeIntervalSince1970: timestamp)
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ extension Mastodon.Entity {
|
|||
public struct History: Codable {
|
||||
/// UNIX timestamp on midnight of the given day
|
||||
public let day: Date
|
||||
public let uses: Int
|
||||
public let accounts: Int
|
||||
public let uses: String
|
||||
public let accounts: String
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue