Skip to content

Commit

Permalink
⚠️ Start to fix subclass name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Feb 11, 2022
1 parent 11c532a commit c47095c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
23 changes: 13 additions & 10 deletions Sources/EasyFirebase/Services/Auth/EasyUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ open class EasyUser: IndexedDocument {
/// The user's email address.
public internal(set) var email: String

/// The user's username.
///
/// This value is automatically generated based on the user's email upon account creation.
public internal(set) var username: String

/// The user's display name.
///
/// This value is automatically updated to a suggested display name when an account is created.
Expand All @@ -100,6 +95,13 @@ open class EasyUser: IndexedDocument {
/// You can specify a default profile image by setting `EasyAuth.defaultProfileImageURLs`.
public var profileImageURL: URL?

// MARK: - Objective C Exposed Mixed Properties

/// The user's username.
///
/// This value is automatically generated based on the user's email upon account creation.
@objc public internal(set) var username: String

// MARK: - Inherited Properties

public var index: Int?
Expand Down Expand Up @@ -200,10 +202,11 @@ public extension EasyUser {
- parameter suggestionGenerator: A function that takes in a username and provides a new username (hopefully unique). See **Discussion** for more information.
- parameter completion: The completion handler. See **Discussion** for more information.
*/
func safelyUpdateUsername(to newUsername: String,
suggesting suggestionGenerator: @escaping (String) -> String = defaultSuggestionGenerator,
completion: @escaping (Error?, String?) -> Void) {
EasyAuth.checkUsernameAvailable(newUsername, forUserType: Self.self) { available in
func safelyUpdateUsername<T>(to newUsername: String,
ofType type: T.Type,
suggesting suggestionGenerator: @escaping (String) -> String = defaultSuggestionGenerator,
completion: @escaping (Error?, String?) -> Void) where T: EasyUser {
EasyAuth.checkUsernameAvailable(newUsername, forUserType: T.self) { available in
if available {
self.unsafelyUpdateUsername(to: newUsername) { error in
completion(error, nil)
Expand All @@ -227,7 +230,7 @@ public extension EasyUser {
*/
func unsafelyUpdateUsername(to newUsername: String, completion: @escaping (Error?) -> Void = { _ in }) {
self.username = newUsername
set(\.username)
set(\.username, completion: completion)
}

/**
Expand Down
5 changes: 3 additions & 2 deletions Sources/EasyFirebase/Services/Firestore/Querying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ extension EasyFirestore {
}

private static func `where`<T, V>(_ conditions: [Condition<T, V>], order: Order?, limit: Int?, completion: @escaping ([T]) -> Void) where T: Document {
let collection = db.collection(String(describing: T.self))
let collectionName = String(describing: T.self)
let collection = db.collection(collectionName)
guard conditions.count > 0 else { return }
var query: Query = conditions.first!.apply(to: collection)
for condition in conditions.dropFirst() {
Expand All @@ -126,8 +127,8 @@ extension EasyFirestore {
if let object = object {
arr.append(object)
}
completion(arr)
}
completion(arr)
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/EasyFirebase/Services/Firestore/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ extension EasyFirestore {
*/
public static func set<T, U>(_ path: KeyPath<T, U>, in document: T, completion: @escaping (Error?) -> Void = { _ in }) where T: Document, U: Codable {
let value = document[keyPath: path]
db.collection(String(describing: T.self)).document(document.id).updateData([path.string: value], completion: completion)
let collectionName = String(describing: T.self)
db.collection(collectionName).document(document.id).updateData([path.string: value], completion: completion)
}

/**
Expand Down

0 comments on commit c47095c

Please sign in to comment.