You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Foundation
import Combine
import Pyramid
import UIKit
class UserViewModel: ObservableObject {
@Published var user: CurrentUser = CurrentUser.dInit
@Published var uploading = false
let provider = Pyramid()
var cancellationToken: AnyCancellable?
init() {
self.fetchMySelf()
}
}
extension UserViewModel {
func fetchMySelf() {
guard let my: CurrentUser = KeychainService.loadCodable(for: .currentUser) else {
return
}
cancellationToken = provider.request(
with: UserAPI.me(my.id),
scheduler: RunLoop.main,
class: CurrentUser.self
)
.receive(on: RunLoop.main)
.sink(receiveCompletion: { completionResponse in
switch completionResponse {
case .failure(let error):
print(error)
case .finished:
break
}
}, receiveValue: { [weak self] res in
guard let self = self else { return }
self.user = res
KeychainService.save(codable: res, for: .currentUser)
})
}
func uploadAvatar(_ image: UIImage) {
uploading = true
guard let me: CurrentUser = KeychainService.loadCodable(for: .currentUser) else {
return
}
AWSS3Helper.uploadImage(image, conversationId: nil, userId: me.id) { [weak self] imageURLString in
DispatchQueue.main.async {
self?.uploading = false
let attachment = Attachment(type: .image, userId: me.id, imageUrlString: imageURLString)
self?.createAttachment(attachment)
}
}
}
func createAttachment(_ attachment: Attachment) {
cancellationToken = provider.request(
with: AttachmentAPI.create(attachment),
scheduler: RunLoop.main,
class: Attachment.self
).sink(receiveCompletion: { completionResponse in
switch completionResponse {
case .failure(let error):
print(error)
case .finished:
break
}
}, receiveValue: { res in
print(#line, self, res)
self.fetchMySelf()
})
}
}
I added the default URL when 1st-time load or I don't have any URL
so when my user want to upload photo then get back the image URL my image never change
I added the default URL when 1st-time load or I don't have any URL
so when my user want to upload photo then get back the image URL my image never change
always same photo even when I have new image link
The text was updated successfully, but these errors were encountered: