|
|
@@ -40,10 +40,15 @@ class LNGiftManager {
|
|
|
}
|
|
|
|
|
|
func fetchGiftList(roomId: String, queue: DispatchQueue = .main, handler: @escaping ([LNGiftItemVO]?) -> Void) {
|
|
|
- LNHttpManager.shared.loadGiftList(roomId: roomId) { res, err in
|
|
|
+ LNHttpManager.shared.loadGiftList(roomId: roomId) { [weak self] res, err in
|
|
|
queue.asyncIfNotGlobal {
|
|
|
handler(res?.list)
|
|
|
}
|
|
|
+ if let res, let self, res.list.contains(where: {
|
|
|
+ self.resourceMap[$0.resId] == nil
|
|
|
+ }) {
|
|
|
+ updateGiftResource()
|
|
|
+ }
|
|
|
if let err {
|
|
|
showToast(err.errorDesc)
|
|
|
}
|
|
|
@@ -52,14 +57,18 @@ class LNGiftManager {
|
|
|
}
|
|
|
|
|
|
extension LNGiftManager {
|
|
|
- private func updateGiftResource() {
|
|
|
+ func updateGiftResource() {
|
|
|
+ guard !isRefreshing else { return }
|
|
|
+
|
|
|
var changedGifts: [LNGiftResource] = []
|
|
|
var newVersion = ""
|
|
|
+ isRefreshing = true
|
|
|
|
|
|
func _fetchResource(next: String) {
|
|
|
LNHttpManager.shared.loadResourceList(version: resourceVersion, size: pageSize, next: next) { [weak self] res, err in
|
|
|
guard let self else { return }
|
|
|
guard let res else {
|
|
|
+ isRefreshing = false
|
|
|
return
|
|
|
}
|
|
|
if !res.list.isEmpty {
|
|
|
@@ -70,6 +79,7 @@ extension LNGiftManager {
|
|
|
}
|
|
|
if res.list.isEmpty || res.next.isEmpty != false {
|
|
|
mergeChangedResources(changedGifts, version: newVersion)
|
|
|
+ isRefreshing = false
|
|
|
} else {
|
|
|
_fetchResource(next: next)
|
|
|
}
|