Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

Commit

Permalink
change message data protocol and model to use senderId and senderDisp…
Browse files Browse the repository at this point in the history
…layName. closes #389.
  • Loading branch information
jessesquires committed Sep 2, 2014
1 parent 8324746 commit 7516773
Show file tree
Hide file tree
Showing 14 changed files with 423 additions and 230 deletions.
6 changes: 6 additions & 0 deletions JSQMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
88D1B0C9190604AF00AFE162 /* JSQMessagesTypingIndicatorFooterView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 88D1B0C8190604AF00AFE162 /* JSQMessagesTypingIndicatorFooterView.xib */; };
88D1B0CC190606F100AFE162 /* typing.png in Resources */ = {isa = PBXBuildFile; fileRef = 88D1B0CA190606F100AFE162 /* typing.png */; };
88D1B0CD190606F100AFE162 /* typing@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 88D1B0CB190606F100AFE162 /* typing@2x.png */; };
88D4ED7319B555E800C2DCF9 /* JSQDemoModelData.m in Sources */ = {isa = PBXBuildFile; fileRef = 88D4ED7219B555E800C2DCF9 /* JSQDemoModelData.m */; };
C78CEF093F584B85B4321C83 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 343577012CC24261BE4B61A1 /* libPods.a */; };
D68A9FB68FC5463D9A5B23E0 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 343577012CC24261BE4B61A1 /* libPods.a */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -228,6 +229,8 @@
88D1B0C8190604AF00AFE162 /* JSQMessagesTypingIndicatorFooterView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = JSQMessagesTypingIndicatorFooterView.xib; sourceTree = "<group>"; };
88D1B0CA190606F100AFE162 /* typing.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = typing.png; sourceTree = "<group>"; };
88D1B0CB190606F100AFE162 /* typing@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "typing@2x.png"; sourceTree = "<group>"; };
88D4ED7119B555E800C2DCF9 /* JSQDemoModelData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSQDemoModelData.h; path = JSQMessagesDemo/JSQDemoModelData.h; sourceTree = SOURCE_ROOT; };
88D4ED7219B555E800C2DCF9 /* JSQDemoModelData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSQDemoModelData.m; path = JSQMessagesDemo/JSQDemoModelData.m; sourceTree = SOURCE_ROOT; };
88FFE06619B2E5CB0038C3FF /* JSQMessagesCollectionViewDelegateFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSQMessagesCollectionViewDelegateFlowLayout.h; sourceTree = "<group>"; };
A0F1B1EFE54F44FEA6C4F786 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -458,6 +461,8 @@
885D596418CBD2A600D77BB3 /* Images.xcassets */,
885D596518CBD2A600D77BB3 /* JSQAppDelegate.h */,
885D596618CBD2A600D77BB3 /* JSQAppDelegate.m */,
88D4ED7119B555E800C2DCF9 /* JSQDemoModelData.h */,
88D4ED7219B555E800C2DCF9 /* JSQDemoModelData.m */,
8897FBF718CBF967004F59C3 /* JSQDemoViewController.h */,
8897FBF818CBF967004F59C3 /* JSQDemoViewController.m */,
885D596718CBD2A600D77BB3 /* JSQTableViewController.h */,
Expand Down Expand Up @@ -760,6 +765,7 @@
8816A6A218E9250400111919 /* UIColor+JSQMessages.m in Sources */,
8816A6A518E9250400111919 /* JSQMessagesViewController.m in Sources */,
8816A6B718E9250400111919 /* JSQMessagesToolbarContentView.m in Sources */,
88D4ED7319B555E800C2DCF9 /* JSQDemoModelData.m in Sources */,
885D596A18CBD2A600D77BB3 /* JSQAppDelegate.m in Sources */,
8816A6AE18E9250400111919 /* JSQMessagesCollectionView.m in Sources */,
8816A6AB18E9250400111919 /* JSQMessagesCollectionViewFlowLayout.m in Sources */,
Expand Down
55 changes: 55 additions & 0 deletions JSQMessagesDemo/JSQDemoModelData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Created by Jesse Squires
// http://www.hexedbits.com
//
//
// Documentation
// http://cocoadocs.org/docsets/JSQMessagesViewController
//
//
// GitHub
// https://github.com/jessesquires/JSQMessagesViewController
//
//
// License
// Copyright (c) 2014 Jesse Squires
// Released under an MIT license: http://opensource.org/licenses/MIT
//

