Skip to content

Commit

Permalink
Fix few code
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-amisha-i committed Mar 20, 2024
1 parent abed1ed commit d990fc6
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 130 deletions.
6 changes: 0 additions & 6 deletions BaseStyle/BaseStyle/CustomUI/ImagePickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ public class ImagePickerViewCoordinator: NSObject, UINavigationControllerDelegat
let image = info[infoKey] as? UIImage

updateImageCallBack(image)

// if cropOption == .custom {
// let viewController = UIHostingController(rootView: ImageCropView(image: image, fileName: fileName, isDarkModeEnabled: isDarkMode, updateImageCallBack: updateImageCallBack(_:_:)))
//
// picker.present(viewController, animated: true)
// }
}

func updateImageCallBack(_ image: UIImage?) {
Expand Down
2 changes: 1 addition & 1 deletion BaseStyle/BaseStyle/Extension/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension String {

public func randomString(length: Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
return String((0..<length).map { _ in letters.randomElement()! })
return String((0..<length).compactMap { _ in letters.randomElement() })
}
}

Expand Down
231 changes: 125 additions & 106 deletions Data/Data/Repository/GroupRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,168 +11,187 @@ public class GroupRepository: ObservableObject {

@Inject private var store: GroupStore

@Inject var preference: SplitoPreference
@Inject var storageManager: StorageManager
@Inject var memberRepository: MemberRepository
@Inject private var preference: SplitoPreference
@Inject private var storageManager: StorageManager
@Inject private var memberRepository: MemberRepository

private var cancelables = Set<AnyCancellable>()

public func createGroup(group: Groups, imageData: Data?) -> AnyPublisher<String, ServiceError> {
Future { [weak self] promise in

guard let self else { return }

self.createGroupInStore(group: group)
.flatMap { docId -> AnyPublisher<(String, Member), ServiceError> in
return self.addCreatorToMembers(groupId: docId)
.map { (docId, $0) }
.eraseToAnyPublisher()
}
.flatMap { docId, member -> AnyPublisher<String, ServiceError> in
var newGroup = group
newGroup.id = docId
newGroup.members.append(member)
return self.finalizeGroupCreation(group: newGroup, imageData: imageData)
}
.sink { completion in
if case let .failure(error) = completion {
promise(.failure(error))
}
} receiveValue: { docId in
promise(.success(docId))
}
.store(in: &self.cancelables)
}
.eraseToAnyPublisher()
}

private func createGroupInStore(group: Groups) -> AnyPublisher<String, ServiceError> {
Future { [weak self] promise in

guard let self else {
promise(.failure(.unexpectedError))
return
}

var newGroup = group
self.store.createGroup(group: group) { docId in
guard let docId else {
promise(.failure(.databaseError))
return
}
promise(.success(docId))
}
}.eraseToAnyPublisher()
}

newGroup.id = docId
private func addCreatorToMembers(groupId: String) -> AnyPublisher<Member, ServiceError> {
Future { [weak self] promise in

self.addCreatorToMembers(groupId: docId) { member in
guard let member else {
promise(.failure(.databaseError))
return
}
newGroup.members.append(member)
guard let self, let userId = self.preference.user?.id else { return }
var member = Member(userId: userId, groupId: groupId)

if let imageData {
self.uploadImage(imageData: imageData, group: newGroup)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(docId))
}.store(in: &self.cancelables)
} else {
self.updateGroup(group: newGroup)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(docId))
}.store(in: &self.cancelables)
}
self.memberRepository.addMemberToMembers(member: member) { memberId in
if let memberId {
member.id = memberId
promise(.success(member))
} else {
promise(.failure(.databaseError))
}
}
}.eraseToAnyPublisher()
}

