mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 00:02:47 +00:00
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:
commit
3205dffcf8
4 changed files with 65 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue