Merge pull request #137 from vector-im/vector_126

BugFix #126: The timestamp of the unsent messages are not stable
This commit is contained in:
giomfo 2016-03-03 18:31:36 +01:00
commit 3205dffcf8
4 changed files with 65 additions and 9 deletions

View file

@ -160,9 +160,19 @@ NSString *const kMXKRoomBubbleCellVectorEditButtonPressed = @"kMXKRoomBubbleCell
if ([self.bubbleData isKindOfClass:RoomBubbleCellData.class])
{
RoomBubbleCellData *cellData = (RoomBubbleCellData*)self.bubbleData;
if (cellData.isLastBubble && cellData.bubbleComponents.count)
if (cellData.containsLastMessage)
{
[self addTimestampLabelForComponent:cellData.bubbleComponents.count - 1];
NSArray *components = cellData.bubbleComponents;
NSInteger index = components.count;
while (index--)
{
MXKRoomBubbleComponent *component = components[index];
if (component.date)
{
[self addTimestampLabelForComponent:index];
break;
}
}
}
}

View file

@ -22,12 +22,12 @@
@interface RoomBubbleCellData : MXKRoomBubbleCellDataWithAppendingMode
/**
A Boolean value that determines whether this bubble is the current last one.
A Boolean value that determines whether this bubble contains the current last message.
Used to keep displaying the timestamp of the last message.
CAUTION: This property is presently set during bubble rendering in order to be used during bubble cell life.
*/
@property(nonatomic) BOOL isLastBubble;
@property(nonatomic) BOOL containsLastMessage;
/**
A Boolean value that determines whether some read receipts are currently displayed in this bubble.

View file

@ -22,6 +22,15 @@
#import "MXKRoomBubbleTableViewCell+Vector.h"
#import "AvatarGenerator.h"
@interface RoomDataSource ()
{
/**
Store here the cell index of the last message (Updated at each table refresh).
*/
NSInteger lastMessageCellIndex;
}
@end
@implementation RoomDataSource
- (instancetype)initWithRoomId:(NSString *)roomId andMatrixSession:(MXSession *)matrixSession
@ -76,6 +85,30 @@
[super didReceiveReceiptEvent:receiptEvent roomState:roomState];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger count = [super tableView:tableView numberOfRowsInSection:section];
if (count)
{
// Refresh the cell index of the last message
lastMessageCellIndex = 0;
MXEvent *lastMessage = self.lastMessage;
if (lastMessage.eventId)
{
lastMessageCellIndex = [self indexOfCellDataWithEventId:lastMessage.eventId];
// Sanity check
if (lastMessageCellIndex == NSNotFound)
{
lastMessageCellIndex = 0;
}
}
}
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
@ -87,14 +120,21 @@
RoomBubbleCellData *cellData = (RoomBubbleCellData*)bubbleCell.bubbleData;
// Check whether this bubble is the last one
cellData.isLastBubble = (indexPath.row == [tableView numberOfRowsInSection:0] - 1);
cellData.containsLastMessage = (indexPath.row == lastMessageCellIndex);
// Display timestamp for the last message.
if (cellData.isLastBubble)
// Display timestamp for the last message
if (cellData.containsLastMessage)
{
if (cellData.bubbleComponents.count)
NSArray *components = cellData.bubbleComponents;
NSInteger index = components.count;
while (index--)
{
[bubbleCell addTimestampLabelForComponent:cellData.bubbleComponents.count - 1];
MXKRoomBubbleComponent *component = components[index];
if (component.date)
{
[bubbleCell addTimestampLabelForComponent:index];
break;
}
}
}

View file

@ -106,6 +106,12 @@
- (NSString*)dateStringFromDate:(NSDate *)date withTime:(BOOL)time
{
// Check the provided date
if (!date)
{
return nil;
}
// Retrieve today date at midnight
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:[NSDate date]];
NSDate *today = [calendar dateFromComponents:components];