Hook up the new system
This commit is contained in:
parent
0dd63229ef
commit
017e4f7d50
|
@ -263,9 +263,9 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
|
|||
Storage.write(with: { [weak self] transaction in
|
||||
do {
|
||||
if !members.contains(getUserHexEncodedPublicKey()) {
|
||||
try MessageSender.leave(groupPublicKey, using: transaction)
|
||||
try MessageSender.v2_leave(groupPublicKey, using: transaction)
|
||||
} else {
|
||||
try MessageSender.update(groupPublicKey, with: members, name: name, transaction: transaction)
|
||||
try MessageSender.v2_update(groupPublicKey, with: members, name: name, transaction: transaction)
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
|
|
|
@ -939,7 +939,7 @@ static CGRect oldframe;
|
|||
if (gThread.isClosedGroup) {
|
||||
NSString *groupPublicKey = [LKGroupUtilities getDecodedGroupID:gThread.groupModel.groupId];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[SNMessageSender leaveClosedGroupWithPublicKey:groupPublicKey using:transaction error:nil];
|
||||
[SNMessageSender v2_leaveClosedGroupWithPublicKey:groupPublicKey using:transaction error:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
@ -379,7 +379,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIViewC
|
|||
let groupID = thread.groupModel.groupId
|
||||
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
|
||||
do {
|
||||
try MessageSender.leave(groupPublicKey, using: transaction)
|
||||
try MessageSender.v2_leave(groupPublicKey, using: transaction)
|
||||
} catch {
|
||||
// TODO: Handle
|
||||
}
|
||||
|
|
|
@ -78,6 +78,25 @@ extension MessageSender {
|
|||
}
|
||||
}
|
||||
|
||||
public static func v2_update(_ groupPublicKey: String, with members: Set<String>, name: String, transaction: YapDatabaseReadWriteTransaction) throws {
|
||||
// Get the group, check preconditions & prepare
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
let threadID = TSGroupThread.threadId(fromGroupId: groupID)
|
||||
guard let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction) else {
|
||||
SNLog("Can't update nonexistent closed group.")
|
||||
throw Error.noThread
|
||||
}
|
||||
let group = thread.groupModel
|
||||
// Update name if needed
|
||||
if name != group.groupName { setName(to: name, for: groupPublicKey, using: transaction) }
|
||||
// Add members if needed
|
||||
let addedMembers = members.subtracting(group.groupMemberIds)
|
||||
if !addedMembers.isEmpty { addMembers(addedMembers, to: groupPublicKey, using: transaction) }
|
||||
// Remove members if needed
|
||||
let removedMembers = Set(group.groupMemberIds).subtracting(members)
|
||||
if !removedMembers.isEmpty { removeMembers(addedMembers, to: groupPublicKey, using: transaction) }
|
||||
}
|
||||
|
||||
public static func setName(to name: String, for groupPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) throws {
|
||||
// Get the group, check preconditions & prepare
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
|
|
Loading…
Reference in New Issue