@@ -81,7 +81,7 @@ open class OTRRoomOccupantsViewController: UIViewController {
81
81
var notificationToken : NSObjectProtocol ? = nil
82
82
83
83
/// opens implicit db transaction
84
- open var room : OTRXMPPRoom ? {
84
+ private var room : OTRXMPPRoom ? {
85
85
return connections? . ui. fetch { self . room ( $0) }
86
86
}
87
87
@@ -117,19 +117,17 @@ open class OTRRoomOccupantsViewController: UIViewController {
117
117
118
118
@objc public func setupViewHandler( databaseConnection: YapDatabaseConnection , roomKey: String ) {
119
119
self . roomUniqueId = roomKey
120
- guard let _ = self . room else {
120
+ guard let room = self . room else {
121
121
return
122
122
}
123
- self . fetchMembersList ( )
123
+ self . fetchMembersList ( room : room )
124
124
viewHandler = OTRYapViewHandler ( databaseConnection: databaseConnection)
125
125
if let viewHandler = self . viewHandler {
126
126
viewHandler. delegate = self
127
127
viewHandler. setup ( DatabaseExtensionName . groupOccupantsViewName. name ( ) , groups: [ GroupName . header. rawValue, roomKey, GroupName . footer. rawValue] )
128
128
}
129
129
130
- self . notificationToken = NotificationCenter . default. addObserver ( forName: NSNotification . Name. YapDatabaseModified, object: OTRDatabaseManager . shared. database, queue: OperationQueue . main) { [ weak self] ( notification) -> Void in
131
- self ? . yapDatabaseModified ( notification)
132
- }
130
+
133
131
}
134
132
135
133
deinit {
@@ -171,11 +169,16 @@ open class OTRRoomOccupantsViewController: UIViewController {
171
169
self . tableView. register ( GenericHeaderCell . self, forCellReuseIdentifier: DynamicCellIdentifier . omemoConfig. rawValue)
172
170
self . tableView. register ( GenericHeaderCell . self, forCellReuseIdentifier: DynamicCellIdentifier . omemoToggle. rawValue)
173
171
172
+ self . tableView. reloadData ( )
174
173
self . updateUIBasedOnOwnRole ( )
174
+
175
+ self . notificationToken = NotificationCenter . default. addObserver ( forName: NSNotification . Name. YapDatabaseModified, object: OTRDatabaseManager . shared. database, queue: OperationQueue . main) { [ weak self] ( notification) -> Void in
176
+ self ? . yapDatabaseModified ( notification)
177
+ }
175
178
}
176
179
177
180
func yapDatabaseModified( _ notification: Notification ) {
178
- guard let connection = self . connection , let roomUniqueId = self . roomUniqueId else { return }
181
+ guard let connection = self . connections ? . ui , let roomUniqueId = self . roomUniqueId else { return }
179
182
if connection. hasChange ( forKey: roomUniqueId, inCollection: OTRXMPPRoom . collection, in: [ notification] ) {
180
183
// Subject has changed, update cell
181
184
refreshSubjectCell ( )
@@ -408,18 +411,20 @@ open class OTRRoomOccupantsViewController: UIViewController {
408
411
default : break
409
412
}
410
413
}
411
- @objc func didChangeNotificationSwitch( _ sender: UIControl ! ) {
412
- guard let notificationSwitch = sender as? UISwitch ,
413
- let room = self . room? . copyAsSelf ( ) else {
414
- return
415
- }
416
- if notificationSwitch. isOn {
417
- room. muteExpiration = Date . distantFuture
418
- } else {
419
- room. muteExpiration = nil
420
- }
421
- connection? . readWrite ( { ( transaction) in
414
+
415
+ @objc func didChangeNotificationSwitch( _ sender: UISwitch ) {
416
+ let notificationSwitchIsOn = sender. isOn
417
+ connections? . write. asyncReadWrite ( { [ weak self] ( transaction) in
418
+ guard let room = self ? . room ( transaction) else { return }
419
+ if notificationSwitchIsOn {
420
+ room. muteExpiration = Date . distantPast
421
+ } else {
422
+ room. muteExpiration = Date . distantFuture
423
+ }
422
424
room. save ( with: transaction)
425
+ } , completionBlock: { [ weak self] in
426
+ guard let room = self ? . room else { return }
427
+ self ? . refreshNotificationSwitch ( sender, room: room, animated: false )
423
428
} )
424
429
}
425
430
@@ -510,9 +515,8 @@ extension OTRRoomOccupantsViewController {
510
515
return xmpp? . roomManager
511
516
}
512
517
513
- fileprivate func fetchMembersList( ) {
514
- guard let room = self . room,
515
- let xmppRoom = xmppRoom ( for: room) else {
518
+ fileprivate func fetchMembersList( room: OTRXMPPRoom ) {
519
+ guard let xmppRoom = xmppRoom ( for: room) else {
516
520
return
517
521
}
518
522
ignoreChanges = true
0 commit comments