From 3a9c08aa5ffb7899e2b8a2bf47503a4399ae00dd Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Wed, 26 Jan 2011 00:19:43 +0100 Subject: [PATCH] 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__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 --- indra/llmessage/llcachename.cpp | 16 ++- indra/llmessage/llcachename.h | 5 + indra/newview/app_settings/settings.xml | 11 ++ indra/newview/llgiveinventory.cpp | 13 ++- indra/newview/llimview.cpp | 118 +++++++++++++++++--- indra/newview/llimview.h | 7 ++ indra/newview/llnotificationhandlerutil.cpp | 44 ++++++-- indra/newview/llnotificationtiphandler.cpp | 7 +- 8 files changed, 188 insertions(+), 33 deletions(-) diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp index 4ab6bd2438..427e52eb69 100644 --- a/indra/llmessage/llcachename.cpp +++ b/indra/llmessage/llcachename.cpp @@ -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 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; diff --git a/indra/llmessage/llcachename.h b/indra/llmessage/llcachename.h index b108e37157..ea008a85b2 100644 --- a/indra/llmessage/llcachename.h +++ b/indra/llmessage/llcachename.h @@ -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 diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 3dea67694e..f91c13a475 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -11655,6 +11655,17 @@ Value 0 + UseLegacyIMLogNames + + Comment + Use legacy filenames for P2P IMs logs + Persist + 1 + Type + Boolean + Value + 1 + UseOcclusion Comment diff --git a/indra/newview/llgiveinventory.cpp b/indra/newview/llgiveinventory.cpp index 754237d9f1..422c23ff2b 100644 --- a/indra/newview/llgiveinventory.cpp +++ b/indra/newview/llgiveinventory.cpp @@ -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] } } diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp index 3ed5e610b8..5e4edefb96 100644 --- a/indra/newview/llimview.cpp +++ b/indra/newview/llimview.cpp @@ -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 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 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] } } } diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h index 3581312b0c..a2d613321d 100644 --- a/indra/newview/llimview.h +++ b/indra/newview/llimview.h @@ -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 */ diff --git a/indra/newview/llnotificationhandlerutil.cpp b/indra/newview/llnotificationhandlerutil.cpp index 70d588db52..c3cee66e93 100644 --- a/indra/newview/llnotificationhandlerutil.cpp +++ b/indra/newview/llnotificationhandlerutil.cpp @@ -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] } } } diff --git a/indra/newview/llnotificationtiphandler.cpp b/indra/newview/llnotificationtiphandler.cpp index 02b217fc94..126b82c9ce 100644 --- a/indra/newview/llnotificationtiphandler.cpp +++ b/indra/newview/llnotificationtiphandler.cpp @@ -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))