mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Loading images and user avatars.
This commit is contained in:
@@ -9,15 +9,12 @@ import Foundation
|
||||
import MatrixRustSDK
|
||||
import Combine
|
||||
import UIKit
|
||||
import Kingfisher
|
||||
|
||||
enum UserSessionCallback {
|
||||
case updatedRoomsList
|
||||
}
|
||||
|
||||
enum UserSessionError: Error {
|
||||
case failedRetrievingAvatar
|
||||
}
|
||||
|
||||
private class WeakUserSessionWrapper: ClientDelegate {
|
||||
private weak var userSession: UserSession?
|
||||
|
||||
@@ -41,6 +38,8 @@ class UserSession: ClientDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
let mediaProvider: MediaProviderProtocol
|
||||
|
||||
deinit {
|
||||
client.setDelegate(delegate: nil)
|
||||
}
|
||||
@@ -49,6 +48,7 @@ class UserSession: ClientDelegate {
|
||||
|
||||
init(client: Client) {
|
||||
self.client = client
|
||||
self.mediaProvider = MediaProvider(client: client, imageCache: ImageCache.default)
|
||||
|
||||
client.setDelegate(delegate: WeakUserSessionWrapper(userSession: self))
|
||||
client.startSync()
|
||||
@@ -72,22 +72,6 @@ class UserSession: ClientDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func loadUserAvatar(_ completion: @escaping (Result<UIImage?, Error>) -> Void) {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
do {
|
||||
let avatarData = try self.client.avatar()
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(UIImage(data: Data(bytes: avatarData, count: avatarData.count))))
|
||||
}
|
||||
} catch {
|
||||
MXLog.error("Failed retrieving room name with error: \(error)")
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(UserSessionError.failedRetrievingAvatar))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getRoomList(_ completion: @escaping ([RoomProxyProtocol]) -> Void) {
|
||||
fetchRoomList(completion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user