Room details: display error message on unsupported attachments

This commit is contained in:
giomfo 2014-11-14 18:36:05 +01:00
parent b34f46137f
commit c4441a79a8

View file

@ -579,14 +579,23 @@ NSString *const kFailedEventId = @"failedEventId";
// Get event related to this row // Get event related to this row
MatrixHandler *mxHandler = [MatrixHandler sharedHandler]; MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
MXEvent *mxEvent = [messages objectAtIndex:indexPath.row]; MXEvent *mxEvent = [messages objectAtIndex:indexPath.row];
// Check whether the cell will display an attachment or a text message
CGSize contentSize; CGSize contentSize;
NSString *displayText = nil;
if ([mxHandler isAttachment:mxEvent]) { if ([mxHandler isAttachment:mxEvent]) {
contentSize = [self attachmentContentSize:mxEvent]; contentSize = [self attachmentContentSize:mxEvent];
if (!contentSize.width || !contentSize.height) {
displayText = [NSString stringWithFormat:@"%@%@", kMatrixHandlerUnsupportedMessagePrefix, mxEvent.description];
}
} else { } else {
displayText = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO];
}
if (displayText) {
// Use a TextView template to compute cell height // Use a TextView template to compute cell height
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH, MAXFLOAT)]; UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH, MAXFLOAT)];
dummyTextView.font = [UIFont systemFontOfSize:14]; dummyTextView.font = [UIFont systemFontOfSize:14];
dummyTextView.text = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO]; dummyTextView.text = displayText;
contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size]; contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size];
} }
@ -758,28 +767,37 @@ NSString *const kFailedEventId = @"failedEventId";
cell.attachmentView.hidden = NO; cell.attachmentView.hidden = NO;
cell.messageTextView.text = nil; // Note: Text view is used as attachment background view cell.messageTextView.text = nil; // Note: Text view is used as attachment background view
CGSize contentSize = [self attachmentContentSize:mxEvent]; CGSize contentSize = [self attachmentContentSize:mxEvent];
cell.msgTextViewWidthConstraint.constant = contentSize.width; if (!contentSize.width || !contentSize.height) {
// Align attachment inside text view by considering text view edge inset NSLog(@"ERROR: Unsupported message %@", mxEvent.description);
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top; // Display an error message
cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top; cell.attachmentView.hidden = YES;
cell.messageTextView.text = [NSString stringWithFormat:@"%@%@", kMatrixHandlerUnsupportedMessagePrefix, mxEvent.description];
// Fade attachments during upload cell.messageTextView.textColor = [UIColor redColor];
if (isIncomingMsg == NO && [mxEvent.eventId hasPrefix:kLocalEchoEventIdPrefix]) { enableLinkDetection = NO;
cell.attachmentView.alpha = 0.5;
[((OutgoingMessageTableCell*)cell).activityIndicator startAnimating];
} else { } else {
cell.attachmentView.alpha = 1; cell.msgTextViewWidthConstraint.constant = contentSize.width;
} // Align attachment inside text view by considering text view edge inset
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top;
NSString *msgtype = mxEvent.content[@"msgtype"]; cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top;
if ([msgtype isEqualToString:kMXMessageTypeImage]) {
NSString *url = mxEvent.content[@"thumbnail_url"]; // Fade attachments during upload
if (url == nil) { if (isIncomingMsg == NO && [mxEvent.eventId hasPrefix:kLocalEchoEventIdPrefix]) {
url = mxEvent.content[@"url"]; cell.attachmentView.alpha = 0.5;
[((OutgoingMessageTableCell*)cell).activityIndicator startAnimating];
} else {
cell.attachmentView.alpha = 1;
}
NSString *msgtype = mxEvent.content[@"msgtype"];
if ([msgtype isEqualToString:kMXMessageTypeImage]) {
NSString *url = mxEvent.content[@"thumbnail_url"];
if (url == nil) {
url = mxEvent.content[@"url"];
}
cell.attachedImageURL = url;
} else {
cell.attachedImageURL = nil;
} }
cell.attachedImageURL = url;
} else {
cell.attachedImageURL = nil;
} }
} else { } else {
// Text message will be displayed in textView with max width // Text message will be displayed in textView with max width
@ -796,13 +814,14 @@ NSString *const kFailedEventId = @"failedEventId";
} else if (isIncomingMsg && ([displayText rangeOfString:mxHandler.userDisplayName options:NSCaseInsensitiveSearch].location != NSNotFound || [displayText rangeOfString:mxHandler.userId options:NSCaseInsensitiveSearch].location != NSNotFound)) { } else if (isIncomingMsg && ([displayText rangeOfString:mxHandler.userDisplayName options:NSCaseInsensitiveSearch].location != NSNotFound || [displayText rangeOfString:mxHandler.userId options:NSCaseInsensitiveSearch].location != NSNotFound)) {
cell.messageTextView.textColor = [UIColor blueColor]; cell.messageTextView.textColor = [UIColor blueColor];
} }
// Turn on link detection only when it is usefull
if (enableLinkDetection) {
cell.messageTextView.dataDetectorTypes = UIDataDetectorTypeLink;
}
cell.messageTextView.text = displayText; cell.messageTextView.text = displayText;
} }
// Turn on link detection only when it is usefull
if (enableLinkDetection) {
cell.messageTextView.dataDetectorTypes = UIDataDetectorTypeLink;
}
// Handle timestamp display // Handle timestamp display
if (dateFormatter && mxEvent.originServerTs) { if (dateFormatter && mxEvent.originServerTs) {
cell.dateTimeLabel.hidden = NO; cell.dateTimeLabel.hidden = NO;
@ -822,7 +841,7 @@ NSString *const kFailedEventId = @"failedEventId";
NSString *msgtype = mxEvent.content[@"msgtype"]; NSString *msgtype = mxEvent.content[@"msgtype"];
if ([msgtype isEqualToString:kMXMessageTypeImage]) { if ([msgtype isEqualToString:kMXMessageTypeImage]) {
CGFloat width, height; CGFloat width, height;
width = height = ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH; width = height = 0;
NSDictionary *thumbInfo = mxEvent.content[@"thumbnail_info"]; NSDictionary *thumbInfo = mxEvent.content[@"thumbnail_info"];
if (thumbInfo) { if (thumbInfo) {
width = [thumbInfo[@"w"] integerValue] + 2 * ROOM_MESSAGE_CELL_IMAGE_MARGIN; width = [thumbInfo[@"w"] integerValue] + 2 * ROOM_MESSAGE_CELL_IMAGE_MARGIN;