Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions indra/llui/llurlaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ void LLUrlAction::copyLabelToClipboard(std::string url)
}
}

std::string LLUrlAction::getURLLabel(std::string url)
{
LLUrlMatch match;
if (LLUrlRegistry::instance().findUrl(url, match))
{
return match.getLabel();
}
return "";
}

void LLUrlAction::showProfile(std::string url)
{
// Get id from 'secondlife:///app/{cmd}/{id}/{action}'
Expand Down
2 changes: 2 additions & 0 deletions indra/llui/llurlaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class LLUrlAction
/// copy a Url to the clipboard
static void copyURLToClipboard(std::string url);

static std::string getURLLabel(std::string url);

/// if the Url specifies an SL command in the form like 'app/{cmd}/{id}/*', show its profile
static void showProfile(std::string url);
static std::string getUserID(std::string url);
Expand Down
2 changes: 0 additions & 2 deletions indra/llui/llurlentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include "message.h"
#include "llexperiencecache.h"

#define APP_HEADER_REGEX "((x-grid-location-info://[-\\w\\.]+/app)|(secondlife:///app))"

// Utility functions
std::string localize_slapp_label(const std::string& url, const std::string& full_name);

Expand Down
2 changes: 2 additions & 0 deletions indra/llui/llurlentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

class LLAvatarName;

#define APP_HEADER_REGEX "((x-grid-location-info://[-\\w\\.]+/app)|(secondlife:///app))"

typedef boost::signals2::signal<void (const std::string& url,
const std::string& label,
const std::string& icon)> LLUrlLabelSignal;
Expand Down
33 changes: 32 additions & 1 deletion indra/newview/lllogchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "lllogchat.h"
#include "llregex.h"
#include "lltrans.h"
#include "llurlaction.h"
#include "llurlentry.h"
#include "llviewercontrol.h"

#include "lldiriterator.h"
Expand Down Expand Up @@ -358,13 +360,29 @@ void LLLogChat::saveHistory(const std::string& filename,
return;
}

std::string altered_line = line;

// avoid costly regex calls
if (line.find("/mention") != std::string::npos)
{
static const boost::regex mention_regex(APP_HEADER_REGEX "/agent/[\\da-f-]+/mention", boost::regex::perl | boost::regex::icase);

// replace mention URL with [@username](URL)
altered_line = boost::regex_replace(line, mention_regex, [](const boost::smatch& match) -> std::string
{
std::string url = match[0].str();
std::string username = LLUrlAction::getURLLabel(url);
return "[" + username + "](" + url + ")";
});
}

LLSD item;

if (gSavedPerAccountSettings.getBOOL("LogTimestamp"))
item["time"] = LLLogChat::timestamp2LogString(0, gSavedPerAccountSettings.getBOOL("LogTimestampDate"));

item["from_id"] = from_id;
item["message"] = line;
item["message"] = altered_line;

//adding "Second Life:" for all system messages to make chat log history parsing more reliable
if (from.empty() && from_id.isNull())
Expand Down Expand Up @@ -470,6 +488,19 @@ void LLLogChat::loadChatHistory(const std::string& file_name, std::list<LLSD>& m

std::string line(remove_utf8_bom(buffer));


// fast heuristic test for a mention URL in a string
// this is used to avoid costly regex calls
if (line.find("/mention)") != std::string::npos)
{
// restore original mention URL from [@username](URL) format
static const boost::regex altered_mention_regex("\\[@([^\\]]+)\\]\\((" APP_HEADER_REGEX "/agent/[\\da-f-]+/mention)\\)",
boost::regex::perl | boost::regex::icase);

// $2 captures the URL part
line = boost::regex_replace(line, altered_mention_regex, "$2");
}

//updated 1.23 plain text log format requires a space added before subsequent lines in a multilined message
if (' ' == line[0])
{
Expand Down
Loading