#import <Foundation/Foundation.h>

#import "JSQMessages.h"

/**
* This is for demo/testing purposes only.
* This object sets up some fake model data.
* Do not actually do anything like this.
*/

static NSString * const kJSQDemoAvatarDisplayNameSquires = @"Jesse Squires";
static NSString * const kJSQDemoAvatarDisplayNameCook = @"Tim Cook";
static NSString * const kJSQDemoAvatarDisplayNameJobs = @"Jobs";
static NSString * const kJSQDemoAvatarDisplayNameWoz = @"Steve Wozniak";

static NSString * const kJSQDemoAvatarIdSquires = @"053496-4509-289";
static NSString * const kJSQDemoAvatarIdCook = @"468-768355-23123";
static NSString * const kJSQDemoAvatarIdJobs = @"707-8956784-57";
static NSString * const kJSQDemoAvatarIdWoz = @"309-41802-93823";

static const CGFloat kJSQDemoAvatarSize = 34.0f;



@interface JSQDemoModelData : NSObject

@property (strong, nonatomic) NSMutableArray *messages;

@property (strong, nonatomic) NSDictionary *avatars;

@property (strong, nonatomic) UIImageView *outgoingBubbleImageView;

@property (strong, nonatomic) UIImageView *incomingBubbleImageView;

@property (strong, nonatomic) NSDictionary *users;

@end
140 changes: 140 additions & 0 deletions JSQMessagesDemo/JSQDemoModelData.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//
// Created by Jesse Squires
// http://www.hexedbits.com
//
//
// Documentation
// http://cocoadocs.org/docsets/JSQMessagesViewController
//
//
// GitHub
// https://github.com/jessesquires/JSQMessagesViewController
//
//
// License
// Copyright (c) 2014 Jesse Squires
// Released under an MIT license: http://opensource.org/licenses/MIT
//

#import "JSQDemoModelData.h"

/**
* This is for demo/testing purposes only.
* This object sets up some fake model data.
* Do not actually do anything like this.
*/

@implementation JSQDemoModelData

