/indra/newview/llmutelist.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 178 lines · 97 code · 37 blank · 44 comment · 0 complexity · 56336d0538b2ba91e9770d16bb40c861 MD5 · raw file

  1. /**
  2. * @file llmutelist.h
  3. * @brief Management of list of muted players
  4. *
  5. * $LicenseInfo:firstyear=2003&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. #ifndef LL_MUTELIST_H
  27. #define LL_MUTELIST_H
  28. #include "llstring.h"
  29. #include "lluuid.h"
  30. class LLViewerObject;
  31. class LLMessageSystem;
  32. class LLMuteListObserver;
  33. // An entry in the mute list.
  34. class LLMute
  35. {
  36. public:
  37. // Legacy mutes are BY_NAME and have null UUID.
  38. // EXTERNAL mutes are only processed through an external system (e.g. Voice) and not stored.
  39. enum EType { BY_NAME = 0, AGENT = 1, OBJECT = 2, GROUP = 3, EXTERNAL = 4, COUNT = 5 };
  40. // Bits in the mute flags. For backwards compatibility (since any mute list entries that were created before the flags existed
  41. // will have a flags field of 0), some of the flags are "inverted".
  42. // Note that it's possible, through flags, to completely disable an entry in the mute list. The code should detect this case
  43. // and remove the mute list entry instead.
  44. enum
  45. {
  46. flagTextChat = 0x00000001, // If set, don't mute user's text chat
  47. flagVoiceChat = 0x00000002, // If set, don't mute user's voice chat
  48. flagParticles = 0x00000004, // If set, don't mute user's particles
  49. flagObjectSounds = 0x00000008, // If set, mute user's object sounds
  50. flagAll = 0x0000000F // Mask of all currently defined flags
  51. };
  52. LLMute(const LLUUID& id, const std::string& name = std::string(), EType type = BY_NAME, U32 flags = 0);
  53. // Returns localized type name of muted item
  54. std::string getDisplayType() const;
  55. public:
  56. LLUUID mID; // agent or object id
  57. std::string mName; // agent or object name, does not store last name "Resident"
  58. EType mType; // needed for UI display of existing mutes
  59. U32 mFlags; // flags pertaining to this mute entry
  60. };
  61. class LLMuteList : public LLSingleton<LLMuteList>
  62. {
  63. public:
  64. // reasons for auto-unmuting a resident
  65. enum EAutoReason
  66. {
  67. AR_IM = 0, // agent IMed a muted resident
  68. AR_MONEY = 1, // agent paid L$ to a muted resident
  69. AR_INVENTORY = 2, // agent offered inventory to a muted resident
  70. AR_COUNT // enum count
  71. };
  72. LLMuteList();
  73. ~LLMuteList();
  74. // Implemented locally so that we can perform some delayed initialization.
  75. // Callers should be careful to call this one and not LLSingleton<LLMuteList>::getInstance()
  76. // which would circumvent that mechanism. -MG
  77. static LLMuteList* getInstance();
  78. void addObserver(LLMuteListObserver* observer);
  79. void removeObserver(LLMuteListObserver* observer);
  80. // Add either a normal or a BY_NAME mute, for any or all properties.
  81. BOOL add(const LLMute& mute, U32 flags = 0);
  82. // Remove both normal and legacy mutes, for any or all properties.
  83. BOOL remove(const LLMute& mute, U32 flags = 0);
  84. BOOL autoRemove(const LLUUID& agent_id, const EAutoReason reason);
  85. // Name is required to test against legacy text-only mutes.
  86. BOOL isMuted(const LLUUID& id, const std::string& name = LLStringUtil::null, U32 flags = 0) const;
  87. // Alternate (convenience) form for places we don't need to pass the name, but do need flags
  88. BOOL isMuted(const LLUUID& id, U32 flags) const { return isMuted(id, LLStringUtil::null, flags); };
  89. BOOL isLinden(const std::string& name) const;
  90. BOOL isLoaded() const { return mIsLoaded; }
  91. std::vector<LLMute> getMutes() const;
  92. // request the mute list
  93. void requestFromServer(const LLUUID& agent_id);
  94. // call this method on logout to save everything.
  95. void cache(const LLUUID& agent_id);
  96. private:
  97. BOOL loadFromFile(const std::string& filename);
  98. BOOL saveToFile(const std::string& filename);
  99. void setLoaded();
  100. void notifyObservers();
  101. void updateAdd(const LLMute& mute);
  102. void updateRemove(const LLMute& mute);
  103. // TODO: NULL out mute_id in database
  104. static void processMuteListUpdate(LLMessageSystem* msg, void**);
  105. static void processUseCachedMuteList(LLMessageSystem* msg, void**);
  106. static void onFileMuteList(void** user_data, S32 code, LLExtStat ext_status);
  107. private:
  108. struct compare_by_name
  109. {
  110. bool operator()(const LLMute& a, const LLMute& b) const
  111. {
  112. std::string name1 = a.mName;
  113. std::string name2 = b.mName;
  114. LLStringUtil::toUpper(name1);
  115. LLStringUtil::toUpper(name2);
  116. return name1 < name2;
  117. }
  118. };
  119. struct compare_by_id
  120. {
  121. bool operator()(const LLMute& a, const LLMute& b) const
  122. {
  123. return a.mID < b.mID;
  124. }
  125. };
  126. typedef std::set<LLMute, compare_by_id> mute_set_t;
  127. mute_set_t mMutes;
  128. typedef std::set<std::string> string_set_t;
  129. string_set_t mLegacyMutes;
  130. typedef std::set<LLMuteListObserver*> observer_set_t;
  131. observer_set_t mObservers;
  132. BOOL mIsLoaded;
  133. friend class LLDispatchEmptyMuteList;
  134. };
  135. class LLMuteListObserver
  136. {
  137. public:
  138. virtual ~LLMuteListObserver() { }
  139. virtual void onChange() = 0;
  140. };
  141. #endif //LL_MUTELIST_H