BugFix #126: The timestamp of the unsent messages are not stable

This commit is contained in:
giomfo
2016-03-03 17:39:10 +01:00
parent 316e8065b5
commit 2646d4f2d7
4 changed files with 65 additions and 9 deletions
+45 -5
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;
}
}
}