Imported Chat-Logs patch from Catznip (revision e6e0393682f8)

-> Description:
- changed : LLCacheName::buildUsername() will properly extract the username if the passed name is a "complete name"
    -> "Catznip Catnap" => "catznip.catnap"
    -> "Catznip Tester (catznip.catnap)" => "catznip.catnap"
- fixed   : P2P IM session names are inconsistent (chiclet hover tip shows the legacy name rather than the complete name for incoming IM sessions)
    -> incoming IM session would have a session name of "Catznip Catnap" (legacy name)
    -> outgoing IM session would have a session name of "Catznip Tester (catznip.catnap)" (complete name)
    -> standarized P2P IM session names to "complete name"
- added   : LLIMModel::buildIMP2PLogFilename() to have one single function to construct log filenames for P2P IMs
- fixed   : teleport offers to another avie are logged to the wrong file when no IM session is open for that avie
    -> open IM session => logged to "catznip_catnap.txt"
    -> no open IM session => logged to "Catznip Catnap.txt"
- fixed   : inventory offers to another avie are logged to the wrong file when no IM session is open for that avie
    -> no open IM session => logged to "Catznip Catnap.txt"
- fixed   : inventory accepted/declined notifications are logged to the wrong file
    -> no open IM session => logged to secondlife____app_agent_<uuid>_completename.txt
- added   : "UseLegacyIMLogNames" setting to use "old-style" log filenames for P2P IM sessions (TRUE by default)
    -> needed for people who mix older and newer viewers
    -> side-steps any other remaining bugs due to log filename change
master
Kitty Barnett 2011-01-26 00:19:43 +01:00
parent a044f06459
commit 3a9c08aa5f
8 changed files with 188 additions and 33 deletions

View File

