pull/330/head
Niels Andriesse 4 years ago
parent d5228abea9
commit a6e44ca0f0

@ -554,7 +554,7 @@ typedef enum : NSUInteger {
}
if ([self.thread isKindOfClass:TSGroupThread.class] && !((TSGroupThread *)self.thread).isOpenGroup
&& !((TSGroupThread *)self.thread).usesSharedSenderKeys) {
&& !((TSGroupThread *)self.thread).isClosedGroup) {
self.inputToolbar.hidden = YES;
} else if (self.userLeftGroup) {
self.inputToolbar.hidden = YES; // user has requested they leave the group. further sends disallowed
@ -1190,7 +1190,7 @@ typedef enum : NSUInteger {
[self ensureScrollDownButton];
if ([self.thread isKindOfClass:TSGroupThread.class] && !((TSGroupThread *)self.thread).isOpenGroup
&& !((TSGroupThread *)self.thread).usesSharedSenderKeys) {
&& !((TSGroupThread *)self.thread).isClosedGroup) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Session"
message:@"Legacy closed groups are no longer supported. Please create a new group to continue." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];

@ -485,7 +485,7 @@ const CGFloat kIconViewLength = 24;
}
if (self.isGroupThread && self.isClosedGroup && isUserMember) {
if (((TSGroupThread *)self.thread).usesSharedSenderKeys) {
if (((TSGroupThread *)self.thread).isClosedGroup) {
[mainSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
UITableViewCell *cell =
@ -936,7 +936,7 @@ static CGRect oldframe;
{
TSGroupThread *gThread = (TSGroupThread *)self.thread;
if (gThread.usesSharedSenderKeys) {
if (gThread.isClosedGroup) {
NSString *groupPublicKey = [LKGroupUtilities getDecodedGroupID:gThread.groupModel.groupId];
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[SNMessageSender leaveClosedGroupWithPublicKey:groupPublicKey using:transaction error:nil];

@ -398,7 +398,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
let openGroup = Storage.shared.getOpenGroup(for: thread.uniqueId!)
let delete = UITableViewRowAction(style: .destructive, title: NSLocalizedString("TXT_DELETE_TITLE", comment: "")) { [weak self] _, _ in
var message = NSLocalizedString("CONVERSATION_DELETE_CONFIRMATION_ALERT_MESSAGE", comment: "")
if let thread = thread as? TSGroupThread, thread.usesSharedSenderKeys, thread.groupModel.groupAdminIds.contains(getUserHexEncodedPublicKey()) {
if let thread = thread as? TSGroupThread, thread.isClosedGroup, thread.groupModel.groupAdminIds.contains(getUserHexEncodedPublicKey()) {
message = "Because you are the creator of this group it will be deleted for everyone. This cannot be undone."
}
let alert = UIAlertController(title: NSLocalizedString("CONVERSATION_DELETE_CONFIRMATION_ALERT_TITLE", comment: ""), message: message, preferredStyle: .alert)
@ -416,7 +416,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
let _ = OpenGroupAPI.leave(openGroup.channel, on: openGroup.server)
thread.removeAllThreadInteractions(with: transaction)
thread.remove(with: transaction)
} else if let thread = thread as? TSGroupThread, thread.usesSharedSenderKeys == true {
} else if let thread = thread as? TSGroupThread, thread.isClosedGroup == true {
let groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
do {

@ -265,14 +265,6 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
{
// Given how sensitive this migration is, we verbosely
// log the contents of all involved paths before and after.
NSArray<NSString *> *paths = @[
self.legacyDatabaseFilePath,
self.legacyDatabaseFilePath_SHM,
self.legacyDatabaseFilePath_WAL,
self.sharedDataDatabaseFilePath,
self.sharedDataDatabaseFilePath_SHM,
self.sharedDataDatabaseFilePath_WAL,
];
NSFileManager *fileManager = [NSFileManager defaultManager];
// We protect the db files here, which is somewhat redundant with what will happen in

@ -9,7 +9,7 @@ public extension Message {
static func from(_ thread: TSThread) -> Message.Destination {
if let thread = thread as? TSContactThread {
return .contact(publicKey: thread.contactIdentifier())
} else if let thread = thread as? TSGroupThread, thread.usesSharedSenderKeys {
} else if let thread = thread as? TSGroupThread, thread.isClosedGroup {
let groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
return .closedGroup(groupPublicKey: groupPublicKey)

@ -49,7 +49,7 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is
}
public func setGroupContextIfNeeded(on dataMessage: SNProtoDataMessage.SNProtoDataMessageBuilder, using transaction: YapDatabaseReadTransaction) throws {
guard let thread = TSThread.fetch(uniqueId: threadID!, transaction: transaction) as? TSGroupThread, thread.usesSharedSenderKeys else { return }
guard let thread = TSThread.fetch(uniqueId: threadID!, transaction: transaction) as? TSGroupThread, thread.isClosedGroup else { return }
// Android needs a group context or it'll interpret the message as a one-to-one message
let groupProto = SNProtoGroupContext.builder(id: thread.groupModel.groupId, type: .deliver)
dataMessage.setGroup(try groupProto.build())

@ -23,7 +23,6 @@ public extension TSIncomingMessage {
wasReceivedByUD: true
)
result.openGroupServerMessageID = openGroupServerMessageID
result.isOpenGroupMessage = isOpenGroupMessage
return result
}
}

@ -40,7 +40,6 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value);
@property (nonatomic, readonly) uint64_t sortId;
@property (nonatomic, readonly) uint64_t receivedAtTimestamp;
@property (nonatomic, readonly) BOOL shouldUseServerTime;
@property (nonatomic) BOOL isOpenGroupMessage;
- (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp;

@ -199,7 +199,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
// In open groups messages should be sorted by server timestamp. `sortId` represents the order in which messages
// were processed. Since in the open group poller we sort messages by their server timestamp, sorting by `sortId` is
// effectively the same as sorting by server timestamp.
if (self.isOpenGroupMessage) {
if ([self isKindOfClass:TSMessage.class] && ((TSMessage *)self).isOpenGroupMessage) {
sortId1 = self.sortId;
sortId2 = other.sortId;
} else {

@ -35,6 +35,7 @@ extern const NSUInteger kOversizeTextMessageSizeThreshold;
@property (nonatomic, readonly, nullable) TSQuotedMessage *quotedMessage;
@property (nonatomic, nullable) OWSLinkPreview *linkPreview;
@property (nonatomic) uint64_t openGroupServerMessageID;
@property (nonatomic, readonly) BOOL isOpenGroupMessage;
- (instancetype)initInteractionWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread NS_UNAVAILABLE;

@ -392,6 +392,11 @@ const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024;
[self.quotedMessage setThumbnailAttachmentStream:attachmentStream];
}
- (BOOL)isOpenGroupMessage
{
return (self.openGroupServerMessageID != 0);
}
#pragma mark - Update With... Methods
- (void)updateWithExpireStartedAt:(uint64_t)expireStartedAt transaction:(YapDatabaseReadWriteTransaction *)transaction

@ -31,7 +31,7 @@ import SessionUtilitiesKit
result.threadID = tsMessage.uniqueThreadId
result.sentTimestamp = tsMessage.timestamp
result.recipient = tsMessage.recipientIds().first
if let thread = tsMessage.thread as? TSGroupThread, thread.usesSharedSenderKeys {
if let thread = tsMessage.thread as? TSGroupThread, thread.isClosedGroup {
let groupID = thread.groupModel.groupId
result.groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
}

@ -241,7 +241,6 @@ extension MessageReceiver {
thread.setGroupModel(group, with: transaction)
} else {
thread = TSGroupThread.getOrCreateThread(with: group, transaction: transaction)
thread.usesSharedSenderKeys = true
thread.save(with: transaction)
}
// Add the group to the user's set of public keys to poll for

@ -20,7 +20,6 @@ extension MessageSender {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
let group = TSGroupModel(title: name, memberIds: [String](members), image: nil, groupId: groupID, groupType: .closedGroup, adminIds: admins)
let thread = TSGroupThread.getOrCreateThread(with: group, transaction: transaction)
thread.usesSharedSenderKeys = true // TODO: We should be able to safely deprecate this
thread.save(with: transaction)
// Send a closed group update message to all members individually
var promises: [Promise<Void>] = []

@ -342,10 +342,9 @@ public final class MessageSender : NSObject {
public static func handleSuccessfulMessageSend(_ message: Message, to destination: Message.Destination, using transaction: Any) {
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
tsMessage.isOpenGroupMessage = tsMessage.openGroupServerMessageID != 0
var recipients = [ message.recipient! ]
if case .closedGroup(_) = destination, let threadID = message.threadID, // threadID should always be set at this point
let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction as! YapDatabaseReadTransaction), thread.usesSharedSenderKeys {
let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction as! YapDatabaseReadTransaction), thread.isClosedGroup {
recipients = thread.groupModel.groupMemberIds
}
recipients.forEach { recipient in

@ -17,7 +17,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
@property (nonatomic, strong) TSGroupModel *groupModel;
@property (nonatomic, readonly) BOOL isOpenGroup;
@property (nonatomic) BOOL usesSharedSenderKeys;
@property (nonatomic, readonly) BOOL isClosedGroup;
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel;
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel

@ -156,6 +156,11 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
return true;
}
- (BOOL)isClosedGroup
{
return (self.groupModel.groupType == closedGroup);
}
- (BOOL)isOpenGroup
{
return (self.groupModel.groupType == openGroup);

@ -2742,8 +2742,8 @@
C33FDA67255A57F900E217F9 /* OWSPrimaryStorage.h */,
C33FDC02255A581D00E217F9 /* OWSPrimaryStorage.m */,
C33FDAFE255A580600E217F9 /* OWSStorage.h */,
C33FDAB9255A580100E217F9 /* OWSStorage+Subclass.h */,
C33FDAB1255A580000E217F9 /* OWSStorage.m */,
C33FDAB9255A580100E217F9 /* OWSStorage+Subclass.h */,
B8D8F1372566120F0092EF10 /* Storage+ClosedGroups.swift */,
B8B32032258B235D0020074B /* Storage+Contacts.swift */,
B8D8F17625661AFA0092EF10 /* Storage+Jobs.swift */,

@ -36,7 +36,7 @@ public class ContactsMigration : OWSDatabaseMigration {
}
// Closed groups
TSGroupThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard let thread = object as? TSGroupThread, thread.usesSharedSenderKeys else { return }
guard let thread = object as? TSGroupThread, thread.isClosedGroup else { return }
let memberSessionIDs = thread.groupModel.groupMemberIds
memberSessionIDs.forEach { memberSessionID in
guard !contacts.contains(where: { $0.sessionID == memberSessionID }) else { return }

Loading…
Cancel
Save