|
|
|
@ -6,6 +6,15 @@ import SessionUIKit
|
|
|
|
|
import SessionMessagingKit
|
|
|
|
|
|
|
|
|
|
public enum MentionUtilities {
|
|
|
|
|
public enum MentionLocation {
|
|
|
|
|
case incomingMessage
|
|
|
|
|
case outgoingMessage
|
|
|
|
|
case incomingQuote
|
|
|
|
|
case outgoingQuote
|
|
|
|
|
case quoteDraft
|
|
|
|
|
case styleFree
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func highlightMentionsNoAttributes(
|
|
|
|
|
in string: String,
|
|
|
|
|
threadVariant: SessionThread.Variant,
|
|
|
|
@ -20,7 +29,7 @@ public enum MentionUtilities {
|
|
|
|
|
currentUserPublicKey: currentUserPublicKey,
|
|
|
|
|
currentUserBlinded15PublicKey: currentUserBlinded15PublicKey,
|
|
|
|
|
currentUserBlinded25PublicKey: currentUserBlinded25PublicKey,
|
|
|
|
|
isOutgoingMessage: false,
|
|
|
|
|
location: .styleFree,
|
|
|
|
|
textColor: .black,
|
|
|
|
|
theme: .classicDark,
|
|
|
|
|
primaryColor: Theme.PrimaryColor.green,
|
|
|
|
@ -34,7 +43,7 @@ public enum MentionUtilities {
|
|
|
|
|
currentUserPublicKey: String?,
|
|
|
|
|
currentUserBlinded15PublicKey: String?,
|
|
|
|
|
currentUserBlinded25PublicKey: String?,
|
|
|
|
|
isOutgoingMessage: Bool,
|
|
|
|
|
location: MentionLocation,
|
|
|
|
|
textColor: UIColor,
|
|
|
|
|
theme: Theme,
|
|
|
|
|
primaryColor: Theme.PrimaryColor,
|
|
|
|
@ -93,27 +102,36 @@ public enum MentionUtilities {
|
|
|
|
|
mentions.forEach { mention in
|
|
|
|
|
result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.smallFontSize), range: mention.range)
|
|
|
|
|
|
|
|
|
|
if mention.isCurrentUser {
|
|
|
|
|
if mention.isCurrentUser && location == .incomingMessage {
|
|
|
|
|
// Note: The designs don't match with the dynamic sizing so these values need to be calculated
|
|
|
|
|
// to maintain a "rounded rect" effect rather than a "pill" effect
|
|
|
|
|
result.addAttribute(.currentUserMentionBackgroundCornerRadius, value: (8 * sizeDiff), range: mention.range)
|
|
|
|
|
result.addAttribute(.currentUserMentionBackgroundPadding, value: (3 * sizeDiff), range: mention.range)
|
|
|
|
|
result.addAttribute(.currentUserMentionBackgroundColor, value: primaryColor.color, range: mention.range)
|
|
|
|
|
result.addAttribute(
|
|
|
|
|
.foregroundColor,
|
|
|
|
|
value: UIColor.black, // Note: This text should always be black
|
|
|
|
|
range: mention.range
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result.addAttribute(
|
|
|
|
|
.foregroundColor,
|
|
|
|
|
value: (isOutgoingMessage || theme.interfaceStyle == .light ?
|
|
|
|
|
textColor :
|
|
|
|
|
primaryColor.color
|
|
|
|
|
),
|
|
|
|
|
range: mention.range
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
switch (location, mention.isCurrentUser, theme.interfaceStyle) {
|
|
|
|
|
// 1 - Incoming messages where the mention is for the current user
|
|
|
|
|
case (.incomingMessage, true, .dark): result.addAttribute(.foregroundColor, value: UIColor.black, range: mention.range)
|
|
|
|
|
case (.incomingMessage, true, _): result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
|
|
|
|
|
// 2 - Incoming messages where the mention is for another user
|
|
|
|
|
case (.incomingMessage, false, .dark): result.addAttribute(.foregroundColor, value: primaryColor.color, range: mention.range)
|
|
|
|
|
case (.incomingMessage, false, _): result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
|
|
|
|
|
// 3 - Outgoing messages
|
|
|
|
|
case (.outgoingMessage, _, .dark): result.addAttribute(.foregroundColor, value: UIColor.black, range: mention.range)
|
|
|
|
|
case (.outgoingMessage, _, _): result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
|
|
|
|
|
// 4 - Mentions in quotes
|
|
|
|
|
case (.outgoingQuote, _, .dark): result.addAttribute(.foregroundColor, value: UIColor.black, range: mention.range)
|
|
|
|
|
case (.outgoingQuote, _, _): result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
case (.incomingQuote, _, .dark): result.addAttribute(.foregroundColor, value: primaryColor.color, range: mention.range)
|
|
|
|
|
case (.incomingQuote, _, _): result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
|
|
|
|
|
// 5 - Mentions in quote drafts
|
|
|
|
|
case (.quoteDraft, _, _), (.styleFree, _, _):
|
|
|
|
|
result.addAttribute(.foregroundColor, value: textColor, range: mention.range)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|