|
@@ -27,6 +27,12 @@ var myVoiceBarInfo: LNUserVoiceStateVO {
|
|
|
LNProfileManager.shared.myVoiceState
|
|
LNProfileManager.shared.myVoiceState
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+class LNProfileUserInfo {
|
|
|
|
|
+ var uid: String = ""
|
|
|
|
|
+ var name: String = ""
|
|
|
|
|
+ var avatar: String = ""
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
class LNProfileManager {
|
|
class LNProfileManager {
|
|
|
static let shared = LNProfileManager()
|
|
static let shared = LNProfileManager()
|
|
|
static let nameMaxInput = 25
|
|
static let nameMaxInput = 25
|
|
@@ -37,6 +43,11 @@ class LNProfileManager {
|
|
|
|
|
|
|
|
private var randomProfile: LNRandomProfileResponse?
|
|
private var randomProfile: LNRandomProfileResponse?
|
|
|
|
|
|
|
|
|
|
+ private static let profileCacheLimit = 300
|
|
|
|
|
+ private var profileCache: [String: LNProfileUserInfo] = [:]
|
|
|
|
|
+ private var profileCacheOrder: [String] = []
|
|
|
|
|
+ private let profileCacheLock = NSLock()
|
|
|
|
|
+
|
|
|
private let captchaCoolDown = 60
|
|
private let captchaCoolDown = 60
|
|
|
private var captchaRemain = 0
|
|
private var captchaRemain = 0
|
|
|
private var captchaTimer: Timer?
|
|
private var captchaTimer: Timer?
|
|
@@ -50,8 +61,8 @@ class LNProfileManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
extension LNProfileManager {
|
|
extension LNProfileManager {
|
|
|
- func reloadMyProfile() {
|
|
|
|
|
- LNHttpManager.shared.getMyProfile { [weak self] res, err in
|
|
|
|
|
|
|
+ func reloadMyProfileDetail() {
|
|
|
|
|
+ LNHttpManager.shared.getMyProfileDetail { [weak self] res, err in
|
|
|
guard let self else { return }
|
|
guard let self else { return }
|
|
|
guard err == nil, let res else { return }
|
|
guard err == nil, let res else { return }
|
|
|
if let relation = res.userFollowStat {
|
|
if let relation = res.userFollowStat {
|
|
@@ -62,7 +73,7 @@ extension LNProfileManager {
|
|
|
notifyUserVoiceBarInfoChanged()
|
|
notifyUserVoiceBarInfoChanged()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- getUserProfile(uid: myUid) { _ in }
|
|
|
|
|
|
|
+ getUserProfileDetail(uid: myUid) { _ in }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func modifyMyProfile(config: LNProfileUpdateConfig, queue: DispatchQueue = .main,
|
|
func modifyMyProfile(config: LNProfileUpdateConfig, queue: DispatchQueue = .main,
|
|
@@ -73,7 +84,7 @@ extension LNProfileManager {
|
|
|
if let err {
|
|
if let err {
|
|
|
showToast(err.errorDesc)
|
|
showToast(err.errorDesc)
|
|
|
} else {
|
|
} else {
|
|
|
- reloadMyProfile()
|
|
|
|
|
|
|
+ reloadMyProfileDetail()
|
|
|
if config.interest != nil {
|
|
if config.interest != nil {
|
|
|
LNGameMateManager.shared.getGameTypeList { _ in }
|
|
LNGameMateManager.shared.getGameTypeList { _ in }
|
|
|
}
|
|
}
|
|
@@ -94,7 +105,7 @@ extension LNProfileManager {
|
|
|
showToast(err.errorDesc)
|
|
showToast(err.errorDesc)
|
|
|
} else {
|
|
} else {
|
|
|
guard let self else { return }
|
|
guard let self else { return }
|
|
|
- reloadMyProfile()
|
|
|
|
|
|
|
+ reloadMyProfileDetail()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -108,14 +119,14 @@ extension LNProfileManager {
|
|
|
showToast(err.errorDesc)
|
|
showToast(err.errorDesc)
|
|
|
} else {
|
|
} else {
|
|
|
guard let self else { return }
|
|
guard let self else { return }
|
|
|
- reloadMyProfile()
|
|
|
|
|
|
|
+ reloadMyProfileDetail()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
extension LNProfileManager {
|
|
extension LNProfileManager {
|
|
|
- func getUserProfile(uid: String, queue: DispatchQueue = .main, handler: @escaping (LNUserProfileVO?) -> Void) {
|
|
|
|
|
|
|
+ func getUserProfileDetail(uid: String, queue: DispatchQueue = .main, handler: @escaping (LNUserProfileVO?) -> Void) {
|
|
|
LNHttpManager.shared.getUsersInfo(uids: [uid]) { [weak self] res, err in
|
|
LNHttpManager.shared.getUsersInfo(uids: [uid]) { [weak self] res, err in
|
|
|
guard let self else { return }
|
|
guard let self else { return }
|
|
|
if let res, err == nil {
|
|
if let res, err == nil {
|
|
@@ -125,6 +136,11 @@ extension LNProfileManager {
|
|
|
self.notifyUserInfoChanged(newInfo: $0)
|
|
self.notifyUserInfoChanged(newInfo: $0)
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ self.updateProfileCache(
|
|
|
|
|
+ uid: $0.userNo,
|
|
|
|
|
+ name: $0.nickname,
|
|
|
|
|
+ avatar: $0.cover
|
|
|
|
|
+ )
|
|
|
self.notifyUserInfoChanged(newInfo: $0)
|
|
self.notifyUserInfoChanged(newInfo: $0)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -164,6 +180,85 @@ extension LNProfileManager {
|
|
|
// }
|
|
// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+extension LNProfileManager {
|
|
|
|
|
+ func getCachedProfileUserInfo(uid: String) -> LNProfileUserInfo? {
|
|
|
|
|
+ profileCacheLock.lock()
|
|
|
|
|
+ defer { profileCacheLock.unlock() }
|
|
|
|
|
+ guard let info = profileCache[uid] else {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ touchProfileCacheKey(uid)
|
|
|
|
|
+ return info
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ func getCachedProfileUserInfo(uid: String,
|
|
|
|
|
+ fetchIfNeeded: Bool = true,
|
|
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
|
|
+ handler: @escaping (LNProfileUserInfo?) -> Void) {
|
|
|
|
|
+ if let info = getCachedProfileUserInfo(uid: uid) {
|
|
|
|
|
+ queue.asyncIfNotGlobal {
|
|
|
|
|
+ handler(info)
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ guard fetchIfNeeded else {
|
|
|
|
|
+ queue.asyncIfNotGlobal {
|
|
|
|
|
+ handler(nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getUserProfileDetail(uid: uid, queue: queue) { [weak self] profile in
|
|
|
|
|
+ guard let self, let profile else {
|
|
|
|
|
+ handler(nil)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ self.updateProfileCache(
|
|
|
|
|
+ uid: profile.userNo,
|
|
|
|
|
+ name: profile.nickname,
|
|
|
|
|
+ avatar: profile.cover
|
|
|
|
|
+ )
|
|
|
|
|
+ handler(self.getCachedProfileUserInfo(uid: uid))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ func updateProfileCache(uid: String,
|
|
|
|
|
+ name: String,
|
|
|
|
|
+ avatar: String) {
|
|
|
|
|
+ guard !uid.isEmpty else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ profileCacheLock.lock()
|
|
|
|
|
+ defer { profileCacheLock.unlock() }
|
|
|
|
|
+
|
|
|
|
|
+ let info = profileCache[uid] ?? LNProfileUserInfo()
|
|
|
|
|
+ info.uid = uid
|
|
|
|
|
+ info.name = name
|
|
|
|
|
+ info.avatar = avatar
|
|
|
|
|
+
|
|
|
|
|
+ profileCache[uid] = info
|
|
|
|
|
+ touchProfileCacheKey(uid)
|
|
|
|
|
+ trimProfileCacheIfNeeded()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func touchProfileCacheKey(_ uid: String) {
|
|
|
|
|
+ if let index = profileCacheOrder.firstIndex(of: uid) {
|
|
|
|
|
+ profileCacheOrder.remove(at: index)
|
|
|
|
|
+ }
|
|
|
|
|
+ profileCacheOrder.append(uid)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func trimProfileCacheIfNeeded() {
|
|
|
|
|
+ while profileCacheOrder.count > Self.profileCacheLimit {
|
|
|
|
|
+ let expiredUid = profileCacheOrder.removeFirst()
|
|
|
|
|
+ profileCache.removeValue(forKey: expiredUid)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
extension LNProfileManager {
|
|
extension LNProfileManager {
|
|
|
func getBindPhoneCaptcha(code: String, phone: String,
|
|
func getBindPhoneCaptcha(code: String, phone: String,
|
|
|
queue: DispatchQueue = .main,
|
|
queue: DispatchQueue = .main,
|
|
@@ -234,7 +329,7 @@ extension LNProfileManager {
|
|
|
|
|
|
|
|
extension LNProfileManager: LNAccountManagerNotify {
|
|
extension LNProfileManager: LNAccountManagerNotify {
|
|
|
func onUserLogin() {
|
|
func onUserLogin() {
|
|
|
- reloadMyProfile()
|
|
|
|
|
|
|
+ reloadMyProfileDetail()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func onUserLogout() {
|
|
func onUserLogout() {
|