Make show/hide reblogs finally work (#365)
oh, and also indent to 4 spaces. I needed some time to wrap my head around the data model and especially the various view-models, but hey, in the end it works. I still feel like this "I have no idea what I'm doing"-dog :D
This commit is contained in:
parent
18720a9a51
commit
ee523c098e
|
@ -128,11 +128,15 @@ extension APIService {
|
|||
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
|
||||
|
||||
let managedObjectContext = backgroundManagedObjectContext
|
||||
guard let user = user.object(in: managedObjectContext) else { throw APIError.implicit(.badRequest) }
|
||||
guard let user = user.object(in: managedObjectContext),
|
||||
let authentication = authenticationBox.authenticationRecord.object(in: managedObjectContext)
|
||||
else { throw APIError.implicit(.badRequest) }
|
||||
|
||||
let me = authentication.user
|
||||
let result: Result<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error>
|
||||
let showReblogs = false //FIXME: Use showReblogs-value from data
|
||||
let oldShowReblogs = true
|
||||
|
||||
let oldShowReblogs = me.showingReblogsBy.contains(user)
|
||||
let newShowReblogs = (oldShowReblogs == false)
|
||||
|
||||
do {
|
||||
let response = try await Mastodon.API.Account.follow(
|
||||
|
|
|
@ -27,6 +27,7 @@ public enum RelationshipAction: Int, CaseIterable {
|
|||
case edit
|
||||
case editing
|
||||
case updating
|
||||
case showReblogs
|
||||
|
||||
public var option: RelationshipActionOptionSet {
|
||||
return RelationshipActionOptionSet(rawValue: 1 << rawValue)
|
||||
|
@ -57,6 +58,7 @@ public struct RelationshipActionOptionSet: OptionSet {
|
|||
public static let edit = RelationshipAction.edit.option
|
||||
public static let editing = RelationshipAction.editing.option
|
||||
public static let updating = RelationshipAction.updating.option
|
||||
public static let showReblogs = RelationshipAction.showReblogs.option
|
||||
|
||||
public static let editOptions: RelationshipActionOptionSet = [.edit, .editing, .updating]
|
||||
|
||||
|
@ -90,9 +92,9 @@ public struct RelationshipActionOptionSet: OptionSet {
|
|||
case .edit: return L10n.Common.Controls.Friendship.editInfo
|
||||
case .editing: return L10n.Common.Controls.Actions.done
|
||||
case .updating: return " "
|
||||
case .showReblogs: return ""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final class RelationshipViewModel {
|
||||
|
@ -185,6 +187,7 @@ extension RelationshipViewModel {
|
|||
self.isBlockingBy = optionSet.contains(.blockingBy)
|
||||
self.isBlocking = optionSet.contains(.blocking)
|
||||
self.isSuspended = optionSet.contains(.suspended)
|
||||
self.showReblogs = optionSet.contains(.showReblogs)
|
||||
|
||||
self.optionSet = optionSet
|
||||
}
|
||||
|
@ -197,6 +200,7 @@ extension RelationshipViewModel {
|
|||
isBlockingBy = false
|
||||
isBlocking = false
|
||||
optionSet = nil
|
||||
showReblogs = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,6 +219,7 @@ extension RelationshipViewModel {
|
|||
let isMuting = user.mutingBy.contains(me)
|
||||
let isBlockingBy = me.blockingBy.contains(user)
|
||||
let isBlocking = user.blockingBy.contains(me)
|
||||
let isShowingReblogs = me.showingReblogsBy.contains(user)// user.showingReblogsBy.contains(me)
|
||||
|
||||
var optionSet: RelationshipActionOptionSet = [.follow]
|
||||
|
||||
|
@ -254,6 +259,10 @@ extension RelationshipViewModel {
|
|||
optionSet.insert(.suspended)
|
||||
}
|
||||
|
||||
if isShowingReblogs {
|
||||
optionSet.insert(.showReblogs)
|
||||
}
|
||||
|
||||
return optionSet
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue