This commit is contained in:
Niels Andriesse 2019-12-10 10:12:51 +11:00
parent 713c5fa15e
commit 842c4ea303
3 changed files with 43 additions and 36 deletions

View File

@ -15,27 +15,28 @@ public final class MentionUtilities : NSObject {
}
var string = string
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
let knownUserHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[threadID] ?? [] // Should always be populated at this point
let knownHexEncodedPublicKeys = LokiAPI.userHexEncodedPublicKeyCache[threadID] ?? [] // Should always be populated at this point
var mentions: [NSRange] = []
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count))
while let match = outerMatch {
let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
let matchEnd: Int
if knownUserHexEncodedPublicKeys.contains(hexEncodedPublicKey) {
var userDisplayName: String?
if hexEncodedPublicKey == OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey {
userDisplayName = OWSProfileManager.shared().localProfileName()
if knownHexEncodedPublicKeys.contains(hexEncodedPublicKey) {
var displayName: String?
let userHexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
if hexEncodedPublicKey == userHexEncodedPublicKey {
displayName = OWSProfileManager.shared().localProfileName()
} else {
if let publicChat = publicChat {
userDisplayName = DisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
displayName = DisplayNameUtilities.getPublicChatDisplayName(for: hexEncodedPublicKey, in: publicChat.channel, on: publicChat.server)
} else {
userDisplayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey)
}
}
if let userDisplayName = userDisplayName {
string = (string as NSString).replacingCharacters(in: match.range, with: "@\(userDisplayName)")
mentions.append(NSRange(location: match.range.location, length: userDisplayName.count + 1)) // + 1 to include the @
matchEnd = match.range.location + userDisplayName.count
if let displayName = displayName {
string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)")
mentions.append(NSRange(location: match.range.location, length: displayName.count + 1)) // + 1 to include the @
matchEnd = match.range.location + displayName.count
} else {
matchEnd = match.range.location + match.range.length
}

View File

@ -587,18 +587,22 @@ const CGFloat kMaxTextViewHeight = 120;
[self.voiceMemoLockView removeFromSuperview];
self.voiceMemoUI = [UIView new];
self.voiceMemoUI.backgroundColor = Theme.toolbarBackgroundColor;
self.voiceMemoUI.backgroundColor = LKColors.composeViewBackground;
[self addSubview:self.voiceMemoUI];
[self.voiceMemoUI autoPinEdgesToSuperviewEdges];
SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, _voiceMemoUI);
self.voiceMemoContentView = [UIView new];
[self.voiceMemoUI addSubview:self.voiceMemoContentView];
[self.voiceMemoContentView ows_autoPinToSuperviewEdges];
[self.voiceMemoContentView autoPinLeadingToEdgeOfView:self.voiceMemoUI];
[self.voiceMemoContentView autoPinTopToSuperviewMargin];
[self.voiceMemoContentView autoPinTrailingToEdgeOfView:self.voiceMemoUI];
[self.voiceMemoContentView autoPinBottomToSuperviewMargin];
self.recordingLabel = [UILabel new];
self.recordingLabel.textColor = [UIColor ows_destructiveRedColor];
self.recordingLabel.font = [UIFont ows_mediumFontWithSize:14.f];
self.recordingLabel.textColor = LKColors.destructive;
self.recordingLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize];
[self.voiceMemoContentView addSubview:self.recordingLabel];
SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, _recordingLabel);
@ -611,24 +615,24 @@ const CGFloat kMaxTextViewHeight = 120;
[self updateVoiceMemo];
UIImage *icon = [UIImage imageNamed:@"voice-memo-button"];
UIImage *icon = [UIImage imageNamed:@"Microphone"];
OWSAssertDebug(icon);
UIImageView *imageView =
[[UIImageView alloc] initWithImage:[icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
imageView.tintColor = [UIColor ows_destructiveRedColor];
imageView.tintColor = LKColors.destructive;
[imageView setContentHuggingHigh];
[self.voiceMemoContentView addSubview:imageView];
NSMutableAttributedString *cancelString = [NSMutableAttributedString new];
const CGFloat cancelArrowFontSize = ScaleFromIPhone5To7Plus(18.4, 20.f);
const CGFloat cancelFontSize = ScaleFromIPhone5To7Plus(14.f, 16.f);
const CGFloat cancelFontSize = ScaleFromIPhone5To7Plus(LKValues.smallFontSize, LKValues.mediumFontSize);
NSString *arrowHead = (CurrentAppContext().isRTL ? @"\uf105" : @"\uf104");
[cancelString
appendAttributedString:[[NSAttributedString alloc]
initWithString:arrowHead
attributes:@{
NSFontAttributeName : [UIFont ows_fontAwesomeFont:cancelArrowFontSize],
NSForegroundColorAttributeName : [UIColor ows_destructiveRedColor],
NSForegroundColorAttributeName : LKColors.destructive,
NSBaselineOffsetAttributeName : @(-1.f),
}]];
[cancelString
@ -636,7 +640,7 @@ const CGFloat kMaxTextViewHeight = 120;
initWithString:@" "
attributes:@{
NSFontAttributeName : [UIFont ows_fontAwesomeFont:cancelArrowFontSize],
NSForegroundColorAttributeName : [UIColor ows_destructiveRedColor],
NSForegroundColorAttributeName : LKColors.destructive,
NSBaselineOffsetAttributeName : @(-1.f),
}]];
[cancelString
@ -644,15 +648,15 @@ const CGFloat kMaxTextViewHeight = 120;
initWithString:NSLocalizedString(@"VOICE_MESSAGE_CANCEL_INSTRUCTIONS",
@"Indicates how to cancel a voice message.")
attributes:@{
NSFontAttributeName : [UIFont ows_mediumFontWithSize:cancelFontSize],
NSForegroundColorAttributeName : [UIColor ows_destructiveRedColor],
NSFontAttributeName : [UIFont systemFontOfSize:cancelFontSize],
NSForegroundColorAttributeName : LKColors.destructive,
}]];
[cancelString
appendAttributedString:[[NSAttributedString alloc]
initWithString:@" "
attributes:@{
NSFontAttributeName : [UIFont ows_fontAwesomeFont:cancelArrowFontSize],
NSForegroundColorAttributeName : [UIColor ows_destructiveRedColor],
NSForegroundColorAttributeName : LKColors.destructive,
NSBaselineOffsetAttributeName : @(-1.f),
}]];
[cancelString
@ -660,7 +664,7 @@ const CGFloat kMaxTextViewHeight = 120;
initWithString:arrowHead
attributes:@{
NSFontAttributeName : [UIFont ows_fontAwesomeFont:cancelArrowFontSize],
NSForegroundColorAttributeName : [UIColor ows_destructiveRedColor],
NSForegroundColorAttributeName : LKColors.destructive,
NSBaselineOffsetAttributeName : @(-1.f),
}]];
UILabel *cancelLabel = [UILabel new];
@ -671,7 +675,7 @@ const CGFloat kMaxTextViewHeight = 120;
const CGFloat kRedCircleSize = 100.f;
UIView *redCircleView = [UIView new];
self.voiceMemoRedRecordingCircle = redCircleView;
redCircleView.backgroundColor = [UIColor ows_destructiveRedColor];
redCircleView.backgroundColor = LKColors.destructive;
redCircleView.layer.cornerRadius = kRedCircleSize * 0.5f;
[redCircleView autoSetDimension:ALDimensionWidth toSize:kRedCircleSize];
[redCircleView autoSetDimension:ALDimensionHeight toSize:kRedCircleSize];
@ -679,16 +683,16 @@ const CGFloat kMaxTextViewHeight = 120;
[redCircleView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.voiceMemoButton];
[redCircleView autoAlignAxis:ALAxisVertical toSameAxisOfView:self.voiceMemoButton];
UIImage *whiteIcon = [UIImage imageNamed:@"voice-message-large-white"];
UIImage *whiteIcon = [UIImage imageNamed:@"Microphone"];
OWSAssertDebug(whiteIcon);
UIImageView *whiteIconView = [[UIImageView alloc] initWithImage:whiteIcon];
[redCircleView addSubview:whiteIconView];
[whiteIconView autoCenterInSuperview];
[imageView autoVCenterInSuperview];
[imageView autoPinLeadingToSuperviewMarginWithInset:10.f];
[imageView autoPinLeadingToSuperviewMarginWithInset:LKValues.smallSpacing];
[self.recordingLabel autoVCenterInSuperview];
[self.recordingLabel autoPinLeadingToTrailingEdgeOfView:imageView offset:5.f];
[self.recordingLabel autoPinLeadingToTrailingEdgeOfView:imageView offset:4.f];
[cancelLabel autoVCenterInSuperview];
[cancelLabel autoHCenterInSuperview];
[self.voiceMemoUI layoutIfNeeded];
@ -794,10 +798,11 @@ const CGFloat kMaxTextViewHeight = 120;
[weakSelf.inputToolbarDelegate voiceMemoGestureDidComplete];
}];
[sendVoiceMemoButton setTitle:MessageStrings.sendButton forState:UIControlStateNormal];
[sendVoiceMemoButton setTitleColor:UIColor.ows_signalBlueColor forState:UIControlStateNormal];
[sendVoiceMemoButton setTitleColor:LKColors.text forState:UIControlStateNormal];
sendVoiceMemoButton.titleLabel.font = [UIFont boldSystemFontOfSize:LKValues.mediumFontSize];
sendVoiceMemoButton.alpha = 0;
[self.voiceMemoContentView addSubview:sendVoiceMemoButton];
[sendVoiceMemoButton autoPinEdgeToSuperviewMargin:ALEdgeTrailing withInset:10.f];
[sendVoiceMemoButton autoPinEdgeToSuperviewMargin:ALEdgeTrailing withInset:LKValues.smallSpacing];
[sendVoiceMemoButton autoVCenterInSuperview];
[sendVoiceMemoButton setCompressionResistanceHigh];
[sendVoiceMemoButton setContentHuggingHigh];
@ -807,7 +812,8 @@ const CGFloat kMaxTextViewHeight = 120;
[weakSelf.inputToolbarDelegate voiceMemoGestureDidCancel];
}];
[cancelButton setTitle:CommonStrings.cancelButton forState:UIControlStateNormal];
[cancelButton setTitleColor:UIColor.ows_destructiveRedColor forState:UIControlStateNormal];
[cancelButton setTitleColor:LKColors.destructive forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont boldSystemFontOfSize:LKValues.mediumFontSize];
cancelButton.alpha = 0;
cancelButton.titleLabel.textAlignment = NSTextAlignmentCenter;
SET_SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, cancelButton);

