PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llgroupactions.h"
  28. #include "message.h"
  29. #include "llagent.h"
  30. #include "llcommandhandler.h"
  31. #include "llfloaterreg.h"
  32. #include "llfloatersidepanelcontainer.h"
  33. #include "llgroupmgr.h"
  34. #include "llimview.h" // for gIMMgr
  35. #include "llnotificationsutil.h"
  36. #include "llstatusbar.h" // can_afford_transaction()
  37. #include "llimfloater.h"
  38. #include "groupchatlistener.h"
  39. //
  40. // Globals
  41. //
  42. static GroupChatListener sGroupChatListener;
  43. class LLGroupHandler : public LLCommandHandler
  44. {
  45. public:
  46. // requires trusted browser to trigger
  47. LLGroupHandler() : LLCommandHandler("group", UNTRUSTED_THROTTLE) { }
  48. bool handle(const LLSD& tokens, const LLSD& query_map,
  49. LLMediaCtrl* web)
  50. {
  51. if (!LLUI::sSettingGroups["config"]->getBOOL("EnableGroupInfo"))
  52. {
  53. LLNotificationsUtil::add("NoGroupInfo", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
  54. return true;
  55. }
  56. if (tokens.size() < 1)
  57. {
  58. return false;
  59. }
  60. if (tokens[0].asString() == "create")
  61. {
  62. LLGroupActions::createGroup();
  63. return true;
  64. }
  65. if (tokens.size() < 2)
  66. {
  67. return false;
  68. }
  69. if (tokens[0].asString() == "list")
  70. {
  71. if (tokens[1].asString() == "show")
  72. {
  73. LLSD params;
  74. params["people_panel_tab_name"] = "groups_panel";
  75. LLFloaterSidePanelContainer::showPanel("people", "panel_people", params);
  76. return true;
  77. }
  78. return false;
  79. }
  80. LLUUID group_id;
  81. if (!group_id.set(tokens[0], FALSE))
  82. {
  83. return false;
  84. }
  85. if (tokens[1].asString() == "about")
  86. {
  87. if (group_id.isNull())
  88. return true;
  89. LLGroupActions::show(group_id);
  90. return true;
  91. }
  92. if (tokens[1].asString() == "inspect")
  93. {
  94. if (group_id.isNull())
  95. return true;
  96. LLGroupActions::inspect(group_id);
  97. return true;
  98. }
  99. return false;
  100. }
  101. };
  102. LLGroupHandler gGroupHandler;
  103. // static
  104. void LLGroupActions::search()
  105. {
  106. LLFloaterReg::showInstance("search", LLSD().with("category", "groups"));
  107. }
  108. // static
  109. void LLGroupActions::startCall(const LLUUID& group_id)
  110. {
  111. // create a new group voice session
  112. LLGroupData gdata;
  113. if (!gAgent.getGroupData(group_id, gdata))
  114. {
  115. llwarns << "Error getting group data" << llendl;
  116. return;
  117. }
  118. LLUUID session_id = gIMMgr->addSession(gdata.mName, IM_SESSION_GROUP_START, group_id, true);
  119. if (session_id == LLUUID::null)
  120. {
  121. llwarns << "Error adding session" << llendl;
  122. return;
  123. }
  124. // start the call
  125. gIMMgr->autoStartCallOnStartup(session_id);
  126. make_ui_sound("UISndStartIM");
  127. }
  128. // static
  129. void LLGroupActions::join(const LLUUID& group_id)
  130. {
  131. if (!gAgent.canJoinGroups())
  132. {
  133. LLNotificationsUtil::add("JoinedTooManyGroups");
  134. return;
  135. }
  136. LLGroupMgrGroupData* gdatap =
  137. LLGroupMgr::getInstance()->getGroupData(group_id);
  138. if (gdatap)
  139. {
  140. S32 cost = gdatap->mMembershipFee;
  141. LLSD args;
  142. args["COST"] = llformat("%d", cost);
  143. args["NAME"] = gdatap->mName;
  144. LLSD payload;
  145. payload["group_id"] = group_id;
  146. if (can_afford_transaction(cost))
  147. {
  148. if(cost > 0)
  149. LLNotificationsUtil::add("JoinGroupCanAfford", args, payload, onJoinGroup);
  150. else
  151. LLNotificationsUtil::add("JoinGroupNoCost", args, payload, onJoinGroup);
  152. }
  153. else
  154. {
  155. LLNotificationsUtil::add("JoinGroupCannotAfford", args, payload);
  156. }
  157. }
  158. else
  159. {
  160. llwarns << "LLGroupMgr::getInstance()->getGroupData(" << group_id
  161. << ") was NULL" << llendl;
  162. }
  163. }
  164. // static
  165. bool LLGroupActions::onJoinGroup(const LLSD& notification, const LLSD& response)
  166. {
  167. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  168. if (option == 1)
  169. {
  170. // user clicked cancel
  171. return false;
  172. }
  173. LLGroupMgr::getInstance()->
  174. sendGroupMemberJoin(notification["payload"]["group_id"].asUUID());
  175. return false;
  176. }
  177. // static
  178. void LLGroupActions::leave(const LLUUID& group_id)
  179. {
  180. if (group_id.isNull())
  181. return;
  182. S32 count = gAgent.mGroups.count();
  183. S32 i;
  184. for (i = 0; i < count; ++i)
  185. {
  186. if(gAgent.mGroups.get(i).mID == group_id)
  187. break;
  188. }
  189. if (i < count)
  190. {
  191. LLSD args;
  192. args["GROUP"] = gAgent.mGroups.get(i).mName;
  193. LLSD payload;
  194. payload["group_id"] = group_id;
  195. LLNotificationsUtil::add("GroupLeaveConfirmMember", args, payload, onLeaveGroup);
  196. }
  197. }
  198. // static
  199. void LLGroupActions::activate(const LLUUID& group_id)
  200. {
  201. LLMessageSystem* msg = gMessageSystem;
  202. msg->newMessageFast(_PREHASH_ActivateGroup);
  203. msg->nextBlockFast(_PREHASH_AgentData);
  204. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  205. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  206. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  207. gAgent.sendReliableMessage();
  208. }
  209. static bool isGroupUIVisible()
  210. {
  211. static LLPanel* panel = 0;
  212. if(!panel)
  213. panel = LLFloaterSidePanelContainer::getPanel("people", "panel_group_info_sidetray");
  214. if(!panel)
  215. return false;
  216. return panel->isInVisibleChain();
  217. }
  218. // static
  219. void LLGroupActions::inspect(const LLUUID& group_id)
  220. {
  221. LLFloaterReg::showInstance("inspect_group", LLSD().with("group_id", group_id));
  222. }
  223. // static
  224. void LLGroupActions::show(const LLUUID& group_id)
  225. {
  226. if (group_id.isNull())
  227. return;
  228. LLSD params;
  229. params["group_id"] = group_id;
  230. params["open_tab_name"] = "panel_group_info_sidetray";
  231. LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
  232. }
  233. void LLGroupActions::refresh_notices()
  234. {
  235. if(!isGroupUIVisible())
  236. return;
  237. LLSD params;
  238. params["group_id"] = LLUUID::null;
  239. params["open_tab_name"] = "panel_group_info_sidetray";
  240. params["action"] = "refresh_notices";
  241. LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
  242. }
  243. //static
  244. void LLGroupActions::refresh(const LLUUID& group_id)
  245. {
  246. if(!isGroupUIVisible())
  247. return;
  248. LLSD params;
  249. params["group_id"] = group_id;
  250. params["open_tab_name"] = "panel_group_info_sidetray";
  251. params["action"] = "refresh";
  252. LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
  253. }
  254. //static
  255. void LLGroupActions::createGroup()
  256. {
  257. LLSD params;
  258. params["group_id"] = LLUUID::null;
  259. params["open_tab_name"] = "panel_group_info_sidetray";
  260. params["action"] = "create";
  261. LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
  262. }
  263. //static
  264. void LLGroupActions::closeGroup(const LLUUID& group_id)
  265. {
  266. if(!isGroupUIVisible())
  267. return;
  268. LLSD params;
  269. params["group_id"] = group_id;
  270. params["open_tab_name"] = "panel_group_info_sidetray";
  271. params["action"] = "close";
  272. LLFloaterSidePanelContainer::showPanel("people", "panel_group_info_sidetray", params);
  273. }
  274. // static
  275. LLUUID LLGroupActions::startIM(const LLUUID& group_id)
  276. {
  277. if (group_id.isNull()) return LLUUID::null;
  278. LLGroupData group_data;
  279. if (gAgent.getGroupData(group_id, group_data))
  280. {
  281. LLUUID session_id = gIMMgr->addSession(
  282. group_data.mName,
  283. IM_SESSION_GROUP_START,
  284. group_id);
  285. if (session_id != LLUUID::null)
  286. {
  287. LLIMFloater::show(session_id);
  288. }
  289. make_ui_sound("UISndStartIM");
  290. return session_id;
  291. }
  292. else
  293. {
  294. // this should never happen, as starting a group IM session
  295. // relies on you belonging to the group and hence having the group data
  296. make_ui_sound("UISndInvalidOp");
  297. return LLUUID::null;
  298. }
  299. }
  300. // static
  301. void LLGroupActions::endIM(const LLUUID& group_id)
  302. {
  303. if (group_id.isNull())
  304. return;
  305. LLUUID session_id = gIMMgr->computeSessionID(IM_SESSION_GROUP_START, group_id);
  306. if (session_id != LLUUID::null)
  307. {
  308. gIMMgr->leaveSession(session_id);
  309. }
  310. }
  311. // static
  312. bool LLGroupActions::isInGroup(const LLUUID& group_id)
  313. {
  314. // *TODO: Move all the LLAgent group stuff into another class, such as
  315. // this one.
  316. return gAgent.isInGroup(group_id);
  317. }
  318. // static
  319. bool LLGroupActions::isAvatarMemberOfGroup(const LLUUID& group_id, const LLUUID& avatar_id)
  320. {
  321. if(group_id.isNull() || avatar_id.isNull())
  322. {
  323. return false;
  324. }
  325. LLGroupMgrGroupData* group_data = LLGroupMgr::getInstance()->getGroupData(group_id);
  326. if(!group_data)
  327. {
  328. return false;
  329. }
  330. if(group_data->mMembers.end() == group_data->mMembers.find(avatar_id))
  331. {
  332. return false;
  333. }
  334. return true;
  335. }
  336. //-- Private methods ----------------------------------------------------------
  337. // static
  338. bool LLGroupActions::onLeaveGroup(const LLSD& notification, const LLSD& response)
  339. {
  340. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  341. LLUUID group_id = notification["payload"]["group_id"].asUUID();
  342. if(option == 0)
  343. {
  344. LLMessageSystem* msg = gMessageSystem;
  345. msg->newMessageFast(_PREHASH_LeaveGroupRequest);
  346. msg->nextBlockFast(_PREHASH_AgentData);
  347. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  348. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  349. msg->nextBlockFast(_PREHASH_GroupData);
  350. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  351. gAgent.sendReliableMessage();
  352. }
  353. return false;
  354. }