Hook up the new system

pull/341/head
Niels Andriesse 4 years ago
parent 0dd63229ef
commit 017e4f7d50

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

@ -939,7 +939,7 @@ static CGRect oldframe;
if (gThread.isClosedGroup) { if (gThread.isClosedGroup) {
NSString *groupPublicKey = [LKGroupUtilities getDecodedGroupID:gThread.groupModel.groupId]; NSString *groupPublicKey = [LKGroupUtilities getDecodedGroupID:gThread.groupModel.groupId];
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [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 groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID) let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
do { do {
try MessageSender.leave(groupPublicKey, using: transaction) try MessageSender.v2_leave(groupPublicKey, using: transaction)
} catch { } catch {
// TODO: Handle // 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 { public static func setName(to name: String, for groupPublicKey: String, using transaction: YapDatabaseReadWriteTransaction) throws {
// Get the group, check preconditions & prepare // Get the group, check preconditions & prepare
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey) let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)

Loading…
Cancel
Save