#3758 show mention name in bubble chat

master
Mnikolenko Productengine 2025-04-23 21:01:46 +03:00
parent da2234a563
commit 17561e2ad1
6 changed files with 62 additions and 23 deletions

View File

@ -2335,7 +2335,7 @@ void LLTextBase::appendTextImpl(const std::string& new_text, const LLStyle::Para
LLUrlMatch match;
std::string text = new_text;
while (LLUrlRegistry::instance().findUrl(text, match,
boost::bind(&LLTextBase::replaceUrl, this, _1, _2, _3), isContentTrusted() || mAlwaysShowIcons))
boost::bind(&LLTextBase::replaceUrl, this, _1, _2, _3), isContentTrusted() || mAlwaysShowIcons, force_slurl))
{
start = match.getStart();
end = match.getEnd()+1;

View File

@ -580,7 +580,7 @@ LLUrlEntrySimpleSecondlifeURL::LLUrlEntrySimpleSecondlifeURL()
//
LLUrlEntryAgent::LLUrlEntryAgent()
{
mPattern = boost::regex(APP_HEADER_REGEX "/agent/[\\da-f-]+/(mention|(?!mention)\\w+)",
mPattern = boost::regex(APP_HEADER_REGEX "/agent/[\\da-f-]+/\\w+",
boost::regex::perl|boost::regex::icase);
mMenuName = "menu_url_agent.xml";
mIcon = "Generic_Person";
@ -673,19 +673,9 @@ LLUrlMatch::EUnderlineLink LLUrlEntryAgent::getUnderline(const std::string& stri
{
return LLUrlMatch::EUnderlineLink::UNDERLINE_ON_HOVER;
}
else if (LLStringUtil::endsWith(url, "/mention"))
{
return LLUrlMatch::EUnderlineLink::UNDERLINE_NEVER;
}
return LLUrlMatch::EUnderlineLink::UNDERLINE_ALWAYS;
}
bool LLUrlEntryAgent::getSkipProfileIcon(const std::string& string) const
{
std::string url = getUrl(string);
return (LLStringUtil::endsWith(url, "/mention")) ? true : false;
}
std::string LLUrlEntryAgent::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
if (!gCacheName)
@ -730,14 +720,7 @@ LLStyle::Params LLUrlEntryAgent::getStyle(const std::string &url) const
LLStyle::Params style_params = LLUrlEntryBase::getStyle(url);
style_params.color = LLUIColorTable::instance().getColor("HTMLLinkColor");
style_params.readonly_color = LLUIColorTable::instance().getColor("HTMLLinkColor");
if (LLStringUtil::endsWith(url, "/mention"))
{
style_params.font.style = "NORMAL";
style_params.draw_highlight_bg = true;
LLUUID agent_id(getIDStringFromUrl(url));
style_params.highlight_bg_color = LLUIColorTable::instance().getColor((agent_id == sAgentID) ? "ChatSelfMentionHighlight" : "ChatMentionHighlight");
}
return style_params;
}
@ -784,7 +767,35 @@ std::string LLUrlEntryAgent::getIcon(const std::string &url)
{
// *NOTE: Could look up a badge here by calling getIDStringFromUrl()
// and looking up the badge for the agent.
return LLStringUtil::endsWith(url, "/mention") ? std::string() : mIcon;
return mIcon;
}
///
/// LLUrlEntryAgentMention Describes a chat mention Url, e.g.,
/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/mention
///
LLUrlEntryAgentMention::LLUrlEntryAgentMention()
{
mPattern = boost::regex(APP_HEADER_REGEX "/agent/[\\da-f-]+/mention", boost::regex::perl | boost::regex::icase);
mMenuName = "menu_url_agent.xml";
mIcon = std::string();
}
LLUrlMatch::EUnderlineLink LLUrlEntryAgentMention::getUnderline(const std::string& string) const
{
return LLUrlMatch::EUnderlineLink::UNDERLINE_NEVER;
}
LLStyle::Params LLUrlEntryAgentMention::getStyle(const std::string& url) const
{
LLStyle::Params style_params = LLUrlEntryAgent::getStyle(url);
style_params.font.style = "NORMAL";
style_params.draw_highlight_bg = true;
LLUUID agent_id(getIDStringFromUrl(url));
style_params.highlight_bg_color = LLUIColorTable::instance().getColor((agent_id == sAgentID) ? "ChatSelfMentionHighlight" : "ChatMentionHighlight");
return style_params;
}
//

View File

@ -234,7 +234,6 @@ public:
/*virtual*/ LLUUID getID(const std::string &string) const;
LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const;
bool getSkipProfileIcon(const std::string& string) const;
protected:
/*virtual*/ void callObservers(const std::string &id, const std::string &label, const std::string& icon);
@ -245,6 +244,19 @@ private:
avatar_name_cache_connection_map_t mAvatarNameCacheConnections;
};
///
/// LLUrlEntryAgentMention Describes a chat mention Url, e.g.,
/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/mention
class LLUrlEntryAgentMention : public LLUrlEntryAgent
{
public:
LLUrlEntryAgentMention();
LLStyle::Params getStyle(const std::string& url) const;
LLUrlMatch::EUnderlineLink getUnderline(const std::string& string) const;
bool getSkipProfileIcon(const std::string& string) const { return true; };
};
///
/// LLUrlEntryAgentName Describes a Second Life agent name Url, e.g.,
/// secondlife:///app/agent/0e346d8b-4433-4d66-a6b0-fd37083abc4c/(completename|displayname|username)

View File

@ -62,6 +62,8 @@ LLUrlRegistry::LLUrlRegistry()
registerUrl(new LLUrlEntryAgentUserName());
// LLUrlEntryAgent*Name must appear before LLUrlEntryAgent since
// LLUrlEntryAgent is a less specific (catchall for agent urls)
mUrlEntryAgentMention = new LLUrlEntryAgentMention();
registerUrl(mUrlEntryAgentMention);
registerUrl(new LLUrlEntryAgent());
registerUrl(new LLUrlEntryChat());
registerUrl(new LLUrlEntryGroup());
@ -155,7 +157,7 @@ static bool stringHasUrl(const std::string &text)
text.find("@") != std::string::npos);
}
bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LLUrlLabelCallback &cb, bool is_content_trusted)
bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LLUrlLabelCallback &cb, bool is_content_trusted, bool skip_non_mentions)
{
// avoid costly regexes if there is clearly no URL in the text
if (! stringHasUrl(text))
@ -176,6 +178,11 @@ bool LLUrlRegistry::findUrl(const std::string &text, LLUrlMatch &match, const LL
continue;
}
if (skip_non_mentions && (mUrlEntryAgentMention != *it))
{
continue;
}
LLUrlEntryBase *url_entry = *it;
U32 start = 0, end = 0;

View File

@ -76,7 +76,7 @@ public:
/// your callback is invoked if the matched Url's label changes in the future
bool findUrl(const std::string &text, LLUrlMatch &match,
const LLUrlLabelCallback &cb = &LLUrlRegistryNullCallback,
bool is_content_trusted = false);
bool is_content_trusted = false, bool skip_non_mentions = false);
/// a slightly less efficient version of findUrl for wide strings
bool findUrl(const LLWString &text, LLUrlMatch &match,
@ -102,6 +102,7 @@ private:
LLUrlEntryBase* mUrlEntrySLLabel;
LLUrlEntryBase* mUrlEntryNoLink;
LLUrlEntryBase* mUrlEntryKeybinding;
LLUrlEntryBase* mUrlEntryAgentMention;
};
#endif

View File

@ -36,6 +36,7 @@
#include "llviewerregion.h"
#include "llworld.h"
#include "llinstantmessage.h" //SYSTEM_FROM
#include "llurlregistry.h"
// LLViewerChat
LLViewerChat::font_change_signal_t LLViewerChat::sChatFontChangedSignal;
@ -222,6 +223,13 @@ void LLViewerChat::formatChatMsg(const LLChat& chat, std::string& formated_msg)
{
std::string tmpmsg = chat.mText;
// show @name instead of slurl for chat mentions
LLUrlMatch match;
while (LLUrlRegistry::instance().findUrl(tmpmsg, match, LLUrlRegistryNullCallback, false, true))
{
tmpmsg.replace(match.getStart(), match.getEnd() - match.getStart() + 1, match.getLabel());
}
if(chat.mChatStyle == CHAT_STYLE_IRC)
{
formated_msg = chat.mFromName + tmpmsg.substr(3);