@ -532,8 +532,22 @@ std::string LLCacheName::buildUsername(const std::string& full_name)
return "(\?\?\?)";
}
std::string::size_type index = full_name.find(' ');
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
// regexp doesn't play nice with unicode, chop off the display name
S32 open_paren = full_name.rfind(" (");
if (open_paren != std::string::npos)
{
std::string username = full_name.substr(open_paren + 2, full_name.length() - open_paren - 3);
boost::regex complete_name_regex("^[a-z0-9]+(\\.[a-z]+)?$");
boost::match_results<std::string::const_iterator> name_results;
if (boost::regex_match(username, name_results, complete_name_regex))
{
return username;
}
}
// [/SL:KB]
std::string::size_type index = full_name.find(' ');
if (index != std::string::npos)
{
std::string username;

View File

@ -88,6 +88,11 @@ public:
// Converts a standard legacy name to a username
// "bobsmith123 Resident" -> "bobsmith"
// "Random Linden" -> "random.linden"
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
// Additionally, converts a complete display name to a username
// "bobsmith123 Resident (bobsmith123)" -> "bobsmith123"
// "Alias (random.linden)" -> "random.linden"
// [/SL:KB]
static std::string buildUsername(const std::string& name);
// Converts a complete display name to a legacy name

View File

@ -11655,6 +11655,17 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>UseLegacyIMLogNames</key>
<map>
<key>Comment</key>
<string>Use legacy filenames for P2P IMs logs</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>1</integer>
</map>
<key>UseOcclusion</key>
<map>
<key>Comment</key>

View File

@ -327,11 +327,18 @@ void LLGiveInventory::logInventoryOffer(const LLUUID& to_agent, const LLUUID &im
// If this item was given by drag-and-drop on avatar while IM panel wasn't open, log this action to IM history.
else
{
std::string full_name;
if (gCacheName->getFullName(to_agent, full_name))
// std::string full_name;
// if (gCacheName->getFullName(to_agent, full_name))
// {
// LLIMModel::instance().logToFile(full_name, LLTrans::getString("SECOND_LIFE"), im_session_id, LLTrans::getString("inventory_item_offered-im"));
// }
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
std::string strFilename;
if (LLIMModel::buildIMP2PLogFilename(to_agent, LLStringUtil::null, strFilename))
{
LLIMModel::instance().logToFile(full_name, LLTrans::getString("SECOND_LIFE"), im_session_id, LLTrans::getString("inventory_item_offered-im"));
LLIMModel::instance().logToFile(strFilename, LLTrans::getString("SECOND_LIFE"), im_session_id, LLTrans::getString("inventory_item_offered-im"));
}
// [/SL:KB]
}
}

View File

@ -557,23 +557,53 @@ bool LLIMModel::LLIMSession::isOtherParticipantAvaline()
void LLIMModel::LLIMSession::onAvatarNameCache(const LLUUID& avatar_id, const LLAvatarName& av_name)
{
if (av_name.mUsername.empty())
// if (av_name.mUsername.empty())
// {
// // display names is off, use mDisplayName which will be the legacy name
// mHistoryFileName = LLCacheName::buildUsername(av_name.mDisplayName);
// }
// else
// {
// mHistoryFileName = av_name.mUsername;
// }
// [SL:KB] - Patch: Chat-Logs | Checked: 2011-01-16 (Catznip-2.4.0h) | Modified: Catznip-2.4.0h
if (!av_name.mIsDummy)
{
// display names is off, use mDisplayName which will be the legacy name
mHistoryFileName = LLCacheName::buildUsername(av_name.mDisplayName);
}
else
{
mHistoryFileName = av_name.mUsername;
LLIMModel::buildIMP2PLogFilename(avatar_id, mName, mHistoryFileName);
// See note in LLIMModel::LLIMSession::buildHistoryFileName() - standardize P2P IM session names to "complete name"
mName = av_name.getCompleteName();
}
// [/SL:KB]
}
void LLIMModel::LLIMSession::buildHistoryFileName()
{
mHistoryFileName = mName;
//ad-hoc requires sophisticated chat history saving schemes
if (isAdHoc())
// mHistoryFileName = mName;
//
// //ad-hoc requires sophisticated chat history saving schemes
// if (isAdHoc())
// {
// //in case of outgoing ad-hoc sessions
// if (mInitialTargetIDs.size())
// {
// std::set<LLUUID> sorted_uuids(mInitialTargetIDs.begin(), mInitialTargetIDs.end());
// mHistoryFileName = mName + " hash" + generateHash(sorted_uuids);
// return;
// }
//
// //in case of incoming ad-hoc sessions
// mHistoryFileName = mName + " " + LLLogChat::timestamp(true) + " " + mSessionID.asString().substr(0, 4);
// }
//
// // look up username to use as the log name
// if (isP2P())
// {
// LLAvatarNameCache::get(mOtherParticipantID, boost::bind(&LLIMModel::LLIMSession::onAvatarNameCache, this, _1, _2));
// }
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
// Not all of the code above is broken but it becomes a bit of a mess otherwise
if (isAdHoc()) //ad-hoc requires sophisticated chat history saving schemes
{
/* in case of outgoing ad-hoc sessions we need to make specilized names
* if this naming system is ever changed then the filtering definitions in
@ -591,12 +621,20 @@ void LLIMModel::LLIMSession::buildHistoryFileName()
//in case of incoming ad-hoc sessions
mHistoryFileName = mName + " " + LLLogChat::timestamp(true) + " " + mSessionID.asString().substr(0, 4);
}
// look up username to use as the log name
if (isP2P())
else if (isP2P()) // look up username to use as the log name
{
// NOTE-Catznip: [SL-2.4.0] mName will be:
// - the "complete name" if display names are enabled and it's an outgoing IM
// - the "legacy name" if display names are disabled or if it's an incoming IM
LLIMModel::buildIMP2PLogFilename(mOtherParticipantID, mName, mHistoryFileName);
LLAvatarNameCache::get(mOtherParticipantID, boost::bind(&LLIMModel::LLIMSession::onAvatarNameCache, this, _1, _2));
}
else
{
mHistoryFileName = mName;
}
// [/SL:KB]
}
//static
@ -777,6 +815,43 @@ bool LLIMModel::addToHistory(const LLUUID& session_id, const std::string& from,
return true;
}
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
bool LLIMModel::buildIMP2PLogFilename(const LLUUID& idAgent, const std::string& strName, std::string& strFilename)
{
static LLCachedControl<bool> fLegacyFilenames(gSavedSettings, "UseLegacyIMLogNames");
// If we have the name cached then we can simply return the username
LLAvatarName avName;
if ( (LLAvatarNameCache::get(idAgent, &avName)) && (!avName.mIsDummy) )
{
if (!fLegacyFilenames)
{
// If display names are turned off mUserName will be empty and we have to construct it from the legacy name
strFilename = (!avName.mUsername.empty()) ? avName.mUsername : LLCacheName::buildUsername(avName.mDisplayName);
}
else
{
// Use the legacy name to base the filename on
strFilename = LLCacheName::cleanFullName( (!avName.mLegacyFirstName.empty()) ? avName.getLegacyName() : avName.mDisplayName );
}
return true;
}
if (!fLegacyFilenames)
{
// If we don't have it cached 'strName' *should* be a legacy name (or a complete name) and we can construct a username from that
strFilename = LLCacheName::buildUsername(strName);
return strName != strFilename; // If the assumption above was wrong then the two will match which signals failure
}
else
{
// Strip any possible mention of a username
strFilename = LLCacheName::buildLegacyName(strName);
return (!strFilename.empty()); // Assume success as long as the filename isn't an empty string
}
}
// [/SL:KB]
bool LLIMModel::logToFile(const std::string& file_name, const std::string& from, const LLUUID& from_id, const std::string& utf8_text)
{
if (gSavedPerAccountSettings.getBOOL("LogInstantMessages"))
@ -2466,10 +2541,17 @@ void LLIMMgr::addSystemMessage(const LLUUID& session_id, const std::string& mess
// log message to file
else
{
std::string session_name;
// since we select user to share item with - his name is already in cache
gCacheName->getFullName(args["user_id"], session_name);
LLIMModel::instance().logToFile(session_name, SYSTEM_FROM, LLUUID::null, message.getString());
// std::string session_name;
// // since we select user to share item with - his name is already in cache
// gCacheName->getFullName(args["user_id"], session_name);
// LLIMModel::instance().logToFile(session_name, SYSTEM_FROM, LLUUID::null, message.getString());
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
std::string strFilename;
if (LLIMModel::buildIMP2PLogFilename(args["user_id"], LLStringUtil::null, strFilename))
{
LLIMModel::instance().logToFile(strFilename, SYSTEM_FROM, LLUUID::null, message.getString());
}
// [/SL:KB]
}
}
}

View File

@ -283,6 +283,13 @@ public:
void testMessages();
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
/**
* Attempts to build the correct IM P2P log filename for the specified agent UUID and agent name
*/
static bool buildIMP2PLogFilename(const LLUUID& idAgent, const std::string& strName, std::string& strFilename);
// [/SL:KB]
/**
* Saves an IM message into a file
*/

View File

@ -31,6 +31,9 @@
#include "llnotifications.h"
#include "llimview.h"
#include "llagent.h"
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
#include "llavatarnamecache.h"
// [/SL:KB]
#include "llfloaterreg.h"
#include "llnearbychat.h"
#include "llimfloater.h"
@ -254,7 +257,10 @@ bool LLHandlerUtil::isIMFloaterFocused(const LLNotificationPtr& notification)
// static
void LLHandlerUtil::logToIM(const EInstantMessage& session_type,
const std::string& session_name, const std::string& from_name,
// const std::string& session_name, const std::string& from_name,
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
const std::string& file_name, const std::string& from_name,
// [/SL:KB]
const std::string& message, const LLUUID& session_owner_id,
const LLUUID& from_id)
{
@ -275,7 +281,10 @@ void LLHandlerUtil::logToIM(const EInstantMessage& session_type,
{
from = SYSTEM_FROM;
}
LLIMModel::instance().logToFile(session_name, from, from_id, message);
// LLIMModel::instance().logToFile(session_name, from, from_id, message);
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
LLIMModel::instance().logToFile(file_name, from, from_id, message);
// [/SL:KB]
}
else
{
@ -315,13 +324,24 @@ void LLHandlerUtil::logToIMP2P(const LLNotificationPtr& notification)
logToIMP2P(notification, false);
}
void log_name_callback(const std::string& full_name, const std::string& from_name,
const std::string& message, const LLUUID& from_id)
//void log_name_callback(const std::string& full_name, const std::string& from_name,
// const std::string& message, const LLUUID& from_id)
//
//{
// LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, full_name, from_name, message,
// from_id, LLUUID());
//}
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
void log_name_callback(const LLUUID& agent_id, const LLAvatarName& av_name,
const std::string& from_name, const std::string& message, const LLUUID& from_id)
{
LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, full_name, from_name, message,
from_id, LLUUID());
std::string strFilename;
if (LLIMModel::buildIMP2PLogFilename(agent_id, av_name.getCompleteName(), strFilename))
{
LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, strFilename, from_name, message, from_id, LLUUID());
}
}
// [/SL:KB]
// static
void LLHandlerUtil::logToIMP2P(const LLNotificationPtr& notification, bool to_file_only)
@ -339,11 +359,17 @@ void LLHandlerUtil::logToIMP2P(const LLNotificationPtr& notification, bool to_fi
if(to_file_only)
{
gCacheName->get(from_id, false, boost::bind(&log_name_callback, _2, "", notification->getMessage(), LLUUID()));
// gCacheName->get(from_id, false, boost::bind(&log_name_callback, _2, "", notification->getMessage(), LLUUID()));
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
LLAvatarNameCache::get(from_id, boost::bind(&log_name_callback, _1, _2, "", notification->getMessage(), LLUUID()));
// [/SL:KB]
}
else
{
gCacheName->get(from_id, false, boost::bind(&log_name_callback, _2, INTERACTIVE_SYSTEM_FROM, notification->getMessage(), from_id));
// gCacheName->get(from_id, false, boost::bind(&log_name_callback, _2, INTERACTIVE_SYSTEM_FROM, notification->getMessage(), from_id));
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
LLAvatarNameCache::get(from_id, boost::bind(&log_name_callback, _1, _2, INTERACTIVE_SYSTEM_FROM, notification->getMessage(), from_id));
// [/SL:KB]
}
}
}

View File

@ -109,8 +109,11 @@ bool LLTipHandler::processNotification(const LLSD& notify)
LLUUID from_id = notification->getPayload()["from_id"];
if (LLHandlerUtil::canLogToIM(notification))
{
LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, session_name, name,
notification->getMessage(), from_id, from_id);
// LLHandlerUtil::logToIM(IM_NOTHING_SPECIAL, session_name, name,
// notification->getMessage(), from_id, from_id);
// [SL:KB] - Patch: Chat-Logs | Checked: 2010-11-18 (Catznip-2.4.0c) | Added: Catznip-2.4.0c
LLHandlerUtil::logToIMP2P(notification, false);
// [/SL:KB]
}
if (LLHandlerUtil::canSpawnIMSession(notification))