@@ -67,6 +67,7 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
67
67
// MARK: - Lifecycle
68
68
open override func loadView( ) {
69
69
super. loadView ( )
70
+ SBULog . info ( " " )
70
71
71
72
// tableview
72
73
self . tableView. delegate = self
@@ -106,9 +107,8 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
106
107
}
107
108
108
109
public func setupStyles( ) {
109
-
110
- self . navigationController? . navigationBar. backgroundColor = . clear
111
- self . navigationController? . navigationBar. barTintColor = theme. navigationBarTintColor
110
+
111
+ self . navigationController? . navigationBar. setBackgroundImage ( UIImage . from ( color: theme. navigationBarTintColor) , for: . default)
112
112
self . navigationController? . navigationBar. shadowImage = UIImage . from ( color: theme. navigationBarShadowColor)
113
113
114
114
self . view. backgroundColor = theme. backgroundColor
@@ -155,10 +155,14 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
155
155
self . setupStyles ( )
156
156
157
157
if self . isLoading { return }
158
- self . loadChannelChangeLogs ( hasMore: true , token: self . lastUpdatedToken)
158
+
159
+ if self . lastUpdatedToken != nil {
160
+ self . loadChannelChangeLogs ( hasMore: true , token: self . lastUpdatedToken)
161
+ }
159
162
}
160
163
161
164
deinit {
165
+ SBULog . info ( " " )
162
166
SBDMain . removeChannelDelegate ( forIdentifier: self . description)
163
167
SBDMain . removeConnectionDelegate ( forIdentifier: self . description)
164
168
}
@@ -190,6 +194,9 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
190
194
self . channelList = [ ]
191
195
self . lastUpdatedTimestamp = Int64 ( Date ( ) . timeIntervalSince1970*1000)
192
196
self . lastUpdatedToken = nil
197
+ SBULog . info ( " [Request] Channel List " )
198
+ } else {
199
+ SBULog . info ( " [Request] Next channel List " )
193
200
}
194
201
195
202
if self . channelListQuery == nil {
@@ -200,19 +207,24 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
200
207
}
201
208
202
209
guard self . channelListQuery? . hasNext == true else {
210
+ SBULog . info ( " All channels have been loaded. " )
203
211
self . setLoading ( false , false )
204
212
return
205
213
}
206
-
214
+
207
215
self . channelListQuery? . loadNextPage ( completionHandler: { [ weak self] channels, error in
208
216
defer { self ? . setLoading ( false , false ) }
209
217
210
- guard error == nil else {
211
- self ? . didReceiveError ( error? . localizedDescription)
218
+ if let error = error {
219
+ SBULog . error ( " [Failed] Channel list request : \( String ( describing: error. localizedDescription) ) " )
220
+ self ? . didReceiveError ( error. localizedDescription)
212
221
self ? . showNetworkError ( )
213
222
return
214
223
}
215
224
guard let channels = channels else { return }
225
+
226
+ SBULog . info ( " [Response] \( channels. count) channels " )
227
+
216
228
217
229
self ? . channelList += channels
218
230
self ? . sortChannelList ( needReload: true )
@@ -222,28 +234,41 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
222
234
223
235
func loadChannelChangeLogs( hasMore: Bool , token: String ? ) {
224
236
guard hasMore == true else {
237
+ SBULog . info ( " All channel changes have been loaded. " )
225
238
self . sortChannelList ( needReload: true )
226
239
return
227
240
}
228
241
229
242
if let token = token {
243
+ SBULog . info ( " [Request] Channel change logs with token " )
230
244
SBDMain . getMyGroupChannelChangeLogs ( byToken: token, customTypes: nil ) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
231
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
245
+ if let error = error {
246
+ SBULog . error ( " [Failed] Channel change logs request : \( error. localizedDescription) " )
247
+ self ? . didReceiveError ( error. localizedDescription)
248
+ }
232
249
233
250
self ? . lastUpdatedToken = token
234
251
252
+ SBULog . info ( " [Response] \( String ( format: " %d updated channels " , updatedChannels? . count ?? 0 ) ) , \( String ( format: " %d deleted channels " , deletedChannelUrls? . count ?? 0 ) ) " )
253
+
235
254
self ? . upsertChannels ( channels: updatedChannels, needReload: false )
236
255
self ? . deleteChannels ( channelUrls: deletedChannelUrls, needReload: false )
237
256
238
257
self ? . loadChannelChangeLogs ( hasMore: hasMore, token: token)
239
258
}
240
259
}
241
260
else {
261
+ SBULog . info ( " [Request] Channel change logs with last updated timestamp " )
242
262
SBDMain . getMyGroupChannelChangeLogs ( byTimestamp: self . lastUpdatedTimestamp, customTypes: nil ) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
243
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
263
+ if let error = error {
264
+ SBULog . error ( " [Failed] Channel change logs request : \( error. localizedDescription) " )
265
+ self ? . didReceiveError ( error. localizedDescription)
266
+ }
244
267
245
268
self ? . lastUpdatedToken = token
246
269
270
+ SBULog . info ( " [Response] \( String ( format: " %d updated channels " , updatedChannels? . count ?? 0 ) ) , \( String ( format: " %d deleted channels " , deletedChannelUrls? . count ?? 0 ) ) " )
271
+
247
272
self ? . upsertChannels ( channels: updatedChannels, needReload: false )
248
273
self ? . deleteChannels ( channelUrls: deletedChannelUrls, needReload: false )
249
274
@@ -450,10 +475,16 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
450
475
let iconSize : CGFloat = 40.0
451
476
452
477
let leaveAction = UIContextualAction ( style: . normal, title: " " ) { action, view, success in
478
+ SBULog . info ( " [Request] Leave channel, ChannelUrl: \( channel. channelUrl) " )
453
479
channel. leave { [ weak self] error in
454
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
480
+ if let error = error {
481
+ SBULog . error ( " [Failed] Leave channel request: \( String ( error. localizedDescription) ) " )
482
+ self ? . didReceiveError ( error. localizedDescription)
483
+ }
484
+
485
+ SBULog . info ( " [Succeed] Leave channel request, ChannelUrl: \( channel. channelUrl) " )
486
+ success ( true )
455
487
}
456
- success ( true )
457
488
}
458
489
459
490
let leaveTypeView = UIImageView ( frame: CGRect ( x: ( size- iconSize) / 2 , y: ( size- iconSize) / 2 , width: iconSize, height: iconSize) )
@@ -468,13 +499,20 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
468
499
let pushOption = channel. myPushTriggerOption
469
500
470
501
let alarmAction = UIContextualAction ( style: . normal, title: " " ) { action, view, success in
502
+ SBULog . info ( " [Request] Channel push status : \( pushOption == . off ? " on " : " off " ) , ChannelUrl: \( channel. channelUrl) " )
471
503
channel. setMyPushTriggerOption ( pushOption == . off ? . all : . off) { [ weak self] error in
472
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
504
+ if let error = error {
505
+ SBULog . error ( " [Failed] Channel push status request: \( String ( error. localizedDescription) ) " )
506
+ self ? . didReceiveError ( error. localizedDescription)
507
+ }
508
+
509
+ SBULog . info ( " [Succeed] Channel push status, ChannelUrl: \( channel. channelUrl) " )
510
+ success ( true )
511
+
473
512
DispatchQueue . main. async {
474
513
tableView. reloadRows ( at: [ indexPath] , with: . automatic)
475
514
}
476
515
}
477
- success ( true )
478
516
}
479
517
480
518
let alarmTypeView = UIImageView ( frame: CGRect ( x: ( size- iconSize) / 2 , y: ( size- iconSize) / 2 , width: iconSize, height: iconSize) )
@@ -503,8 +541,14 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
503
541
let iconSize : CGFloat = 40.0
504
542
505
543
let leave = UITableViewRowAction ( style: . normal, title: " " ) { action, indexPath in
544
+ SBULog . info ( " [Request] Leave channel, ChannelUrl: \( channel. channelUrl) " )
506
545
channel. leave { [ weak self] error in
507
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
546
+ if let error = error {
547
+ SBULog . error ( " [Failed] Leave channel request: \( String ( error. localizedDescription) ) " )
548
+ self ? . didReceiveError ( error. localizedDescription)
549
+ }
550
+
551
+ SBULog . info ( " [Succeed] Leave channel request, ChannelUrl: \( channel. channelUrl) " )
508
552
}
509
553
}
510
554
@@ -520,8 +564,14 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
520
564
521
565
let pushOption = channel. myPushTriggerOption
522
566
let alarm = UITableViewRowAction ( style: . normal, title: " " ) { action, indexPath in
567
+ SBULog . info ( " [Request] Channel push status : \( pushOption == . off ? " on " : " off " ) , ChannelUrl: \( channel. channelUrl) " )
523
568
channel. setMyPushTriggerOption ( pushOption == . off ? . all : . off) { [ weak self] error in
524
- if let error = error { self ? . didReceiveError ( error. localizedDescription) }
569
+ if let error = error {
570
+ SBULog . error ( " [Failed] Channel push status request: \( String ( error. localizedDescription) ) " )
571
+ self ? . didReceiveError ( error. localizedDescription)
572
+ }
573
+
574
+ SBULog . info ( " [Succeed] Channel push status, ChannelUrl: \( channel. channelUrl) " )
525
575
526
576
DispatchQueue . main. async {
527
577
tableView. reloadRows ( at: [ indexPath] , with: . automatic)
@@ -550,6 +600,8 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
550
600
551
601
// MARK: - SBDChannelDelegate
552
602
open func channel( _ sender: SBDGroupChannel , userDidJoin user: SBDUser ) {
603
+ SBULog . info ( " User did join the channel, Nickname: \( String ( user. nickname ?? " " ) ) - ChannelUrl: \( sender. channelUrl) " )
604
+
553
605
if self . channelListQuery? . includeEmptyChannel == false {
554
606
self . updateChannels ( channels: [ sender] , needReload: true )
555
607
} else {
@@ -559,17 +611,22 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
559
611
560
612
open func channel( _ sender: SBDGroupChannel , userDidLeave user: SBDUser ) {
561
613
guard user. userId == SBUGlobals . CurrentUser? . userId else { return }
562
-
614
+ SBULog . info ( " User did leave the channel, Nickname: \( String ( user. nickname ?? " " ) ) - ChannelUrl: \( sender. channelUrl) " )
615
+
563
616
self . deleteChannels ( channelUrls: [ sender. channelUrl] , needReload: true )
564
617
}
565
618
566
619
open func channelWasChanged( _ sender: SBDBaseChannel ) {
567
620
guard let channel = sender as? SBDGroupChannel else { return }
621
+ SBULog . info ( " Channel was changed, ChannelUrl: \( sender. channelUrl) " ) // markAsRead, didReceiveMsg
622
+
568
623
self . upsertChannels ( channels: [ channel] , needReload: true )
569
624
}
570
625
571
626
open func channel( _ sender: SBDBaseChannel , messageWasDeleted messageId: Int64 ) {
572
627
guard let channel = sender as? SBDGroupChannel else { return }
628
+ SBULog . info ( " Message was deleted in the channel, MessageID: \( String ( messageId) ) - channelUrl: \( channel. channelUrl) " )
629
+
573
630
self . upsertChannels ( channels: [ channel] , needReload: false )
574
631
}
575
632
@@ -579,12 +636,13 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
579
636
/// If necessary, override to handle errors.
580
637
/// - Parameter message: error message
581
638
open func didReceiveError( _ message: String ? ) {
582
-
639
+ SBULog . error ( " Did receive error: \( message ?? " " ) " )
583
640
}
584
641
585
642
586
643
// MARK: - SBDConnectionDelegate
587
644
open func didSucceedReconnection( ) {
645
+ SBULog . info ( " Did succeed reconnection " )
588
646
self . loadChannelChangeLogs ( hasMore: true , token: self . lastUpdatedToken)
589
647
}
590
648
@@ -593,10 +651,14 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
593
651
func didSelectRetry( ) {
594
652
self . emptyView. updateType ( . noChannels)
595
653
654
+ SBULog . info ( " [Request] Retry load channel list " )
596
655
SBUMain . connectionCheck { [ weak self] user, error in
597
656
guard let self = self else { return }
598
657
599
- if let error = error { self . didReceiveError ( error. localizedDescription) }
658
+ if let error = error {
659
+ SBULog . error ( " [Failed] Retry request: \( String ( error. localizedDescription) ) " )
660
+ self . didReceiveError ( error. localizedDescription)
661
+ }
600
662
601
663
SBDMain . removeChannelDelegate ( forIdentifier: self . description)
602
664
SBDMain . removeConnectionDelegate ( forIdentifier: self . description)
0 commit comments