From 0f00dc2f658869cc73a18b03b024a6cc88964e0b Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Wed, 22 May 2024 20:29:55 +0300 Subject: Add support for sending messages to Nearby chat from Lua script --- indra/newview/llchathistory.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'indra/newview/llchathistory.cpp') diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index 4a08eace62..6f02a08020 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -125,6 +125,7 @@ public: mUserNameTextBox(NULL), mTimeBoxTextBox(NULL), mNeedsTimeBox(true), + mIsFromScript(false), mAvatarNameCacheConnection() {} @@ -658,11 +659,12 @@ public: const LLUUID& getAvatarId () const { return mAvatarID;} - void setup(const LLChat& chat, const LLStyle::Params& style_params, const LLSD& args) + void setup(const LLChat& chat, const LLStyle::Params& style_params, const LLSD& args, bool is_script) { mAvatarID = chat.mFromID; mSessionID = chat.mSessionID; mSourceType = chat.mSourceType; + mIsFromScript = is_script; // To be able to report a message, we need a copy of it's text // and it's easier to store text directly than trying to get @@ -732,7 +734,7 @@ public: username_end == (chat.mFromName.length() - 1)) { mFrom = chat.mFromName.substr(0, username_start); - user_name->setValue(mFrom); + user_name->setValue(mIsFromScript ? LLTrans::getString("ScriptBy") + mFrom : mFrom); if (gSavedSettings.getBOOL("NameTagShowUsernames")) { @@ -774,7 +776,7 @@ public: switch (mSourceType) { case CHAT_SOURCE_AGENT: - icon->setValue(chat.mFromID); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : chat.mFromID); break; case CHAT_SOURCE_OBJECT: icon->setValue(LLSD("OBJECT_Icon")); @@ -787,7 +789,7 @@ public: icon->setValue(LLSD("Command_Destinations_Icon")); break; case CHAT_SOURCE_UNKNOWN: - icon->setValue(LLSD("Unknown_Icon")); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : chat.mFromID); } // In case the message came from an object, save the object info @@ -1029,7 +1031,14 @@ private: mFrom = av_name.getDisplayName(); LLTextBox* user_name = getChild("user_name"); - user_name->setValue( LLSD(av_name.getDisplayName() ) ); + if(mIsFromScript) + { + user_name->setValue(LLSD(LLTrans::getString("ScriptBy") + av_name.getDisplayName())); + } + else + { + user_name->setValue(LLSD(av_name.getDisplayName())); + } user_name->setToolTip( av_name.getUserName() ); if (gSavedSettings.getBOOL("NameTagShowUsernames") && @@ -1071,6 +1080,8 @@ protected: bool mNeedsTimeBox; + bool mIsFromScript; + private: boost::signals2::connection mAvatarNameCacheConnection; }; @@ -1088,6 +1099,7 @@ LLChatHistory::LLChatHistory(const LLChatHistory::Params& p) mTopHeaderPad(p.top_header_pad), mBottomHeaderPad(p.bottom_header_pad), mIsLastMessageFromLog(false), + mIsLastFromScript(false), mNotifyAboutUnreadMsg(p.notify_unread_msg) { LLTextEditor::Params editor_params(p); @@ -1185,11 +1197,11 @@ LLView* LLChatHistory::getSeparator() return separator; } -LLView* LLChatHistory::getHeader(const LLChat& chat,const LLStyle::Params& style_params, const LLSD& args) +LLView* LLChatHistory::getHeader(const LLChat& chat,const LLStyle::Params& style_params, const LLSD& args, bool is_script) { LLChatHistoryHeader* header = LLChatHistoryHeader::createInstance(mMessageHeaderFilename); if (header) - header->setup(chat, style_params, args); + header->setup(chat, style_params, args, is_script); return header; } @@ -1258,8 +1270,8 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL name_params.color(name_color); name_params.readonly_color(name_color); - std::string prefix = chat.mText.substr(0, 4); - + bool is_lua = (chat.mText.substr(0, LUA_PREFIX.size()) == LUA_PREFIX); + std::string prefix = chat.mText.substr(is_lua ? LUA_PREFIX.size() : 0, 4); //IRC styled /me messages. bool irc_me = prefix == "/me " || prefix == "/me'"; @@ -1393,7 +1405,8 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL && mLastFromID == chat.mFromID && mLastMessageTime.notNull() && (new_message_time.secondsSinceEpoch() - mLastMessageTime.secondsSinceEpoch()) < 60.0 - && mIsLastMessageFromLog == message_from_log) //distinguish between current and previous chat session's histories + && mIsLastMessageFromLog == message_from_log //distinguish between current and previous chat session's histories + && mIsLastFromScript == is_lua) { view = getSeparator(); if (!view) @@ -1408,7 +1421,7 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL } else { - view = getHeader(chat, name_params, args); + view = getHeader(chat, name_params, args, is_lua); if (!view) { LL_WARNS() << "Failed to create header from " << mMessageHeaderFilename << ": can't append to history" << LL_ENDL; @@ -1437,6 +1450,7 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL mLastFromID = chat.mFromID; mLastMessageTime = new_message_time; mIsLastMessageFromLog = message_from_log; + mIsLastFromScript = is_lua; } // body of the message processing @@ -1491,7 +1505,8 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL // usual messages showing else if (!teleport_separator) { - std::string message = irc_me ? chat.mText.substr(3) : chat.mText; + std::string message = is_lua ? chat.mText.substr(LUA_PREFIX.size()) : chat.mText; + message = irc_me ? message.substr(3) : message; //MESSAGE TEXT PROCESSING //*HACK getting rid of redundant sender names in system notifications sent using sender name (see EXT-5010) -- cgit v1.2.3 From c38e71411080af9e03646bbe34f766201d942afd Mon Sep 17 00:00:00 2001 From: Maxim Nikolenko Date: Thu, 23 May 2024 13:13:47 +0300 Subject: mac build fix --- indra/newview/llchathistory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llchathistory.cpp') diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index 6f02a08020..54b0c171f1 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -776,7 +776,7 @@ public: switch (mSourceType) { case CHAT_SOURCE_AGENT: - icon->setValue(mIsFromScript ? LLSD("Inv_Script") : chat.mFromID); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD(chat.mFromID)); break; case CHAT_SOURCE_OBJECT: icon->setValue(LLSD("OBJECT_Icon")); @@ -789,7 +789,7 @@ public: icon->setValue(LLSD("Command_Destinations_Icon")); break; case CHAT_SOURCE_UNKNOWN: - icon->setValue(mIsFromScript ? LLSD("Inv_Script") : chat.mFromID); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD(chat.mFromID)); } // In case the message came from an object, save the object info -- cgit v1.2.3 From e4b7d2f463d19cab28985414365fd8415e3dc700 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 24 May 2024 15:24:50 +0300 Subject: Mark script messages in compact mode too; code clean up --- indra/newview/llchathistory.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'indra/newview/llchathistory.cpp') diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index 54b0c171f1..7ee0f3dd7a 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -665,6 +665,7 @@ public: mSessionID = chat.mSessionID; mSourceType = chat.mSourceType; mIsFromScript = is_script; + mPrefix = mIsFromScript ? LLTrans::getString("ScriptBy") : ""; // To be able to report a message, we need a copy of it's text // and it's easier to store text directly than trying to get @@ -734,7 +735,7 @@ public: username_end == (chat.mFromName.length() - 1)) { mFrom = chat.mFromName.substr(0, username_start); - user_name->setValue(mIsFromScript ? LLTrans::getString("ScriptBy") + mFrom : mFrom); + user_name->setValue(mPrefix + mFrom); if (gSavedSettings.getBOOL("NameTagShowUsernames")) { @@ -789,7 +790,7 @@ public: icon->setValue(LLSD("Command_Destinations_Icon")); break; case CHAT_SOURCE_UNKNOWN: - icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD(chat.mFromID)); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD("Unknown_Icon")); } // In case the message came from an object, save the object info @@ -1031,14 +1032,7 @@ private: mFrom = av_name.getDisplayName(); LLTextBox* user_name = getChild("user_name"); - if(mIsFromScript) - { - user_name->setValue(LLSD(LLTrans::getString("ScriptBy") + av_name.getDisplayName())); - } - else - { - user_name->setValue(LLSD(av_name.getDisplayName())); - } + user_name->setValue(LLSD(mPrefix + av_name.getDisplayName())); user_name->setToolTip( av_name.getUserName() ); if (gSavedSettings.getBOOL("NameTagShowUsernames") && @@ -1081,6 +1075,7 @@ protected: bool mNeedsTimeBox; bool mIsFromScript; + std::string mPrefix; private: boost::signals2::connection mAvatarNameCacheConnection; @@ -1270,8 +1265,11 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL name_params.color(name_color); name_params.readonly_color(name_color); - bool is_lua = (chat.mText.substr(0, LUA_PREFIX.size()) == LUA_PREFIX); - std::string prefix = chat.mText.substr(is_lua ? LUA_PREFIX.size() : 0, 4); + bool is_lua = LLStringUtil::startsWith(chat.mText, LUA_PREFIX); + + std::string message = remove_LUA_PREFIX(chat.mText, is_lua); + std::string prefix = message.substr(0, 4); + //IRC styled /me messages. bool irc_me = prefix == "/me " || prefix == "/me'"; @@ -1347,6 +1345,7 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL // names showing if (args["show_names_for_p2p_conv"].asBoolean() && utf8str_trim(chat.mFromName).size()) { + std::string script_prefix = is_lua ? LLTrans::getString("ScriptBy") : ""; // Don't hotlink any messages from the system (e.g. "Second Life:"), so just add those in plain text. if (chat.mSourceType == CHAT_SOURCE_OBJECT && chat.mFromID.notNull()) { @@ -1371,7 +1370,7 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL link_params.overwriteFrom(LLStyleMap::instance().lookupAgent(chat.mFromID)); // Add link to avatar's inspector and delimiter to message. - mEditor->appendText(std::string(link_params.link_href) + delimiter, + mEditor->appendText(script_prefix + std::string(link_params.link_href) + delimiter, prependNewLineState, link_params); prependNewLineState = false; } @@ -1384,7 +1383,7 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL } else { - mEditor->appendText("" + chat.mFromName + "" + delimiter, + mEditor->appendText(script_prefix + "" + chat.mFromName + "" + delimiter, prependNewLineState, body_message_params); prependNewLineState = false; } @@ -1505,7 +1504,6 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL // usual messages showing else if (!teleport_separator) { - std::string message = is_lua ? chat.mText.substr(LUA_PREFIX.size()) : chat.mText; message = irc_me ? message.substr(3) : message; //MESSAGE TEXT PROCESSING -- cgit v1.2.3 From b0ef843fe0702482e843379b4975b2dda4d58935 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 24 May 2024 09:22:40 -0400 Subject: Nat's ideas from PR #1547 --- indra/newview/llchathistory.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'indra/newview/llchathistory.cpp') diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index 54b0c171f1..f16377d7e3 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -665,6 +665,7 @@ public: mSessionID = chat.mSessionID; mSourceType = chat.mSourceType; mIsFromScript = is_script; + mScriptPrefix = is_script? LLTrans::getString("ScriptBy") : ""; // To be able to report a message, we need a copy of it's text // and it's easier to store text directly than trying to get @@ -734,7 +735,7 @@ public: username_end == (chat.mFromName.length() - 1)) { mFrom = chat.mFromName.substr(0, username_start); - user_name->setValue(mIsFromScript ? LLTrans::getString("ScriptBy") + mFrom : mFrom); + user_name->setValue(mScriptPrefix + mFrom); if (gSavedSettings.getBOOL("NameTagShowUsernames")) { @@ -789,7 +790,7 @@ public: icon->setValue(LLSD("Command_Destinations_Icon")); break; case CHAT_SOURCE_UNKNOWN: - icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD(chat.mFromID)); + icon->setValue(mIsFromScript ? LLSD("Inv_Script") : LLSD("Unknown_Icon")); } // In case the message came from an object, save the object info @@ -1031,14 +1032,7 @@ private: mFrom = av_name.getDisplayName(); LLTextBox* user_name = getChild("user_name"); - if(mIsFromScript) - { - user_name->setValue(LLSD(LLTrans::getString("ScriptBy") + av_name.getDisplayName())); - } - else - { - user_name->setValue(LLSD(av_name.getDisplayName())); - } + user_name->setValue(LLSD(mScriptPrefix + av_name.getDisplayName())); user_name->setToolTip( av_name.getUserName() ); if (gSavedSettings.getBOOL("NameTagShowUsernames") && @@ -1070,6 +1064,7 @@ protected: std::string mFrom; LLUUID mSessionID; std::string mText; + std::string mScriptPrefix; F64 mTime; // IM's frame time time_t mCreationTime; // Views's time @@ -1080,7 +1075,7 @@ protected: bool mNeedsTimeBox; - bool mIsFromScript; + bool mIsFromScript; private: boost::signals2::connection mAvatarNameCacheConnection; @@ -1270,8 +1265,8 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL name_params.color(name_color); name_params.readonly_color(name_color); - bool is_lua = (chat.mText.substr(0, LUA_PREFIX.size()) == LUA_PREFIX); - std::string prefix = chat.mText.substr(is_lua ? LUA_PREFIX.size() : 0, 4); + auto [message, is_lua] = LLStringUtil::withoutPrefix(chat.mText, LUA_PREFIX); + std::string prefix = message.substr(0, 4); //IRC styled /me messages. bool irc_me = prefix == "/me " || prefix == "/me'"; @@ -1505,7 +1500,6 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL // usual messages showing else if (!teleport_separator) { - std::string message = is_lua ? chat.mText.substr(LUA_PREFIX.size()) : chat.mText; message = irc_me ? message.substr(3) : message; //MESSAGE TEXT PROCESSING -- cgit v1.2.3 From 94cac4c443b5acc189b5223c78eb278648846338 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 24 May 2024 10:15:24 -0400 Subject: Fix merge glitches --- indra/newview/llchathistory.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'indra/newview/llchathistory.cpp') diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index e5878a9a24..d549f372e3 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -1265,19 +1265,8 @@ void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LL name_params.color(name_color); name_params.readonly_color(name_color); -<<<<<<< variant A auto [message, is_lua] = LLStringUtil::withoutPrefix(chat.mText, LUA_PREFIX); std::string prefix = message.substr(0, 4); ->>>>>>> variant B - bool is_lua = LLStringUtil::startsWith(chat.mText, LUA_PREFIX); - - std::string message = remove_LUA_PREFIX(chat.mText, is_lua); - std::string prefix = message.substr(0, 4); - -####### Ancestor - bool is_lua = (chat.mText.substr(0, LUA_PREFIX.size()) == LUA_PREFIX); - std::string prefix = chat.mText.substr(is_lua ? LUA_PREFIX.size() : 0, 4); -======= end //IRC styled /me messages. bool irc_me = prefix == "/me " || prefix == "/me'"; -- cgit v1.2.3