Skip to content

Commit

Permalink
Merge branch 'release/v0.5.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
normansander committed Mar 13, 2015
2 parents 6511ad1 + 49bc3a4 commit 1650491
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
1 change: 0 additions & 1 deletion CriticalMass/PLChatModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

@property(nonatomic, strong) PLDataModel *data;
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, strong) NSArray *sortedMessages;

+ (id)sharedManager;
- (void)collectMessage:(NSString*)message;
Expand Down
18 changes: 9 additions & 9 deletions CriticalMass/PLChatModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ - (void)collectMessage:(NSString*) text {

[_messages addObject:co];

// TODO: sort not working here WTF
// [_messages sortUsingDescriptors:
// [NSArray arrayWithObjects:
// [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES], nil]];

[_data request];

// notify view
Expand Down Expand Up @@ -75,6 +80,7 @@ - (void)addMessages: (NSDictionary*)messages {
co.isActive = YES;

// fill dict

[_messages addObject:co];
}
}
Expand All @@ -90,14 +96,9 @@ - (void)addMessages: (NSDictionary*)messages {
}

// sort
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timestamp"
ascending:YES];

NSArray *sortDescriptors;
sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

_sortedMessages = [_messages sortedArrayUsingDescriptors:sortDescriptors];
[_messages sortUsingDescriptors:
[NSArray arrayWithObjects:
[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES], nil]];

// Notify view
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationChatMessagesReceived object:self];
Expand Down Expand Up @@ -130,5 +131,4 @@ - (NSArray*)getMessagesArray {
return ret;
}


@end
12 changes: 6 additions & 6 deletions CriticalMass/PLChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,23 @@ - (void)moveContent:(BOOL)moveUp{

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _chatModel.sortedMessages.count;
return _chatModel.messages.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];

if(!_chatModel.sortedMessages){
if(!_chatModel.messages){
return cell;
}

if(!(_chatModel.sortedMessages.count > indexPath.row)){
if(!(_chatModel.messages.count > indexPath.row)){
return cell;
}

PLChatObject *message = [_chatModel.sortedMessages objectAtIndex:indexPath.row];
PLChatObject *message = [_chatModel.messages objectAtIndex:indexPath.row];

cell.textLabel.text = message.text;
cell.imageView.image = [UIImage imageNamed:@"Punk"];
Expand Down Expand Up @@ -182,8 +182,8 @@ - (void)onTap:(UITapGestureRecognizer *)recognizer {

- (void)onMessagesReceived {
[self.tableView reloadData];
NSIndexPath* ipath = [NSIndexPath indexPathForRow: _chatModel.sortedMessages.count-1 inSection: 0];
[self.tableView scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES];
// NSIndexPath* ipath = [NSIndexPath indexPathForRow: _chatModel.sortedMessages.count-1 inSection: 0];
// [self.tableView scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Expand Down
6 changes: 3 additions & 3 deletions CriticalMass/PLConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ @implementation PLConstants
@end

// Debug
BOOL const kDebug = YES;
BOOL const kDebug = NO;
BOOL const kDebugEnableTestURL = NO;
BOOL const kDebugEnableTestLocation = YES;
BOOL const kDebugEnableTestLocation = NO;
BOOL const kDebugDisableHTTPRequests = NO;
BOOL const kDebugInitialTabIndex = 4;
BOOL const kDebugInitialTabIndex = 0;
BOOL const kDebugShowAppirater = NO;


Expand Down

0 comments on commit 1650491

Please sign in to comment.