From a23f1b86ef522376b5901e72a82e54fef1b10b97 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 12 Feb 2018 22:10:29 -0800 Subject: [PATCH] nullability annotations for TSGroupModel - add readonly where possible - group members needn't be a mutable array // FREEBIE --- .../ViewControllers/DebugUI/DebugUIStress.m | 4 ++-- .../UpdateGroupViewController.m | 4 ++-- .../src/Contacts/Threads/TSGroupThread.m | 4 +--- .../src/Messages/OWSMessageManager.m | 2 +- SignalServiceKit/src/Messages/TSGroupModel.h | 20 +++++++++++-------- SignalServiceKit/src/Messages/TSGroupModel.m | 10 +++++++--- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m index df510bc74..23c4838d0 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "DebugUIStress.h" @@ -479,7 +479,7 @@ NS_ASSUME_NONNULL_BEGIN readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:[groupThread.groupModel.groupName stringByAppendingString:@" Copy"] - memberIds:[groupThread.groupModel.groupMemberIds mutableCopy] + memberIds:groupThread.groupModel.groupMemberIds image:groupThread.groupModel.groupImage groupId:[SecurityUtils generateRandomBytes:16]]; thread = [TSGroupThread getOrCreateThreadWithGroupModel:groupModel transaction:transaction]; diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index 908d96ab0..c9c915472 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "UpdateGroupViewController.h" @@ -375,7 +375,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *groupName = [self.groupNameTextField.text ows_stripped]; TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:groupName - memberIds:[self.memberRecipientIds.allObjects mutableCopy] + memberIds:self.memberRecipientIds.allObjects image:self.groupAvatar groupId:self.thread.groupModel.groupId]; [self.conversationSettingsViewDelegate groupWasUpdated:groupModel]; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index b1ed36197..284de2482 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -44,9 +44,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(localNumber.length > 0); TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:nil - memberIds:[@[ - localNumber, - ] mutableCopy] + memberIds:@[ localNumber ] image:nil groupId:groupId]; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 75dac61d0..36be5e9f6 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -922,7 +922,7 @@ NS_ASSUME_NONNULL_BEGIN [TSGroupThread getOrCreateThreadWithGroupId:groupId transaction:transaction]; TSGroupModel *newGroupModel = [[TSGroupModel alloc] initWithTitle:dataMessage.group.name - memberIds:[newMemberIds.allObjects mutableCopy] + memberIds:newMemberIds.allObjects image:oldGroupThread.groupModel.groupImage groupId:dataMessage.group.id]; NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel diff --git a/SignalServiceKit/src/Messages/TSGroupModel.h b/SignalServiceKit/src/Messages/TSGroupModel.h index 84bf3ef31..b590a22d6 100644 --- a/SignalServiceKit/src/Messages/TSGroupModel.h +++ b/SignalServiceKit/src/Messages/TSGroupModel.h @@ -1,22 +1,24 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSYapDatabaseObject.h" #import "ContactsManagerProtocol.h" +NS_ASSUME_NONNULL_BEGIN + @interface TSGroupModel : TSYapDatabaseObject -@property (nonatomic, strong) NSArray *groupMemberIds; -@property (nonatomic, strong) NSString *groupName; -@property (nonatomic, strong) NSData *groupId; +@property (nonatomic) NSArray *groupMemberIds; +@property (nullable, readonly, nonatomic) NSString *groupName; +@property (readonly, nonatomic) NSData *groupId; #if TARGET_OS_IOS -@property (nonatomic, strong) UIImage *groupImage; +@property (nullable, nonatomic, strong) UIImage *groupImage; -- (instancetype)initWithTitle:(NSString *)title - memberIds:(NSMutableArray *)memberIds - image:(UIImage *)image +- (instancetype)initWithTitle:(nullable NSString *)title + memberIds:(NSArray *)memberIds + image:(nullable UIImage *)image groupId:(NSData *)groupId; - (BOOL)isEqual:(id)other; @@ -25,3 +27,5 @@ #endif @end + +NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/TSGroupModel.m b/SignalServiceKit/src/Messages/TSGroupModel.m index 2844bd3fe..a07e2ee5a 100644 --- a/SignalServiceKit/src/Messages/TSGroupModel.m +++ b/SignalServiceKit/src/Messages/TSGroupModel.m @@ -1,16 +1,18 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSGroupModel.h" #import "FunctionalUtil.h" +NS_ASSUME_NONNULL_BEGIN + @implementation TSGroupModel #if TARGET_OS_IOS -- (instancetype)initWithTitle:(NSString *)title +- (instancetype)initWithTitle:(nullable NSString *)title memberIds:(NSArray *)memberIds - image:(UIImage *)image + image:(nullable UIImage *)image groupId:(NSData *)groupId { _groupName = title; @@ -106,3 +108,5 @@ #endif @end + +NS_ASSUME_NONNULL_END