Skip to content

Commit

Permalink
format objc.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michaelkirk committed Jul 15, 2016
1 parent 4d320d6 commit 933281f
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 120 deletions.
10 changes: 3 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions Signal/src/Models/JSQCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
typedef enum : NSUInteger {
kCallOutgoing = 1,
kCallIncoming = 2,
kCallMissed = 3,
kCallMissed = 3,
kGroupUpdateJoin = 4,
kGroupUpdateLeft = 5,
kGroupUpdate = 6
Expand All @@ -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;
Expand All @@ -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 changes: 47 additions & 45 deletions Signal/src/Models/JSQCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ @implementation JSQCall

#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];
Expand All @@ -31,25 +31,28 @@ -(instancetype)initWithCallerId:(NSString *)senderId
_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;
Expand All @@ -58,9 +61,10 @@ -(NSString*)dateText
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) {
Expand All @@ -86,49 +90,47 @@ -(UIImage*)thumbnailImage {
}
}


#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) {
Expand All @@ -150,21 +152,21 @@ - (void)encodeWithCoder:(NSCoder *)aCoder

#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 changes: 4 additions & 4 deletions Signal/src/Models/JSQDisplayedMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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 changes: 11 additions & 7 deletions Signal/src/Models/JSQDisplayedMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions Signal/src/Models/JSQErrorMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "JSQDisplayedMessage.h"

typedef NS_ENUM(NSInteger, JSQErrorMessageType){
typedef NS_ENUM(NSInteger, JSQErrorMessageType) {
JSQErrorMessageNoSession,
JSQErrorMessageWrongTrustedIdentityKey,
JSQErrorMessageInvalidKeyException,
Expand All @@ -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 changes: 11 additions & 7 deletions Signal/src/Models/JSQErrorMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ - (instancetype)initWithErrorType:(JSQErrorMessageType)messageType
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:
Expand All @@ -49,7 +49,7 @@ - (NSString*)text
case JSQErrorMessageInvalidVersion:
return [NSString stringWithFormat:@"Error: Invalid version for contact %@.", self.senderDisplayName];
break;

default:
return nil;
break;
Expand All @@ -61,13 +61,17 @@ - (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.errorMessageType];
[self class],
self.senderId,
self.senderDisplayName,
self.date,
self.errorMessageType];
}

-(TSMessageAdapterType)messageType
- (TSMessageAdapterType)messageType
{
return TSErrorMessageAdapter;
}
Expand Down
10 changes: 5 additions & 5 deletions Signal/src/Models/JSQInfoMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "JSQDisplayedMessage.h"

typedef NS_ENUM(NSInteger, JSQInfoMessageType){
typedef NS_ENUM(NSInteger, JSQInfoMessageType) {
JSQInfoMessageTypeSessionDidEnd,
};

Expand All @@ -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
Loading

0 comments on commit 933281f

Please sign in to comment.