2626#include " llviewerprecompiledheaders.h"
2727
2828#include " llagent.h"
29+ #include " llnotificationsutil.h"
2930#include " llviewerregion.h"
3031#include " llvoavatar.h"
32+ #include " llvoiceclient.h"
3133#include " llviewerobjectlist.h"
3234
3335#include " llnearbyvoicemoderation.h"
3436
37+ LLNearbyVoiceModeration::LLNearbyVoiceModeration ()
38+ {
39+ // TODO: default to false, when appropriate info cap is added
40+ mIsNearbyChatModerator = true ;
41+ mParcelCallbackConnection = gAgent .addParcelChangedCallback ([this ]() { updateModeratorStatus (); });
42+ }
43+
44+ LLNearbyVoiceModeration::~LLNearbyVoiceModeration ()
45+ {
46+ if (mParcelCallbackConnection .connected ())
47+ {
48+ mParcelCallbackConnection .disconnect ();
49+ }
50+ }
51+
3552LLVOAvatar* LLNearbyVoiceModeration::getVOAvatarFromId (const LLUUID& agent_id)
3653{
3754 LLViewerObject *obj = gObjectList .findObject (agent_id);
@@ -54,18 +71,12 @@ const std::string LLNearbyVoiceModeration::getCapUrlFromRegion(LLViewerRegion* r
5471{
5572 if (! region || ! region->capabilitiesReceived ())
5673 {
57- // TODO: Retry if fails since the capabilities may not have been received
58- // if this is called early into a region entry
59- LL_INFOS () << " Region or region capabilities unavailable." << LL_ENDL;
6074 return std::string ();
6175 }
62- LL_INFOS () << " Capabilities for region " << region->getName () << " received." << LL_ENDL;
6376
6477 std::string url = region->getCapability (" SpatialVoiceModerationRequest" );
6578 if (url.empty ())
6679 {
67- // TODO: Retry if fails since URL may not have not be available
68- // if this is called early into a region entry
6980 LL_INFOS () << " Capability URL for region " << region->getName () << " is empty" << LL_ENDL;
7081 return std::string ();
7182 }
@@ -139,3 +150,93 @@ void LLNearbyVoiceModeration::requestMuteAll(bool mute)
139150 failure_msg);
140151 }
141152}
153+
154+ void LLNearbyVoiceModeration::setMutedInfo (const std::string& channelID, bool mute)
155+ {
156+ auto it = mChannelMuteMap .find (channelID);
157+ if (it == mChannelMuteMap .end ())
158+ {
159+ if (mute)
160+ {
161+ // Channel is new and being muted
162+ showMutedNotification (true );
163+ }
164+ mChannelMuteMap [channelID] = mute;
165+ }
166+ else
167+ {
168+ if (it->second != mute)
169+ {
170+ // Flag changed
171+ showMutedNotification (mute);
172+ it->second = mute;
173+ }
174+ }
175+ }
176+
177+ void LLNearbyVoiceModeration::showNotificationIfNeeded ()
178+ {
179+ if (LLVoiceClient::getInstance ()->inProximalChannel () &&
180+ LLVoiceClient::getInstance ()->getIsModeratorMuted (gAgentID ))
181+ {
182+ showMutedNotification (true );
183+ }
184+ }
185+
186+ void LLNearbyVoiceModeration::showMutedNotification (bool is_muted)
187+ {
188+ // Check if the current voice channel is nearby chat
189+ if (LLVoiceClient::getInstance ()->inProximalChannel ())
190+ {
191+ LLNotificationsUtil::add (is_muted ? " NearbyVoiceMutedByModerator" : " NearbyVoiceUnmutedByModerator" );
192+ }
193+ }
194+
195+ void LLNearbyVoiceModeration::updateModeratorStatus ()
196+ {
197+ LL_WARNS () << " Request moderator status info" << LL_ENDL;
198+ // TODO: Uncomment and set correct capability name, when appropriate info cap is added
199+ /*
200+ if (LLViewerRegion* region = gAgent.getRegion())
201+ {
202+
203+ std::string url = region->getCapability("SpatialVoiceModerationInfoRequest");
204+ if (!url.empty())
205+ {
206+ LLCoros::instance().launch("getModeratorStatusCoro", [url]() { getModeratorStatusCoro(url); });
207+ }
208+ }
209+ */
210+ }
211+
212+ void LLNearbyVoiceModeration::getModeratorStatusCoro (std::string cap_url)
213+ {
214+ LLCore::HttpRequest::policy_t httpPolicy (LLCore::HttpRequest::DEFAULT_POLICY_ID);
215+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter (new LLCoreHttpUtil::HttpCoroutineAdapter (" getModeratorStatusCoro" , httpPolicy));
216+ LLCore::HttpRequest::ptr_t httpRequest (new LLCore::HttpRequest);
217+ LLCore::HttpOptions::ptr_t httpOpts (new LLCore::HttpOptions);
218+ LLCore::HttpHeaders::ptr_t httpHeaders;
219+
220+ httpOpts->setFollowRedirects (true );
221+
222+ LLSD result = httpAdapter->getAndSuspend (httpRequest, cap_url, httpOpts, httpHeaders);
223+
224+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
225+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD (httpResults);
226+
227+ if (!status)
228+ {
229+ LL_WARNS () << " Failed to get nearby voice moderator info" << LL_ENDL;
230+ return ;
231+ }
232+ else if (!result[" success" ].asBoolean ())
233+ {
234+ LL_WARNS () << " Failed to get nearby voice moderator info: " << result[" message" ] << LL_ENDL;
235+ return ;
236+ }
237+
238+ // TODO: update the field, when appropriate info cap is added
239+ bool is_moderator = result[" moderator" ].asBoolean ();
240+ LLNearbyVoiceModeration::getInstance ()->setNearbyChatModerator (is_moderator);
241+ }
242+
0 commit comments