Merge pull request #658 from vector-im/vector_361

Room message search : the message date & time are not displayed
This commit is contained in:
giomfo 2016-09-28 10:25:18 +02:00 committed by GitHub
commit a4f1dc17a9
4 changed files with 101 additions and 5 deletions

View file

@ -51,6 +51,11 @@ extern NSString *const kMXKRoomBubbleCellVectorEditButtonPressed;
*/
- (void)markComponent:(NSUInteger)componentIndex;
/**
Add a label to display the date of the cell.
*/
- (void)addDateLabel;
/**
Blur the view by adding a transparent overlay. Default is NO.
*/

View file

@ -203,6 +203,66 @@ NSString *const kMXKRoomBubbleCellVectorEditButtonPressed = @"kMXKRoomBubbleCell
}
}
- (void)addDateLabel
{
self.bubbleInfoContainer.hidden = NO;
NSDate *date = bubbleData.date;
if (date)
{
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bubbleInfoContainer.frame.size.width , 18)];
timeLabel.text = [bubbleData.eventFormatter dateStringFromDate:date withTime:NO];
timeLabel.textAlignment = NSTextAlignmentRight;
timeLabel.textColor = kVectorTextColorGray;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)])
{
timeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightLight];
}
else
{
timeLabel.font = [UIFont systemFontOfSize:12];
}
timeLabel.adjustsFontSizeToFitWidth = YES;
[timeLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.bubbleInfoContainer addSubview:timeLabel];
// Define timeLabel constraints (to handle auto-layout in case of screen rotation)
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:timeLabel
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.bubbleInfoContainer
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0];
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:timeLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.bubbleInfoContainer
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0];
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:timeLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.bubbleInfoContainer
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:0];
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:timeLabel
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:18];
// Available on iOS 8 and later
[NSLayoutConstraint activateConstraints:@[rightConstraint, topConstraint, widthConstraint, heightConstraint]];
}
}
- (void)setBlurred:(BOOL)blurred
{
objc_setAssociatedObject(self, @selector(blurred), [NSNumber numberWithBool:blurred], OBJC_ASSOCIATION_RETAIN_NONATOMIC);

View file

@ -18,6 +18,8 @@
#import "RoomBubbleCellData.h"
#import "MXKRoomBubbleTableViewCell+Vector.h"
@interface RoomSearchDataSource ()
{
MXKRoomDataSource *roomDataSource;
@ -61,4 +63,20 @@
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
// Finalize cell view customization here
if ([cell isKindOfClass:MXKRoomBubbleTableViewCell.class])
{
MXKRoomBubbleTableViewCell *bubbleCell = (MXKRoomBubbleTableViewCell*)cell;
// Display date for each message
[bubbleCell addDateLabel];
}
return cell;
}
@end

View file

@ -30,7 +30,7 @@
// We are displaying a search over all user's rooms
// As title, display the room name of this search result
MXRoom *room = [searchDataSource.mxSession roomWithRoomId:searchResult2.result.roomId];
MXRoom *room = [searchDataSource.mxSession roomWithRoomId:searchResult.result.roomId];
if (room)
{
title = room.vectorDisplayname;
@ -41,13 +41,26 @@
}
else
{
title = searchResult2.result.roomId;
title = searchResult.result.roomId;
}
date = [searchDataSource.eventFormatter dateStringFromEvent:searchResult2.result withTime:YES];
date = [searchDataSource.eventFormatter dateStringFromEvent:searchResult.result withTime:YES];
// Code from [MXEventFormatter stringFromEvent] for the particular case of a text message
message = [searchResult2.result.content[@"body"] isKindOfClass:[NSString class]] ? searchResult2.result.content[@"body"] : nil;
// Use the event formatter to display correctly the message in case of formatted body.
if (searchResult.result.eventType == MXEventTypeRoomMessage)
{
MXKEventFormatterError error;
message = [searchDataSource.eventFormatter stringFromEvent:searchResult.result withRoomState:nil error:&error];
if (error != MXKEventFormatterErrorNone)
{
message = nil;
}
}
if (!message.length)
{
message = [searchResult.result.content[@"body"] isKindOfClass:[NSString class]] ? searchResult.result.content[@"body"] : nil;
}
}
return self;
}