Room details: enable link detection in displayed messages

This commit is contained in:
giomfo
2014-11-14 14:35:04 +01:00
parent 4818d2c18d
commit b8378abddb
2 changed files with 33 additions and 7 deletions

View File

@@ -51,13 +51,12 @@
<constraint firstAttribute="height" constant="40" id="i0S-s4-q4U"/>
</constraints>
</imageView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="J5R-Mh-3hV">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="text message" translatesAutoresizingMaskIntoConstraints="NO" id="J5R-Mh-3hV">
<rect key="frame" x="51" y="20" width="200" height="30"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="rsq-bW-mGt"/>
</constraints>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
@@ -137,13 +136,12 @@
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="eVZ-HH-LWn" id="5tf-BC-9Ed">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" textAlignment="right" translatesAutoresizingMaskIntoConstraints="NO" id="7qn-gi-w7s">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="text message" textAlignment="right" translatesAutoresizingMaskIntoConstraints="NO" id="7qn-gi-w7s">
<rect key="frame" x="349" y="20" width="200" height="30"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="a6g-WS-jjN"/>
</constraints>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>

View File

@@ -64,6 +64,10 @@ NSString *const kFailedEventId = @"failedEventId";
// Date formatter (nil if dateTimeLabel is hidden)
NSDateFormatter *dateFormatter;
// Text view settings
NSAttributedString *initialAttributedStringForOutgoingMessage;
NSAttributedString *initialAttributedStringForIncomingMessage;
// Cache
NSMutableArray *tmpCachedAttachments;
}
@@ -132,6 +136,9 @@ NSString *const kFailedEventId = @"failedEventId";
if (dateFormatter) {
dateFormatter = nil;
}
initialAttributedStringForOutgoingMessage = nil;
initialAttributedStringForIncomingMessage = nil;
}
- (void)didReceiveMemoryWarning {
@@ -632,13 +639,28 @@ NSString *const kFailedEventId = @"failedEventId";
RoomMessageTableCell *cell;
MXEvent *mxEvent = [messages objectAtIndex:indexPath.row];
BOOL isIncomingMsg = NO;
BOOL enableLinkDetection = YES;
if ([mxEvent.userId isEqualToString:mxHandler.userId]) {
cell = [tableView dequeueReusableCellWithIdentifier:@"OutgoingMessageCell" forIndexPath:indexPath];
[((OutgoingMessageTableCell*)cell).activityIndicator stopAnimating];
// Restore initial settings in text view
if (initialAttributedStringForOutgoingMessage == nil) {
initialAttributedStringForOutgoingMessage = cell.messageTextView.attributedText;
} else {
cell.messageTextView.attributedText = initialAttributedStringForOutgoingMessage;
cell.messageTextView.dataDetectorTypes = UIDataDetectorTypeNone;
}
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"IncomingMessageCell" forIndexPath:indexPath];
isIncomingMsg = YES;
// Restore initial settings in text view
if (initialAttributedStringForIncomingMessage == nil) {
initialAttributedStringForIncomingMessage = cell.messageTextView.attributedText;
} else {
cell.messageTextView.attributedText = initialAttributedStringForIncomingMessage;
cell.messageTextView.dataDetectorTypes = UIDataDetectorTypeNone;
}
}
// Check whether the previous message has been sent by the same user.
@@ -704,8 +726,10 @@ NSString *const kFailedEventId = @"failedEventId";
// Set the right text color for outgoing messages
if ([mxEvent.eventId hasPrefix:kLocalEchoEventIdPrefix]) {
cell.messageTextView.textColor = [UIColor lightGrayColor];
enableLinkDetection = NO;
} else if ([mxEvent.eventId hasPrefix:kFailedEventId]) {
cell.messageTextView.textColor = [UIColor redColor];
enableLinkDetection = NO;
outgoingMsgCell.unsentLabel.hidden = NO;
// Align unsent label with the textView
outgoingMsgCell.unsentLabelTopConstraint.constant = cell.msgTextViewTopConstraint.constant + cell.messageTextView.contentInset.top - ROOM_MESSAGE_CELL_TEXTVIEW_EDGE_INSET_TOP_IN_CHUNK;
@@ -719,7 +743,7 @@ NSString *const kFailedEventId = @"failedEventId";
cell.messageTextView.text = nil; // Note: Text view is used as attachment background view
CGSize contentSize = [self attachmentContentSize:mxEvent];
cell.msgTextViewWidthConstraint.constant = contentSize.width;
// Adjust attachment alignment by considering text view edge inset
// Align attachment inside text view by considering text view edge inset
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top;
cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_CELL_IMAGE_MARGIN + cell.messageTextView.contentInset.top;
@@ -752,9 +776,14 @@ NSString *const kFailedEventId = @"failedEventId";
// Update text color according to text content
if ([displayText hasPrefix:kMatrixHandlerUnsupportedMessagePrefix]) {
cell.messageTextView.textColor = [UIColor redColor];
enableLinkDetection = NO;
} else if (isIncomingMsg && ([displayText rangeOfString:mxHandler.userDisplayName options:NSCaseInsensitiveSearch].location != NSNotFound || [displayText rangeOfString:mxHandler.userId options:NSCaseInsensitiveSearch].location != NSNotFound)) {
cell.messageTextView.textColor = [UIColor blueColor];
}
// Turn on link detection only when it is usefull
if (enableLinkDetection) {
cell.messageTextView.dataDetectorTypes = UIDataDetectorTypeLink;
}
cell.messageTextView.text = displayText;
}
@@ -772,8 +801,7 @@ NSString *const kFailedEventId = @"failedEventId";
return cell;
}
- (CGSize)attachmentContentSize:(MXEvent*)mxEvent;
{
- (CGSize)attachmentContentSize:(MXEvent*)mxEvent {
CGSize contentSize;
NSString *msgtype = mxEvent.content[@"msgtype"];
if ([msgtype isEqualToString:kMXMessageTypeImage]) {