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)
FileServerAPI.addDeviceLink(signedDeviceLink).done(on: DispatchQueue.main) { [weak self] in
SSKEnvironment.shared.messageSender.send(linkingAuthorizationMessage, success: {
let storage = OWSPrimaryStorage.shared()
let slaveHexEncodedPublicKey = deviceLink.slave.publicKey
let slavePublicKey = deviceLink.slave.publicKey
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)
}
let _ = SSKEnvironment.shared.syncManager.syncAllGroups().ensure {
@ -195,6 +194,9 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
// to the AFR mechanism
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()
DispatchQueue.main.async {
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(handleLocalProfileDidChangeNotification(_:)), name: Notification.Name(kNSNotificationName_LocalProfileDidChange), 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
if OWSIdentityManager.shared().identityKeyPair() != nil {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
@ -279,6 +280,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
tableViewTopConstraint = tableView.pin(.top, to: .top, of: view, withInset: Values.smallSpacing)
seedReminderView.removeFromSuperview()
}
@objc private func handleBlockedContactsUpdatedNotification(_ notification: Notification) {
self.tableView.reloadData() // TODO: Just reload the affected cell
}
private func updateNavigationBarButtons() {
let profilePictureSize = Values.verySmallProfilePictureSize
@ -402,10 +407,12 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
blockingManager.addBlockedPhoneNumber(publicKey)
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
blockingManager.removeBlockedPhoneNumber(publicKey)
tableView.reloadRows(at: [ indexPath ], with: UITableView.RowAnimation.fade)
}
unblock.backgroundColor = Colors.unimportant
return [ delete, (isBlocked ? unblock : block) ]
} else {
return [ delete ]

@ -2,6 +2,7 @@
public extension Notification.Name {
// State changes
public static let blockedContactsUpdated = Notification.Name("blockedContactsUpdated")
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
public static let groupThreadUpdated = Notification.Name("groupThreadUpdated")
public static let threadDeleted = Notification.Name("threadDeleted")
@ -27,6 +28,7 @@ public extension Notification.Name {
@objc public extension NSNotification {
// 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 groupThreadUpdated = Notification.Name.groupThreadUpdated.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];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[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) {
OWSLogInfo(@"Received %lu read receipt(s)", (unsigned long)syncMessage.read.count);

Loading…
Cancel
Save