Browse Source

Clean

pull/330/head
Niels Andriesse 2 years ago
parent
commit
a6e44ca0f0
  1. 4
      Session/Signal/ConversationView/ConversationViewController.m
  2. 4
      Session/Signal/OWSConversationSettingsViewController.m
  3. 4
      Session/View Controllers/HomeVC.swift
  4. 8
      SessionMessagingKit/Database/OWSPrimaryStorage.m
  5. 2
      SessionMessagingKit/Messages/Message+Destination.swift
  6. 2
      SessionMessagingKit/Messages/Message.swift
  7. 1
      SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift
  8. 1
      SessionMessagingKit/Messages/Signal/TSInteraction.h
  9. 2
      SessionMessagingKit/Messages/Signal/TSInteraction.m
  10. 1
      SessionMessagingKit/Messages/Signal/TSMessage.h
  11. 5
      SessionMessagingKit/Messages/Signal/TSMessage.m
  12. 2
      SessionMessagingKit/Messages/Signal/TSOutgoingMessage+Conversion.swift
  13. 1
      SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift
  14. 1
      SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift
  15. 3
      SessionMessagingKit/Sending & Receiving/MessageSender.swift
  16. 2
      SessionMessagingKit/Threads/TSGroupThread.h
  17. 5
      SessionMessagingKit/Threads/TSGroupThread.m
  18. 2
      Signal.xcodeproj/project.pbxproj
  19. 2
      SignalUtilitiesKit/Database/Migration/ContactsMigration.swift

4
Session/Signal/ConversationView/ConversationViewController.m

@ -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]];

4
Session/Signal/OWSConversationSettingsViewController.m

@ -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];

4
Session/View Controllers/HomeVC.swift

@ -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 {

8
SessionMessagingKit/Database/OWSPrimaryStorage.m

@ -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

2
SessionMessagingKit/Messages/Message+Destination.swift

@ -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)

2
SessionMessagingKit/Messages/Message.swift

@ -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())

1
SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift

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

1
SessionMessagingKit/Messages/Signal/TSInteraction.h

@ -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;

2
SessionMessagingKit/Messages/Signal/TSInteraction.m

@ -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 {

1
SessionMessagingKit/Messages/Signal/TSMessage.h

@ -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;

5
SessionMessagingKit/Messages/Signal/TSMessage.m

@ -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

2
SessionMessagingKit/Messages/Signal/TSOutgoingMessage+Conversion.swift

@ -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)
}

1
SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift

@ -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

1
SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift

@ -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>] = []

3
SessionMessagingKit/Sending & Receiving/MessageSender.swift

@ -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

2
SessionMessagingKit/Threads/TSGroupThread.h

@ -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

5
SessionMessagingKit/Threads/TSGroupThread.m

@ -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);

2
Signal.xcodeproj/project.pbxproj

@ -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 */,

2
SignalUtilitiesKit/Database/Migration/ContactsMigration.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