| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Browser; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.NotificationModel; |
| | 6 | | using DCL.Tasks; |
| | 7 | | using DCLServices.PlacesAPIService; |
| | 8 | | using System; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Threading; |
| | 11 | | using UnityEngine; |
| | 12 | |
|
| | 13 | | namespace DCL.ContentModeration |
| | 14 | | { |
| | 15 | | public class ContentModerationHUDController |
| | 16 | | { |
| | 17 | | private const int SECONDS_TO_HIDE_ADULT_CONTENT_ENABLED_NOTIFICATION = 5; |
| | 18 | | private const int REPORT_PLACE_TIMEOUT = 30; |
| | 19 | | private const string LEARN_MORE_URL = "https://docs.decentraland.org/player/general/in-world-features/age-rating |
| | 20 | | private const string REPORTING_ERROR_MESSAGE = "There was an error sending the information. Please try again lat |
| | 21 | |
|
| | 22 | | private readonly IAdultContentSceneWarningComponentView adultContentSceneWarningComponentView; |
| | 23 | | private readonly IAdultContentAgeConfirmationComponentView adultContentAgeConfirmationComponentView; |
| | 24 | | private readonly IAdultContentEnabledNotificationComponentView adultContentEnabledNotificationComponentView; |
| | 25 | | private readonly IContentModerationReportingComponentView contentModerationReportingComponentView; |
| | 26 | | private readonly IContentModerationReportingButtonComponentView contentModerationReportingButtonForWorldsCompone |
| | 27 | | private readonly IWorldState worldState; |
| | 28 | | private readonly DataStore_Common commonDataStore; |
| | 29 | | private readonly DataStore_Settings settingsDataStore; |
| | 30 | | private readonly DataStore_ContentModeration contentModerationDataStore; |
| | 31 | | private readonly IBrowserBridge browserBridge; |
| | 32 | | private readonly IPlacesAPIService placesAPIService; |
| | 33 | | private readonly IUserProfileBridge userProfileBridge; |
| | 34 | | private readonly IContentModerationAnalytics contentModerationAnalytics; |
| | 35 | | private readonly NotificationsController notificationsController; |
| | 36 | |
|
| | 37 | | private string currentPlaceId; |
| | 38 | | private SceneContentCategory currentContentCategory; |
| | 39 | | private CancellationTokenSource reportPlaceCts; |
| | 40 | |
|
| 23 | 41 | | public ContentModerationHUDController( |
| | 42 | | IAdultContentSceneWarningComponentView adultContentSceneWarningComponentView, |
| | 43 | | IAdultContentAgeConfirmationComponentView adultContentAgeConfirmationComponentView, |
| | 44 | | IAdultContentEnabledNotificationComponentView adultContentEnabledNotificationComponentView, |
| | 45 | | IContentModerationReportingComponentView contentModerationReportingComponentView, |
| | 46 | | IContentModerationReportingButtonComponentView contentModerationReportingButtonForWorldsComponentView, |
| | 47 | | IWorldState worldState, |
| | 48 | | DataStore_Common commonDataStore, |
| | 49 | | DataStore_Settings settingsDataStore, |
| | 50 | | DataStore_ContentModeration contentModerationDataStore, |
| | 51 | | IBrowserBridge browserBridge, |
| | 52 | | IPlacesAPIService placesAPIService, |
| | 53 | | IUserProfileBridge userProfileBridge, |
| | 54 | | IContentModerationAnalytics contentModerationAnalytics, |
| | 55 | | NotificationsController notificationsController) |
| | 56 | | { |
| 23 | 57 | | this.adultContentSceneWarningComponentView = adultContentSceneWarningComponentView; |
| 23 | 58 | | this.adultContentAgeConfirmationComponentView = adultContentAgeConfirmationComponentView; |
| 23 | 59 | | this.adultContentEnabledNotificationComponentView = adultContentEnabledNotificationComponentView; |
| 23 | 60 | | this.contentModerationReportingComponentView = contentModerationReportingComponentView; |
| 23 | 61 | | this.contentModerationReportingButtonForWorldsComponentView = contentModerationReportingButtonForWorldsCompo |
| 23 | 62 | | this.worldState = worldState; |
| 23 | 63 | | this.commonDataStore = commonDataStore; |
| 23 | 64 | | this.settingsDataStore = settingsDataStore; |
| 23 | 65 | | this.contentModerationDataStore = contentModerationDataStore; |
| 23 | 66 | | this.browserBridge = browserBridge; |
| 23 | 67 | | this.placesAPIService = placesAPIService; |
| 23 | 68 | | this.userProfileBridge = userProfileBridge; |
| 23 | 69 | | this.contentModerationAnalytics = contentModerationAnalytics; |
| 23 | 70 | | this.notificationsController = notificationsController; |
| | 71 | |
|
| 23 | 72 | | OnSceneNumberChanged(CommonScriptableObjects.sceneNumber.Get(), 0); |
| 23 | 73 | | CommonScriptableObjects.sceneNumber.OnChange += OnSceneNumberChanged; |
| 23 | 74 | | UpdateSceneNameByCoords(CommonScriptableObjects.playerCoords.Get(), Vector2Int.zero); |
| 23 | 75 | | CommonScriptableObjects.playerCoords.OnChange += UpdateSceneNameByCoords; |
| 23 | 76 | | adultContentSceneWarningComponentView.OnGoToSettingsClicked += OnGoToSettingsPanelClicked; |
| 23 | 77 | | contentModerationDataStore.adultContentAgeConfirmationVisible.OnChange += OnAdultContentAgeConfirmationVisib |
| 23 | 78 | | adultContentAgeConfirmationComponentView.OnConfirmClicked += OnAgeConfirmationAccepted; |
| 23 | 79 | | adultContentAgeConfirmationComponentView.OnCancelClicked += OnAgeConfirmationRejected; |
| 23 | 80 | | contentModerationDataStore.adultContentSettingEnabled.OnChange += OnAdultContentSettingChanged; |
| 23 | 81 | | contentModerationDataStore.reportingScenePanelVisible.OnChange += OnReportingScenePanelVisible; |
| 23 | 82 | | contentModerationReportingComponentView.OnPanelClosed += OnContentModerationReportingClosed; |
| 23 | 83 | | contentModerationReportingComponentView.OnSendClicked += OnContentModerationReportingSendClicked; |
| 23 | 84 | | contentModerationReportingComponentView.OnLearnMoreClicked += OnLearnMoreClicked; |
| 23 | 85 | | contentModerationReportingButtonForWorldsComponentView.OnContentModerationPressed += OpenContentModerationPa |
| 23 | 86 | | OnIsWorldChanged(commonDataStore.isWorld.Get(), false); |
| 23 | 87 | | commonDataStore.isWorld.OnChange += OnIsWorldChanged; |
| 23 | 88 | | } |
| | 89 | |
|
| | 90 | | public void Dispose() |
| | 91 | | { |
| 23 | 92 | | CommonScriptableObjects.sceneNumber.OnChange -= OnSceneNumberChanged; |
| 23 | 93 | | CommonScriptableObjects.playerCoords.OnChange -= UpdateSceneNameByCoords; |
| 23 | 94 | | adultContentSceneWarningComponentView.OnGoToSettingsClicked -= OnGoToSettingsPanelClicked; |
| 23 | 95 | | contentModerationDataStore.adultContentAgeConfirmationVisible.OnChange -= OnAdultContentAgeConfirmationVisib |
| 23 | 96 | | adultContentAgeConfirmationComponentView.OnConfirmClicked -= OnAgeConfirmationAccepted; |
| 23 | 97 | | adultContentAgeConfirmationComponentView.OnCancelClicked -= OnAgeConfirmationRejected; |
| 23 | 98 | | contentModerationDataStore.adultContentSettingEnabled.OnChange -= OnAdultContentSettingChanged; |
| 23 | 99 | | contentModerationDataStore.reportingScenePanelVisible.OnChange -= OnReportingScenePanelVisible; |
| 23 | 100 | | contentModerationReportingComponentView.OnPanelClosed -= OnContentModerationReportingClosed; |
| 23 | 101 | | contentModerationReportingComponentView.OnSendClicked -= OnContentModerationReportingSendClicked; |
| 23 | 102 | | contentModerationReportingComponentView.OnLearnMoreClicked -= OnLearnMoreClicked; |
| 23 | 103 | | contentModerationReportingButtonForWorldsComponentView.OnContentModerationPressed -= OpenContentModerationPa |
| 23 | 104 | | commonDataStore.isWorld.OnChange -= OnIsWorldChanged; |
| | 105 | |
|
| 23 | 106 | | reportPlaceCts.SafeCancelAndDispose(); |
| 23 | 107 | | } |
| | 108 | |
|
| | 109 | | private void OnSceneNumberChanged(int currentSceneNumber, int _) |
| | 110 | | { |
| 44 | 111 | | if (!worldState.TryGetScene(currentSceneNumber, out IParcelScene currentParcelScene)) |
| 29 | 112 | | return; |
| | 113 | |
|
| 15 | 114 | | currentContentCategory = currentParcelScene.contentCategory; |
| 15 | 115 | | contentModerationReportingButtonForWorldsComponentView.SetContentCategory(currentParcelScene.contentCategory |
| | 116 | |
|
| 15 | 117 | | switch (currentParcelScene.contentCategory) |
| | 118 | | { |
| 7 | 119 | | case SceneContentCategory.ADULT when !contentModerationDataStore.adultContentSettingEnabled.Get(): |
| 6 | 120 | | Utils.UnlockCursor(); |
| 6 | 121 | | adultContentSceneWarningComponentView.ShowModal(); |
| 6 | 122 | | adultContentSceneWarningComponentView.SetRestrictedMode(false); |
| 6 | 123 | | break; |
| | 124 | | case SceneContentCategory.RESTRICTED: |
| 4 | 125 | | adultContentSceneWarningComponentView.ShowModal(); |
| 4 | 126 | | adultContentSceneWarningComponentView.SetRestrictedMode(true); |
| 4 | 127 | | break; |
| | 128 | | case SceneContentCategory.TEEN: |
| | 129 | | default: |
| 5 | 130 | | adultContentSceneWarningComponentView.HideModal(); |
| | 131 | | break; |
| | 132 | | } |
| | 133 | |
|
| 15 | 134 | | currentPlaceId = currentParcelScene.associatedPlaceId; |
| 15 | 135 | | UpdateSceneNameByCoords(CommonScriptableObjects.playerCoords.Get(), Vector2Int.zero); |
| 15 | 136 | | contentModerationReportingComponentView.HidePanel(true); |
| 15 | 137 | | } |
| | 138 | |
|
| | 139 | | private void UpdateSceneNameByCoords(Vector2Int playerCoords, Vector2Int _) |
| | 140 | | { |
| 38 | 141 | | MinimapMetadata.MinimapSceneInfo sceneInfo = MinimapMetadata.GetMetadata().GetSceneInfo(playerCoords.x, play |
| | 142 | |
|
| 38 | 143 | | if (sceneInfo != null) |
| 0 | 144 | | contentModerationReportingComponentView.SetScene(sceneInfo.name); |
| 38 | 145 | | } |
| | 146 | |
|
| | 147 | | private void OnGoToSettingsPanelClicked() |
| | 148 | | { |
| 1 | 149 | | settingsDataStore.settingsPanelVisible.Set(true); |
| 1 | 150 | | contentModerationAnalytics.OpenSettingsFromContentWarning(); |
| 1 | 151 | | } |
| | 152 | |
|
| | 153 | | private void OnAdultContentAgeConfirmationVisible(bool isVisible, bool _) |
| | 154 | | { |
| 2 | 155 | | if (isVisible) |
| 1 | 156 | | adultContentAgeConfirmationComponentView.ShowModal(); |
| 2 | 157 | | } |
| | 158 | |
|
| | 159 | | private void OnAgeConfirmationAccepted() |
| | 160 | | { |
| 1 | 161 | | contentModerationDataStore.adultContentAgeConfirmationResult.Set(DataStore_ContentModeration.AdultContentAge |
| 1 | 162 | | settingsDataStore.settingsPanelVisible.Set(false); |
| 1 | 163 | | adultContentEnabledNotificationComponentView.ShowNotification(); |
| 1 | 164 | | HideNotificationAfterDelay(SECONDS_TO_HIDE_ADULT_CONTENT_ENABLED_NOTIFICATION).Forget(); |
| 1 | 165 | | } |
| | 166 | |
|
| | 167 | | private UniTask HideNotificationAfterDelay(int delayInSeconds) |
| | 168 | | { |
| 1 | 169 | | return UniTask.Delay(delayInSeconds * 1000).ContinueWith(() => |
| 1 | 170 | | adultContentEnabledNotificationComponentView.HideNotification()); |
| | 171 | | } |
| | 172 | |
|
| | 173 | | private void OnAgeConfirmationRejected() |
| | 174 | | { |
| 1 | 175 | | contentModerationDataStore.adultContentAgeConfirmationResult.Set(DataStore_ContentModeration.AdultContentAge |
| 1 | 176 | | } |
| | 177 | |
|
| | 178 | | private void OnAdultContentSettingChanged(bool currentIsEnabled, bool previousIsEnabled) |
| | 179 | | { |
| 2 | 180 | | if (!currentIsEnabled) |
| 1 | 181 | | adultContentEnabledNotificationComponentView.HideNotification(); |
| | 182 | |
|
| 2 | 183 | | OnSceneNumberChanged(CommonScriptableObjects.sceneNumber.Get(), 0); |
| | 184 | |
|
| 2 | 185 | | if (currentIsEnabled != previousIsEnabled) |
| 2 | 186 | | contentModerationAnalytics.SwitchAdultContentSetting(currentIsEnabled); |
| 2 | 187 | | } |
| | 188 | |
|
| | 189 | | private void OnReportingScenePanelVisible((bool isVisible, SceneContentCategory rating) panelStatus, (bool isVis |
| | 190 | | { |
| 6 | 191 | | if (panelStatus.isVisible) |
| | 192 | | { |
| 3 | 193 | | contentModerationReportingComponentView.ShowPanel(); |
| 3 | 194 | | contentModerationReportingComponentView.SetRatingAsMarked(panelStatus.rating); |
| 3 | 195 | | contentModerationReportingComponentView.SetRating(panelStatus.rating); |
| 3 | 196 | | contentModerationAnalytics.OpenReportForm(currentPlaceId); |
| | 197 | | } |
| | 198 | | else |
| 3 | 199 | | contentModerationReportingComponentView.HidePanel(false); |
| 3 | 200 | | } |
| | 201 | |
|
| | 202 | | private void OnContentModerationReportingClosed(bool isCancelled) |
| | 203 | | { |
| 6 | 204 | | contentModerationDataStore.reportingScenePanelVisible.Set((false, contentModerationDataStore.reportingSceneP |
| 6 | 205 | | contentModerationAnalytics.CloseReportForm(currentPlaceId, isCancelled); |
| 6 | 206 | | } |
| | 207 | |
|
| | 208 | | private void OnContentModerationReportingSendClicked((SceneContentCategory contentCategory, List<string> issues, |
| | 209 | | { |
| 0 | 210 | | reportPlaceCts = reportPlaceCts.SafeRestart(); |
| 0 | 211 | | SendReportAsync( |
| | 212 | | new PlaceContentReportPayload |
| | 213 | | { |
| | 214 | | placeId = currentPlaceId, |
| | 215 | | guest = userProfileBridge.GetOwn().isGuest, |
| | 216 | | coordinates = $"{CommonScriptableObjects.playerCoords.Get().x},{CommonScriptableObjects.playerCo |
| | 217 | | rating = report.contentCategory switch |
| | 218 | | { |
| 0 | 219 | | SceneContentCategory.TEEN => "T", |
| 0 | 220 | | SceneContentCategory.ADULT => "A", |
| 0 | 221 | | SceneContentCategory.RESTRICTED => "R", |
| 0 | 222 | | _ => "E", |
| | 223 | | }, |
| | 224 | | issues = report.issues.ToArray(), |
| | 225 | | comment = report.comments, |
| | 226 | | }, |
| | 227 | | reportPlaceCts.Token) |
| | 228 | | .Forget(); |
| 0 | 229 | | } |
| | 230 | |
|
| | 231 | | private async UniTask SendReportAsync(PlaceContentReportPayload placeContentReport, CancellationToken ct) |
| | 232 | | { |
| | 233 | | try |
| | 234 | | { |
| 0 | 235 | | contentModerationAnalytics.SubmitReportForm( |
| | 236 | | placeContentReport.placeId, |
| | 237 | | placeContentReport.rating, |
| | 238 | | placeContentReport.issues, |
| | 239 | | placeContentReport.comment); |
| | 240 | |
|
| 0 | 241 | | contentModerationReportingComponentView.SetLoadingState(true); |
| 0 | 242 | | await placesAPIService.ReportPlace(placeContentReport, ct) |
| | 243 | | .Timeout(TimeSpan.FromSeconds(REPORT_PLACE_TIMEOUT)); |
| 0 | 244 | | contentModerationReportingComponentView.SetPanelAsSent(true); |
| 0 | 245 | | contentModerationReportingComponentView.SetLoadingState(false); |
| 0 | 246 | | } |
| 0 | 247 | | catch (Exception ex) |
| | 248 | | { |
| 0 | 249 | | contentModerationAnalytics.ErrorSendingReportingForm(currentPlaceId); |
| 0 | 250 | | contentModerationReportingComponentView.ResetPanelState(); |
| 0 | 251 | | notificationsController.ShowNotification(new Model |
| | 252 | | { |
| | 253 | | message = REPORTING_ERROR_MESSAGE, |
| | 254 | | type = NotificationModel.Type.ERROR, |
| | 255 | | timer = 10f, |
| | 256 | | destroyOnFinish = true, |
| | 257 | | }); |
| 0 | 258 | | Debug.LogError($"An error occurred while reporting the content category for ({placeContentReport.coordin |
| 0 | 259 | | } |
| 0 | 260 | | } |
| | 261 | |
|
| | 262 | | private void OnLearnMoreClicked() |
| | 263 | | { |
| 1 | 264 | | browserBridge.OpenUrl(LEARN_MORE_URL); |
| 1 | 265 | | contentModerationAnalytics.ClickLearnMoreContentModeration(currentPlaceId); |
| 1 | 266 | | } |
| | 267 | |
|
| | 268 | | private void OpenContentModerationPanel() => |
| 0 | 269 | | contentModerationDataStore.reportingScenePanelVisible.Set((!contentModerationDataStore.reportingScenePanelVi |
| | 270 | |
|
| | 271 | | private void OnIsWorldChanged(bool current, bool _) |
| | 272 | | { |
| 23 | 273 | | if (current) |
| 0 | 274 | | contentModerationReportingButtonForWorldsComponentView.Show(); |
| | 275 | | else |
| 23 | 276 | | contentModerationReportingButtonForWorldsComponentView.Hide(); |
| 23 | 277 | | } |
| | 278 | | } |
| | 279 | | } |