@@ -53,12 +53,13 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
53
53
} ( )
54
54
55
55
// for Logic
56
- @SBUAtomic var channelList : [ SBDGroupChannel ] = [ ]
56
+ @SBUAtomic public private ( set ) var channelList : [ SBDGroupChannel ] = [ ]
57
57
var channelListQuery : SBDGroupChannelListQuery ?
58
58
var lastUpdatedTimestamp : Int64 = 0
59
59
var lastUpdatedToken : String ? = nil
60
60
var isLoading = false
61
61
var limit : UInt = 20
62
+ var includeEmptyChannel : Bool = false
62
63
63
64
// for cell
64
65
var channelCell : SBUBaseChannelCell ? = nil
@@ -78,7 +79,6 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
78
79
SBULog . info ( " " )
79
80
}
80
81
81
-
82
82
open override func loadView( ) {
83
83
super. loadView ( )
84
84
SBULog . info ( " " )
@@ -121,7 +121,6 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
121
121
}
122
122
123
123
public func setupStyles( ) {
124
-
125
124
self . navigationController? . navigationBar. setBackgroundImage ( UIImage . from ( color: theme. navigationBarTintColor) , for: . default)
126
125
self . navigationController? . navigationBar. shadowImage = UIImage . from ( color: theme. navigationBarShadowColor)
127
126
@@ -182,23 +181,52 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
182
181
}
183
182
184
183
185
- // MARK: - Custom viewController relations
184
+ // MARK: - SDK Data relations
186
185
187
- /// If you want to use a custom channelViewController, override it and implement it.
188
- /// - Parameter channelUrl: channel url for use in channelViewController.
189
- open func showChannel( channelUrl: String ) {
190
- let channelVC = SBUChannelViewController ( channelUrl: channelUrl)
191
- self . navigationController? . pushViewController ( channelVC, animated: true )
186
+ /// Changes push trigger option on a channel.
187
+ /// - Parameters:
188
+ /// - option: Push trigger option to change
189
+ /// - channel: Channel to change option
190
+ /// - completionHandler: Completion handler
191
+ /// - Since: 1.0.9
192
+ public func changePushTriggerOption( option: SBDGroupChannelPushTriggerOption , channel: SBDGroupChannel , completionHandler: ( ( Bool ) -> Void ) ? = nil ) {
193
+ SBULog . info ( " [Request] Channel push status : \( option == . off ? " on " : " off " ) , ChannelUrl: \( channel. channelUrl) " )
194
+ channel. setMyPushTriggerOption ( option) { [ weak self] error in
195
+ if let error = error {
196
+ SBULog . error ( " [Failed] Channel push status request: \( String ( error. localizedDescription) ) " )
197
+ completionHandler ? ( false )
198
+ self ? . didReceiveError ( error. localizedDescription)
199
+ return
200
+ }
201
+
202
+ SBULog . info ( " [Succeed] Channel push status, ChannelUrl: \( channel. channelUrl) " )
203
+
204
+ completionHandler ? ( true )
205
+ }
192
206
}
193
207
194
- /// If you want to use a custom createChannelViewController, override it and implement it.
195
- open func showCreateChannel( ) {
196
- let createChannelVC = SBUCreateChannelViewController ( )
197
- self . navigationController? . pushViewController ( createChannelVC, animated: true )
208
+ /// Leaves the channel.
209
+ /// - Parameters:
210
+ /// - channel: Channel to leave
211
+ /// - completionHandler: Completion handler
212
+ /// - Since: 1.0.9
213
+ public func leaveChannel( _ channel: SBDGroupChannel , completionHandler: ( ( Bool ) -> Void ) ? = nil ) {
214
+ SBULog . info ( " [Request] Leave channel, ChannelUrl: \( channel. channelUrl) " )
215
+
216
+ channel. leave { [ weak self] error in
217
+ if let error = error {
218
+ SBULog . error ( " [Failed] Leave channel request: \( String ( error. localizedDescription) ) " )
219
+ completionHandler ? ( false )
220
+ self ? . didReceiveError ( error. localizedDescription)
221
+ return
222
+ }
223
+
224
+ SBULog . info ( " [Succeed] Leave channel request, ChannelUrl: \( channel. channelUrl) " )
225
+
226
+ completionHandler ? ( true )
227
+ }
198
228
}
199
229
200
-
201
- // MARK: - SDK Data relations
202
230
func loadNextChannelList( reset: Bool ) {
203
231
if self . isLoading { return }
204
232
self . setLoading ( true , false )
@@ -217,7 +245,7 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
217
245
self . channelListQuery = SBDGroupChannel . createMyGroupChannelListQuery ( )
218
246
self . channelListQuery? . order = . latestLastMessage
219
247
self . channelListQuery? . limit = self . limit
220
- self . channelListQuery? . includeEmptyChannel = false
248
+ self . channelListQuery? . includeEmptyChannel = self . includeEmptyChannel
221
249
}
222
250
223
251
guard self . channelListQuery? . hasNext == true else {
@@ -253,9 +281,14 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
253
281
return
254
282
}
255
283
284
+ let channelLogsParams = SBDGroupChannelChangeLogsParams ( )
285
+ channelLogsParams. includeEmptyChannel = self . includeEmptyChannel
286
+ channelLogsParams. includeFrozenChannel = true
287
+
256
288
if let token = token {
257
289
SBULog . info ( " [Request] Channel change logs with token " )
258
- SBDMain . getMyGroupChannelChangeLogs ( byToken: token, customTypes: nil ) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
290
+
291
+ SBDMain . getMyGroupChannelChangeLogs ( byToken: token, params: channelLogsParams) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
259
292
if let error = error {
260
293
SBULog . error ( " [Failed] Channel change logs request : \( error. localizedDescription) " )
261
294
self ? . didReceiveError ( error. localizedDescription)
@@ -273,7 +306,7 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
273
306
}
274
307
else {
275
308
SBULog . info ( " [Request] Channel change logs with last updated timestamp " )
276
- SBDMain . getMyGroupChannelChangeLogs ( byTimestamp: self . lastUpdatedTimestamp, customTypes : nil ) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
309
+ SBDMain . getMyGroupChannelChangeLogs ( byTimestamp: self . lastUpdatedTimestamp, params : channelLogsParams ) { [ weak self] updatedChannels, deletedChannelUrls, hasMore, token, error in
277
310
if let error = error {
278
311
SBULog . error ( " [Failed] Channel change logs request : \( error. localizedDescription) " )
279
312
self ? . didReceiveError ( error. localizedDescription)
@@ -367,6 +400,22 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
367
400
368
401
self . sortChannelList ( needReload: needReload)
369
402
}
403
+
404
+
405
+ // MARK: - Custom viewController relations
406
+
407
+ /// If you want to use a custom channelViewController, override it and implement it.
408
+ /// - Parameter channelUrl: channel url for use in channelViewController.
409
+ open func showChannel( channelUrl: String ) {
410
+ let channelVC = SBUChannelViewController ( channelUrl: channelUrl)
411
+ self . navigationController? . pushViewController ( channelVC, animated: true )
412
+ }
413
+
414
+ /// If you want to use a custom createChannelViewController, override it and implement it.
415
+ open func showCreateChannel( ) {
416
+ let createChannelVC = SBUCreateChannelViewController ( )
417
+ self . navigationController? . pushViewController ( createChannelVC, animated: true )
418
+ }
370
419
371
420
372
421
// MARK: - Common
@@ -488,16 +537,9 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
488
537
let size = tableView. visibleCells [ 0 ] . frame. height
489
538
let iconSize : CGFloat = 40.0
490
539
491
- let leaveAction = UIContextualAction ( style: . normal, title: " " ) { action, view, success in
492
- SBULog . info ( " [Request] Leave channel, ChannelUrl: \( channel. channelUrl) " )
493
- channel. leave { [ weak self] error in
494
- if let error = error {
495
- SBULog . error ( " [Failed] Leave channel request: \( String ( error. localizedDescription) ) " )
496
- self ? . didReceiveError ( error. localizedDescription)
497
- }
498
-
499
- SBULog . info ( " [Succeed] Leave channel request, ChannelUrl: \( channel. channelUrl) " )
500
- success ( true )
540
+ let leaveAction = UIContextualAction ( style: . normal, title: " " ) { action, view, actionHandler in
541
+ self . leaveChannel ( channel) { success in
542
+ actionHandler ( success)
501
543
}
502
544
}
503
545
@@ -509,19 +551,12 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
509
551
510
552
leaveAction. backgroundColor = UIColor . from ( image: leaveIcon, imageView: leaveTypeView, size: size, backgroundColor: theme. alertBackgroundColor)
511
553
512
-
513
554
let pushOption = channel. myPushTriggerOption
514
-
515
- let alarmAction = UIContextualAction ( style: . normal, title: " " ) { action, view, success in
516
- SBULog . info ( " [Request] Channel push status : \( pushOption == . off ? " on " : " off " ) , ChannelUrl: \( channel. channelUrl) " )
517
- channel. setMyPushTriggerOption ( pushOption == . off ? . all : . off) { [ weak self] error in
518
- if let error = error {
519
- SBULog . error ( " [Failed] Channel push status request: \( String ( error. localizedDescription) ) " )
520
- self ? . didReceiveError ( error. localizedDescription)
521
- }
522
-
523
- SBULog . info ( " [Succeed] Channel push status, ChannelUrl: \( channel. channelUrl) " )
524
- success ( true )
555
+ let alarmAction = UIContextualAction ( style: . normal, title: " " ) { action, view, actionHandler in
556
+ self . changePushTriggerOption ( option: ( pushOption == . off ? . all : . off) , channel: channel) { success in
557
+ guard success else { return }
558
+
559
+ actionHandler ( true )
525
560
526
561
DispatchQueue . main. async {
527
562
tableView. reloadRows ( at: [ indexPath] , with: . automatic)
@@ -555,15 +590,7 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
555
590
let iconSize : CGFloat = 40.0
556
591
557
592
let leave = UITableViewRowAction ( style: . normal, title: " " ) { action, indexPath in
558
- SBULog . info ( " [Request] Leave channel, ChannelUrl: \( channel. channelUrl) " )
559
- channel. leave { [ weak self] error in
560
- if let error = error {
561
- SBULog . error ( " [Failed] Leave channel request: \( String ( error. localizedDescription) ) " )
562
- self ? . didReceiveError ( error. localizedDescription)
563
- }
564
-
565
- SBULog . info ( " [Succeed] Leave channel request, ChannelUrl: \( channel. channelUrl) " )
566
- }
593
+ self . leaveChannel ( channel)
567
594
}
568
595
569
596
leave. title = SBUUtils . emptyTitleForRowEditAction ( for: CGSize ( width: size, height: size) )
@@ -575,18 +602,11 @@ open class SBUChannelListViewController: UIViewController, UITableViewDelegate,
575
602
576
603
leave. backgroundColor = UIColor . from ( image: leaveIcon, imageView: leaveTypeView, size: size, backgroundColor: theme. alertBackgroundColor)
577
604
578
-
579
605
let pushOption = channel. myPushTriggerOption
580
606
let alarm = UITableViewRowAction ( style: . normal, title: " " ) { action, indexPath in
581
- SBULog . info ( " [Request] Channel push status : \( pushOption == . off ? " on " : " off " ) , ChannelUrl: \( channel. channelUrl) " )
582
- channel. setMyPushTriggerOption ( pushOption == . off ? . all : . off) { [ weak self] error in
583
- if let error = error {
584
- SBULog . error ( " [Failed] Channel push status request: \( String ( error. localizedDescription) ) " )
585
- self ? . didReceiveError ( error. localizedDescription)
586
- }
587
-
588
- SBULog . info ( " [Succeed] Channel push status, ChannelUrl: \( channel. channelUrl) " )
589
-
607
+ self . changePushTriggerOption ( option: ( pushOption == . off ? . all : . off) , channel: channel) { success in
608
+ guard success else { return }
609
+
590
610
DispatchQueue . main. async {
591
611
tableView. reloadRows ( at: [ indexPath] , with: . automatic)
592
612
}
0 commit comments