From 754c70770ace6829c154bfaae415ebf09e6c262b Mon Sep 17 00:00:00 2001 From: Siana Gearz Date: Thu, 3 Mar 2011 03:38:33 +0100 Subject: [PATCH] Ignore group chat, from Imprudence --- indra/newview/llappviewer.cpp | 2 + indra/newview/llimview.cpp | 130 ++++++++++++++++++ indra/newview/llimview.h | 12 ++ indra/newview/llpanelgroupgeneral.cpp | 27 ++++ indra/newview/llpanelgroupgeneral.h | 1 + indra/newview/llstartup.cpp | 3 + .../default/xui/en-us/panel_group_general.xml | 5 + 7 files changed, 180 insertions(+) diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index a3742afe1..34fbbdbd0 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -3654,6 +3654,8 @@ void LLAppViewer::idleShutdown() // close IM interface if(gIMMgr) { + // Save group chat ignore list -- MC + gIMMgr->saveIgnoreGroup(); gIMMgr->disconnectAllSessions(); } diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp index 1f7f1bb04..b1e7dd664 100644 --- a/indra/newview/llimview.cpp +++ b/indra/newview/llimview.cpp @@ -53,6 +53,7 @@ #include "llhttpnode.h" #include "llimpanel.h" #include "llresizebar.h" +#include "llsdserialize.h" #include "lltabcontainer.h" #include "llviewercontrol.h" #include "llfloater.h" @@ -605,6 +606,30 @@ void LLIMMgr::addMessage( // create IM window as necessary if(!floater) { + if (gIMMgr->getIgnoreGroupListCount() > 0 && gAgent.isInGroup(session_id)) + { + // Check to see if we're blocking this group's chat + LLGroupData* group_data = NULL; + + // Search for this group in the agent's groups list + LLDynamicArray::iterator i; + + for (i = gAgent.mGroups.begin(); i != gAgent.mGroups.end(); i++) + { + if (i->mID == session_id) + { + group_data = &*i; + break; + } + } + + // If the group is in our list then return + if (group_data && gIMMgr->getIgnoreGroup(group_data->mID)) + { + return; + } + } + std::string name = from; if(!session_name.empty() && session_name.size()>1) { @@ -1286,6 +1311,111 @@ void LLIMMgr::updateFloaterSessionID( } } +void LLIMMgr::loadIgnoreGroup() +{ + std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "ignore_groups.xml"); + + LLSD settings_llsd; + llifstream file; + file.open(filename); + if (file.is_open()) + { + // llinfos << "loading group chat ignore from " << filename << "..." << llendl; + LLSDSerialize::fromXML(settings_llsd, file); + + mIgnoreGroupList.clear(); + + for(LLSD::array_const_iterator iter = settings_llsd.beginArray(); + iter != settings_llsd.endArray(); ++iter) + { + // llinfos << "added " << iter->asUUID() + // << " to group chat ignore list" << llendl; + mIgnoreGroupList.push_back( iter->asUUID() ); + } + } + else + { + // llinfos << "can't load " << filename + // << " (probably it doesn't exist yet)" << llendl; + } +} + +void LLIMMgr::saveIgnoreGroup() +{ + // llinfos << "saving ignore_groups.xml" << llendl; + + std::string user_dir = gDirUtilp->getLindenUserDir(); + if (!user_dir.empty()) + { + std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "ignore_groups.xml"); + + LLSD settings_llsd = LLSD::emptyArray(); + + for(std::list::iterator iter = mIgnoreGroupList.begin(); + iter != mIgnoreGroupList.end(); ++iter) + { + settings_llsd.append(*iter); + } + + llofstream file; + file.open(filename); + LLSDSerialize::toPrettyXML(settings_llsd, file); + } +} + +void LLIMMgr::updateIgnoreGroup(const LLUUID& group_id, bool ignore) +{ + if (group_id.notNull()) + { + std::list::iterator found = + std::find( mIgnoreGroupList.begin(), mIgnoreGroupList.end(), + group_id); + + if (found != mIgnoreGroupList.end() && !ignore) + { + // change from ignored to not ignored + // llinfos << "unignoring group " << group_id << llendl; + mIgnoreGroupList.remove(group_id); + } + else if (found == mIgnoreGroupList.end() && ignore) + { + // change from not ignored to ignored + // llinfos << "ignoring group " << group_id << llendl; + mIgnoreGroupList.push_back(group_id); + } + else + { + // nothing to do + // llinfos << "no change to group " << group_id << ", it is already " + // << (ignore ? "" : "not ") << "ignored" << llendl; + } + } +} + +bool LLIMMgr::getIgnoreGroup(const LLUUID& group_id) +{ + if (group_id.notNull()) + { + std::list::iterator found = + std::find( mIgnoreGroupList.begin(), mIgnoreGroupList.end(), + group_id); + + if (found != mIgnoreGroupList.end()) + { + // llinfos << "group " << group_id << " is ignored." << llendl; + return true; + } + } + // llinfos << "group " << group_id << " is not ignored." << llendl; + return false; +} + + +////////////////////// +///// ChatterBox ///// +////////////////////// + + LLFloaterChatterBox* LLIMMgr::getFloater() { return LLFloaterChatterBox::getInstance(LLSD()); diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h index 115076bf3..e1052c273 100644 --- a/indra/newview/llimview.h +++ b/indra/newview/llimview.h @@ -172,6 +172,12 @@ public: //HACK: need a better way of enumerating existing session, or listening to session create/destroy events const std::set >& getIMFloaterHandles() { return mFloaters; } + void loadIgnoreGroup(); + void saveIgnoreGroup(); + void updateIgnoreGroup(const LLUUID& group_id, bool ignore); + // Returns true if group chat is ignored for the UUID, false if not + bool getIgnoreGroup(const LLUUID& group_id); + private: // create a panel and update internal representation for // consistency. Returns the pointer, caller (the class instance @@ -211,6 +217,12 @@ private: LLSD mPendingInvitations; LLSD mPendingAgentListUpdates; + + std::list mIgnoreGroupList; + +public: + + S32 getIgnoreGroupListCount() { return mIgnoreGroupList.size(); } }; diff --git a/indra/newview/llpanelgroupgeneral.cpp b/indra/newview/llpanelgroupgeneral.cpp index c19011014..f5dbfc6c7 100644 --- a/indra/newview/llpanelgroupgeneral.cpp +++ b/indra/newview/llpanelgroupgeneral.cpp @@ -45,6 +45,7 @@ #include "llcheckboxctrl.h" #include "llcombobox.h" #include "lldbstrings.h" +#include "llimview.h" #include "lllineeditor.h" #include "llnamebox.h" #include "llnamelistctrl.h" @@ -91,6 +92,7 @@ LLPanelGroupGeneral::LLPanelGroupGeneral(const std::string& name, mCtrlEnrollmentFee(NULL), mSpinEnrollmentFee(NULL), mCtrlReceiveNotices(NULL), + mCtrlReceiveChat(NULL), mCtrlListGroup(NULL), mActiveTitleLabel(NULL), mComboActiveTitle(NULL) @@ -219,6 +221,15 @@ BOOL LLPanelGroupGeneral::postBuild() mCtrlReceiveNotices->set(accept_notices); mCtrlReceiveNotices->setEnabled(data.mID.notNull()); } + + mCtrlReceiveChat = getChild("receive_chat", recurse); + if (mCtrlReceiveChat) + { + mCtrlReceiveChat->setCommitCallback(onCommitUserOnly); + mCtrlReceiveChat->setCallbackUserData(this); + mCtrlReceiveChat->set(!gIMMgr->getIgnoreGroup(mGroupID)); + mCtrlReceiveChat->setEnabled(mGroupID.notNull()); + } mCtrlListGroup = getChild("list_groups_in_profile", recurse); if (mCtrlListGroup) @@ -544,6 +555,14 @@ bool LLPanelGroupGeneral::apply(std::string& mesg) gAgent.setUserGroupFlags(mGroupID, receive_notices, list_in_profile); + if (mCtrlReceiveChat) + { + bool receive_chat = mCtrlReceiveChat->get(); + gIMMgr->updateIgnoreGroup(mGroupID, !receive_chat); + // Save here too in case we crash somewhere down the road -- MC + gIMMgr->saveIgnoreGroup(); + } + mChanged = FALSE; return true; @@ -760,6 +779,13 @@ void LLPanelGroupGeneral::update(LLGroupChange gc) mCtrlReceiveNotices->resetDirty(); } + if (mCtrlReceiveChat) + { + mCtrlReceiveChat->setVisible(is_member); + mCtrlReceiveChat->setEnabled(TRUE); + mCtrlReceiveChat->resetDirty(); + } + if (mInsignia) mInsignia->setEnabled(mAllowEdit && can_change_ident); if (mEditCharter) mEditCharter->setEnabled(mAllowEdit && can_change_ident); @@ -914,6 +940,7 @@ void LLPanelGroupGeneral::updateChanged() mCtrlEnrollmentFee, mSpinEnrollmentFee, mCtrlReceiveNotices, + mCtrlReceiveChat, mCtrlListGroup, mActiveTitleLabel, mComboActiveTitle diff --git a/indra/newview/llpanelgroupgeneral.h b/indra/newview/llpanelgroupgeneral.h index 71356677f..c4572e2d4 100644 --- a/indra/newview/llpanelgroupgeneral.h +++ b/indra/newview/llpanelgroupgeneral.h @@ -107,6 +107,7 @@ private: LLCheckBoxCtrl *mCtrlEnrollmentFee; LLSpinCtrl *mSpinEnrollmentFee; LLCheckBoxCtrl *mCtrlReceiveNotices; + LLCheckBoxCtrl *mCtrlReceiveChat; LLCheckBoxCtrl *mCtrlListGroup; LLTextBox *mActiveTitleLabel; LLComboBox *mComboActiveTitle; diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index b67178de1..9224cb5b0 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -119,6 +119,7 @@ #include "llhudmanager.h" #include "llhttpclient.h" #include "llimagebmp.h" +#include "llimview.h" // for gIMMgr #include "llinventorymodel.h" #include "llinventoryview.h" #include "llkeyboard.h" @@ -1833,6 +1834,8 @@ bool idle_startup() // OGPX : successful login path common to OGP and XML-RPC if (successful_login) { + gIMMgr->loadIgnoreGroup(); + // JC: gesture loading done below, when we have an asset system // in place. Don't delete/clear user_credentials until then. diff --git a/indra/newview/skins/default/xui/en-us/panel_group_general.xml b/indra/newview/skins/default/xui/en-us/panel_group_general.xml index eeeeb0afe..4580ed72e 100644 --- a/indra/newview/skins/default/xui/en-us/panel_group_general.xml +++ b/indra/newview/skins/default/xui/en-us/panel_group_general.xml @@ -137,6 +137,11 @@ Hover your mouse over the options for more help. mouse_opaque="true" name="receive_notices" radio_style="false" tool_tip="Sets whether you want to receive Notices from this group. Uncheck this box if this group is spamming you." width="95" /> +