Browse Source

format objc.

This is part of unforking JSQMVC, but I'm only reformatting files
otherwise changed rather than reformatting the entire project for git
sanity.

This is intentionally a second commit so we can separate formatting
changes from code changes

* brace should drop after method definition (this is common across
  almost all objc projects, and allows you to quickly differentiate
  multi-line method signatures from their implementation.
* aligning consecutive assignments ongoingly muddies git history

// FREEBIE
pull/1/head
Michael Kirk 5 years ago
parent
commit
933281f234
  1. 10
      .clang-format
  2. 12
      Signal/src/Models/JSQCall.h
  3. 92
      Signal/src/Models/JSQCall.m
  4. 8
      Signal/src/Models/JSQDisplayedMessage.h
  5. 18
      Signal/src/Models/JSQDisplayedMessage.m
  6. 10
      Signal/src/Models/JSQErrorMessage.h
  7. 18
      Signal/src/Models/JSQErrorMessage.m
  8. 10
      Signal/src/Models/JSQInfoMessage.h
  9. 20
      Signal/src/Models/JSQInfoMessage.m
  10. 9
      Signal/src/Models/OWSMessagesBubblesSizeCalculator.m
  11. 2
      Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.h
  12. 2
      Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m
  13. 2
      Signal/src/views/JSQCallCollectionViewCell.h
  14. 12
      Signal/src/views/JSQCallCollectionViewCell.m
  15. 6
      Signal/src/views/JSQDisplayedMessageCollectionViewCell.h
  16. 16
      Signal/src/views/JSQDisplayedMessageCollectionViewCell.m

10
.clang-format

@ -1,14 +1,10 @@
---
BasedOnStyle: Chromium
AlignTrailingComments: true
AlignConsecutiveAssignments: true
AllowShortIfStatementsOnASingleLine: false
BreakBeforeBraces: Attach
BasedOnStyle: WebKit
AllowShortFunctionsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 120
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
IndentCaseLabels: true
MaxEmptyLinesToKeep: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

12
Signal/src/Models/JSQCall.h

@ -13,7 +13,7 @@
typedef enum : NSUInteger {
kCallOutgoing = 1,
kCallIncoming = 2,
kCallMissed = 3,
kCallMissed = 3,
kGroupUpdateJoin = 4,
kGroupUpdateLeft = 5,
kGroupUpdate = 6
@ -39,7 +39,7 @@ typedef enum : NSUInteger {
@property (copy, nonatomic, readonly) NSDate *date;
/*
* Returns the call status
* Returns the call status
* @see CallStatus
*/
@property (nonatomic) CallStatus status;
@ -61,16 +61,16 @@ typedef enum : NSUInteger {
@property (nonatomic, copy) NSString *detailString;
#pragma mark - Initialization
#pragma mark - Initialization
- (instancetype)initWithCallerId:(NSString *)callerId
callerDisplayName:(NSString *)callerDisplayName
date:(NSDate *)date
status:(CallStatus)status
displayString:(NSString*)detailString;
displayString:(NSString *)detailString;
-(NSString*)dateText;
- (NSString *)dateText;
-(UIImage*)thumbnailImage;
- (UIImage *)thumbnailImage;
@end

92
Signal/src/Models/JSQCall.m

@ -14,15 +14,15 @@
#pragma mark - Initialzation
-(instancetype)initWithCallerId:(NSString *)senderId
callerDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date
status:(CallStatus)status
displayString:(NSString *)detailString
- (instancetype)initWithCallerId:(NSString *)senderId
callerDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date
status:(CallStatus)status
displayString:(NSString *)detailString
{
NSParameterAssert(senderId != nil);
NSParameterAssert(senderDisplayName != nil);
self = [super init];
if (self) {
_senderId = [senderId copy];
@ -31,25 +31,28 @@
_status = status;
_messageType = TSCallAdapter;
_detailString = [detailString stringByAppendingFormat:@" "];
}
return self;
}
-(id)init
- (id)init
{
NSAssert(NO,@"%s is not a valid initializer for %@. Use %@ instead", __PRETTY_FUNCTION__, [self class], NSStringFromSelector(@selector(initWithCallerId:callerDisplayName:date:status:displayString:)));
NSAssert(NO,
@"%s is not a valid initializer for %@. Use %@ instead",
__PRETTY_FUNCTION__,
[self class],
NSStringFromSelector(@selector(initWithCallerId:callerDisplayName:date:status:displayString:)));
return nil;
}
-(void)dealloc
- (void)dealloc
{
_senderId = nil;
_senderDisplayName = nil;
_date = nil;
}
-(NSString*)dateText
- (NSString *)dateText
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
@ -58,9 +61,10 @@
return [dateFormatter stringFromDate:_date];
}
-(UIImage*)thumbnailImage {
- (UIImage *)thumbnailImage
{
// This relies on those assets being in the project
if(!_useThumbnail) {
if (!_useThumbnail) {
return nil;
}
switch (_status) {
@ -86,49 +90,47 @@
}
}
#pragma mark - NSObject
-(BOOL)isEqual:(id)object
- (BOOL)isEqual:(id)object
{
if (self==object) {
if (self == object) {
return YES;
}
if (![object isKindOfClass:[self class]])
{
if (![object isKindOfClass:[self class]]) {
return NO;
}
JSQCall * aCall = (JSQCall*)object;
return [self.senderId isEqualToString:aCall.senderId]
&& [self.senderDisplayName isEqualToString:aCall.senderDisplayName]
&& ([self.date compare:aCall.date] == NSOrderedSame)
&& self.status == aCall.status;
JSQCall *aCall = (JSQCall *)object;
return [self.senderId isEqualToString:aCall.senderId] &&
[self.senderDisplayName isEqualToString:aCall.senderDisplayName]
&& ([self.date compare:aCall.date] == NSOrderedSame) && self.status == aCall.status;
}
-(NSUInteger)hash
- (NSUInteger)hash
{
return self.senderId.hash ^ self.date.hash;
}
-(NSString*)description
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: senderId=%@, senderDisplayName=%@, date=%@>",
[self class], self.senderId, self.senderDisplayName, self.date];
[self class],
self.senderId,
self.senderDisplayName,
self.date];
}
#pragma mark - JSQMessageData
//TODO I'm not sure this is right. It affects bubble rendering.
- (BOOL)isMediaMessage {
// TODO I'm not sure this is right. It affects bubble rendering.
- (BOOL)isMediaMessage
{
return NO;
}
#pragma mark - NSCoding
-(instancetype)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
@ -150,21 +152,21 @@
#pragma mark - NSCopying
-(instancetype)copyWithZone:(NSZone *)zone
- (instancetype)copyWithZone:(NSZone *)zone
{
return [[[self class] allocWithZone:zone]initWithCallerId:self.senderId
callerDisplayName:self.senderDisplayName
date:self.date
status:self.status
displayString:self.detailString];
return [[[self class] allocWithZone:zone] initWithCallerId:self.senderId
callerDisplayName:self.senderDisplayName
date:self.date
status:self.status
displayString:self.detailString];
}
- (NSUInteger)messageHash{
- (NSUInteger)messageHash
{
return self.hash;
}
- (NSString *)text{
- (NSString *)text
{
return _detailString;
}
@end

8
Signal/src/Models/JSQDisplayedMessage.h

@ -6,9 +6,9 @@
// Copyright (c) 2014 Hexed Bits. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "JSQMessageData.h"
#import "TSMessageAdapter.h"
#import <Foundation/Foundation.h>
/* JSQDisplayed message is the parent class for displaying information to the user
* from within the conversation view. Do not use directly :
@ -38,8 +38,8 @@
#pragma mark - Initializer
-(instancetype)initWithSenderId:(NSString*)senderId
senderDisplayName:(NSString*)senderDisplayName
date:(NSDate*)date;
- (instancetype)initWithSenderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date;
@end

18
Signal/src/Models/JSQDisplayedMessage.m

@ -10,24 +10,28 @@
@implementation JSQDisplayedMessage
-(id)init
- (id)init
{
NSAssert(NO,@"%s is not a valid initializer for %@. Use %@ instead", __PRETTY_FUNCTION__, [self class], NSStringFromSelector(@selector(initWithSenderId:senderDisplayName:date:)));
NSAssert(NO,
@"%s is not a valid initializer for %@. Use %@ instead",
__PRETTY_FUNCTION__,
[self class],
NSStringFromSelector(@selector(initWithSenderId:senderDisplayName:date:)));
return nil;
}
-(instancetype)initWithSenderId:(NSString*)senderId
senderDisplayName:(NSString*)senderDisplayName
date:(NSDate*)date
- (instancetype)initWithSenderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date
{
self = [super init];
if (self) {
_senderId = [senderId copy];
_senderDisplayName = [senderDisplayName copy];
_date = [date copy];
}
return self;
}

10
Signal/src/Models/JSQErrorMessage.h

@ -8,7 +8,7 @@
#import "JSQDisplayedMessage.h"
typedef NS_ENUM(NSInteger, JSQErrorMessageType){
typedef NS_ENUM(NSInteger, JSQErrorMessageType) {
JSQErrorMessageNoSession,
JSQErrorMessageWrongTrustedIdentityKey,
JSQErrorMessageInvalidKeyException,
@ -27,10 +27,10 @@ typedef NS_ENUM(NSInteger, JSQErrorMessageType){
#pragma mark - Initialization
- (instancetype)initWithErrorType:(JSQErrorMessageType)messageType
senderId:(NSString*)senderId
senderDisplayName:(NSString*)senderDisplayName
date:(NSDate*)date;
senderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date;
- (NSString*)text;
- (NSString *)text;
@end

18
Signal/src/Models/JSQErrorMessage.m

@ -16,16 +16,16 @@
date:(NSDate *)date
{
self = [super initWithSenderId:senderId senderDisplayName:senderDisplayName date:date];
if (self) {
_errorMessageType = messageType;
_messageType = TSErrorMessageAdapter;
}
return self;
}
- (NSString*)text
- (NSString *)text
{
switch (self.errorMessageType) {
case JSQErrorMessageNoSession:
@ -49,7 +49,7 @@
case JSQErrorMessageInvalidVersion:
return [NSString stringWithFormat:@"Error: Invalid version for contact %@.", self.senderDisplayName];
break;
default:
return nil;
break;
@ -61,13 +61,17 @@
return self.senderId.hash ^ self.date.hash;
}
- (NSString*)description
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: senderId=%@, senderDisplayName=%@, date=%@, type=%ld>",
[self class], self.senderId, self.senderDisplayName, self.date, self.errorMessageType];
[self class],
self.senderId,
self.senderDisplayName,
self.date,
self.errorMessageType];
}
-(TSMessageAdapterType)messageType
- (TSMessageAdapterType)messageType
{
return TSErrorMessageAdapter;
}

10
Signal/src/Models/JSQInfoMessage.h

@ -8,7 +8,7 @@
#import "JSQDisplayedMessage.h"
typedef NS_ENUM(NSInteger, JSQInfoMessageType){
typedef NS_ENUM(NSInteger, JSQInfoMessageType) {
JSQInfoMessageTypeSessionDidEnd,
};
@ -21,11 +21,11 @@ typedef NS_ENUM(NSInteger, JSQInfoMessageType){
#pragma mark - Initialization
- (instancetype)initWithInfoType:(JSQInfoMessageType)messageType
senderId:(NSString*)senderId
senderDisplayName:(NSString*)senderDisplayName
date:(NSDate*)date;
senderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date;
- (NSString*)text;
- (NSString *)text;
@end

20
Signal/src/Models/JSQInfoMessage.m

@ -16,39 +16,43 @@
date:(NSDate *)date
{
//@discussion: NSParameterAssert() ?
self = [super initWithSenderId:senderId senderDisplayName:senderDisplayName date:date];
if (self) {
_infoMessageType = messageType;
_messageType = TSInfoMessageAdapter;
}
return self;
}
-(NSString*)text
- (NSString *)text
{
switch (self.infoMessageType) {
case JSQInfoMessageTypeSessionDidEnd:
return [NSString stringWithFormat:@"Session with %@ ended.", self.senderDisplayName];
break;
default:
return nil;
break;
}
}
-(NSUInteger)hash
- (NSUInteger)hash
{
return self.senderId.hash ^ self.date.hash;
}
-(NSString*)description
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: senderId=%@, senderDisplayName=%@, date=%@, type=%ld>",
[self class], self.senderId, self.senderDisplayName, self.date, self.infoMessageType];
[self class],
self.senderId,
self.senderDisplayName,
self.date,
self.infoMessageType];
}
@end

9
Signal/src/Models/OWSMessagesBubblesSizeCalculator.m

@ -7,8 +7,8 @@
//
#import "OWSMessagesBubblesSizeCalculator.h"
#import "TSMessageAdapter.h"
#import "JSQDisplayedMessageCollectionViewCell.h"
#import "TSMessageAdapter.h"
@implementation OWSMessagesBubblesSizeCalculator
@ -27,13 +27,10 @@
atIndexPath:(NSIndexPath *)indexPath
withLayout:(JSQMessagesCollectionViewFlowLayout *)layout
{
CGSize superSize = [super messageBubbleSizeForMessageData:messageData
atIndexPath:indexPath
withLayout:layout];
CGSize superSize = [super messageBubbleSizeForMessageData:messageData atIndexPath:indexPath withLayout:layout];
TSMessageAdapter *message = (TSMessageAdapter *)messageData;
if (message.messageType == TSInfoMessageAdapter ||
message.messageType == TSErrorMessageAdapter) {
if (message.messageType == TSInfoMessageAdapter || message.messageType == TSErrorMessageAdapter) {
// Prevent cropping message text by accounting for message container/icon
superSize.height = OWSDisplayedMessageCellHeight;

2
Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.h

@ -22,7 +22,7 @@ typedef NS_ENUM(NSInteger, TSMessageAdapterType) {
TSInfoMessageAdapter,
TSErrorMessageAdapter,
TSMediaAttachmentAdapter,
TSGenericTextMessageAdapter, //Used when message direction is unknown (outgoing or incoming)
TSGenericTextMessageAdapter, // Used when message direction is unknown (outgoing or incoming)
};
@interface TSMessageAdapter : NSObject <JSQMessageData>

2
Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m

@ -254,7 +254,7 @@
{
if (self.isMediaMessage) {
return [self.mediaItem mediaHash];
} else {
} else {
return self.identifier;
}
}

2
Signal/src/views/JSQCallCollectionViewCell.h

@ -14,7 +14,7 @@
@interface JSQCallCollectionViewCell : JSQMessagesCollectionViewCell
//TODO can we use an existing label from JSQMessagesCollectionViewCell?
// TODO can we use an existing label from JSQMessagesCollectionViewCell?
@property (weak, nonatomic, readonly) JSQMessagesLabel *cellLabel;
@property (weak, nonatomic, readonly) UIImageView *outgoingCallImageView;

12
Signal/src/views/JSQCallCollectionViewCell.m

@ -34,27 +34,27 @@
#pragma mark - Initializer
-(void)awakeFromNib
- (void)awakeFromNib
{
[super awakeFromNib];
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
self.backgroundColor = [UIColor whiteColor];
self.cellLabel.textAlignment = NSTextAlignmentCenter;
self.cellLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f];
self.cellLabel.textColor = [UIColor lightGrayColor];
}
-(void)dealloc
- (void)dealloc
{
_cellLabel = nil;
}
#pragma mark - Collection view cell
-(void)prepareForReuse
- (void)prepareForReuse
{
[super prepareForReuse];
self.cellLabel.text = nil;

6
Signal/src/views/JSQDisplayedMessageCollectionViewCell.h

@ -6,16 +6,16 @@
// Copyright (c) 2014 Hexed Bits. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <JSQMessagesViewController/JSQMessagesCollectionViewCell.h>
#import <UIKit/UIKit.h>
static const CGFloat OWSDisplayedMessageCellHeight = 70.0f;
@interface JSQDisplayedMessageCollectionViewCell : JSQMessagesCollectionViewCell
// TODO can we use existing label from superclass?
@property (weak, nonatomic, readonly) JSQMessagesLabel * cellLabel;
@property (weak, nonatomic, readonly) UIImageView * headerImageView;
@property (weak, nonatomic, readonly) JSQMessagesLabel *cellLabel;
@property (weak, nonatomic, readonly) UIImageView *headerImageView;
@property (strong, nonatomic, readonly) UIView *textContainer;
@end

16
Signal/src/views/JSQDisplayedMessageCollectionViewCell.m

@ -12,8 +12,8 @@
@interface JSQDisplayedMessageCollectionViewCell ()
@property(weak, nonatomic) IBOutlet JSQMessagesLabel* cellLabel;
@property (weak, nonatomic) IBOutlet UIImageView* headerImageView;
@property (weak, nonatomic) IBOutlet JSQMessagesLabel *cellLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
@property (strong, nonatomic) IBOutlet UIView *textContainer;
@end
@ -34,14 +34,14 @@
#pragma mark - Initializer
-(void)awakeFromNib
- (void)awakeFromNib
{
[super awakeFromNib];
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
self.backgroundColor = [UIColor whiteColor];
// self.cellLabelHeightConstraint.constant = 0.0f;
// self.cellLabelHeightConstraint.constant = 0.0f;
self.textContainer.layer.borderColor = [[UIColor lightGrayColor] CGColor];
self.textContainer.layer.borderWidth = 0.75f;
@ -53,10 +53,10 @@
#pragma mark - Collection view cell
-(void)prepareForReuse
- (void)prepareForReuse
{
[super prepareForReuse];
self.cellLabel.text = nil;
}

Loading…
Cancel
Save