View File

@ -51,7 +51,7 @@ public class VoiceMemoLockView: UIView {
private lazy var lockIconView: UIImageView = {
let imageTemplate = #imageLiteral(resourceName: "ic_lock_outline").withRenderingMode(.alwaysTemplate)
let imageView = UIImageView(image: imageTemplate)
imageView.tintColor = .ows_destructiveRed
imageView.tintColor = Colors.destructive
imageView.autoSetDimensions(to: CGSize(width: 24, height: 24))
return imageView
}()
@ -59,7 +59,7 @@ public class VoiceMemoLockView: UIView {
private lazy var chevronView: UIView = {
let label = UILabel()
label.text = "\u{2303}"
label.textColor = .ows_destructiveRed
label.textColor = Colors.destructive
label.textAlignment = .center
return label
}()
@ -69,10 +69,10 @@ public class VoiceMemoLockView: UIView {
let width: CGFloat = 36
view.autoSetDimension(.width, toSize: width)
view.backgroundColor = Theme.scrollButtonBackgroundColor
view.backgroundColor = Colors.composeViewBackground
view.layer.cornerRadius = width / 2
view.layer.borderColor = Theme.offBackgroundColor.cgColor
view.layer.borderWidth = CGHairlineWidth()
view.layer.borderColor = Colors.text.withAlphaComponent(Values.composeViewTextFieldBorderOpacity).cgColor
view.layer.borderWidth = Values.composeViewTextFieldBorderThickness
return view
}()