Skip to content

Commit

Permalink
Merge pull request #63 from afallenhope/FLN-auto-respond
Browse files Browse the repository at this point in the history
FLN Auto Respond
  • Loading branch information
RyeMutt authored Sep 4, 2024
2 parents 387b577 + 7957ef9 commit 2c867cf
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 60 deletions.
68 changes: 67 additions & 1 deletion indra/newview/app_settings/settings_per_account_alchemy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,71 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>AlchemyAutoresponseChanged</key>
<map>
<key>Comment</key>
<string>Does user's autoresponse response message differ from default?</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>AlchemyAutoresponseEnable</key>
<map>
<key>Comment</key>
<string>Automatically respond when someone messages you</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>AlchemyAutoresponseNotFriendEnable</key>
<map>
<key>Comment</key>
<string>Automatically respond when someone messages you</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>AlchemyAutoresponse</key>
<map>
<key>Comment</key>
<string>Auto response to instant messages.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>String</string>
<key>Value</key>
<string>This resident has turned on &apos;Autorespond mode&apos; like a boss.</string>
</map>
<key>AlchemyAutoresponseNotFriendChanged</key>
<map>
<key>Comment</key>
<string>Does user's autoresponse not friend response message differ from default?</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>AlchemyAutoresponseNotFriend</key>
<map>
<key>Comment</key>
<string>Auto response to instant messages to strangers. Stranger danger!</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>String</string>
<key>Value</key>
<string>This resident has turned on &apos;Autorespond mode&apos; like a boss.</string>
</map>
</map>
</llsd>
</llsd>
39 changes: 39 additions & 0 deletions indra/newview/llagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ LLAgent::LLAgent() :
mShowAvatar(TRUE),
mFrameAgent(),

mIsAutoRespond(false),
mIsAutoRespondNonFriends(false),

mIsDoNotDisturb(false),
mIsRejectTeleportOffers(false),
mIgnorePrejump(FALSE),
Expand Down Expand Up @@ -1800,6 +1803,42 @@ BOOL LLAgent::getRejectFriendshipRequests() const
return mIsRejectFriendshipRequests;
}

//-----------------------------------------------------------------------------
// setAutoRespond()
//-----------------------------------------------------------------------------
void LLAgent::setAutoRespond(bool pIsAutoRespond)
{
LL_INFOS() << "Setting autorespond mode to " << pIsAutoRespond << LL_ENDL;
mIsAutoRespond = pIsAutoRespond;
gSavedPerAccountSettings.setBOOL("AlchemyAutoresponseEnable", pIsAutoRespond);
}

//-----------------------------------------------------------------------------
// getAutoRespond()
//-----------------------------------------------------------------------------
bool LLAgent::getAutoRespond() const
{
return mIsAutoRespond;
}

//-----------------------------------------------------------------------------
// setAutoRespondNonFriends()
//-----------------------------------------------------------------------------
void LLAgent::setAutoRespondNonFriends(bool pIsAutoRespondNonFriends)
{
LL_INFOS() << "Setting AutoRespondingNonFriends mode to " << pIsAutoRespondNonFriends << LL_ENDL;
mIsAutoRespondNonFriends = pIsAutoRespondNonFriends;
gSavedPerAccountSettings.setBOOL("AlchemyAutoresponseNotFriendEnable", pIsAutoRespondNonFriends);
}

//-----------------------------------------------------------------------------
// getAutoRespondNonFriends()
//-----------------------------------------------------------------------------
bool LLAgent::getAutoRespondNonFriends() const
{
return mIsAutoRespondNonFriends;
}

//-----------------------------------------------------------------------------
// startAutoPilotGlobal()
//-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions indra/newview/llagent.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ class LLAgent final : public LLOldEvents::LLObservable
private:
BOOL mIsRejectFriendshipRequests;

public:
void setAutoRespond(bool pIsAutoRespond);
bool getAutoRespond() const;
private:
BOOL mIsAutoRespond;

public:
void setAutoRespondNonFriends(bool pIsAutoRespondNonFriends);
bool getAutoRespondNonFriends() const;
private:
BOOL mIsAutoRespondNonFriends;

//--------------------------------------------------------------------
// Grab
//--------------------------------------------------------------------
Expand Down
49 changes: 49 additions & 0 deletions indra/newview/llfloaterpreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ BOOL LLFloaterPreference::postBuild()
gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
gSavedPerAccountSettings.setString("ALRejectTeleportOffersResponse", LLTrans::getString("RejectTeleportOffersResponseDefault"));
gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));

gSavedPerAccountSettings.setString("AlchemyAutoresponse", LLTrans::getString("AutoResponseModeDefault"));
gSavedPerAccountSettings.setString("AlchemyAutoresponseNotFriend", LLTrans::getString("AutoResponseModeNonFriendsDefault"));
}

