PageRenderTime 646ms CodeModel.GetById 187ms app.highlight 227ms RepoModel.GetById 228ms app.codeStats 1ms

/indra/newview/llgroupactions.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 414 lines | 301 code | 60 blank | 53 comment | 50 complexity | c1e3e73e52740493cc0dc6104c9d905d MD5 | raw file
  1/** 
  2 * @file llgroupactions.cpp
  3 * @brief Group-related actions (join, leave, new, delete, etc)
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llgroupactions.h"
 31
 32#include "message.h"
 33
 34#include "llagent.h"
 35#include "llcommandhandler.h"
 36#include "llfloaterreg.h"
 37#include "llfloatersidepanelcontainer.h"
 38#include "llgroupmgr.h"
 39#include "llimview.h" // for gIMMgr
 40#include "llnotificationsutil.h"
 41#include "llstatusbar.h"	// can_afford_transaction()
 42#include "llimfloater.h"
 43#include "groupchatlistener.h"
 44
 45//
 46// Globals
 47//
 48static GroupChatListener sGroupChatListener;
 49
 50class LLGroupHandler : public LLCommandHandler
 51{
 52public:
 53	// requires trusted browser to trigger
 54	LLGroupHandler() : LLCommandHandler("group", UNTRUSTED_THROTTLE) { }
 55	bool handle(const LLSD& tokens, const LLSD& query_map,
 56				LLMediaCtrl* web)
 57	{
 58		if (!LLUI::sSettingGroups["config"]->getBOOL("EnableGroupInfo"))
 59		{
 60			LLNotificationsUtil::add("NoGroupInfo", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
 61			return true;
 62		}
 63
 64		if (tokens.size() < 1)
 65		{
 66			return false;
 67		}
 68
 69		if (tokens[0].asString() == "create")
 70		{
 71			LLGroupActions::createGroup();
 72			return true;
 73		}
 74
 75		if (tokens.size() < 2)
 76		{
 77			return false;
 78		}
 79
 80		if (tokens[0].asString() == "list")
 81		{
 82			if (tokens[1].asString() == "show")
 83			{
 84				LLSD params;
 85				params["people_panel_tab_name"] = "groups_panel";
 86				LLFloaterSidePanelContainer::showPanel("people", "panel_people", params);
 87				return true;
 88			}
 89            return false;
 90		}
 91
 92		LLUUID group_id;
 93		if (!group_id.set(tokens[0], FALSE))
 94		{
 95			return false;
 96		}
 97
 98		if (tokens[1].asString() == "about")
 99		{
100			if (group_id.isNull())
101				return true;
102
103			LLGroupActions::show(group_id);
104
105			return true;
106		}
107		if (tokens[1].asString() == "inspect")
108		{
109			if (group_id.isNull())
110				return true;
111			LLGroupActions::inspect(group_id);
112			return true;
113		}
114		return false;
115	}
116};
117LLGroupHandler gGroupHandler;
118
119// static
120void LLGroupActions::search()
121{
122	LLFloaterReg::showInstance("search", LLSD().with("category", "groups"));
123}
124
125// static
126void LLGroupActions::startCall(const LLUUID& group_id)
127{
128	// create a new group voice session
129	LLGroupData gdata;
130
131	if (!gAgent.getGroupData(group_id, gdata))
132	{
133		llwarns << "Error getting group data" << llendl;
134		return;
135	}
136
137	LLUUID session_id = gIMMgr->addSession(gdata.mName, IM_SESSION_GROUP_START, group_id, true);
138	if (session_id == LLUUID::null)
139	{
140		llwarns << "Error adding session" << llendl;
141		return;
142	}
143
144	// start the call
145	gIMMgr->autoStartCallOnStartup(session_id);
146
147	make_ui_sound("UISndStartIM");
148}
149
150// static
151void LLGroupActions::join(const LLUUID& group_id)
152{
153	if (!gAgent.canJoinGroups())
154	{
155		LLNotificationsUtil::add("JoinedTooManyGroups");
156		return;
157	}
158
159	LLGroupMgrGroupData* gdatap = 
160		LLGroupMgr::getInstance()->getGroupData(group_id);
161
162	if (gdatap)
163	{
164		S32 cost = gdatap->mMembershipFee;
165		LLSD args;
166		args["COST"] = llformat("%d", cost);
167		args["NAME"] = gdatap->mName;
168		LLSD payload;
169		payload["group_id"] = group_id;
170
171		if (can_afford_transaction(cost))
172		{
173			if(cost > 0)
174				LLNotificationsUtil::add("JoinGroupCanAfford", args, payload, onJoinGroup);
175			else
176				LLNotificationsUtil::add("JoinGroupNoCost", args, payload, onJoinGroup);
177				
178		}
179		else
180		{
181			LLNotificationsUtil::add("JoinGroupCannotAfford", args, payload);
182		}
183	}
184	else
185	{
186		llwarns << "LLGroupMgr::getInstance()->getGroupData(" << group_id 
187			<< ") was NULL" << llendl;
188	}
189}
190
191// static
192bool LLGroupActions::onJoinGroup(const LLSD& notification, const LLSD& response)
193{
194	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
195
196	if (option == 1)
197	{
198		// user clicked cancel
199		return false;
200	}
201
202	LLGroupMgr::getInstance()->
203		sendGroupMemberJoin(notification["payload"]["group_id"].asUUID());
204	return false;
205}
206
207// static
208void LLGroupActions::leave(const LLUUID& group_id)
209{
210	if (group_id.isNull())
211		return;
212
213	S32 count = gAgent.mGroups.count();
214	S32 i;
215	for (i = 0; i < count; ++i)
216	{
217		if(gAgent.mGroups.get(i).mID == group_id)
218			break;
219	}
220	if (i < count)
221	{
222		LLSD args;
223		args["GROUP"] = gAgent.mGroups.get(i).mName;
224		LLSD payload;
225		payload["group_id"] = group_id;
226		LLNotificationsUtil::add("GroupLeaveConfirmMember", args, payload, onLeaveGroup);
227	}
228}
229
230// static
231void LLGroupActions::activate(const LLUUID& group_id)
232{
233	LLMessageSystem* msg = gMessageSystem;
234	msg->newMessageFast(_PREHASH_ActivateGroup);
235	msg->nextBlockFast(_PREHASH_AgentData);
236	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
237	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
238	msg->addUUIDFast(_PREHASH_GroupID, group_id);
239	gAgent.sendReliableMessage();
240}
241
242static bool isGroupUIVisible()
243{
244	static LLPanel* panel = 0;
245	if(!panel)
246		panel = LLFloaterSidePanelContainer::getPanel("people", "panel_group_info_sidetray");
247	if(!panel)
248		return false;
249	return panel->isInVisibleChain();
250}
251
252// static 
253void LLGroupActions::inspect(const LLUUID& group_id)
254{
255	LLFloaterReg::showInstance("inspect_group", LLSD().with("group_id", group_id));
256}
257
258// static
259void LLGroupActions::show(const LLUUID& group_id)
260{
261	if (group_id.isNull())
262		return;
263
264	LLSD params;
265	params["group_id"] = group_id;
266	params["open_tab_name"] = "panel_group_info_sidetray";
267
268	LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
269}
270
271void LLGroupActions::refresh_notices()
272{
273	if(!isGroupUIVisible())
274		return;
275
276	LLSD params;
277	params["group_id"] = LLUUID::null;
278	params["open_tab_name"] = "panel_group_info_sidetray";
279	params["action"] = "refresh_notices";
280
281	LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
282}
283
284//static 
285void LLGroupActions::refresh(const LLUUID& group_id)
286{
287	if(!isGroupUIVisible())
288		return;
289
290	LLSD params;
291	params["group_id"] = group_id;
292	params["open_tab_name"] = "panel_group_info_sidetray";
293	params["action"] = "refresh";
294
295	LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
296}
297
298//static 
299void LLGroupActions::createGroup()
300{
301	LLSD params;
302	params["group_id"] = LLUUID::null;
303	params["open_tab_name"] = "panel_group_info_sidetray";
304	params["action"] = "create";
305
306	LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
307
308}
309//static
310void LLGroupActions::closeGroup(const LLUUID& group_id)
311{
312	if(!isGroupUIVisible())
313		return;
314
315	LLSD params;
316	params["group_id"] = group_id;
317	params["open_tab_name"] = "panel_group_info_sidetray";
318	params["action"] = "close";
319
320	LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
321}
322
323
324// static
325LLUUID LLGroupActions::startIM(const LLUUID& group_id)
326{
327	if (group_id.isNull()) return LLUUID::null;
328
329	LLGroupData group_data;
330	if (gAgent.getGroupData(group_id, group_data))
331	{
332		LLUUID session_id = gIMMgr->addSession(
333			group_data.mName,
334			IM_SESSION_GROUP_START,
335			group_id);
336		if (session_id != LLUUID::null)
337		{
338			LLIMFloater::show(session_id);
339		}
340		make_ui_sound("UISndStartIM");
341		return session_id;
342	}
343	else
344	{
345		// this should never happen, as starting a group IM session
346		// relies on you belonging to the group and hence having the group data
347		make_ui_sound("UISndInvalidOp");
348		return LLUUID::null;
349	}
350}
351
352// static
353void LLGroupActions::endIM(const LLUUID& group_id)
354{
355	if (group_id.isNull())
356		return;
357	
358	LLUUID session_id = gIMMgr->computeSessionID(IM_SESSION_GROUP_START, group_id);
359	if (session_id != LLUUID::null)
360	{
361		gIMMgr->leaveSession(session_id);
362	}
363}
364
365// static
366bool LLGroupActions::isInGroup(const LLUUID& group_id)
367{
368	// *TODO: Move all the LLAgent group stuff into another class, such as
369	// this one.
370	return gAgent.isInGroup(group_id);
371}
372
373// static
374bool LLGroupActions::isAvatarMemberOfGroup(const LLUUID& group_id, const LLUUID& avatar_id)
375{
376	if(group_id.isNull() || avatar_id.isNull())
377	{
378		return false;
379	}
380
381	LLGroupMgrGroupData* group_data = LLGroupMgr::getInstance()->getGroupData(group_id);
382	if(!group_data)
383	{
384		return false;
385	}
386
387	if(group_data->mMembers.end() == group_data->mMembers.find(avatar_id))
388	{
389		return false;
390	}
391
392	return true;
393}
394
395//-- Private methods ----------------------------------------------------------
396
397// static
398bool LLGroupActions::onLeaveGroup(const LLSD& notification, const LLSD& response)
399{
400	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
401	LLUUID group_id = notification["payload"]["group_id"].asUUID();
402	if(option == 0)
403	{
404		LLMessageSystem* msg = gMessageSystem;
405		msg->newMessageFast(_PREHASH_LeaveGroupRequest);
406		msg->nextBlockFast(_PREHASH_AgentData);
407		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
408		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
409		msg->nextBlockFast(_PREHASH_GroupData);
410		msg->addUUIDFast(_PREHASH_GroupID, group_id);
411		gAgent.sendReliableMessage();
412	}
413	return false;
414}