Implement syncing of blocked contacts

pull/228/head
nielsandriesse 4 years ago
parent 023b931d8c
commit e5f8dd277e

@ -184,10 +184,9 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave) let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave)
FileServerAPI.addDeviceLink(signedDeviceLink).done(on: DispatchQueue.main) { [weak self] in FileServerAPI.addDeviceLink(signedDeviceLink).done(on: DispatchQueue.main) { [weak self] in
SSKEnvironment.shared.messageSender.send(linkingAuthorizationMessage, success: { SSKEnvironment.shared.messageSender.send(linkingAuthorizationMessage, success: {
let storage = OWSPrimaryStorage.shared() let slavePublicKey = deviceLink.slave.publicKey
let slaveHexEncodedPublicKey = deviceLink.slave.publicKey
try! Storage.writeSync { transaction in try! Storage.writeSync { transaction in
let thread = TSContactThread.getOrCreateThread(withContactId: slaveHexEncodedPublicKey, transaction: transaction) let thread = TSContactThread.getOrCreateThread(withContactId: slavePublicKey, transaction: transaction)
thread.save(with: transaction) thread.save(with: transaction)
} }
let _ = SSKEnvironment.shared.syncManager.syncAllGroups().ensure { let _ = SSKEnvironment.shared.syncManager.syncAllGroups().ensure {
@ -195,6 +194,9 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
// to the AFR mechanism // to the AFR mechanism
let _ = SSKEnvironment.shared.syncManager.syncAllContacts() let _ = SSKEnvironment.shared.syncManager.syncAllContacts()
} }
let blockedContacts = SSKEnvironment.shared.blockingManager.blockedPhoneNumbers()
let blockedContactsSyncMessage = OWSBlockedPhoneNumbersMessage(phoneNumbers: blockedContacts, groupIds: [])
SSKEnvironment.shared.messageSender.send(blockedContactsSyncMessage, success: { }) { _ in }
let _ = SSKEnvironment.shared.syncManager.syncAllOpenGroups() let _ = SSKEnvironment.shared.syncManager.syncAllOpenGroups()
DispatchQueue.main.async { DispatchQueue.main.async {
self?.dismiss(animated: true, completion: nil) self?.dismiss(animated: true, completion: nil)

@ -145,6 +145,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
notificationCenter.addObserver(self, selector: #selector(handleProfileDidChangeNotification(_:)), name: NSNotification.Name(rawValue: kNSNotificationName_OtherUsersProfileDidChange), object: nil) notificationCenter.addObserver(self, selector: #selector(handleProfileDidChangeNotification(_:)), name: NSNotification.Name(rawValue: kNSNotificationName_OtherUsersProfileDidChange), object: nil)
notificationCenter.addObserver(self, selector: #selector(handleLocalProfileDidChangeNotification(_:)), name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil) notificationCenter.addObserver(self, selector: #selector(handleLocalProfileDidChangeNotification(_:)), name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil)
notificationCenter.addObserver(self, selector: #selector(handleSeedViewedNotification(_:)), name: .seedViewed, object: nil) notificationCenter.addObserver(self, selector: #selector(handleSeedViewedNotification(_:)), name: .seedViewed, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleBlockedContactsUpdatedNotification(_:)), name: .blockedContactsUpdated, object: nil)
// Set up public chats and RSS feeds if needed // Set up public chats and RSS feeds if needed
if OWSIdentityManager.shared().identityKeyPair() != nil { if OWSIdentityManager.shared().identityKeyPair() != nil {
let appDelegate = UIApplication.shared.delegate as! AppDelegate let appDelegate = UIApplication.shared.delegate as! AppDelegate
@ -280,6 +281,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
seedReminderView.removeFromSuperview() seedReminderView.removeFromSuperview()
} }
@objc private func handleBlockedContactsUpdatedNotification(_ notification: Notification) {
self.tableView.reloadData() // TODO: Just reload the affected cell
}
private func updateNavigationBarButtons() { private func updateNavigationBarButtons() {
let profilePictureSize = Values.verySmallProfilePictureSize let profilePictureSize = Values.verySmallProfilePictureSize
let profilePictureView = ProfilePictureView() let profilePictureView = ProfilePictureView()
@ -402,10 +407,12 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
blockingManager.addBlockedPhoneNumber(publicKey) blockingManager.addBlockedPhoneNumber(publicKey)
tableView.reloadRows(at: [ indexPath ], with: UITableView.RowAnimation.fade) tableView.reloadRows(at: [ indexPath ], with: UITableView.RowAnimation.fade)
} }
block.backgroundColor = Colors.unimportant
let unblock = UITableViewRowAction(style: .normal, title: NSLocalizedString("BLOCK_LIST_UNBLOCK_BUTTON", comment: "")) { _, _ in let unblock = UITableViewRowAction(style: .normal, title: NSLocalizedString("BLOCK_LIST_UNBLOCK_BUTTON", comment: "")) { _, _ in
blockingManager.removeBlockedPhoneNumber(publicKey) blockingManager.removeBlockedPhoneNumber(publicKey)
tableView.reloadRows(at: [ indexPath ], with: UITableView.RowAnimation.fade) tableView.reloadRows(at: [ indexPath ], with: UITableView.RowAnimation.fade)
} }
unblock.backgroundColor = Colors.unimportant
return [ delete, (isBlocked ? unblock : block) ] return [ delete, (isBlocked ? unblock : block) ]
} else { } else {
return [ delete ] return [ delete ]

@ -2,6 +2,7 @@
public extension Notification.Name { public extension Notification.Name {
// State changes // State changes
public static let blockedContactsUpdated = Notification.Name("blockedContactsUpdated")
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged") public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
public static let groupThreadUpdated = Notification.Name("groupThreadUpdated") public static let groupThreadUpdated = Notification.Name("groupThreadUpdated")
public static let threadDeleted = Notification.Name("threadDeleted") public static let threadDeleted = Notification.Name("threadDeleted")
@ -27,6 +28,7 @@ public extension Notification.Name {
@objc public extension NSNotification { @objc public extension NSNotification {
// State changes // State changes
@objc public static let blockedContactsUpdated = Notification.Name.blockedContactsUpdated.rawValue as NSString
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString @objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
@objc public static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString @objc public static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString
@objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString @objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString

@ -975,6 +975,9 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<NSString *> *blockedPhoneNumbers = [syncMessage.blocked.numbers copy]; NSArray<NSString *> *blockedPhoneNumbers = [syncMessage.blocked.numbers copy];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.blockingManager setBlockedPhoneNumbers:blockedPhoneNumbers sendSyncMessage:NO]; [self.blockingManager setBlockedPhoneNumbers:blockedPhoneNumbers sendSyncMessage:NO];
dispatch_async(dispatch_get_main_queue(), ^{
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.blockedContactsUpdated object:nil];
});
}); });
} else if (syncMessage.read.count > 0) { } else if (syncMessage.read.count > 0) {
OWSLogInfo(@"Received %lu read receipt(s)", (unsigned long)syncMessage.read.count); OWSLogInfo(@"Received %lu read receipt(s)", (unsigned long)syncMessage.read.count);

Loading…
Cancel
Save