@@ -171,6 +171,12 @@ open class MessageComposerViewModel: ObservableObject {
171
171
self . channelController = channelController
172
172
self . messageController = messageController
173
173
listenToCooldownUpdates ( )
174
+ NotificationCenter . default. addObserver (
175
+ self ,
176
+ selector: #selector( applicationWillEnterForeground) ,
177
+ name: UIApplication . willEnterForegroundNotification,
178
+ object: nil
179
+ )
174
180
}
175
181
176
182
public func sendMessage(
@@ -401,22 +407,7 @@ open class MessageComposerViewModel: ObservableObject {
401
407
switch status {
402
408
case . authorized, . limited:
403
409
log. debug ( " Access to photos granted. " )
404
- let fetchOptions = PHFetchOptions ( )
405
- let supportedTypes = self . utils. composerConfig. gallerySupportedTypes
406
- var predicate : NSPredicate ?
407
- if supportedTypes == . images {
408
- predicate = NSPredicate ( format: " mediaType = \( PHAssetMediaType . image. rawValue) " )
409
- } else if supportedTypes == . videos {
410
- predicate = NSPredicate ( format: " mediaType = \( PHAssetMediaType . video. rawValue) " )
411
- }
412
- if let predicate {
413
- fetchOptions. predicate = predicate
414
- }
415
- fetchOptions. sortDescriptors = [ NSSortDescriptor ( key: " creationDate " , ascending: false ) ]
416
- let assets = PHAsset . fetchAssets ( with: fetchOptions)
417
- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.25 ) { [ weak self] in
418
- self ? . imageAssets = assets
419
- }
410
+ self . fetchAssets ( )
420
411
case . denied, . restricted, . notDetermined:
421
412
DispatchQueue . main. async { [ weak self] in
422
413
self ? . imageAssets = PHFetchResult < PHAsset > ( )
@@ -449,6 +440,25 @@ open class MessageComposerViewModel: ObservableObject {
449
440
450
441
// MARK: - private
451
442
443
+ private func fetchAssets( ) {
444
+ let fetchOptions = PHFetchOptions ( )
445
+ let supportedTypes = self . utils. composerConfig. gallerySupportedTypes
446
+ var predicate : NSPredicate ?
447
+ if supportedTypes == . images {
448
+ predicate = NSPredicate ( format: " mediaType = \( PHAssetMediaType . image. rawValue) " )
449
+ } else if supportedTypes == . videos {
450
+ predicate = NSPredicate ( format: " mediaType = \( PHAssetMediaType . video. rawValue) " )
451
+ }
452
+ if let predicate {
453
+ fetchOptions. predicate = predicate
454
+ }
455
+ fetchOptions. sortDescriptors = [ NSSortDescriptor ( key: " creationDate " , ascending: false ) ]
456
+ let assets = PHAsset . fetchAssets ( with: fetchOptions)
457
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.25 ) { [ weak self] in
458
+ self ? . imageAssets = assets
459
+ }
460
+ }
461
+
452
462
private func checkForMentionedUsers(
453
463
commandId: String ? ,
454
464
extraData: [ String : Any ]
@@ -607,4 +617,11 @@ open class MessageComposerViewModel: ObservableObject {
607
617
return false
608
618
}
609
619
}
620
+
621
+ @objc
622
+ private func applicationWillEnterForeground( ) {
623
+ if ( imageAssets? . count ?? 0 ) > 0 {
624
+ self . fetchAssets ( )
625
+ }
626
+ }
610
627
}
0 commit comments