mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 19:10:49 +02:00
Room details: restore timestamp and unsent label display
This commit is contained in:
@@ -66,7 +66,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
NSString *AVAudioSessionCategory;
|
||||
MPMoviePlayerController *videoPlayer;
|
||||
|
||||
// Date formatter (nil if dateTimeLabel is hidden)
|
||||
// Date formatter (nil if dateTime info is hidden)
|
||||
NSDateFormatter *dateFormatter;
|
||||
|
||||
// Cache
|
||||
@@ -818,7 +818,14 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
|
||||
if ([message.senderId isEqualToString:mxHandler.userId]) {
|
||||
cell = [tableView dequeueReusableCellWithIdentifier:@"OutgoingMessageCell" forIndexPath:indexPath];
|
||||
[((OutgoingMessageTableCell*)cell).activityIndicator stopAnimating];
|
||||
OutgoingMessageTableCell* outgoingMsgCell = (OutgoingMessageTableCell*)cell;
|
||||
// Hide potential loading wheel
|
||||
[outgoingMsgCell.activityIndicator stopAnimating];
|
||||
// Hide unsent view by default, and remove potential unsent label(s)
|
||||
outgoingMsgCell.unsentView.hidden = YES;
|
||||
for (UIView *view in outgoingMsgCell.unsentView.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
} else {
|
||||
cell = [tableView dequeueReusableCellWithIdentifier:@"IncomingMessageCell" forIndexPath:indexPath];
|
||||
isIncomingMsg = YES;
|
||||
@@ -834,6 +841,17 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
}
|
||||
cell.attachmentViewTopAlignmentConstraint.constant = 0;
|
||||
cell.attachmentViewBottomAlignmentConstraint.constant = 0;
|
||||
// Remove potential dateTime label(s)
|
||||
if (cell.dateTimeView.constraints.count) {
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
|
||||
[NSLayoutConstraint deactivateConstraints:cell.dateTimeView.constraints];
|
||||
} else {
|
||||
[cell.dateTimeView removeConstraints:cell.dateTimeView.constraints];
|
||||
}
|
||||
for (UIView *view in cell.dateTimeView.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the previous message has been sent by the same user.
|
||||
// The user's picture and name are displayed only for the first message.
|
||||
@@ -868,8 +886,20 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
incomingMsgCell.userNameLabel.text = message.senderName;
|
||||
} else {
|
||||
OutgoingMessageTableCell* outgoingMsgCell = (OutgoingMessageTableCell*)cell;
|
||||
// Hide unsent label by default
|
||||
outgoingMsgCell.unsentLabel.hidden = YES; // TODO handle unsentLabel display
|
||||
// Add unsent label for failed components
|
||||
CGFloat yPosition = ROOM_MESSAGE_TEXTVIEW_MARGIN;
|
||||
for (RoomMessageComponent *component in message.components) {
|
||||
if (component.status == RoomMessageComponentStatusFailed) {
|
||||
UILabel *unsentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, yPosition, outgoingMsgCell.unsentView.frame.size.width , 20)];
|
||||
unsentLabel.text = @"Unsent";
|
||||
unsentLabel.textAlignment = NSTextAlignmentCenter;
|
||||
unsentLabel.textColor = [UIColor redColor];
|
||||
unsentLabel.font = [UIFont systemFontOfSize:14];
|
||||
[outgoingMsgCell.unsentView addSubview:unsentLabel];
|
||||
outgoingMsgCell.unsentView.hidden = NO;
|
||||
}
|
||||
yPosition += component.height;
|
||||
}
|
||||
}
|
||||
CGSize contentSize = message.contentSize;
|
||||
if (message.messageType != RoomMessageTypeText) {
|
||||
@@ -906,17 +936,61 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
|
||||
// Adjust constraint constant
|
||||
cell.msgTextViewWidthConstraint.constant = contentSize.width;
|
||||
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_CELL_IMAGE_MARGIN;
|
||||
cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_CELL_IMAGE_MARGIN;
|
||||
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_IMAGE_MARGIN;
|
||||
cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_IMAGE_MARGIN;
|
||||
} else {
|
||||
cell.messageTextView.attributedText = message.attributedTextMessage;
|
||||
// Adjust textView width constraint
|
||||
cell.msgTextViewWidthConstraint.constant = contentSize.width;
|
||||
}
|
||||
|
||||
// TODO Handle timestamp display
|
||||
cell.dateTimeLabel.hidden = YES;
|
||||
|
||||
// Handle timestamp display
|
||||
if (dateFormatter) {
|
||||
cell.dateTimeView.hidden = NO;
|
||||
// Add datetime label for each component
|
||||
CGFloat yPosition = ROOM_MESSAGE_TEXTVIEW_MARGIN;
|
||||
for (RoomMessageComponent *component in message.components) {
|
||||
if (component.date) {
|
||||
UILabel *dateTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, yPosition, cell.dateTimeView.frame.size.width , 20)];
|
||||
dateTimeLabel.text = [dateFormatter stringFromDate:component.date];
|
||||
if (isIncomingMsg) {
|
||||
dateTimeLabel.textAlignment = NSTextAlignmentRight;
|
||||
} else {
|
||||
dateTimeLabel.textAlignment = NSTextAlignmentLeft;
|
||||
}
|
||||
dateTimeLabel.textColor = [UIColor lightGrayColor];
|
||||
dateTimeLabel.font = [UIFont systemFontOfSize:12];
|
||||
dateTimeLabel.adjustsFontSizeToFitWidth = YES;
|
||||
dateTimeLabel.minimumScaleFactor = 0.6;
|
||||
[dateTimeLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[cell.dateTimeView addSubview:dateTimeLabel];
|
||||
// Force dateTimeLabel in full width (to handle auto-layout in case of screen rotation)
|
||||
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:dateTimeLabel
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:cell.dateTimeView
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:dateTimeLabel
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:cell.dateTimeView
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
|
||||
[NSLayoutConstraint activateConstraints:@[leftConstraint, rightConstraint]];
|
||||
} else {
|
||||
[cell.dateTimeView addConstraint:leftConstraint];
|
||||
[cell.dateTimeView addConstraint:rightConstraint];
|
||||
}
|
||||
}
|
||||
yPosition += component.height;
|
||||
}
|
||||
} else {
|
||||
cell.dateTimeView.hidden = YES;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
@@ -1623,7 +1697,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
MXEvent *localEvent = [self addLocalEventForAttachedImage:selectedImage];
|
||||
// Upload image and its thumbnail
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
NSUInteger thumbnailSize = ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_CELL_IMAGE_MARGIN;
|
||||
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_IMAGE_MARGIN;
|
||||
[mxHandler.mxRestClient uploadImage:selectedImage thumbnailSize:thumbnailSize timeout:30 success:^(NSDictionary *imageMessage) {
|
||||
// Send image
|
||||
[self postMessage:imageMessage withLocalEvent:localEvent];
|
||||
@@ -1644,7 +1718,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
||||
|
||||
if (videoThumbnail) {
|
||||
// Prepare video thumbnail description
|
||||
NSUInteger thumbnailSize = ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_CELL_IMAGE_MARGIN;
|
||||
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_IMAGE_MARGIN;
|
||||
UIImage *thumbnail = [MediaManager resize:videoThumbnail toFitInSize:CGSizeMake(thumbnailSize, thumbnailSize)];
|
||||
NSMutableDictionary *thumbnailInfo = [[NSMutableDictionary alloc] init];
|
||||
[thumbnailInfo setValue:@"image/jpeg" forKey:@"mimetype"];
|
||||
|
||||
Reference in New Issue
Block a user