// set 'enable' property for 'Clear log...' button
Expand Down Expand Up @@ -574,6 +577,24 @@ void LLFloaterPreference::onRejectTeleportOffersResponseChanged()
gSavedPerAccountSettings.setBOOL("ALRejectTeleportOffersResponseChanged", reject_teleport_offers_response_changed_flag);
}

void LLFloaterPreference::onAutoRespondResponseChanged()
{
bool auto_response_changed_flag =
LLTrans::getString("AutoResponseModeDefault")
!= getChild<LLUICtrl>("autorespond_response")->getValue().asString();

gSavedPerAccountSettings.setBOOL("AlchemyAutoresponseChanged", auto_response_changed_flag);
}

void LLFloaterPreference::onAutoRespondNonFriendsResponseChanged()
{
bool auto_response_non_friends_changed_flag =
LLTrans::getString("AutoResponseModeNonFriendsDefault")
!= getChild<LLUICtrl>("AlchemyAutoresponseNotFriend")->getValue().asString();

gSavedPerAccountSettings.setBOOL("AlchemyAutoresponseNotFriendChanged", auto_response_non_friends_changed_flag);
}

#if !LL_HAVOK
////////////////////////////////////////////////////
// Grid panel
Expand Down Expand Up @@ -951,6 +972,8 @@ LLFloaterPreference::~LLFloaterPreference()
mComplexityChangedSignal.disconnect();
mDnDModeConnection.disconnect();
mRejectTeleportConnection.disconnect();
mAutoResponseConnection.disconnect();
mAutoResponseNonFriendsConnection.disconnect();
}

void LLFloaterPreference::draw()
Expand Down Expand Up @@ -1037,6 +1060,15 @@ void LLFloaterPreference::apply()
}
}

// Setting this up so we sync the settings with menu.
// i.e Checking the checkox form the Preferences will also check it in the menu.
// --FLN
bool autoresponse_enabled = getChild<LLCheckBoxCtrl>("AlchemyAutoresponseEnable")->get();
bool autoresponse_notfriends_enabled = getChild<LLCheckBoxCtrl>("AlchemyAutoresponseNotFriendEnable")->get();

gAgent.setAutoRespond(autoresponse_enabled);
gAgent.setAutoRespondNonFriends(autoresponse_notfriends_enabled);

saveAvatarProperties();
}

Expand Down Expand Up @@ -1113,6 +1145,10 @@ void LLFloaterPreference::onOpen(const LLSD& key)

mRejectTeleportConnection = gSavedPerAccountSettings.getControl("ALRejectTeleportOffersResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onRejectTeleportOffersResponseChanged, this));

mAutoResponseConnection = gSavedPerAccountSettings.getControl("AlchemyAutoresponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onAutoRespondResponseChanged, this));

mAutoResponseNonFriendsConnection = gSavedPerAccountSettings.getControl("AlchemyAutoresponseNotFriend")->getSignal()->connect(boost::bind(&LLFloaterPreference::onAutoRespondNonFriendsResponseChanged, this));

}
gAgent.sendAgentUserInfoRequest();

Expand Down Expand Up @@ -1227,6 +1263,19 @@ void LLFloaterPreference::initDoNotDisturbResponse()
{
gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));
}

// This is called on viewer init so we setup defaults
// not sure this is necessary anymore ???
// -- FLN
if (!gSavedPerAccountSettings.getBOOL("AlchemyAutoresponseChanged"))
{
gSavedPerAccountSettings.setString("AlchemyAutoresponse", LLTrans::getString("AlchemyAutoresponseDefault"));
}

if (!gSavedPerAccountSettings.getBOOL("AlchemyAutoresponseNotFriendChanged"))
{
gSavedPerAccountSettings.setString("AlchemyAutoresponseNotFriend", LLTrans::getString("AlchemyAutoresponseNotFriendDefault"));
}
}

//static
Expand Down
5 changes: 5 additions & 0 deletions indra/newview/llfloaterpreference.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class LLFloaterPreference final : public LLFloater, public LLAvatarPropertiesObs
// string differs from default after user changes.
void onDoNotDisturbResponseChanged();
void onRejectTeleportOffersResponseChanged();
void onAutoRespondResponseChanged();
void onAutoRespondNonFriendsResponseChanged();

// if the custom settings box is clicked
void onChangeCustom();
void updateMeterText(LLUICtrl* ctrl);
Expand Down Expand Up @@ -267,6 +270,8 @@ class LLFloaterPreference final : public LLFloater, public LLAvatarPropertiesObs
boost::signals2::connection mRejectTeleportConnection;
boost::signals2::connection mChatBubbleOpacityConnection;
boost::signals2::connection mPreferredMaturityConnection;
boost::signals2::connection mAutoResponseConnection;
boost::signals2::connection mAutoResponseNonFriendsConnection;

bool mDnDInit = false;

