| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Browser; |
| | 3 | | using DCL.Tasks; |
| | 4 | | using DCL.UserProfiles; |
| | 5 | | using DCLServices.Lambdas.NamesService; |
| | 6 | | using SocialFeaturesAnalytics; |
| | 7 | | using System; |
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Globalization; |
| | 10 | | using System.Linq; |
| | 11 | | using System.Text.RegularExpressions; |
| | 12 | | using System.Threading; |
| | 13 | | using UnityEngine; |
| | 14 | | using UnityEngine.Networking; |
| | 15 | |
|
| | 16 | | namespace DCL.MyAccount |
| | 17 | | { |
| | 18 | | public class MyProfileController |
| | 19 | | { |
| | 20 | | private const string CLAIM_UNIQUE_NAME_URL = "https://builder.decentraland.org/claim-name?utm_source=dcl_explore |
| | 21 | |
|
| | 22 | | private readonly IMyProfileComponentView view; |
| | 23 | | private readonly DataStore dataStore; |
| | 24 | | private readonly IUserProfileBridge userProfileBridge; |
| | 25 | | private readonly INamesService namesService; |
| | 26 | | private readonly IBrowserBridge browserBridge; |
| | 27 | | private readonly MyAccountSectionHUDController myAccountSectionHUDController; |
| | 28 | | private readonly KernelConfig kernelConfig; |
| | 29 | | private readonly IMyAccountAnalyticsService myAccountAnalyticsService; |
| | 30 | | private readonly ISocialAnalytics socialAnalytics; |
| | 31 | | private readonly IProfileAdditionalInfoValueListProvider countryListProvider; |
| | 32 | | private readonly IProfileAdditionalInfoValueListProvider genderListProvider; |
| | 33 | | private readonly IProfileAdditionalInfoValueListProvider sexualOrientationProvider; |
| | 34 | | private readonly IProfileAdditionalInfoValueListProvider employmentStatusProvider; |
| | 35 | | private readonly IProfileAdditionalInfoValueListProvider relationshipStatusProvider; |
| | 36 | | private readonly IProfileAdditionalInfoValueListProvider languageListProvider; |
| | 37 | | private readonly IProfileAdditionalInfoValueListProvider pronounListProvider; |
| 41 | 38 | | private readonly List<string> loadedNames = new (); |
| | 39 | |
|
| 41 | 40 | | private CancellationTokenSource saveLinkCancellationToken = new (); |
| 41 | 41 | | private CancellationTokenSource saveNameCancellationToken = new (); |
| 41 | 42 | | private CancellationTokenSource saveDescriptionCancellationToken = new (); |
| 41 | 43 | | private CancellationTokenSource additionalInfoCancellationToken = new (); |
| 41 | 44 | | private CancellationTokenSource refreshContentCancellationToken = new (); |
| | 45 | | private CancellationTokenSource lifeTimeCancellationToken; |
| | 46 | | private Regex nameRegex; |
| | 47 | |
|
| 258 | 48 | | private UserProfile ownUserProfile => userProfileBridge.GetOwn(); |
| 35 | 49 | | private string ownUserMainName => SplitUserName(ownUserProfile).mainName; |
| 31 | 50 | | private string ownUserNonClaimedHashtag => SplitUserName(ownUserProfile).nonClaimedHashtag; |
| | 51 | |
|
| 41 | 52 | | public MyProfileController( |
| | 53 | | IMyProfileComponentView view, |
| | 54 | | DataStore dataStore, |
| | 55 | | IUserProfileBridge userProfileBridge, |
| | 56 | | INamesService namesService, |
| | 57 | | IBrowserBridge browserBridge, |
| | 58 | | MyAccountSectionHUDController myAccountSectionHUDController, |
| | 59 | | KernelConfig kernelConfig, |
| | 60 | | IMyAccountAnalyticsService myAccountAnalyticsService, |
| | 61 | | ISocialAnalytics socialAnalytics, |
| | 62 | | IProfileAdditionalInfoValueListProvider countryListProvider, |
| | 63 | | IProfileAdditionalInfoValueListProvider genderListProvider, |
| | 64 | | IProfileAdditionalInfoValueListProvider sexualOrientationProvider, |
| | 65 | | IProfileAdditionalInfoValueListProvider employmentStatusProvider, |
| | 66 | | IProfileAdditionalInfoValueListProvider relationshipStatusProvider, |
| | 67 | | IProfileAdditionalInfoValueListProvider languageListProvider, |
| | 68 | | IProfileAdditionalInfoValueListProvider pronounListProvider) |
| | 69 | | { |
| 41 | 70 | | this.view = view; |
| 41 | 71 | | this.dataStore = dataStore; |
| 41 | 72 | | this.userProfileBridge = userProfileBridge; |
| 41 | 73 | | this.namesService = namesService; |
| 41 | 74 | | this.browserBridge = browserBridge; |
| 41 | 75 | | this.myAccountSectionHUDController = myAccountSectionHUDController; |
| 41 | 76 | | this.kernelConfig = kernelConfig; |
| 41 | 77 | | this.myAccountAnalyticsService = myAccountAnalyticsService; |
| 41 | 78 | | this.socialAnalytics = socialAnalytics; |
| 41 | 79 | | this.countryListProvider = countryListProvider; |
| 41 | 80 | | this.genderListProvider = genderListProvider; |
| 41 | 81 | | this.sexualOrientationProvider = sexualOrientationProvider; |
| 41 | 82 | | this.employmentStatusProvider = employmentStatusProvider; |
| 41 | 83 | | this.relationshipStatusProvider = relationshipStatusProvider; |
| 41 | 84 | | this.languageListProvider = languageListProvider; |
| 41 | 85 | | this.pronounListProvider = pronounListProvider; |
| | 86 | |
|
| 41 | 87 | | dataStore.myAccount.isMyAccountSectionVisible.OnChange += OnMyAccountSectionVisibleChanged; |
| 41 | 88 | | view.OnCurrentNameEdited += OnNameEdited; |
| 41 | 89 | | view.OnCurrentNameSubmitted += OnNameSubmitted; |
| 41 | 90 | | view.OnGoFromClaimedToNonClaimNameClicked += GoFromClaimedToNonClaimName; |
| 41 | 91 | | view.OnClaimNameClicked += OnClaimNameRequested; |
| 41 | 92 | | view.OnAboutDescriptionSubmitted += OnAboutDescriptionSubmitted; |
| 41 | 93 | | view.OnLinkAdded += OnAddLinkRequested; |
| 41 | 94 | | view.OnLinkRemoved += OnRemoveLinkRequested; |
| | 95 | |
|
| 41 | 96 | | ownUserProfile.OnUpdate += OnOwnUserProfileUpdated; |
| | 97 | |
|
| 41 | 98 | | kernelConfig.EnsureConfigInitialized() |
| 41 | 99 | | .Then(config => OnKernelConfigChanged(config, null)); |
| | 100 | |
|
| 41 | 101 | | kernelConfig.OnChange += OnKernelConfigChanged; |
| 41 | 102 | | } |
| | 103 | |
|
| | 104 | | public void Dispose() |
| | 105 | | { |
| 41 | 106 | | dataStore.myAccount.isMyAccountSectionVisible.OnChange -= OnMyAccountSectionVisibleChanged; |
| 41 | 107 | | view.OnCurrentNameEdited -= OnNameEdited; |
| 41 | 108 | | view.OnCurrentNameSubmitted -= OnNameSubmitted; |
| 41 | 109 | | view.OnGoFromClaimedToNonClaimNameClicked -= GoFromClaimedToNonClaimName; |
| 41 | 110 | | view.OnClaimNameClicked -= OnClaimNameRequested; |
| 41 | 111 | | view.OnAboutDescriptionSubmitted -= OnAboutDescriptionSubmitted; |
| 41 | 112 | | view.OnLinkAdded -= OnAddLinkRequested; |
| 41 | 113 | | view.OnLinkRemoved -= OnRemoveLinkRequested; |
| 41 | 114 | | ownUserProfile.OnUpdate -= OnOwnUserProfileUpdated; |
| 41 | 115 | | kernelConfig.OnChange -= OnKernelConfigChanged; |
| | 116 | |
|
| 41 | 117 | | saveLinkCancellationToken.SafeCancelAndDispose(); |
| 41 | 118 | | saveNameCancellationToken.SafeCancelAndDispose(); |
| 41 | 119 | | saveDescriptionCancellationToken.SafeCancelAndDispose(); |
| 41 | 120 | | additionalInfoCancellationToken.SafeCancelAndDispose(); |
| 41 | 121 | | refreshContentCancellationToken.SafeCancelAndDispose(); |
| 41 | 122 | | } |
| | 123 | |
|
| | 124 | | private void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel _) => |
| 41 | 125 | | nameRegex = new Regex(current.profiles.nameValidRegex); |
| | 126 | |
|
| | 127 | | private void OnMyAccountSectionVisibleChanged(bool isVisible, bool _) |
| | 128 | | { |
| 18 | 129 | | if (isVisible) |
| 18 | 130 | | OpenSection(); |
| | 131 | | else |
| 0 | 132 | | CloseSection(); |
| 0 | 133 | | } |
| | 134 | |
|
| | 135 | | private void OpenSection() |
| | 136 | | { |
| 18 | 137 | | lifeTimeCancellationToken = lifeTimeCancellationToken.SafeRestart(); |
| 18 | 138 | | view.SetLoadingActive(true); |
| | 139 | |
|
| 18 | 140 | | ShowAboutDescription(ownUserProfile); |
| 18 | 141 | | ShowLinks(ownUserProfile); |
| 18 | 142 | | UserProfile userProfile = ownUserProfile; |
| 18 | 143 | | ShowAdditionalInfoOptions(userProfile, userProfile.AdditionalInfo); |
| 18 | 144 | | ShowAdditionalInfoValues(userProfile.AdditionalInfo); |
| | 145 | |
|
| 18 | 146 | | LoadAndShowOwnedNamesAsync(lifeTimeCancellationToken.Token) |
| | 147 | | .ContinueWith(() => |
| | 148 | | { |
| 18 | 149 | | view.SetLoadingActive(false); |
| 18 | 150 | | refreshContentCancellationToken = refreshContentCancellationToken.SafeRestart(); |
| 18 | 151 | | RefreshContentLayout(refreshContentCancellationToken.Token).Forget(); |
| 18 | 152 | | }) |
| | 153 | | .Forget(); |
| 18 | 154 | | } |
| | 155 | |
|
| | 156 | | private async UniTask RefreshContentLayout(CancellationToken ct) |
| | 157 | | { |
| 54 | 158 | | await UniTask.DelayFrame(1, cancellationToken: ct); |
| 1 | 159 | | view.RefreshContentLayout(); |
| 1 | 160 | | } |
| | 161 | |
|
| | 162 | | private void CloseSection() => |
| 0 | 163 | | lifeTimeCancellationToken.SafeCancelAndDispose(); |
| | 164 | |
|
| | 165 | | private async UniTask LoadAndShowOwnedNamesAsync(CancellationToken ct) |
| | 166 | | { |
| | 167 | | try |
| | 168 | | { |
| 18 | 169 | | loadedNames.Clear(); |
| | 170 | |
|
| 20 | 171 | | var names = await namesService.RequestOwnedNamesAsync( |
| | 172 | | ownUserProfile.userId, |
| | 173 | | 1, |
| | 174 | | int.MaxValue, |
| | 175 | | true, |
| | 176 | | ct); |
| | 177 | |
|
| 18 | 178 | | var optionsToLoad = new List<string>(); |
| | 179 | |
|
| 18 | 180 | | if (names.names is { Count: > 0 }) |
| | 181 | | { |
| 1 | 182 | | optionsToLoad.AddRange(names.names |
| 3 | 183 | | .OrderBy(x => x.Name) |
| 3 | 184 | | .Select(x => x.Name)); |
| | 185 | |
|
| 1 | 186 | | view.SetClaimedNameDropdownOptions(optionsToLoad); |
| 1 | 187 | | loadedNames.AddRange(optionsToLoad); |
| | 188 | | } |
| | 189 | | else |
| 17 | 190 | | view.SetClaimedNameDropdownOptions(optionsToLoad); |
| 18 | 191 | | } |
| 0 | 192 | | catch (OperationCanceledException) { } |
| 0 | 193 | | catch (Exception e) { Debug.LogError(e.Message); } |
| 18 | 194 | | finally { RefreshNamesSectionStatus(); } |
| 18 | 195 | | } |
| | 196 | |
|
| | 197 | | private void RefreshNamesSectionStatus() |
| | 198 | | { |
| 31 | 199 | | view.SetClaimedNameMode(loadedNames.Count > 0); |
| 31 | 200 | | view.SetClaimedNameModeAsInput(!ownUserProfile.hasClaimedName); |
| 31 | 201 | | view.SetCurrentName(ownUserMainName, ownUserNonClaimedHashtag); |
| 31 | 202 | | view.SetClaimNameBannerActive(loadedNames.Count == 0); |
| 31 | 203 | | } |
| | 204 | |
|
| | 205 | | private void OnNameEdited(string newName) |
| | 206 | | { |
| 2 | 207 | | if (string.IsNullOrEmpty(newName) || newName == ownUserMainName) |
| | 208 | | { |
| 0 | 209 | | view.SetNonValidNameWarningActive(false); |
| 0 | 210 | | return; |
| | 211 | | } |
| | 212 | |
|
| 2 | 213 | | view.SetNonValidNameWarningActive(!IsValidUserName(newName)); |
| 2 | 214 | | } |
| | 215 | |
|
| | 216 | | private void OnNameSubmitted(string newName, bool isClaimed) |
| | 217 | | { |
| 2 | 218 | | if (string.IsNullOrEmpty(newName) || newName == ownUserMainName) |
| | 219 | | { |
| 0 | 220 | | view.SetNonValidNameWarningActive(false); |
| 0 | 221 | | return; |
| | 222 | | } |
| | 223 | |
|
| 2 | 224 | | bool isValidUserName = IsValidUserName(newName); |
| 2 | 225 | | view.SetNonValidNameWarningActive(!isValidUserName); |
| | 226 | |
|
| 2 | 227 | | if (!isValidUserName) return; |
| | 228 | |
|
| | 229 | | async UniTaskVoid SaveNameAsync(string newName, bool isClaimed, CancellationToken cancellationToken) |
| | 230 | | { |
| 2 | 231 | | if (isClaimed) |
| 1 | 232 | | await userProfileBridge.SaveVerifiedName(newName, cancellationToken); |
| | 233 | | else |
| 1 | 234 | | await userProfileBridge.SaveUnverifiedName(newName, cancellationToken); |
| | 235 | |
|
| 2 | 236 | | myAccountSectionHUDController.ShowAccountSettingsUpdatedToast(); |
| 2 | 237 | | myAccountAnalyticsService.SendPlayerSwapNameAnalytic(isClaimed, loadedNames.Count); |
| 2 | 238 | | } |
| | 239 | |
|
| 2 | 240 | | saveNameCancellationToken = saveNameCancellationToken.SafeRestart(); |
| 2 | 241 | | SaveNameAsync(newName, isClaimed, saveNameCancellationToken.Token).Forget(); |
| 2 | 242 | | } |
| | 243 | |
|
| | 244 | | private void OnAboutDescriptionSubmitted(string newDesc) |
| | 245 | | { |
| 1 | 246 | | if (newDesc == ownUserProfile.description) |
| 0 | 247 | | return; |
| | 248 | |
|
| | 249 | | async UniTaskVoid SaveDescriptionAsync(string newDesc, CancellationToken cancellationToken) |
| | 250 | | { |
| 1 | 251 | | await userProfileBridge.SaveDescription(newDesc, cancellationToken); |
| | 252 | |
|
| 1 | 253 | | myAccountSectionHUDController.ShowAccountSettingsUpdatedToast(); |
| 1 | 254 | | myAccountAnalyticsService.SendProfileInfoEditAnalytic(newDesc.Length); |
| 1 | 255 | | socialAnalytics.SendProfileEdit(newDesc.Length, false, PlayerActionSource.MyProfile, ProfileField.Descri |
| 1 | 256 | | } |
| | 257 | |
|
| 1 | 258 | | saveDescriptionCancellationToken = saveDescriptionCancellationToken.SafeRestart(); |
| 1 | 259 | | SaveDescriptionAsync(newDesc, saveDescriptionCancellationToken.Token).Forget(); |
| 1 | 260 | | } |
| | 261 | |
|
| | 262 | | private void ShowAboutDescription(UserProfile userProfile) |
| | 263 | | { |
| 31 | 264 | | view.SetAboutDescription(userProfile.description); |
| 31 | 265 | | view.SetAboutEnabled(!userProfile.isGuest); |
| 31 | 266 | | } |
| | 267 | |
|
| | 268 | | private bool IsValidUserName(string newName) => |
| 4 | 269 | | nameRegex == null || nameRegex.IsMatch(newName); |
| | 270 | |
|
| | 271 | | private void OnOwnUserProfileUpdated(UserProfile userProfile) |
| | 272 | | { |
| 13 | 273 | | if (userProfile == null) |
| 0 | 274 | | return; |
| | 275 | |
|
| 13 | 276 | | RefreshNamesSectionStatus(); |
| 13 | 277 | | ShowAboutDescription(userProfile); |
| 13 | 278 | | ShowLinks(userProfile); |
| 13 | 279 | | ShowAdditionalInfoOptions(userProfile, userProfile.AdditionalInfo); |
| 13 | 280 | | ShowAdditionalInfoValues(userProfile.AdditionalInfo); |
| 13 | 281 | | } |
| | 282 | |
|
| | 283 | | private void ShowLinks(UserProfile userProfile) |
| | 284 | | { |
| 32 | 285 | | view.SetLinks(userProfile.Links ?? new List<UserProfileModel.Link>(0)); |
| 32 | 286 | | view.EnableOrDisableAddLinksOption(userProfile.Links == null || userProfile.Links?.Count < 5); |
| 32 | 287 | | view.SetLinksEnabled(!userProfile.isGuest); |
| 32 | 288 | | } |
| | 289 | |
|
| | 290 | | private void GoFromClaimedToNonClaimName() => |
| 0 | 291 | | view.SetClaimedNameModeAsInput(true, ownUserProfile.hasClaimedName); |
| | 292 | |
|
| | 293 | | private void OnClaimNameRequested() |
| | 294 | | { |
| 1 | 295 | | browserBridge.OpenUrl(CLAIM_UNIQUE_NAME_URL); |
| 1 | 296 | | myAccountAnalyticsService.SendPlayerOpenClaimNameAnalytic(); |
| 1 | 297 | | } |
| | 298 | |
|
| | 299 | | private (string mainName, string nonClaimedHashtag) SplitUserName(UserProfile userProfile) |
| | 300 | | { |
| 66 | 301 | | (string mainName, string nonClaimedHashtag) result = ( |
| | 302 | | string.Empty, |
| | 303 | | userProfile.ethAddress != null ? userProfile.ethAddress.Length >= 4 ? userProfile.ethAddress.Substring(u |
| | 304 | |
|
| 66 | 305 | | string[] splitName = userProfile.userName.Split('#'); |
| | 306 | |
|
| 66 | 307 | | if (splitName.Length > 0) |
| 66 | 308 | | result.mainName = splitName[0]; |
| | 309 | |
|
| 66 | 310 | | if (splitName.Length > 1) |
| 64 | 311 | | result.nonClaimedHashtag = splitName[1]; |
| | 312 | |
|
| 66 | 313 | | return result; |
| | 314 | | } |
| | 315 | |
|
| | 316 | | private void OnAddLinkRequested((string title, string url) obj) |
| | 317 | | { |
| 4 | 318 | | if (ownUserProfile.Links?.Count >= 5) return; |
| | 319 | |
|
| | 320 | | async UniTaskVoid AddAndSaveLinkAsync(string title, string url, CancellationToken cancellationToken) |
| | 321 | | { |
| 2 | 322 | | List<UserProfileModel.Link> links = new ((IEnumerable<UserProfileModel.Link>)ownUserProfile.Links |
| | 323 | | ?? Array.Empty<UserProfileModel.Link>()) |
| | 324 | | { |
| | 325 | | new UserProfileModel.Link(title, url), |
| | 326 | | }; |
| | 327 | |
|
| | 328 | | try |
| | 329 | | { |
| 2 | 330 | | await userProfileBridge.SaveLinks(links, cancellationToken); |
| | 331 | |
|
| 2 | 332 | | view.ClearLinkInput(); |
| 2 | 333 | | myAccountSectionHUDController.ShowAccountSettingsUpdatedToast(); |
| 2 | 334 | | myAccountAnalyticsService.SendProfileLinkAddAnalytic(title, url); |
| 2 | 335 | | } |
| 0 | 336 | | catch (OperationCanceledException) { } |
| 0 | 337 | | catch (Exception e) { Debug.LogException(e); } |
| 2 | 338 | | } |
| | 339 | |
|
| 2 | 340 | | saveLinkCancellationToken = saveLinkCancellationToken.SafeRestart(); |
| 2 | 341 | | AddAndSaveLinkAsync(obj.title, obj.url, saveLinkCancellationToken.Token).Forget(); |
| 2 | 342 | | } |
| | 343 | |
|
| | 344 | | private void OnRemoveLinkRequested((string title, string url) obj) |
| | 345 | | { |
| | 346 | | async UniTaskVoid RemoveAndSaveLinkAsync(string title, string url, CancellationToken cancellationToken) |
| | 347 | | { |
| 1 | 348 | | url = UnityWebRequest.UnEscapeURL(url ?? ""); |
| 1 | 349 | | List<UserProfileModel.Link> links = new (ownUserProfile.Links); |
| 1 | 350 | | links.RemoveAll(link => |
| | 351 | | { |
| 3 | 352 | | string linkTitle = link.title ?? ""; |
| 3 | 353 | | string linkURL = UnityWebRequest.UnEscapeURL(link.url ?? ""); |
| | 354 | |
|
| 3 | 355 | | return linkTitle.Equals(title, StringComparison.OrdinalIgnoreCase) |
| | 356 | | && linkURL.Equals(url, StringComparison.OrdinalIgnoreCase); |
| | 357 | | }); |
| | 358 | |
|
| | 359 | | try |
| | 360 | | { |
| 1 | 361 | | UserProfile profile = await userProfileBridge.SaveLinks(links, cancellationToken); |
| | 362 | |
|
| 1 | 363 | | ShowLinks(profile); |
| 1 | 364 | | myAccountSectionHUDController.ShowAccountSettingsUpdatedToast(); |
| 1 | 365 | | myAccountAnalyticsService.SendProfileLinkRemoveAnalytic(title, url); |
| 1 | 366 | | } |
| 0 | 367 | | catch (OperationCanceledException) { } |
| 0 | 368 | | catch (Exception e) { Debug.LogException(e); } |
| 1 | 369 | | } |
| | 370 | |
|
| 1 | 371 | | saveLinkCancellationToken = saveLinkCancellationToken.SafeRestart(); |
| 1 | 372 | | RemoveAndSaveLinkAsync(obj.title, obj.url, saveLinkCancellationToken.Token).Forget(); |
| 1 | 373 | | } |
| | 374 | |
|
| | 375 | | private void ShowAdditionalInfoOptions(UserProfile userProfile, AdditionalInfo additionalInfo) |
| | 376 | | { |
| 31 | 377 | | Dictionary<string, AdditionalInfoOptionsModel.Option> options = new (); |
| | 378 | |
|
| 31 | 379 | | options.Add("Country", new AdditionalInfoOptionsModel.Option |
| | 380 | | { |
| | 381 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Country), |
| | 382 | | Name = "Country", |
| | 383 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 384 | | Values = GetCountryList(), |
| | 385 | | OnValueSubmitted = country => |
| | 386 | | { |
| 1 | 387 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 388 | | { |
| | 389 | | Country = country, |
| | 390 | | }); |
| | 391 | |
|
| 1 | 392 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Country", country); |
| 1 | 393 | | }, |
| | 394 | | OnRemoved = () => |
| | 395 | | { |
| 1 | 396 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 397 | | { |
| | 398 | | Country = null, |
| | 399 | | }); |
| | 400 | |
|
| 1 | 401 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Country"); |
| 1 | 402 | | }, |
| | 403 | | }); |
| | 404 | |
|
| 31 | 405 | | options.Add("Gender", new AdditionalInfoOptionsModel.Option |
| | 406 | | { |
| | 407 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Gender), |
| | 408 | | Name = "Gender", |
| | 409 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 410 | | Values = GetGenderList(), |
| | 411 | | OnValueSubmitted = gender => |
| | 412 | | { |
| 1 | 413 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 414 | | { |
| | 415 | | Gender = gender, |
| | 416 | | }); |
| | 417 | |
|
| 1 | 418 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Gender", gender); |
| 1 | 419 | | }, |
| | 420 | | OnRemoved = () => |
| | 421 | | { |
| 1 | 422 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 423 | | { |
| | 424 | | Gender = null, |
| | 425 | | }); |
| | 426 | |
|
| 1 | 427 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Gender"); |
| 1 | 428 | | }, |
| | 429 | | }); |
| | 430 | |
|
| 31 | 431 | | options.Add("Pronouns", new AdditionalInfoOptionsModel.Option |
| | 432 | | { |
| | 433 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Pronouns), |
| | 434 | | Name = "Pronouns", |
| | 435 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 436 | | Values = GetPronounList(), |
| | 437 | | OnValueSubmitted = pronouns => |
| | 438 | | { |
| 1 | 439 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 440 | | { |
| | 441 | | Pronouns = pronouns, |
| | 442 | | }); |
| | 443 | |
|
| 1 | 444 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Pronouns", pronouns); |
| 1 | 445 | | }, |
| | 446 | | OnRemoved = () => |
| | 447 | | { |
| 1 | 448 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 449 | | { |
| | 450 | | Pronouns = null, |
| | 451 | | }); |
| | 452 | |
|
| 1 | 453 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Pronouns"); |
| 1 | 454 | | }, |
| | 455 | | }); |
| | 456 | |
|
| 31 | 457 | | options.Add("Relationship Status", new AdditionalInfoOptionsModel.Option |
| | 458 | | { |
| | 459 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.RelationshipStatus), |
| | 460 | | Name = "Relationship Status", |
| | 461 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 462 | | Values = GetRelationshipStatusList(), |
| | 463 | | OnValueSubmitted = relationshipStatus => |
| | 464 | | { |
| 1 | 465 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 466 | | { |
| | 467 | | RelationshipStatus = relationshipStatus, |
| | 468 | | }); |
| | 469 | |
|
| 1 | 470 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Relationship Status", relationsh |
| 1 | 471 | | }, |
| | 472 | | OnRemoved = () => |
| | 473 | | { |
| 1 | 474 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 475 | | { |
| | 476 | | RelationshipStatus = null, |
| | 477 | | }); |
| | 478 | |
|
| 1 | 479 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Relationship Status"); |
| 1 | 480 | | }, |
| | 481 | | }); |
| | 482 | |
|
| 31 | 483 | | options.Add("Sexual Orientation", new AdditionalInfoOptionsModel.Option |
| | 484 | | { |
| | 485 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.SexualOrientation), |
| | 486 | | Name = "Sexual Orientation", |
| | 487 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 488 | | Values = GetSexualOrientationList(), |
| | 489 | | OnValueSubmitted = sexualOrientation => |
| | 490 | | { |
| 1 | 491 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 492 | | { |
| | 493 | | SexualOrientation = sexualOrientation, |
| | 494 | | }); |
| | 495 | |
|
| 1 | 496 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Sexual Orientation", sexualOrien |
| 1 | 497 | | }, |
| | 498 | | OnRemoved = () => |
| | 499 | | { |
| 1 | 500 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 501 | | { |
| | 502 | | SexualOrientation = null, |
| | 503 | | }); |
| | 504 | |
|
| 1 | 505 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Sexual Orientation"); |
| 1 | 506 | | }, |
| | 507 | | }); |
| | 508 | |
|
| 31 | 509 | | options.Add("Language", new AdditionalInfoOptionsModel.Option |
| | 510 | | { |
| | 511 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Language), |
| | 512 | | Name = "Language", |
| | 513 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 514 | | Values = GetLanguageList(), |
| | 515 | | OnValueSubmitted = language => |
| | 516 | | { |
| 1 | 517 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 518 | | { |
| | 519 | | Language = language, |
| | 520 | | }); |
| | 521 | |
|
| 1 | 522 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Language", language); |
| 1 | 523 | | }, |
| | 524 | | OnRemoved = () => |
| | 525 | | { |
| 1 | 526 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 527 | | { |
| | 528 | | Language = null, |
| | 529 | | }); |
| | 530 | |
|
| 1 | 531 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Language"); |
| 1 | 532 | | }, |
| | 533 | | }); |
| | 534 | |
|
| 31 | 535 | | options.Add("Employment Status", new AdditionalInfoOptionsModel.Option |
| | 536 | | { |
| | 537 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.EmploymentStatus), |
| | 538 | | Name = "Employment Status", |
| | 539 | | InputType = AdditionalInfoOptionsModel.InputType.StrictValueList, |
| | 540 | | Values = GetEmploymentStatusList(), |
| | 541 | | OnValueSubmitted = employmentStatus => |
| | 542 | | { |
| 1 | 543 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 544 | | { |
| | 545 | | EmploymentStatus = employmentStatus, |
| | 546 | | }); |
| | 547 | |
|
| 1 | 548 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Employment Status", employmentSt |
| 1 | 549 | | }, |
| | 550 | | OnRemoved = () => |
| | 551 | | { |
| 1 | 552 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 553 | | { |
| | 554 | | EmploymentStatus = null, |
| | 555 | | }); |
| | 556 | |
|
| 1 | 557 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Employment Status"); |
| 1 | 558 | | }, |
| | 559 | | }); |
| | 560 | |
|
| 31 | 561 | | options.Add("Profession", new AdditionalInfoOptionsModel.Option |
| | 562 | | { |
| | 563 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Profession), |
| | 564 | | Name = "Profession", |
| | 565 | | InputType = AdditionalInfoOptionsModel.InputType.FreeFormText, |
| | 566 | | OnValueSubmitted = profession => |
| | 567 | | { |
| 1 | 568 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 569 | | { |
| | 570 | | Profession = profession, |
| | 571 | | }); |
| | 572 | |
|
| 1 | 573 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Profession", profession); |
| 1 | 574 | | }, |
| | 575 | | OnRemoved = () => |
| | 576 | | { |
| 1 | 577 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 578 | | { |
| | 579 | | Profession = null, |
| | 580 | | }); |
| | 581 | |
|
| 1 | 582 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Profession"); |
| 1 | 583 | | }, |
| | 584 | | }); |
| | 585 | |
|
| 31 | 586 | | options.Add("Birth Date", new AdditionalInfoOptionsModel.Option |
| | 587 | | { |
| | 588 | | IsAvailable = additionalInfo.BirthDate == null, |
| | 589 | | Name = "Birth Date", |
| | 590 | | InputType = AdditionalInfoOptionsModel.InputType.Date, |
| | 591 | | DateFormat = "dd/MM/yyyy", |
| | 592 | | OnValueSubmitted = birthDate => |
| | 593 | | { |
| 1 | 594 | | var dateTime = DateTime.ParseExact(birthDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeSt |
| | 595 | |
|
| 1 | 596 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 597 | | { |
| | 598 | | BirthDate = dateTime, |
| | 599 | | }); |
| | 600 | |
|
| 1 | 601 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Birth Date", birthDate); |
| 1 | 602 | | }, |
| | 603 | | OnRemoved = () => |
| | 604 | | { |
| 1 | 605 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 606 | | { |
| | 607 | | BirthDate = null, |
| | 608 | | }); |
| | 609 | |
|
| 1 | 610 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Birth Date"); |
| 1 | 611 | | }, |
| | 612 | | }); |
| | 613 | |
|
| 31 | 614 | | options.Add("Real Name", new AdditionalInfoOptionsModel.Option |
| | 615 | | { |
| | 616 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.RealName), |
| | 617 | | Name = "Real Name", |
| | 618 | | InputType = AdditionalInfoOptionsModel.InputType.FreeFormText, |
| | 619 | | OnValueSubmitted = realName => |
| | 620 | | { |
| 1 | 621 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 622 | | { |
| | 623 | | RealName = realName, |
| | 624 | | }); |
| | 625 | |
|
| 1 | 626 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Real Name", realName); |
| 1 | 627 | | }, |
| | 628 | | OnRemoved = () => |
| | 629 | | { |
| 1 | 630 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 631 | | { |
| | 632 | | RealName = null, |
| | 633 | | }); |
| | 634 | |
|
| 1 | 635 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Real Name"); |
| 1 | 636 | | }, |
| | 637 | | }); |
| | 638 | |
|
| 31 | 639 | | options.Add("Hobbies", new AdditionalInfoOptionsModel.Option |
| | 640 | | { |
| | 641 | | IsAvailable = string.IsNullOrEmpty(additionalInfo.Hobbies), |
| | 642 | | Name = "Hobbies", |
| | 643 | | InputType = AdditionalInfoOptionsModel.InputType.FreeFormText, |
| | 644 | | OnValueSubmitted = hobbies => |
| | 645 | | { |
| 1 | 646 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 647 | | { |
| | 648 | | Hobbies = hobbies, |
| | 649 | | }); |
| | 650 | |
|
| 1 | 651 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoAddAnalytic("Hobbies", hobbies); |
| 1 | 652 | | }, |
| | 653 | | OnRemoved = () => |
| | 654 | | { |
| 1 | 655 | | SaveAdditionalInfo(new AdditionalInfo(additionalInfo) |
| | 656 | | { |
| | 657 | | Hobbies = null, |
| | 658 | | }); |
| | 659 | |
|
| 1 | 660 | | myAccountAnalyticsService.SendProfileInfoAdditionalInfoRemoveAnalytic("Hobbies"); |
| 1 | 661 | | }, |
| | 662 | | }); |
| | 663 | |
|
| 31 | 664 | | view.SetAdditionalInfoOptions(new AdditionalInfoOptionsModel |
| | 665 | | { |
| | 666 | | Options = options, |
| | 667 | | }); |
| | 668 | |
|
| 31 | 669 | | view.SetAdditionalInfoEnabled(!userProfile.isGuest); |
| 31 | 670 | | } |
| | 671 | |
|
| | 672 | | private string[] GetEmploymentStatusList() => |
| 31 | 673 | | employmentStatusProvider.Provide(); |
| | 674 | |
|
| | 675 | | private string[] GetLanguageList() => |
| 31 | 676 | | languageListProvider.Provide(); |
| | 677 | |
|
| | 678 | | private string[] GetSexualOrientationList() => |
| 31 | 679 | | sexualOrientationProvider.Provide(); |
| | 680 | |
|
| | 681 | | private string[] GetRelationshipStatusList() => |
| 31 | 682 | | relationshipStatusProvider.Provide(); |
| | 683 | |
|
| | 684 | | private string[] GetPronounList() => |
| 31 | 685 | | pronounListProvider.Provide(); |
| | 686 | |
|
| | 687 | | private string[] GetGenderList() => |
| 31 | 688 | | genderListProvider.Provide(); |
| | 689 | |
|
| | 690 | | private string[] GetCountryList() => |
| 31 | 691 | | countryListProvider.Provide(); |
| | 692 | |
|
| | 693 | | private void SaveAdditionalInfo(AdditionalInfo additionalInfo) |
| | 694 | | { |
| | 695 | | async UniTaskVoid SaveAdditionalInfoAsync(AdditionalInfo additionalInfo, CancellationToken cancellationToken |
| | 696 | | { |
| 22 | 697 | | await userProfileBridge.SaveAdditionalInfo(additionalInfo, cancellationToken); |
| | 698 | |
|
| 22 | 699 | | myAccountSectionHUDController.ShowAccountSettingsUpdatedToast(); |
| 22 | 700 | | } |
| | 701 | |
|
| 22 | 702 | | additionalInfoCancellationToken = additionalInfoCancellationToken.SafeRestart(); |
| | 703 | |
|
| 22 | 704 | | SaveAdditionalInfoAsync(additionalInfo, |
| | 705 | | additionalInfoCancellationToken.Token) |
| | 706 | | .Forget(); |
| 22 | 707 | | } |
| | 708 | |
|
| | 709 | | private void ShowAdditionalInfoValues(AdditionalInfo additionalInfo) |
| | 710 | | { |
| 31 | 711 | | Dictionary<string, (string title, string value)> values = new (); |
| | 712 | |
|
| 31 | 713 | | if (!string.IsNullOrEmpty(additionalInfo.Country)) |
| 2 | 714 | | values["Country"] = ("Country", additionalInfo.Country); |
| | 715 | |
|
| 31 | 716 | | if (!string.IsNullOrEmpty(additionalInfo.Gender)) |
| 2 | 717 | | values["Gender"] = ("Gender", additionalInfo.Gender); |
| | 718 | |
|
| 31 | 719 | | if (!string.IsNullOrEmpty(additionalInfo.Pronouns)) |
| 2 | 720 | | values["Pronouns"] = ("Pronouns", additionalInfo.Pronouns); |
| | 721 | |
|
| 31 | 722 | | if (!string.IsNullOrEmpty(additionalInfo.RelationshipStatus)) |
| 2 | 723 | | values["Relationship Status"] = ("Relationship Status", additionalInfo.RelationshipStatus); |
| | 724 | |
|
| 31 | 725 | | if (!string.IsNullOrEmpty(additionalInfo.SexualOrientation)) |
| 2 | 726 | | values["Sexual Orientation"] = ("Sexual Orientation", additionalInfo.SexualOrientation); |
| | 727 | |
|
| 31 | 728 | | if (!string.IsNullOrEmpty(additionalInfo.Language)) |
| 2 | 729 | | values["Language"] = ("Language", additionalInfo.Language); |
| | 730 | |
|
| 31 | 731 | | if (!string.IsNullOrEmpty(additionalInfo.EmploymentStatus)) |
| 2 | 732 | | values["Employment Status"] = ("Employment Status", additionalInfo.EmploymentStatus); |
| | 733 | |
|
| 31 | 734 | | if (!string.IsNullOrEmpty(additionalInfo.Profession)) |
| 2 | 735 | | values["Profession"] = ("Profession", additionalInfo.Profession); |
| | 736 | |
|
| 31 | 737 | | if (additionalInfo.BirthDate != null) |
| 2 | 738 | | values["Birth Date"] = ("Birth Date", additionalInfo.BirthDate?.ToString("dd/MM/yyyy")); |
| | 739 | |
|
| 31 | 740 | | if (!string.IsNullOrEmpty(additionalInfo.RealName)) |
| 2 | 741 | | values["Real Name"] = ("Real Name", additionalInfo.RealName); |
| | 742 | |
|
| 31 | 743 | | if (!string.IsNullOrEmpty(additionalInfo.Hobbies)) |
| 2 | 744 | | values["Hobbies"] = ("Hobbies", additionalInfo.Hobbies); |
| | 745 | |
|
| 31 | 746 | | view.SetAdditionalInfoValues(values); |
| 31 | 747 | | } |
| | 748 | | } |
| | 749 | | } |