From 8485bff29b98f47954b78b31b2e0511f94de3be4 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Mon, 18 Jul 2011 21:06:58 +0200 Subject: [PATCH] Option to show (group) IMs in nearby chat plus separate save option. Fixes FIRE-1086 --- indra/llcommon/llchat.h | 3 +- indra/newview/app_settings/settings.xml | 22 ++++++ indra/newview/llchathistory.cpp | 33 +++++++-- indra/newview/llimview.cpp | 19 +++++- indra/newview/lllogchat.cpp | 12 ++++ indra/newview/llnearbychat.cpp | 24 +++++++ .../xui/en/panel_preferences_firestorm.xml | 68 ++++++++++++++----- .../newview/skins/default/xui/en/strings.xml | 1 + 8 files changed, 157 insertions(+), 25 deletions(-) diff --git a/indra/llcommon/llchat.h b/indra/llcommon/llchat.h index 7f196c9fd3..fa390a8889 100644 --- a/indra/llcommon/llchat.h +++ b/indra/llcommon/llchat.h @@ -50,7 +50,8 @@ typedef enum e_chat_type CHAT_TYPE_STOP = 5, CHAT_TYPE_DEBUG_MSG = 6, CHAT_TYPE_REGION = 7, - CHAT_TYPE_OWNER = 8 + CHAT_TYPE_OWNER = 8, + CHAT_TYPE_IM = 9 // Ansariel: Special type for IMs in nearby chat } EChatType; typedef enum e_chat_audible_level diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 5a274dbf6b..6e598a5599 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -2,6 +2,28 @@ + FSShowIMInChatHistory + + Comment + If true, IM will also be shown in the nearby chat history. + Persist + 1 + Type + Boolean + Value + 0 + + FSLogIMInChatHistory + + Comment + If true, IM will also be logged in the nearby chat history if logging nearby chat and showing IMs in nearby chat is enabled. + Persist + 1 + Type + Boolean + Value + 0 + FSPaymentInfoInChat Comment diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index a3073d73c8..1c3fcb5e47 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -307,12 +307,13 @@ public: { user_name->setValue( LLSD() ); LLAvatarNameCache::get(mAvatarID, - boost::bind(&LLChatHistoryHeader::onAvatarNameCache, this, _1, _2)); + boost::bind(&LLChatHistoryHeader::onAvatarNameCache, this, _1, _2, chat.mChatType)); } else { // If the agent's chat was subject to @shownames=n we should display their anonimized name mFrom = chat.mFromName; + if (chat.mChatType == CHAT_TYPE_IM) mFrom = LLTrans::getString("IMPrefix") + " " + mFrom; user_name->setValue(mFrom); user_name->setToolTip(mFrom); setToolTip(mFrom); @@ -331,12 +332,13 @@ public: username_end == (chat.mFromName.length() - 1)) { user_name->setValue( LLSD() ); - LLAvatarNameCache::get(mAvatarID, boost::bind(&LLChatHistoryHeader::onAvatarNameCache, this, _1, _2)); + LLAvatarNameCache::get(mAvatarID, boost::bind(&LLChatHistoryHeader::onAvatarNameCache, this, _1, _2, chat.mChatType)); } else { // If the agent's chat was subject to @shownames=n we should display their anonimized name mFrom = chat.mFromName; + if (chat.mChatType == CHAT_TYPE_IM) mFrom = LLTrans::getString("IMPrefix") + " " + mFrom; user_name->setValue(mFrom); user_name->setToolTip(mFrom); setToolTip(mFrom); @@ -431,12 +433,13 @@ public: } } - void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name) + void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name, EChatType chat_type) { mFrom = av_name.mDisplayName; + if (chat_type == CHAT_TYPE_IM) mFrom = LLTrans::getString("IMPrefix") + " " + mFrom; LLTextBox* user_name = getChild("user_name"); - user_name->setValue( LLSD(av_name.mDisplayName ) ); + user_name->setValue( LLSD(mFrom) ); user_name->setToolTip( av_name.mUsername ); if (gSavedSettings.getBOOL("NameTagShowUsernames") && LLAvatarNameCache::useDisplayNames()) @@ -917,6 +920,12 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL // reset the style parameter for the header only -AO link_params.color(header_name_color); link_params.readonly_color(header_name_color); + + if (chat.mChatType == CHAT_TYPE_IM) + { + mEditor->appendText(LLTrans::getString("IMPrefix") + " ", false, link_params); + } + if ((gSavedSettings.getBOOL("NameTagShowUsernames")) && (gSavedSettings.getBOOL("UseDisplayNames"))) { checkDisplayName(); @@ -938,7 +947,14 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL } else { - mEditor->appendText(chat.mFromName + delimiter, false, style_params); + if (chat.mChatType == CHAT_TYPE_IM) + { + mEditor->appendText(LLTrans::getString("IMPrefix") + " " + chat.mFromName + delimiter, false, style_params); + } + else + { + mEditor->appendText(chat.mFromName + delimiter, false, style_params); + } } } } @@ -952,7 +968,10 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL LLDate new_message_time = LLDate::now(); - if (mLastFromName == chat.mFromName + std::string tmp_from_name(chat.mFromName); + if (chat.mChatType == CHAT_TYPE_IM) tmp_from_name = LLTrans::getString("IMPrefix") + " " + tmp_from_name; + + if (mLastFromName == tmp_from_name && mLastFromID == chat.mFromID && mLastMessageTime.notNull() && (new_message_time.secondsSinceEpoch() - mLastMessageTime.secondsSinceEpoch()) < 60.0 @@ -994,7 +1013,9 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL widget_associated_text += chat.mFromName + delimiter; mEditor->appendWidget(p, widget_associated_text, false); + mLastFromName = chat.mFromName; + if (chat.mChatType == CHAT_TYPE_IM) mLastFromName = LLTrans::getString("IMPrefix") + " " + mLastFromName; mLastFromID = chat.mFromID; mLastMessageTime = new_message_time; mIsLastMessageFromLog = message_from_log; diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp index 594ce66fee..ee6f5a1426 100644 --- a/indra/newview/llimview.cpp +++ b/indra/newview/llimview.cpp @@ -810,7 +810,24 @@ bool LLIMModel::addToHistory(const LLUUID& session_id, const std::string& from, return false; } - session->addMessage(from, from_id, utf8_text, LLLogChat::timestamp(false)); //might want to add date separately + std::string timestr = LLLogChat::timestamp(false); + session->addMessage(from, from_id, utf8_text, timestr); //might want to add date separately + + // Ansariel: Forward IM to nearby chat if wanted + static LLCachedControl show_im_in_chat(gSavedSettings, "FSShowIMInChatHistory"); + if (show_im_in_chat) + { + LLChat chat; + chat.mChatStyle = CHAT_STYLE_NORMAL; + chat.mChatType = CHAT_TYPE_IM; + chat.mFromID = from_id; + chat.mFromName = from; + chat.mSourceType = CHAT_SOURCE_AGENT; + chat.mText = utf8_text; + chat.mTimeStr = timestr; + LLNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance("nearby_chat", LLSD()); + nearby_chat->addMessage(chat, true, LLSD()); + } return true; } diff --git a/indra/newview/lllogchat.cpp b/indra/newview/lllogchat.cpp index b2260d84e2..475aee53d5 100644 --- a/indra/newview/lllogchat.cpp +++ b/indra/newview/lllogchat.cpp @@ -573,6 +573,18 @@ bool LLChatLogParser::parse(std::string& raw, LLSD& im) bool has_name = name_and_text[IDX_NAME].matched; std::string name = name_and_text[IDX_NAME]; + // Ansariel: Handle the case an IM was stored in nearby chat history + if (name == "IM:") + { + U32 divider_pos = stuff.find(NAME_TEXT_DIVIDER, 3); + if (divider_pos != std::string::npos && divider_pos < (stuff.length() - NAME_TEXT_DIVIDER.length())) + { + im[IM_FROM] = stuff.substr(0, divider_pos); + im[IM_TEXT] = stuff.substr(divider_pos + NAME_TEXT_DIVIDER.length()); + return true; + } + } + //we don't need a name/text separator if (has_name && name.length() && name[name.length()-1] == ':') { diff --git a/indra/newview/llnearbychat.cpp b/indra/newview/llnearbychat.cpp index d2b7026ec3..f8edd88d47 100644 --- a/indra/newview/llnearbychat.cpp +++ b/indra/newview/llnearbychat.cpp @@ -291,6 +291,16 @@ void LLNearbyChat::addMessage(const LLChat& chat,bool archive,const LLSD &args) { from_name = av_name.getCompleteName(); } + + // Ansariel: Handle IMs in nearby chat + if (gSavedSettings.getBOOL("FSShowIMInChatHistory") && chat.mChatType == CHAT_TYPE_IM) + { + if (gSavedSettings.getBOOL("FSLogIMInChatHistory")) + { + from_name = "IM: " + from_name; + } + else return; + } } LLLogChat::saveHistory("chat", from_name, chat.mFromID, chat.mText); @@ -562,6 +572,7 @@ void LLNearbyChat::loadHistory() std::list::const_iterator it = history.begin(); while (it != history.end()) { + bool im_type = false; const LLSD& msg = *it; std::string from = msg[IM_FROM]; @@ -572,6 +583,17 @@ void LLNearbyChat::loadHistory() } else { + // Ansariel: Strip IM prefix so we can properly + // retrieve the UUID in case we got a + // saved IM in nearby chat history. + std::string im_prefix = "IM: "; + size_t im_prefix_found = from.find(im_prefix); + if (im_prefix_found != std::string.npos) + { + from = from.substr(im_prefix.length()); + im_type = true; + } + std::string legacy_name = gCacheName->buildLegacyName(from); gCacheName->getUUID(legacy_name, from_id); } @@ -583,6 +605,8 @@ void LLNearbyChat::loadHistory() chat.mTimeStr = msg[IM_TIME].asString(); chat.mChatStyle = CHAT_STYLE_HISTORY; + if (im_type) chat.mChatType = CHAT_TYPE_IM; + chat.mSourceType = CHAT_SOURCE_AGENT; if (from_id.isNull() && SYSTEM_FROM == from) { diff --git a/indra/newview/skins/default/xui/en/panel_preferences_firestorm.xml b/indra/newview/skins/default/xui/en/panel_preferences_firestorm.xml index f756e3b035..e0d08f2224 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_firestorm.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_firestorm.xml @@ -705,7 +705,7 @@ right="-1" follows="all" label="Chat" - name="tab1-2" > + name="firestorm_chat" > @@ -754,7 +754,7 @@ label="Emotes use italic font" layout="topleft" top_pad="0" - height="20" + height="18" width="400" /> (requires restart) @@ -828,7 +828,39 @@ top_pad="0" left="20" width="400" - height="20" + height="18" + name="FSShowIMInChatHistory" + control_name="FSShowIMInChatHistory" + label="Show IMs in nearby chat window"/> + + + (requires saving nearby chat logs) + + @@ -927,7 +961,7 @@ follows="left|top" top_pad="0" width="50" - height="20" + height="18" control_name="PhoenixMuteAllGroups" name="PhoenixMuteAllGroups" label="Disable ALL group chats"/> @@ -936,14 +970,14 @@ follows="left|top" top_pad="0" width="50" - height="20" + height="18" control_name="PhoenixMuteGroupWhenNoticesDisabled" name="PhoenixMuteGroupWhenNoticesDisabled" label="When 'Receive group notices' is disabled, disable group chat as well"/>