private func addCreatorToMembers(groupId: String, completion: @escaping (Member?) -> Void) {
guard let userId = preference.user?.id else { return }

var member = Member(userId: userId, groupId: groupId)

memberRepository.addMemberToMembers(member: member) { id in
member.id = id
completion(id == nil ? nil : member)
}
private func finalizeGroupCreation(group: Groups, imageData: Data?) -> AnyPublisher<String, ServiceError> {
Future { [weak self] promise in
guard let self, let groupId = group.id else { return }
if let imageData {
self.uploadImage(imageData: imageData, group: group)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(groupId))
}.store(in: &self.cancelables)
} else {
self.updateGroup(group: group)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(groupId))
}.store(in: &self.cancelables)
}
}.eraseToAnyPublisher()
}

private func uploadImage(imageData: Data, group: Groups) -> AnyPublisher<Void, ServiceError> {
Future { [weak self] promise in

guard let self else {
guard let self, let groupId = group.id else {
promise(.failure(.unexpectedError))
return
}

if let groupId = group.id {
storageManager.uploadImage(for: .group, id: groupId, imageData: imageData) { url in
guard let url else {
promise(.failure(.databaseError))
return
}

var newGroup = group
newGroup.imageUrl = url
self.updateGroup(group: newGroup)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(()))
}.store(in: &self.cancelables)
self.storageManager.uploadImage(for: .group, id: groupId, imageData: imageData) { url in
guard let url else {
promise(.failure(.databaseError))
return
}

var newGroup = group
newGroup.imageUrl = url

self.updateGroup(group: newGroup)
.sink { completion in
switch completion {
case .finished:
return
case .failure(let error):
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(()))
}.store(in: &self.cancelables)
}
}.eraseToAnyPublisher()
}

public func addMemberToGroup(groupId: String, memberId: String) -> AnyPublisher<String, ServiceError> {
Future { [weak self] promise in

guard let self else {
promise(.failure(.unexpectedError))
return
}

self.fetchGroupBy(id: groupId)
.flatMap { group -> AnyPublisher<(Groups?, Member?), ServiceError> in
return self.fetchMemberWith(id: memberId)
.map { (group, $0) }
.eraseToAnyPublisher()
}
.flatMap { group, member -> AnyPublisher<Void, ServiceError> in
guard var group, let member else {
return Fail(error: .dataNotFound).eraseToAnyPublisher()
}
group.members.append(member)
return self.updateGroup(group: group)
}
.sink { completion in
if case let .failure(error) = completion {
promise(.failure(error))
}
} receiveValue: { _ in
promise(.success(groupId))
}
.store(in: &self.cancelables)
}.eraseToAnyPublisher()
}

public func fetchMemberWith(id: String) -> AnyPublisher<Member?, ServiceError> {
Future { [weak self] promise in
guard let self else { return }
self.memberRepository.fetchMemberBy(id: id)
.sink { completion in
switch completion {
case .failure(let error):
promise(.failure(error))
case .finished:
return
}
} receiveValue: { group in
guard let group else {
promise(.failure(.dataNotFound))
return
}

self.fetchMemberWith(id: memberId) { member in
if let member {
var newGroup = group
newGroup.members.append(member)

self.updateGroup(group: newGroup)
.sink { completion in
switch completion {
case .failure(let error):
promise(.failure(error))
case .finished:
return
}
} receiveValue: { _ in
promise(.success((newGroup.id ?? "")))
}.store(in: &self.cancelables)
}
break
}
} receiveValue: { member in
promise(.success(member))
}.store(in: &self.cancelables)
}.eraseToAnyPublisher()
}

public func fetchMemberWith(id: String, completion: @escaping (Member?) -> Void) {
memberRepository.fetchMemberBy(id: id)
.sink { result in
switch result {
case .failure:
completion(nil)
case .finished:
return
}
} receiveValue: { member in
completion(member)
}.store(in: &cancelables)
}

public func updateGroup(group: Groups) -> AnyPublisher<Void, ServiceError> {
store.updateGroup(group: group)
}
Expand Down
10 changes: 5 additions & 5 deletions Data/Data/Store/ShareCodeStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ShareCodeStore: ObservableObject {
completion(code.documentID)
return
} catch {
print("ShareCodeStore :: \(#function) error: \(error.localizedDescription)")
LogE("ShareCodeStore :: \(#function) error: \(error.localizedDescription)")
}
completion(nil)
}
Expand All @@ -34,13 +34,13 @@ public class ShareCodeStore: ObservableObject {

self.database.collection(DATABASE_NAME).whereField("code", isEqualTo: code).getDocuments { snapshot, error in
if let error {
print("ShareCodeStore :: \(#function) error: \(error.localizedDescription)")
LogE("ShareCodeStore :: \(#function) error: \(error.localizedDescription)")
promise(.failure(.networkError))
return
}

guard let document = snapshot?.documents.first else {
print("ShareCodeStore :: \(#function) The document is not available.")
LogD("ShareCodeStore :: \(#function) The document is not available.")
promise(.success(nil))
return
}
Expand All @@ -49,7 +49,7 @@ public class ShareCodeStore: ObservableObject {
let sharedCode = try document.data(as: SharedCode.self)
promise(.success(sharedCode))
} catch {
print("ShareCodeStore :: \(#function) Decode error: \(error.localizedDescription)")
LogE("ShareCodeStore :: \(#function) Decode error: \(error.localizedDescription)")
promise(.failure(.decodingError))
}
}
Expand All @@ -68,7 +68,7 @@ public class ShareCodeStore: ObservableObject {
LogE("ShareCodeStore :: \(#function): Deleting collection failed with error: \(error.localizedDescription).")
promise(.failure(.databaseError))
} else {
LogE("ShareCodeStore :: \(#function): code deleted successfully.")
LogD("ShareCodeStore :: \(#function): code deleted successfully.")
promise(.success(()))
}
}
Expand Down
17 changes: 7 additions & 10 deletions install_dist_certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@
CERTIFICATE_P12=dist_certificate.p12