Expand Down
95 changes: 95 additions & 0 deletions indra/newview/llimprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "llimprocessing.h"

#include "llagent.h"
#include "llagentui.h"
#include "llappviewer.h"
#include "llavatarnamecache.h"
#include "llfirstuse.h"
Expand Down Expand Up @@ -64,8 +65,28 @@
#include "rlvui.h"
// [/RLVa:KB]

#include <boost/algorithm/string/predicate.hpp> // <alchemy/>
#include <boost/algorithm/string/replace.hpp>
#include "boost/lexical_cast.hpp"



// Resurrect the Autorespond from the archive
// -- FLN
std::string replace_wildcards(std::string input, const LLUUID& id, const std::string& name)
{
boost::algorithm::replace_all(input, "#n", name);
// disable boost::lexical_cast warning
LLSLURL slurl;
LLAgentUI::buildSLURL(slurl);
boost::algorithm::replace_all(input, "#r", slurl.getSLURLString());

LLAvatarName av_name;
boost::algorithm::replace_all(input, "#d", LLAvatarNameCache::get(id, &av_name) ? av_name.getDisplayName() : name);
return input;
}


extern void on_new_message(const LLSD& msg);

// Strip out "Resident" for display, but only if the message came from a user
Expand Down Expand Up @@ -532,6 +553,11 @@ void LLIMProcessing::processNewMessage(LLUUID from_id,
BOOL is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
LLMuteList::isLinden(name);

// Resurrect AutoResponse from Alchemy Archive
// -- FLN
static LLCachedControl<bool> sAutorespond(gSavedPerAccountSettings, "AlchemyAutoresponseEnable");
static LLCachedControl<bool> sAutorespondNonFriend(gSavedPerAccountSettings, "AlchemyAutoresponseNotFriendEnable");

chat.mMuted = is_muted;
chat.mFromID = from_id;
chat.mFromName = name;
Expand Down Expand Up @@ -625,6 +651,49 @@ void LLIMProcessing::processNewMessage(LLUUID from_id,
}

}
else if (offline == IM_ONLINE
&& (sAutorespond || (sAutorespondNonFriend && !is_friend))
&& from_id.notNull() //not a system message
&& to_id.notNull()) //not global message
{
buffer = message;
LL_DEBUGS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
bool send_response = !gIMMgr->hasSession(session_id);
gIMMgr->addMessage(session_id,
from_id,
name,
buffer,
IM_OFFLINE == offline,
LLStringUtil::null,
dialog,
parent_estate_id,
region_id,
position,
true);
if (send_response)
{
std::string my_name;
LLAgentUI::buildFullname(my_name);
std::string response = gSavedPerAccountSettings.getString(sAutorespondNonFriend && !is_friend
? "AlchemyAutoresponseNotFriend"
: "AlchemyAutoresponse");
response = replace_wildcards(response, from_id, name);
pack_instant_message(
gMessageSystem,
gAgent.getID(),
FALSE,
gAgent.getSessionID(),
from_id,
my_name,
response,
IM_ONLINE,
IM_DO_NOT_DISTURB_AUTO_RESPONSE,
session_id);
gAgent.sendReliableMessage();
gIMMgr->addMessage(session_id, gAgent.getID(), my_name, LLTrans::getString("AutoresponsePrefix").append(response));
}
}

else if (from_id.isNull())
{
LLSD args;
Expand Down Expand Up @@ -733,6 +802,32 @@ void LLIMProcessing::processNewMessage(LLUUID from_id,
false,
0
);

// Resurrect Autorespond from Alchemy archive
// -- FLN
if (sAutorespond || (sAutorespondNonFriend && !is_friend))
{
std::string my_name;
LLAgentUI::buildFullname(my_name);
std::string response = gSavedPerAccountSettings.getString(sAutorespondNonFriend && !is_friend
? "AlchemyAutoresponseNotFriend"
: "AlchemyAutoresponse");
response = replace_wildcards(response, from_id, name);
pack_instant_message(gMessageSystem,
gAgent.getID(),
FALSE,
gAgent.getSessionID(),
from_id,
my_name,
response,
IM_ONLINE,
IM_DO_NOT_DISTURB_AUTO_RESPONSE,
session_id);
gAgent.sendReliableMessage();

gIMMgr->addMessage(session_id, gAgent.getID(), my_name, LLTrans::getString("AutoresponsePrefix").append(response));
}

}

gIMMgr->processIMTypingStart(from_id, dialog);
Expand Down
6 changes: 6 additions & 0 deletions indra/newview/llimprocessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ class LLIMProcessing
static void requestOfflineMessagesLegacy();
};

// Resurrect the Autorespond from the archive
// -- FLN
// Replace wild cards in message strings
std::string replace_wildcards(std::string input, const LLUUID& id, const std::string& name);



#endif // LL_LLLLIMPROCESSING_H
Loading

0 comments on commit 2c867cf

Please # to comment.