Skip to content

Commit

Permalink
feat(models): add account type to User access
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed May 15, 2021
1 parent 4492b4a commit 760c12f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Sources/Swiftagram/Models/Specialized/User.swift
Expand Up @@ -25,7 +25,12 @@ public struct User: Wrapped {
public static let `private`: Access = .init(rawValue: 1 << 0)
/// A verified account.
public static let verified: Access = .init(rawValue: 1 << 1)
/// A business account.
public static let business: Access = .init(rawValue: 1 << 2)
/// A creator account.
public static let creator: Access = .init(rawValue: 1 << 3)
}

/// A `struct` representing a profile's `Counter`s.
public struct Counter: Hashable, Codable {
/// Posts.
Expand Down Expand Up @@ -55,6 +60,8 @@ public struct User: Wrapped {
public var name: String? { self["fullName"].string() }
/// The biography.
public var biography: String? { self["biography"].string() }
/// The category.
public var category: String? { self["category"].string() }
/// A lower quality avatar.
public var thumbnail: URL? { self["profilePicUrl"].url() }
/// An higher quality avatar.
Expand All @@ -72,18 +79,16 @@ public struct User: Wrapped {
public var access: Access? {
let isPrivate = self["isPrivate"].bool()
let isVerified = self["isVerified"].bool()
let isBusiness = self["isBusiness"].bool()
let account = self["accountType"].int()
// Deal with condition.
if isPrivate == true && isVerified == true {
return [.private, .verified]
} else if isPrivate == true {
return .private
} else if isVerified == true {
return .verified
} else if isPrivate == nil && isVerified == nil {
return nil
} else {
return []
}
guard isPrivate != nil || isVerified != nil || isBusiness != nil || account != nil else { return nil }
var access: Access = []
if isPrivate ?? false { access.formUnion(.private) }
if isVerified ?? false { access.formUnion(.verified) }
if (isBusiness ?? false) || account == 2 { access.formUnion(.business) }
if account == 3 { access.formUnion(.creator) }
return access
}

/// An optional friendship status.
Expand Down

0 comments on commit 760c12f

Please sign in to comment.