# Recreate the certificate from the secure environment variable
echo $BUILD_CERTIFICATE_KEY | base64 --decode > $CERTIFICATE_P12
echo "$BUILD_CERTIFICATE_KEY" | base64 --decode > "$CERTIFICATE_P12"

# create temporary keychain
security create-keychain -p $BUILD_KEYCHAIN_PASSWORD $BUILD_KEYCHAIN
security create-keychain -p "$BUILD_KEYCHAIN_PASSWORD" "$BUILD_KEYCHAIN"

# Set keychain settings
security set-keychain-settings $BUILD_KEYCHAIN

# Set default keychain
#security default-keychain -s $BUILD_KEYCHAIN
security set-keychain-settings "$BUILD_KEYCHAIN"

# Unlock the keychain
security unlock-keychain -p $BUILD_KEYCHAIN_PASSWORD $BUILD_KEYCHAIN
security unlock-keychain -p "$BUILD_KEYCHAIN_PASSWORD" "$BUILD_KEYCHAIN"

# Import the certificate to the keychain
security import $CERTIFICATE_P12 -k $BUILD_KEYCHAIN -P $BUILD_CERTIFICATE_PASSWORD -T /usr/bin/codesign;
security import "$CERTIFICATE_P12" -k "$BUILD_KEYCHAIN" -P "$BUILD_CERTIFICATE_PASSWORD" -T /usr/bin/codesign;

# Set key partition list
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $BUILD_KEYCHAIN_PASSWORD $BUILD_KEYCHAIN
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$BUILD_KEYCHAIN_PASSWORD" "$BUILD_KEYCHAIN"

# Lock the keychain
security lock-keychain $BUILD_KEYCHAIN
security lock-keychain "$BUILD_KEYCHAIN"

# remove certs
rm -fr *.p12
Loading

0 comments on commit d990fc6

Please sign in to comment.