llimmgr.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * @file llimmgr.h
  3. * @brief Instant Messaging management
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLIMMGR_H
  33. #define LL_LLIMMGR_H
  34. #include "llfloater.h"
  35. #include "llinstantmessage.h"
  36. class LLFloaterChatterBox;
  37. class LLFloaterIM;
  38. class LLFloaterIMSession;
  39. class LLFriendObserver;
  40. class LLHost;
  41. class LLIMMgr
  42. {
  43. friend class LLViewerChatterBoxInvitation;
  44. protected:
  45. LOG_CLASS(LLIMMgr);
  46. public:
  47. enum EInvitationType
  48. {
  49. INVITATION_TYPE_INSTANT_MESSAGE = 0,
  50. INVITATION_TYPE_VOICE = 1,
  51. INVITATION_TYPE_IMMEDIATE = 2
  52. };
  53. LLIMMgr();
  54. virtual ~LLIMMgr();
  55. // Adds a message to a session. The session can be keyed to a session or
  56. // agent id. If link_name is true, then we insert the name and link to the
  57. // profile at the start of the message.
  58. void addMessage(const LLUUID& session_id, const LLUUID& target_id,
  59. const std::string& from, const std::string& msg,
  60. const std::string& session_name = LLStringUtil::null,
  61. EInstantMessage dialog = IM_NOTHING_SPECIAL,
  62. U32 parent_estate_id = 0,
  63. const LLUUID& region_id = LLUUID::null,
  64. const LLVector3& position = LLVector3::zero,
  65. bool link_name = false);
  66. void addSystemMessage(const LLUUID& session_id,
  67. const std::string& message_name, const LLSD& args);
  68. // Adds a session to the talk view. The name is the local name of the
  69. // session, dialog specifies the type of session. Since sessions can be
  70. // keyed off of first recipient or initiator, the session can be matched
  71. // against the id provided. If the session exists, it is brought forward.
  72. // This method accepts a group id or an agent id. Specifying id = NULL
  73. // results in an IM session to everyone. Returns the uuid of the session.
  74. LLUUID addSession(const std::string& name, EInstantMessage dialog,
  75. const LLUUID& other_participant_id,
  76. const LLSD& voice_call_info = LLSD());
  77. // Adds a session using a specific group of starting agents the dialog type
  78. // is assumed correct. Returns the uuid of the session.
  79. LLUUID addSession(const std::string& name, EInstantMessage dialog,
  80. const LLUUID& other_participant_id,
  81. const uuid_vec_t& ids,
  82. const LLSD& voice_call_info = LLSD());
  83. // Creates a P2P session with the requisite handle for responding to voice
  84. // calls
  85. LL_INLINE LLUUID addP2PSession(const std::string& name,
  86. const LLUUID& other_participant_id,
  87. const LLSD& voice_call_info)
  88. {
  89. return addSession(name, IM_NOTHING_SPECIAL, other_participant_id,
  90. voice_call_info);
  91. }
  92. // This leaves the session (by sending a message to the server, unless
  93. // snooze_duration is not zero), removes the panel referenced by session_id
  94. // and then restores internal consistency.
  95. void removeSession(const LLUUID& session_id, const LLUUID& other_part_id,
  96. U32 snooze_duration);
  97. void inviteToSession(const LLUUID& session_id,
  98. const std::string& session_name, const LLUUID& caller,
  99. const std::string& caller_name, EInstantMessage type,
  100. EInvitationType inv_type,
  101. const LLSD& voice_channel_info = LLSD());
  102. // Updates a given session's session IDs. Does not open, create or do
  103. // anything new. If the old session does not exist, then nothing happens.
  104. void updateFloaterSessionID(const LLUUID& old_session_id,
  105. const LLUUID& new_session_id);
  106. // Rebuild stuff
  107. void refresh();
  108. LL_INLINE void clearNewIMNotification()
  109. {
  110. mIMsReceived = 0;
  111. mPrivateIMReceived = false;
  112. }
  113. // IM received that you haven't seen yet
  114. LL_INLINE U32 getIMsReceived() const { return mIMsReceived; }
  115. LL_INLINE bool isPrivateIMReceived() const { return mPrivateIMReceived; }
  116. void setFloaterOpen(bool open);
  117. bool getFloaterOpen();
  118. LLFloaterChatterBox* getFloater();
  119. // This method is used to go through all active sessions and disable all of
  120. // them. This method is usally called when you are forced to log out or
  121. // similar situations where you do not have a good connection.
  122. void disconnectAllSessions();
  123. static void toggle(void*);
  124. // This is a helper function to determine what kind of IM session should be
  125. // used for the given agent.
  126. static EInstantMessage defaultIMTypeForAgent(const LLUUID& agent_id);
  127. static LLUUID computeSessionID(EInstantMessage dialog,
  128. const LLUUID& other_participant_id);
  129. void clearPendingInvitation(const LLUUID& session_id);
  130. LLSD getPendingAgentListUpdates(const LLUUID& session_id);
  131. void addPendingAgentListUpdates(const LLUUID& sessioN_id,
  132. const LLSD& updates);
  133. void clearPendingAgentListUpdates(const LLUUID& session_id);
  134. void processNewMessage(const LLUUID& from_id, bool from_group,
  135. const LLUUID& to_id, U8 offline,
  136. EInstantMessage dialog,
  137. const LLUUID& session_id, U32 timestamp,
  138. std::string name, std::string message,
  139. U32 parent_estate_id,const LLUUID& region_id,
  140. const LLVector3& position, U8* binary_bucket,
  141. S32 bucket_size, const LLHost& sender,
  142. const LLUUID& aux_id = LLUUID::null);
  143. static void deliverMessage(const std::string& utf8_text,
  144. const LLUUID& im_session_id,
  145. const LLUUID& other_participant_id,
  146. EInstantMessage dialog);
  147. static bool sendStartSessionMessages(const LLUUID& temp_session_id,
  148. const LLUUID& other_participant_id,
  149. const uuid_vec_t& ids,
  150. EInstantMessage dialog, bool use_p2p);
  151. // Used by llappviewer.cpp to request stored IMs on login
  152. static bool requestOfflineMessages();
  153. void processAgentListUpdates(const LLUUID& session_id, const LLSD& body);
  154. private:
  155. // Creates a panel and update internal representation for consistency.
  156. // Returns the pointer, caller (the class instance since it is a private
  157. // method) is not responsible for deleting the pointer.
  158. LLFloaterIMSession* createFloater(const LLUUID& session_id,
  159. const LLUUID& target_id,
  160. const std::string& name,
  161. EInstantMessage dialog,
  162. bool user_initiated = false);
  163. LLFloaterIMSession* createFloater(const LLUUID& session_id,
  164. const LLUUID& target_id,
  165. const std::string& name,
  166. const uuid_vec_t& ids,
  167. const LLSD& voice_call_info,
  168. EInstantMessage dialog,
  169. bool user_initiated = false);
  170. // This simple method just iterates through all of the ids, and prints a
  171. // simple message if they are not online. Used to help reduce 'hello'
  172. // messages to the Linden employees unlucky enough to have their calling
  173. // card in the default inventory.
  174. void noteOfflineUsers(LLFloaterIMSession* panel, const uuid_vec_t& ids);
  175. void noteMutedUsers(LLFloaterIMSession* panel, const uuid_vec_t& ids);
  176. // Returns true when the session for from_id does exist already.
  177. bool processIMTypingCore(EInstantMessage dialog, const LLUUID& from_id,
  178. const std::string& from_name, bool typing);
  179. static void onInviteNameLookup(const LLUUID& id,
  180. const std::string& full_name,
  181. bool is_group, LLSD payload);
  182. static bool inviteUserResponse(const LLSD& notification,
  183. const LLSD& response);
  184. static void chatterBoxInvitationCoro(const std::string& url,
  185. LLUUID session_id,
  186. LLIMMgr::EInvitationType type);
  187. static void startDeprecatedConference(const LLUUID& temp_session_id,
  188. const LLUUID& creator_id,
  189. const LLUUID& other_participant_id,
  190. const LLSD& agents_to_invite);
  191. static void startConferenceCoro(const std::string& url,
  192. LLUUID temp_session_id, LLUUID creator_id,
  193. LLUUID other_participant_id, LLSD agents);
  194. static void startP2PVoiceCoro(const std::string& url,
  195. LLUUID temp_session_id, LLUUID creator_id,
  196. LLUUID other_participant_id);
  197. static bool requestOfflineMessagesLegacy();
  198. static void requestOfflineMessagesCoro(const std::string& url);
  199. private:
  200. LLFriendObserver* mFriendObserver;
  201. typedef fast_hmap<LLUUID, F32> snoozed_map_t;
  202. snoozed_map_t mSnoozedSessions;
  203. LLSD mPendingInvitations;
  204. LLSD mPendingAgentListUpdates;
  205. // IMs have been received that you have not seen yet.
  206. U32 mIMsReceived;
  207. bool mPrivateIMReceived;
  208. };
  209. // Globals
  210. extern LLIMMgr* gIMMgrp;
  211. extern const std::string gIMFloaterName;
  212. #endif // LL_LLIMMGR_H