From 8c7fceb0817dfc6be20e095b5bb8d925261aaae1 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Fri, 11 Jan 2019 09:10:56 -0500 Subject: [PATCH] Resolve and link registered SLURLS that are in chat. Adds handle_registered_urls function Use this as a drop in replacement for appendStyledText where applicable --- indra/newview/llfloaterchat.cpp | 29 +++++++++++++++++++++++++++-- indra/newview/llimpanel.cpp | 5 +++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/indra/newview/llfloaterchat.cpp b/indra/newview/llfloaterchat.cpp index 95c683582..7668a94fa 100644 --- a/indra/newview/llfloaterchat.cpp +++ b/indra/newview/llfloaterchat.cpp @@ -61,6 +61,7 @@ #include "llspeakers.h" #include "llstylemap.h" #include "lluictrlfactory.h" +#include "llurlregistry.h" #include "llviewermessage.h" #include "llviewertexteditor.h" #include "llviewerwindow.h" @@ -176,6 +177,31 @@ void LLFloaterChat::updateConsoleVisibility() || (getHost() && getHost()->isMinimized() )); // are we hosted in a minimized floater? } +void handle_registered_urls(std::string ui_msg, bool prepend_newline, LLStyleSP style, LLViewerTextEditor* edit, const LLColor4& color) +{ + LLUrlMatch match; + auto& registry = LLUrlRegistry::instance(); + while (!ui_msg.empty() && registry.findUrl(ui_msg, match)) + { + if (match.getStart() > 0) + { + style->setColor(color); + edit->appendStyledText(ui_msg.substr(0, match.getStart()), false, prepend_newline, style); + prepend_newline = false; + } + style->setColor(gSavedSettings.getColor4("HTMLLinkColor")); + style->setLinkHREF(match.getUrl()); + edit->appendStyledText(match.getLabel(), false, prepend_newline, style); + style->setLinkHREF(LLStringUtil::null); + prepend_newline = false; + + ui_msg = (ui_msg.size() <= match.getEnd() + 1) ? LLStringUtil::null : ui_msg.substr(match.getEnd() + 1); + } + + style->setColor(color); + if (!ui_msg.empty()) edit->appendStyledText(ui_msg, false, prepend_newline, style); +} + void add_timestamped_line(LLViewerTextEditor* edit, LLChat chat, const LLColor4& color) { std::string line = chat.mText; @@ -222,9 +248,8 @@ void add_timestamped_line(LLViewerTextEditor* edit, LLChat chat, const LLColor4& prepend_newline = false; } LLStyleSP style(new LLStyle); - style->setColor(color); style->mItalic = is_irc; - edit->appendStyledText(line, false, prepend_newline, style); + handle_registered_urls(line, prepend_newline, style, edit, color); } void log_chat_text(const LLChat& chat) diff --git a/indra/newview/llimpanel.cpp b/indra/newview/llimpanel.cpp index 4ed076b6d..a16908865 100644 --- a/indra/newview/llimpanel.cpp +++ b/indra/newview/llimpanel.cpp @@ -812,10 +812,11 @@ void LLFloaterIMPanel::addHistoryLine(const std::string &utf8msg, LLColor4 incol // Append the chat message in style { LLStyleSP style(new LLStyle); - style->setColor(incolor); style->mItalic = is_irc; style->mBold = from_user && gSavedSettings.getBOOL("SingularityBoldGroupModerator") && isModerator(source); - mHistoryEditor->appendStyledText(utf8msg, false, prepend_newline, style); + + void handle_registered_urls(std::string ui_msg, bool prepend_newline, LLStyleSP style, LLViewerTextEditor* edit, const LLColor4& color); + handle_registered_urls(utf8msg, prepend_newline, style, mHistoryEditor, incolor); } if (log_to_file