From 1d0f25714e17d1f65ee7ef4c9394fed9210e3cd4 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 28 Jan 2021 21:54:52 +0200 Subject: SL-14486 Avoid accidental truncation of avatar notes field Server sided limitation, web page allows more than server sends to viewer. This is a workaround untill server sided restriction gets lifted. --- indra/newview/llpanelprofile.cpp | 81 +++++++++++++++++++--- indra/newview/llpanelprofile.h | 8 +++ .../skins/default/xui/en/panel_profile_notes.xml | 24 ++++++- 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp index 82515c8d4a..49b18874f3 100644 --- a/indra/newview/llpanelprofile.cpp +++ b/indra/newview/llpanelprofile.cpp @@ -1237,10 +1237,24 @@ void LLPanelProfileFirstLife::updateButtons() LLPanelProfileNotes::LLPanelProfileNotes() : LLPanelProfileTab() +, mAvatarNameCacheConnection() { } +LLPanelProfileNotes::~LLPanelProfileNotes() +{ + if (getAvatarId().notNull()) + { + LLAvatarTracker::instance().removeParticularFriendObserver(getAvatarId(), this); + } + + if (mAvatarNameCacheConnection.connected()) + { + mAvatarNameCacheConnection.disconnect(); + } +} + void LLPanelProfileNotes::updateData() { LLUUID avatar_id = getAvatarId(); @@ -1257,6 +1271,7 @@ BOOL LLPanelProfileNotes::postBuild() mMapRights = getChild("map_check"); mEditObjectRights = getChild("objects_check"); mNotesEditor = getChild("notes_edit"); + mCharacterLimitWarning = getChild("character_limit_warning"); mEditObjectRights->setCommitCallback(boost::bind(&LLPanelProfileNotes::onCommitRights, this)); @@ -1272,6 +1287,8 @@ void LLPanelProfileNotes::onOpen(const LLSD& key) resetData(); fillRightsData(); + + mAvatarNameCacheConnection = LLAvatarNameCache::get(getAvatarId(), boost::bind(&LLPanelProfileNotes::onAvatarNameCache, this, _1, _2)); } void LLPanelProfileNotes::apply() @@ -1379,6 +1396,27 @@ void LLPanelProfileNotes::applyRights() LLAvatarPropertiesProcessor::getInstance()->sendFriendRights(getAvatarId(), rights); } +void LLPanelProfileNotes::updateWarning() +{ + mCharacterLimitWarning->setText(std::string()); + + std::string str = getString("header_symbol_limit"); + mCharacterLimitWarning->appendText(str, false, LLStyle::Params().color(LLColor4::yellow)); + mCharacterLimitWarning->appendText(" ", false, LLStyle::Params()); + + LLStringUtil::format_map_t args; + if (!mURLWebProfile.empty()) + { + args["[PROFILE_URL]"] = mURLWebProfile; + } + else + { + args["[PROFILE_URL]"] = getProfileURL(getAvatarId().asString()); + } + str = getString("body_symbol_limit", args); + mCharacterLimitWarning->appendText(str, false, LLStyle::Params()); +} + void LLPanelProfileNotes::processProperties(void* data, EAvatarProcessorType type) { if (APT_NOTES == type) @@ -1390,6 +1428,16 @@ void LLPanelProfileNotes::processProperties(void* data, EAvatarProcessorType typ mNotesEditor->setEnabled(TRUE); updateButtons(); + if (avatar_notes->notes.size() > 1000) + { + mCharacterLimitWarning->setVisible(TRUE); + updateWarning(); + } + else + { + mCharacterLimitWarning->setVisible(FALSE); + } + LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this); } } @@ -1402,6 +1450,9 @@ void LLPanelProfileNotes::resetData() mOnlineStatus->setValue(FALSE); mMapRights->setValue(FALSE); mEditObjectRights->setValue(FALSE); + mCharacterLimitWarning->setVisible(FALSE); + + mURLWebProfile.clear(); } void LLPanelProfileNotes::enableCheckboxes(bool enable) @@ -1411,14 +1462,6 @@ void LLPanelProfileNotes::enableCheckboxes(bool enable) mEditObjectRights->setEnabled(enable); } -LLPanelProfileNotes::~LLPanelProfileNotes() -{ - if (getAvatarId().notNull()) - { - LLAvatarTracker::instance().removeParticularFriendObserver(getAvatarId(), this); - } -} - // virtual, called by LLAvatarTracker void LLPanelProfileNotes::changed(U32 mask) { @@ -1439,6 +1482,28 @@ void LLPanelProfileNotes::setAvatarId(const LLUUID& avatar_id) } } +void LLPanelProfileNotes::onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name) +{ + mAvatarNameCacheConnection.disconnect(); + + std::string username = av_name.getAccountName(); + if (username.empty()) + { + username = LLCacheName::buildUsername(av_name.getDisplayName()); + } + else + { + LLStringUtil::replaceChar(username, ' ', '.'); + } + + mURLWebProfile = getProfileURL(username, false); + + if (mCharacterLimitWarning->getVisible()) + { + updateWarning(); + } +} + ////////////////////////////////////////////////////////////////////////// // LLPanelProfile diff --git a/indra/newview/llpanelprofile.h b/indra/newview/llpanelprofile.h index de25b92470..a42021af88 100644 --- a/indra/newview/llpanelprofile.h +++ b/indra/newview/llpanelprofile.h @@ -361,6 +361,8 @@ public: */ virtual void apply(); + void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name); + protected: /** * Fills rights data for friends. @@ -374,11 +376,17 @@ protected: void enableCheckboxes(bool enable); void applyRights(); + void updateWarning(); LLCheckBoxCtrl* mOnlineStatus; LLCheckBoxCtrl* mMapRights; LLCheckBoxCtrl* mEditObjectRights; LLTextEditor* mNotesEditor; + LLTextBox* mCharacterLimitWarning; + + std::string mURLWebProfile; + + boost::signals2::connection mAvatarNameCacheConnection; }; diff --git a/indra/newview/skins/default/xui/en/panel_profile_notes.xml b/indra/newview/skins/default/xui/en/panel_profile_notes.xml index 0bafaac361..179fa0136c 100644 --- a/indra/newview/skins/default/xui/en/panel_profile_notes.xml +++ b/indra/newview/skins/default/xui/en/panel_profile_notes.xml @@ -9,6 +9,14 @@ follows="all" layout="topleft" > + + +Warning: Your notes contain more than 1000 characters. + + +Only first 1000 characters are shown here. If you edit your notes and click OK, the extra characters will be lost. To preserve the extra characters, you must edit it [[PROFILE_URL] on the web] + + + + Placeholder: Your notes contain more than 1000 characters. Only first 1000 characters are shown here. If you edit your notes and click OK, the extra characters will be lost. To preserve the extra characters, you must edit it [https://my.secondlife.com/settings/profile on the web] +