stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

Mentioned Users should be clickable in chats

Open SSaleemSSI opened this issue 3 years ago • 3 comments

What are you trying to achieve?

When we mention any user in chats they aren't clickable they should be clickable because we want to show profile of that user. Also they should be treated as token with highlighted background so that we can tell that they are clickable.

If possible, how can you achieve this currently?

currently it is not possible to click the mention but whenever we add text when clicked on user from list we can add as token and make it clickable.

What would be the better way?

GetStream Environment

GetStream Chat version: GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: Swift version: Xcode version: Device:

Additional context

SSaleemSSI avatar Jul 08 '22 13:07 SSaleemSSI

Hi @SSaleemSSI,

This is currently not implemented in the iOS Chat SDK. We are going to bump the priority on this one, and we will let you know when we have an ETA for this.

Best, Nuno

nuno-vieira avatar Jul 11 '22 12:07 nuno-vieira

@SSaleemSSI It has a workaround for it right now. I hope it can help me solve your issue now.

class CustomChatMessageContentView: ChatMessageContentView {
        override func updateContent() {
                self.textView?.attributedText = NSAttributedString(string: content?.textContent ?? "")
                super.updateContent()
                guard let mentionedUsers = self.content?.mentionedUsers else { return }
                for mentionedUser in mentionedUsers {
                    let mention = "@\(mentionedUser.name ?? "")"
                    self.textView?.hightlightMention(userId: mentionedUser.auth0Id ?? "", mention: mention)
                }
            }
}

func hightlightMention(userId: String, mention: String, color: UIColor = AppColor.teal) {
        let attributeTxt = NSMutableAttributedString(attributedString: self.attributedText)
        let string = attributeTxt.string
        let ranges = string.ranges(of: mention, options: .caseInsensitive).map { NSRange($0, in: string) }
        let userUrl = URL(string: AppDeeplinkManager.shared.generateUserScheme(userId: userId))
        for range in ranges {
            attributeTxt.addAttribute(.link, value: userUrl as Any, range: range)
        }
        self.linkTextAttributes = [
            .foregroundColor: color
        ]
        self.attributedText = attributeTxt
    }
    extension CustomChatMessageContentView: UITextViewDelegate {

    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        URLHandler.openURL(with: URL, viewController: appDelegate.appCoordinator.visibleViewController(), viewFrom: .chat)
        return false
    }
}

vankien96 avatar Jul 12 '22 02:07 vankien96

@vankien96 Thank you! Yes, you can always extend the codebase and add the functionality until we officially release it. If you have time, you can also open a PR in the codebase, we always review the PRs of everyone 🙂

Best, Nuno

nuno-vieira avatar Jul 12 '22 10:07 nuno-vieira

Hi!

The issue has been fixed in the 4.22.0 release! 🚀

Thank you for your patient!

Best, Nuno

nuno-vieira avatar Sep 27 '22 17:09 nuno-vieira