Set properties based on Entity.Account (IOS-194)
This commit is contained in:
parent
bbebfac99d
commit
c45252b294
|
@ -16,11 +16,16 @@ import MastodonSDK
|
||||||
extension ProfileCardView {
|
extension ProfileCardView {
|
||||||
|
|
||||||
public func configure(account: Mastodon.Entity.Account) {
|
public func configure(account: Mastodon.Entity.Account) {
|
||||||
//TODO: Implement
|
|
||||||
viewModel.authorBannerImageURL = URL(string: account.header)
|
viewModel.authorBannerImageURL = URL(string: account.header)
|
||||||
|
viewModel.statusesCount = account.statusesCount
|
||||||
|
viewModel.followingCount = account.followingCount
|
||||||
|
viewModel.followersCount = account.followersCount
|
||||||
|
viewModel.authorAvatarImageURL = account.avatarImageURL()
|
||||||
|
|
||||||
|
let emojis = account.emojis?.asDictionary ?? [:]
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let content = MastodonContent(content: account.displayNameWithFallback, emojis: account.emojis?.asDictionary ?? [:])
|
let content = MastodonContent(content: account.displayNameWithFallback, emojis: emojis)
|
||||||
let metaContent = try MastodonMetaContent.convert(document: content)
|
let metaContent = try MastodonMetaContent.convert(document: content)
|
||||||
viewModel.authorName = metaContent
|
viewModel.authorName = metaContent
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -29,73 +34,16 @@ extension ProfileCardView {
|
||||||
viewModel.authorName = metaContent
|
viewModel.authorName = metaContent
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
viewModel.authorUsername = account.acct
|
||||||
|
|
||||||
public func configure(user: MastodonUser) {
|
do {
|
||||||
// author avatar
|
let content = MastodonContent(content: account.note, emojis: emojis)
|
||||||
Publishers.CombineLatest3(
|
let metaContent = try MastodonMetaContent.convert(document: content)
|
||||||
user.publisher(for: \.avatar),
|
viewModel.bioContent = metaContent
|
||||||
user.publisher(for: \.avatarStatic),
|
} catch {
|
||||||
UserDefaults.shared.publisher(for: \.preferredStaticAvatar)
|
assertionFailure(error.localizedDescription)
|
||||||
)
|
let metaContent = PlaintextMetaContent(string: account.note)
|
||||||
.map { _ in user.avatarImageURL() }
|
viewModel.bioContent = metaContent
|
||||||
.assign(to: \.authorAvatarImageURL, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
// name
|
|
||||||
Publishers.CombineLatest(
|
|
||||||
user.publisher(for: \.displayName),
|
|
||||||
user.publisher(for: \.emojis)
|
|
||||||
)
|
|
||||||
.map { _, emojis in
|
|
||||||
do {
|
|
||||||
let content = MastodonContent(content: user.displayNameWithFallback, emojis: emojis.asDictionary)
|
|
||||||
let metaContent = try MastodonMetaContent.convert(document: content)
|
|
||||||
return metaContent
|
|
||||||
} catch {
|
|
||||||
assertionFailure(error.localizedDescription)
|
|
||||||
return PlaintextMetaContent(string: user.displayNameWithFallback)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.assign(to: \.authorName, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
// username
|
|
||||||
user.publisher(for: \.acct)
|
|
||||||
.map { $0 as String? }
|
|
||||||
.assign(to: \.authorUsername, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
// bio
|
|
||||||
Publishers.CombineLatest(
|
|
||||||
user.publisher(for: \.note),
|
|
||||||
user.publisher(for: \.emojis)
|
|
||||||
)
|
|
||||||
.map { note, emojis in
|
|
||||||
guard let note = note else { return nil }
|
|
||||||
do {
|
|
||||||
let content = MastodonContent(content: note, emojis: emojis.asDictionary)
|
|
||||||
let metaContent = try MastodonMetaContent.convert(document: content)
|
|
||||||
return metaContent
|
|
||||||
} catch {
|
|
||||||
assertionFailure(error.localizedDescription)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.assign(to: \.bioContent, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
// relationship
|
|
||||||
viewModel.relationshipViewModel.user = user
|
|
||||||
// dashboard
|
|
||||||
user.publisher(for: \.statusesCount)
|
|
||||||
.map { Int($0) }
|
|
||||||
.assign(to: \.statusesCount, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
user.publisher(for: \.followingCount)
|
|
||||||
.map { Int($0) }
|
|
||||||
.assign(to: \.followingCount, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
user.publisher(for: \.followersCount)
|
|
||||||
.map { Int($0) }
|
|
||||||
.assign(to: \.followersCount, on: viewModel)
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue