@@ -242,6 +242,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
242
242
private func handleChannelListChanges( _ controller: ChatChannelListController ) {
243
243
if selectedChannel != nil || !searchText. isEmpty || deeplinkChannel != nil {
244
244
queuedChannelsChanges = controller. channels
245
+ updateChannelsIfNeeded ( )
245
246
} else {
246
247
channels = controller. channels
247
248
}
@@ -363,35 +364,47 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
363
364
if !queuedChannelsChanges. isEmpty && selectedChannel == nil && deeplinkChannel == nil {
364
365
channels = queuedChannelsChanges
365
366
} else if !queuedChannelsChanges. isEmpty {
366
- let selected = selectedChannel != nil ? selectedChannel? . channel : deeplinkChannel? . channel
367
- var index : Int ?
368
- var temp = Array ( queuedChannelsChanges)
369
- for i in 0 ..< temp. count {
370
- let current = temp [ i]
371
- if current. cid == selected? . cid {
372
- index = i
373
- selectedChannel? . injectedChannelInfo = InjectedChannelInfo (
374
- subtitle: current. subtitleText,
375
- unreadCount: 0 ,
376
- timestamp: current. timestampText,
377
- lastMessageAt: current. lastMessageAt,
378
- latestMessages: current. latestMessages
379
- )
380
- break
381
- }
382
- }
383
- if let index = index, let selected = selected {
384
- temp [ index] = selected
385
- }
386
- markDirty = true
387
- channels = LazyCachedMapCollection ( source: temp, map: { $0 } )
367
+ handleQueuedChanges ( )
388
368
} else if queuedChannelsChanges. isEmpty && ( selectedChannel != nil || deeplinkChannel != nil ) {
389
369
if selectedChannel? . injectedChannelInfo == nil {
390
370
selectedChannel? . injectedChannelInfo = InjectedChannelInfo ( unreadCount: 0 )
391
371
}
392
372
}
393
373
}
394
374
375
+ private func updateChannelsIfNeeded( ) {
376
+ if utils. messageListConfig. updateChannelsFromMessageList {
377
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.5 ) { [ weak self] in
378
+ self ? . handleChannelAppearance ( )
379
+ }
380
+ }
381
+ }
382
+
383
+ private func handleQueuedChanges( ) {
384
+ let selected = selectedChannel != nil ? selectedChannel? . channel : deeplinkChannel? . channel
385
+ var index : Int ?
386
+ var temp = Array ( queuedChannelsChanges)
387
+ for i in 0 ..< temp. count {
388
+ let current = temp [ i]
389
+ if current. cid == selected? . cid {
390
+ index = i
391
+ selectedChannel? . injectedChannelInfo = InjectedChannelInfo (
392
+ subtitle: current. subtitleText,
393
+ unreadCount: 0 ,
394
+ timestamp: current. timestampText,
395
+ lastMessageAt: current. lastMessageAt,
396
+ latestMessages: current. latestMessages
397
+ )
398
+ break
399
+ }
400
+ }
401
+ if let index = index, let selected = selected {
402
+ temp [ index] = selected
403
+ }
404
+ markDirty = true
405
+ channels = LazyCachedMapCollection ( source: temp, map: { $0 } )
406
+ }
407
+
395
408
private func observeChannelDismiss( ) {
396
409
NotificationCenter . default. addObserver (
397
410
self ,
0 commit comments