- (instancetype)init
{
self = [super init];
if (self) {
/**
* Load some fake messages for demo.
*
* You should have a mutable array or orderedSet, or something.
*/
self.messages = [[NSMutableArray alloc] initWithObjects:
[[JSQMessage alloc] initWithText:@"Welcome to JSQMessages: A messaging UI framework for iOS."
senderId:kJSQDemoAvatarIdSquires
senderDisplayName:kJSQDemoAvatarDisplayNameSquires
date:[NSDate distantPast]],

[[JSQMessage alloc] initWithText:@"It is simple, elegant, and easy to use. There are super sweet default settings, but you can customize like crazy."
senderId:kJSQDemoAvatarIdWoz
senderDisplayName:kJSQDemoAvatarDisplayNameWoz
date:[NSDate distantPast]],

[[JSQMessage alloc] initWithText:@"It even has data detectors. You can call me tonight. My cell number is 123-456-7890. My website is www.hexedbits.com."
senderId:kJSQDemoAvatarIdSquires
senderDisplayName:kJSQDemoAvatarDisplayNameSquires
date:[NSDate distantPast]],

[[JSQMessage alloc] initWithText:@"JSQMessagesViewController is nearly an exact replica of the iOS Messages App. And perhaps, better."
senderId:kJSQDemoAvatarIdJobs
senderDisplayName:kJSQDemoAvatarDisplayNameJobs
date:[NSDate date]],

[[JSQMessage alloc] initWithText:@"It is unit-tested, free, and open-source."
senderId:kJSQDemoAvatarIdCook
senderDisplayName:kJSQDemoAvatarDisplayNameCook
date:[NSDate date]],

[[JSQMessage alloc] initWithText:@"Oh, and there's sweet documentation."
senderId:kJSQDemoAvatarIdSquires
senderDisplayName:kJSQDemoAvatarDisplayNameSquires
date:[NSDate date]],
nil];


/**
* Create avatar images once.
*
* Be sure to create your avatars one time and reuse them for good performance.
*
* If you are not using avatars, ignore this.
*/

UIImage *jsqImage = [JSQMessagesAvatarFactory avatarWithUserInitials:@"JSQ"
backgroundColor:[UIColor colorWithWhite:0.85f alpha:1.0f]
textColor:[UIColor colorWithWhite:0.60f alpha:1.0f]
font:[UIFont systemFontOfSize:14.0f]
diameter:kJSQDemoAvatarSize];

UIImage *cookImage = [JSQMessagesAvatarFactory avatarWithImage:[UIImage imageNamed:@"demo_avatar_cook"]
diameter:kJSQDemoAvatarSize];

UIImage *jobsImage = [JSQMessagesAvatarFactory avatarWithImage:[UIImage imageNamed:@"demo_avatar_jobs"]
diameter:kJSQDemoAvatarSize];

UIImage *wozImage = [JSQMessagesAvatarFactory avatarWithImage:[UIImage imageNamed:@"demo_avatar_woz"]
diameter:kJSQDemoAvatarSize];
self.avatars = @{ kJSQDemoAvatarIdSquires : jsqImage,
kJSQDemoAvatarIdCook : cookImage,
kJSQDemoAvatarIdJobs : jobsImage,
kJSQDemoAvatarIdWoz : wozImage };


self.users = @{ kJSQDemoAvatarIdJobs : kJSQDemoAvatarDisplayNameJobs,
kJSQDemoAvatarIdCook : kJSQDemoAvatarDisplayNameCook,
kJSQDemoAvatarIdWoz : kJSQDemoAvatarDisplayNameWoz,
kJSQDemoAvatarIdSquires : kJSQDemoAvatarDisplayNameSquires };


/**
* Create bubble images.
*
* Be sure to create your avatars one time and reuse them for good performance.
*
*/
self.outgoingBubbleImageView = [JSQMessagesBubbleImageFactory
outgoingMessageBubbleImageViewWithColor:[UIColor jsq_messageBubbleLightGrayColor]];

self.incomingBubbleImageView = [JSQMessagesBubbleImageFactory
incomingMessageBubbleImageViewWithColor:[UIColor jsq_messageBubbleGreenColor]];

/**
* Change to add more messages for testing
*/
NSUInteger messagesToAdd = 0;
NSArray *copyOfMessages = [self.messages copy];
for (NSUInteger i = 0; i < messagesToAdd; i++) {
[self.messages addObjectsFromArray:copyOfMessages];
}

/**
* Change to YES to add a super long message for testing
* You should see "END" twice
*/
BOOL addREALLYLongMessage = NO;
if (addREALLYLongMessage) {
JSQMessage *reallyLongMessage = [JSQMessage messageWithText:@"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? END Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? END" senderId:kJSQDemoAvatarIdSquires senderDisplayName:kJSQDemoAvatarDisplayNameSquires];

[self.messages addObject:reallyLongMessage];
}
}
return self;
}

@end
12 changes: 4 additions & 8 deletions JSQMessagesDemo/JSQDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

#import "JSQMessages.h"

@class JSQDemoViewController;

#import "JSQDemoModelData.h"

@class JSQDemoViewController;

@protocol JSQDemoViewControllerDelegate <NSObject>

Expand All @@ -34,16 +36,10 @@

@property (weak, nonatomic) id<JSQDemoViewControllerDelegate> delegateModal;

@property (strong, nonatomic) NSMutableArray *messages;
@property (copy, nonatomic) NSDictionary *avatars;

@property (strong, nonatomic) UIImageView *outgoingBubbleImageView;
@property (strong, nonatomic) UIImageView *incomingBubbleImageView;
@property (strong, nonatomic) JSQDemoModelData *demoData;

- (void)receiveMessagePressed:(UIBarButtonItem *)sender;

- (void)closePressed:(UIBarButtonItem *)sender;

- (void)setupTestModel;

@end
Loading

0 comments on commit 7516773

Please sign in to comment.