Force sync upon creating a closed group or joining an open group

pull/333/head
nielsandriesse 4 years ago
parent 947287e42f
commit b8d9334d19

@ -260,9 +260,9 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
Storage.write(with: { [weak self] transaction in
do {
if !members.contains(getUserHexEncodedPublicKey()) {
try MessageSender.leaveV2(groupPublicKey, using: transaction)
try MessageSender.leave(groupPublicKey, using: transaction)
} else {
try MessageSender.updateV2(groupPublicKey, with: members, name: name, transaction: transaction)
try MessageSender.update(groupPublicKey, with: members, name: name, transaction: transaction)
}
} catch {
DispatchQueue.main.async {

@ -170,9 +170,11 @@ final class NewClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegat
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
var promise: Promise<TSGroupThread>!
Storage.writeSync { transaction in
promise = MessageSender.createV2ClosedGroup(name: name, members: selectedContacts, transaction: transaction)
promise = MessageSender.createClosedGroup(name: name, members: selectedContacts, transaction: transaction)
}
let _ = promise.done(on: DispatchQueue.main) { thread in
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete() // FIXME: It's probably cleaner to do this inside createClosedGroup(...)
self?.presentingViewController?.dismiss(animated: true, completion: nil)
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
}

@ -420,7 +420,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
let groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
do {
try MessageSender.leaveV2(groupPublicKey, using: transaction)
try MessageSender.leave(groupPublicKey, using: transaction)
} catch {
// TODO: Handle
}

@ -5,7 +5,6 @@ extension AppDelegate {
@objc(syncConfigurationIfNeeded)
func syncConfigurationIfNeeded() {
let userDefaults = UserDefaults.standard
guard userDefaults[.isUsingMultiDevice] else { return }
let lastSync = userDefaults[.lastConfigurationSync] ?? .distantPast
guard Date().timeIntervalSince(lastSync) > 2 * 24 * 60 * 60 else { return } // Sync every 2 days
let configurationMessage = ConfigurationMessage.getCurrent()
@ -17,8 +16,6 @@ extension AppDelegate {
}
func forceSyncConfigurationNowIfNeeded() -> Promise<Void> {
let userDefaults = UserDefaults.standard
guard userDefaults[.isUsingMultiDevice] else { return Promise.value(()) }
let configurationMessage = ConfigurationMessage.getCurrent()
let destination = Message.Destination.contact(publicKey: getUserHexEncodedPublicKey())
let (promise, seal) = Promise<Void>.pending()

@ -135,6 +135,8 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
Storage.shared.write { transaction in
OpenGroupManager.shared.addOpenGroup(with: urlAsString, using: transaction)
.done(on: DispatchQueue.main) { [weak self] _ in
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete() // FIXME: It's probably cleaner to do this inside addOpenGroup(...)
self?.presentingViewController!.dismiss(animated: true, completion: nil)
}
.catch(on: DispatchQueue.main) { [weak self] error in

@ -3,7 +3,7 @@ import SessionProtocolKit
extension MessageSender {
public static func createV2ClosedGroup(name: String, members: Set<String>, transaction: YapDatabaseReadWriteTransaction) -> Promise<TSGroupThread> {
public static func createClosedGroup(name: String, members: Set<String>, transaction: YapDatabaseReadWriteTransaction) -> Promise<TSGroupThread> {
// Prepare
var members = members
let userPublicKey = getUserHexEncodedPublicKey()
@ -46,7 +46,7 @@ extension MessageSender {
return when(fulfilled: promises).map2 { thread }
}
public static func updateV2(_ groupPublicKey: String, with members: Set<String>, name: String, transaction: YapDatabaseReadWriteTransaction) throws {
public static func update(_ groupPublicKey: String, with members: Set<String>, name: String, transaction: YapDatabaseReadWriteTransaction) throws {
// Prepare
let userPublicKey = getUserHexEncodedPublicKey()
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
@ -117,7 +117,7 @@ extension MessageSender {
}
@objc(leaveClosedGroupWithPublicKey:using:error:)
public static func leaveV2(_ groupPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) throws {
public static func leave(_ groupPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) throws {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
let threadID = TSGroupThread.threadId(fromGroupId: groupID)
guard let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction) else {
@ -133,7 +133,7 @@ extension MessageSender {
} else {
newMembers = [] // If the admin leaves the group is destroyed
}
return try updateV2(groupPublicKey, with: newMembers, name: group.groupName!, transaction: transaction)
return try update(groupPublicKey, with: newMembers, name: group.groupName!, transaction: transaction)
}
public static func generateAndSendNewEncryptionKeyPair(for groupPublicKey: String, to targetMembers: Set<String>, using transaction: Any) throws {

Loading…
Cancel
Save