|
@@ -379,8 +379,8 @@ extension UIColor {
|
|
|
return renderColor(hex: "#798F9A")
|
|
|
}
|
|
|
|
|
|
- public static var linkColor: UIColor {
|
|
|
- return renderColor(hex: "#0000EE")
|
|
|
+ public static var mentionColor: UIColor {
|
|
|
+ return renderColor(hex: "#53bdea")
|
|
|
}
|
|
|
|
|
|
public static var blueBubbleColor: UIColor {
|
|
@@ -791,23 +791,41 @@ extension String {
|
|
|
//Check Mention
|
|
|
let finalTextAfterRichText = finalText.string
|
|
|
if finalTextAfterRichText.contains("@") {
|
|
|
- let listMembers = Member.getAllMember(group_id: group_id)
|
|
|
- if listMembers.count > 0 {
|
|
|
- for i in 0..<listMembers.count {
|
|
|
- if isEditing {
|
|
|
- if listMentionInTextField.count > 0 {
|
|
|
+ if !group_id.isEmpty {
|
|
|
+ let listMembers = Member.getAllMember(group_id: group_id)
|
|
|
+ if listMembers.count > 0 {
|
|
|
+ for i in 0..<listMembers.count {
|
|
|
+ if isEditing {
|
|
|
+ if listMentionInTextField.count > 0 {
|
|
|
+ let name = (listMembers[i].firstName + " " + listMembers[i].lastName).trimmingCharacters(in: .whitespaces)
|
|
|
+ if listMentionInTextField.firstIndex(where: { ($0.firstName + " " + $0.lastName).trimmingCharacters(in: .whitespaces) == name }) != nil {
|
|
|
+ let range = NSString(string: finalTextAfterRichText).range(of: "@\(name)", options: .caseInsensitive)
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.mentionColor, range: range)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
let name = (listMembers[i].firstName + " " + listMembers[i].lastName).trimmingCharacters(in: .whitespaces)
|
|
|
- if listMentionInTextField.firstIndex(where: { ($0.firstName + " " + $0.lastName).trimmingCharacters(in: .whitespaces) == name }) != nil {
|
|
|
- let range = NSString(string: finalTextAfterRichText).range(of: "@\(name)", options: .caseInsensitive)
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.orangeColor, range: range)
|
|
|
+ let range = NSString(string: finalTextAfterRichText).range(of: listMembers[i].pin, options: .caseInsensitive)
|
|
|
+ if range.lowerBound != range.upperBound {
|
|
|
+ finalText.mutableString.replaceOccurrences(of: listMembers[i].pin, with: name, options: .literal, range: range)
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.mentionColor, range: NSString(string: finalText.string).range(of: "@\(name)"))
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- let name = (listMembers[i].firstName + " " + listMembers[i].lastName).trimmingCharacters(in: .whitespaces)
|
|
|
- let range = NSString(string: finalTextAfterRichText).range(of: listMembers[i].pin, options: .caseInsensitive)
|
|
|
- if range.lowerBound != range.upperBound {
|
|
|
- finalText.mutableString.replaceOccurrences(of: listMembers[i].pin, with: name, options: .literal, range: range)
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.orangeColor, range: NSString(string: finalText.string).range(of: "@\(name)"))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let listTextEnter = finalText.string.split(separator: "\n")
|
|
|
+ for j in 0...listTextEnter.count - 1 {
|
|
|
+ let listText = listTextEnter[j].split(separator: " ")
|
|
|
+ let listMention = listText.filter({ $0.starts(with: "@")})
|
|
|
+ if listMention.count > 0 {
|
|
|
+ for i in 0..<listMention.count {
|
|
|
+ let f_pin = (String(listMention[i])).substring(from: 1, to: listMention[i].count)
|
|
|
+ let member = Member.getMember(f_pin: f_pin)
|
|
|
+ if member != nil {
|
|
|
+ let name = (member!.firstName + " " + member!.lastName).trimmingCharacters(in: .whitespaces)
|
|
|
+ finalText.mutableString.replaceOccurrences(of: f_pin, with: name, options: .literal, range: NSString(string: finalText.string).range(of: f_pin))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|