diff --git a/.DS_Store b/.DS_Store index 3a9fb44..9b3445c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/MMTextureChat.xcworkspace/xcuserdata/mukesh.xcuserdatad/UserInterfaceState.xcuserstate b/MMTextureChat.xcworkspace/xcuserdata/mukesh.xcuserdatad/UserInterfaceState.xcuserstate index abe87fb..38f6733 100644 Binary files a/MMTextureChat.xcworkspace/xcuserdata/mukesh.xcuserdatad/UserInterfaceState.xcuserstate and b/MMTextureChat.xcworkspace/xcuserdata/mukesh.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MMTextureChat/ChatAsyncViewController.swift b/MMTextureChat/ChatAsyncViewController.swift index fa5232f..a193217 100644 --- a/MMTextureChat/ChatAsyncViewController.swift +++ b/MMTextureChat/ChatAsyncViewController.swift @@ -603,21 +603,21 @@ class ChatAsyncViewController: UIViewController ,UITextViewDelegate , ChatDelega // print(textView.attributedText) let attr = NSMutableAttributedString(attributedString: textView.attributedText) - - attr.enumerateAttributes( in: NSMakeRange(0, attr.length), options: NSAttributedString.EnumerationOptions.longestEffectiveRangeNotRequired, using: { (dict, range, bool) in - // print(dict) - - for (key , value) in dict{ - if(key == NSLinkAttributeName){ - // print(value) - if let jid = value as? String{ - attr.replaceCharacters(in: range, with: jid) - - } - - } - } - }) +// +// attr.enumerateAttributes( in: NSMakeRange(0, attr.length), options: NSAttributedString.EnumerationOptions.longestEffectiveRangeNotRequired, using: { (dict, range, bool) in +// // print(dict) +// +// for (key , value) in dict{ +// if(key == NSLinkAttributeName){ +// // print(value) +// if let jid = value as? String{ +// attr.replaceCharacters(in: range, with: jid) +// +// } +// +// } +// } +// }) print(attr.string) diff --git a/MMTextureChat/LICENSE.txt b/MMTextureChat/LICENSE.txt new file mode 100644 index 0000000..5bd6113 --- /dev/null +++ b/MMTextureChat/LICENSE.txt @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2017 Mukesh Mandora + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/MMTextureChat/MessageTextBubbleNode.swift b/MMTextureChat/MessageTextBubbleNode.swift index 677a327..e10965b 100644 --- a/MMTextureChat/MessageTextBubbleNode.swift +++ b/MMTextureChat/MessageTextBubbleNode.swift @@ -39,6 +39,7 @@ public class MessageTextBubbleNode: ASDisplayNode , ASTextNodeDelegate{ textNode.delegate = self let linkcolor = isOutgoing ? UIColor.white : UIColor.blue textNode.addLinkDetection(attr.string, highLightColor: linkcolor) + textNode.addUserMention(highLightColor: linkcolor) } diff --git a/MMTextureChat/TextNodeEx.swift b/MMTextureChat/TextNodeEx.swift index 6d93e66..3d2765e 100644 --- a/MMTextureChat/TextNodeEx.swift +++ b/MMTextureChat/TextNodeEx.swift @@ -37,3 +37,39 @@ extension ASTextNode{ } } + +extension ASTextNode{ + + + func addUserMention(highLightColor : UIColor){ + + if let attrText = self.attributedText{ + let replaced = NSMutableAttributedString(attributedString: attrText) + var ranges : [NSRange] = [] + + do{ + let regex = try NSRegularExpression(pattern: "@(\\w+){1,}?", options: .caseInsensitive) + + + let result = regex.matches(in: attrText.string, options: NSRegularExpression.MatchingOptions.withTransparentBounds, range: NSMakeRange(0,(attrText.string as NSString).length)) + + + let userDict = NSMutableDictionary() + for range in result{ + replaced.addAttribute(NSLinkAttributeName, value: "ptuser", range: range.range) + replaced.addAttribute(NSUnderlineColorAttributeName, value: highLightColor, range: range.range) + replaced.addAttribute(NSForegroundColorAttributeName, value: highLightColor, range: range.range) + + } + + + + + self.attributedText = replaced + + }catch{} + } + + } + +}