| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Interface; |
| | 4 | | using DCL.Social.Friends; |
| | 5 | | using DCL.Tasks; |
| | 6 | | using DCLServices.CopyPaste.Analytics; |
| | 7 | | using SocialFeaturesAnalytics; |
| | 8 | | using System; |
| | 9 | | using System.Collections; |
| | 10 | | using System.Linq; |
| | 11 | | using System.Threading; |
| | 12 | | using TMPro; |
| | 13 | | using UIComponents.ContextMenu; |
| | 14 | | using UnityEngine; |
| | 15 | | using UnityEngine.UI; |
| | 16 | | using Environment = DCL.Environment; |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Contextual menu with different options about an user. |
| | 20 | | /// </summary> |
| | 21 | | [RequireComponent(typeof(RectTransform))] |
| | 22 | |
|
| | 23 | | // TODO: refactor into MVC |
| | 24 | | public class UserContextMenu : ContextMenuComponentView |
| | 25 | | { |
| | 26 | | private const string BLOCK_BTN_BLOCK_TEXT = "Block"; |
| | 27 | | private const string BLOCK_BTN_UNBLOCK_TEXT = "Unblock"; |
| | 28 | | private const string OPEN_PASSPORT_NORMAL_SOURCE = "FriendsHUD"; |
| | 29 | | private const string OPEN_PASSPORT_MENTION_SOURCE = "Mention"; |
| | 30 | | private const MenuConfigFlags HEADER_FLAGS = MenuConfigFlags.Name | MenuConfigFlags.Friendship; |
| | 31 | | private const MenuConfigFlags USES_FRIENDS_API_FLAGS = MenuConfigFlags.Friendship | MenuConfigFlags.Message; |
| | 32 | |
|
| | 33 | | [Flags] |
| | 34 | | public enum MenuConfigFlags |
| | 35 | | { |
| | 36 | | Name = 1, |
| | 37 | | Friendship = 2, |
| | 38 | | Message = 4, |
| | 39 | | Passport = 8, |
| | 40 | | Block = 16, |
| | 41 | | Report = 32, |
| | 42 | | Mention = 64, |
| | 43 | | } |
| | 44 | |
|
| | 45 | | [Header("Optional: Set Confirmation Dialog")] |
| | 46 | | [SerializeField] internal UserContextConfirmationDialog confirmationDialog; |
| | 47 | |
|
| | 48 | | [Header("Enable Actions")] |
| 193 | 49 | | [SerializeField] internal MenuConfigFlags menuConfigFlags = MenuConfigFlags.Passport | MenuConfigFlags.Block | MenuC |
| 193 | 50 | | [SerializeField] internal bool enableSendMessage = true; |
| | 51 | |
|
| | 52 | | [Header("Containers")] |
| | 53 | | [SerializeField] internal GameObject headerContainer; |
| | 54 | | [SerializeField] internal GameObject friendshipContainer; |
| | 55 | | [SerializeField] internal GameObject friendAddContainer; |
| | 56 | | [SerializeField] internal GameObject friendRemoveContainer; |
| | 57 | | [SerializeField] internal GameObject friendRequestedContainer; |
| | 58 | |
|
| | 59 | | [Header("Texts")] |
| | 60 | | [SerializeField] internal TextMeshProUGUI userName; |
| | 61 | | [SerializeField] internal TextMeshProUGUI blockText; |
| | 62 | |
|
| | 63 | | [Header("Buttons")] |
| | 64 | | [SerializeField] internal Button passportButton; |
| | 65 | | [SerializeField] internal Button blockButton; |
| | 66 | | [SerializeField] internal Button reportButton; |
| | 67 | | [SerializeField] internal Button addFriendButton; |
| | 68 | | [SerializeField] internal Button cancelFriendButton; |
| | 69 | | [SerializeField] internal Button deleteFriendButton; |
| | 70 | | [SerializeField] internal Button messageButton; |
| | 71 | | [SerializeField] internal Button mentionButton; |
| | 72 | | [SerializeField] internal Button copyNameButton; |
| | 73 | |
|
| | 74 | | [Header("Misc")] |
| | 75 | | [SerializeField] private ShowHideAnimator nameCopiedToast; |
| | 76 | |
|
| | 77 | | public static event Action<string> OnOpenPrivateChatRequest; |
| | 78 | |
|
| 23 | 79 | | public bool isVisible => gameObject.activeSelf; |
| 0 | 80 | | public string UserId => userId; |
| | 81 | |
|
| | 82 | | public event Action OnShowMenu; |
| | 83 | | public event Action<string> OnPassport; |
| | 84 | | public event Action<string> OnReport; |
| | 85 | | public event Action<string, bool> OnBlock; |
| | 86 | | public event Action<string> OnUnfriend; |
| | 87 | | public event Action OnHide; |
| | 88 | |
|
| | 89 | | private static BaseVariable<(string playerId, string source)> currentPlayerId; |
| | 90 | | private string userId; |
| | 91 | | private bool isBlocked; |
| | 92 | | private MenuConfigFlags currentConfigFlags; |
| | 93 | | private IConfirmationDialog currentConfirmationDialog; |
| 193 | 94 | | private CancellationTokenSource friendOperationsCancellationToken = new (); |
| | 95 | | private bool isFromMentionContextMenu; |
| | 96 | | private IFriendsController friendsControllerInternal; |
| | 97 | | private IClipboard clipboardInternal; |
| 62 | 98 | | private bool isFriendsEnabled => DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("friends_enabled"); |
| | 99 | |
|
| | 100 | | private IFriendsController friendsController |
| | 101 | | { |
| | 102 | | get |
| | 103 | | { |
| 28 | 104 | | return friendsControllerInternal ??= Environment.i.serviceLocator.Get<IFriendsController>(); |
| | 105 | | } |
| | 106 | | } |
| | 107 | |
|
| 0 | 108 | | private IClipboard clipboard => clipboardInternal ??= Clipboard.Create(); |
| 0 | 109 | | private ICopyPasteAnalyticsService copyPasteAnalyticsService => Environment.i.serviceLocator.Get<ICopyPasteAnalytics |
| | 110 | |
|
| | 111 | | internal ISocialAnalytics socialAnalytics; |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// Show context menu |
| | 115 | | /// </summary> |
| | 116 | | /// <param name="userId"> user id</param> |
| | 117 | | public void Show(string userId) |
| | 118 | | { |
| 5 | 119 | | if (string.IsNullOrEmpty(userId)) |
| 1 | 120 | | return; |
| | 121 | |
|
| 4 | 122 | | Show(userId, menuConfigFlags); |
| 4 | 123 | | } |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Show context menu |
| | 127 | | /// </summary> |
| | 128 | | /// <param name="userId"> user id</param> |
| | 129 | | /// <param name="configFlags">set buttons to enable in menu</param> |
| | 130 | | public void Show(string userId, MenuConfigFlags configFlags) |
| | 131 | | { |
| 6 | 132 | | this.userId = userId; |
| 6 | 133 | | ProcessActiveElements(configFlags); |
| | 134 | |
|
| 6 | 135 | | if (!Setup(userId, configFlags)) |
| 0 | 136 | | return; |
| | 137 | |
|
| 6 | 138 | | if (currentConfirmationDialog == null && confirmationDialog != null) |
| 0 | 139 | | SetConfirmationDialog(confirmationDialog); |
| | 140 | |
|
| 6 | 141 | | gameObject.SetActive(true); |
| | 142 | | // wait until the layout is rebuilt, otherwise there is an undesired offset |
| 6 | 143 | | StartCoroutine(ClampPositionToScreenBordersOnNextFrame()); |
| | 144 | |
|
| 6 | 145 | | OnShowMenu?.Invoke(); |
| 1 | 146 | | } |
| | 147 | |
|
| | 148 | | /// <summary> |
| | 149 | | /// Show context menu |
| | 150 | | /// </summary> |
| | 151 | | /// <param name="userName">User name</param> |
| | 152 | | public void ShowByUserName(string userName) |
| | 153 | | { |
| 0 | 154 | | var userProfile = UserProfileController.userProfilesCatalog |
| | 155 | | .GetValues() |
| 0 | 156 | | .FirstOrDefault(p => p.userName.Equals(userName, StringComparison.Ordinal |
| | 157 | |
|
| 0 | 158 | | if (userProfile != null) |
| | 159 | | { |
| 0 | 160 | | if (!Setup(userProfile.userId, menuConfigFlags)) |
| | 161 | | { |
| 0 | 162 | | ShowUserNotificationError(userName); |
| 0 | 163 | | return; |
| | 164 | | } |
| | 165 | |
|
| 0 | 166 | | Show(userProfile.userId, currentConfigFlags); |
| | 167 | | } |
| | 168 | | else |
| 0 | 169 | | ShowUserNotificationError(userName); |
| 0 | 170 | | } |
| | 171 | |
|
| | 172 | | /// <summary> |
| | 173 | | /// Set confirmation popup to reference use |
| | 174 | | /// </summary> |
| | 175 | | /// <param name="confirmationPopup">confirmation popup reference</param> |
| | 176 | | public void SetConfirmationDialog(IConfirmationDialog confirmationPopup) |
| | 177 | | { |
| 0 | 178 | | this.currentConfirmationDialog = confirmationPopup; |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | public override void Hide(bool instant = false) |
| | 182 | | { |
| 5 | 183 | | base.Hide(instant); |
| | 184 | |
|
| 5 | 185 | | friendOperationsCancellationToken = friendOperationsCancellationToken.SafeRestart(); |
| 5 | 186 | | gameObject.SetActive(false); |
| 5 | 187 | | OnHide?.Invoke(); |
| 0 | 188 | | } |
| | 189 | |
|
| | 190 | | /// <summary> |
| | 191 | | /// Shows/Hides the friendship container |
| | 192 | | /// </summary> |
| | 193 | | public void SetFriendshipContentActive(bool isActive) => |
| 2 | 194 | | friendshipContainer.SetActive(isActive); |
| | 195 | |
|
| | 196 | | public void SetPassportOpenSource(bool isFromMention) |
| | 197 | | { |
| 34 | 198 | | isFromMentionContextMenu = isFromMention; |
| 34 | 199 | | } |
| | 200 | |
|
| | 201 | | public override void Awake() |
| | 202 | | { |
| 9 | 203 | | base.Awake(); |
| | 204 | |
|
| 9 | 205 | | currentPlayerId = DataStore.i.HUDs.currentPlayerId; |
| 9 | 206 | | passportButton.onClick.AddListener(OnPassportButtonPressed); |
| 9 | 207 | | blockButton.onClick.AddListener(OnBlockUserButtonPressed); |
| 9 | 208 | | reportButton.onClick.AddListener(OnReportUserButtonPressed); |
| 9 | 209 | | deleteFriendButton.onClick.AddListener(OnDeleteUserButtonPressed); |
| 9 | 210 | | addFriendButton.onClick.AddListener(OnAddFriendButtonPressed); |
| 9 | 211 | | cancelFriendButton.onClick.AddListener(OnCancelFriendRequestButtonPressed); |
| 9 | 212 | | messageButton.onClick.AddListener(OnMessageButtonPressed); |
| 9 | 213 | | copyNameButton.onClick.AddListener(OnCopyNameButtonPressed); |
| | 214 | |
|
| 9 | 215 | | if (mentionButton != null) |
| 9 | 216 | | mentionButton.onClick.AddListener(OnMentionButtonPressed); |
| 9 | 217 | | } |
| | 218 | |
|
| | 219 | | public override void OnDisable() |
| | 220 | | { |
| 9 | 221 | | base.OnDisable(); |
| | 222 | |
|
| 9 | 223 | | friendsController.OnUpdateFriendship -= OnFriendActionUpdate; |
| 9 | 224 | | } |
| | 225 | |
|
| | 226 | | public override void RefreshControl() |
| | 227 | | { |
| 0 | 228 | | } |
| | 229 | |
|
| | 230 | | private void OnPassportButtonPressed() |
| | 231 | | { |
| 1 | 232 | | OnPassport?.Invoke(userId); |
| 1 | 233 | | currentPlayerId.Set((userId, isFromMentionContextMenu ? OPEN_PASSPORT_MENTION_SOURCE : OPEN_PASSPORT_NORMAL_SOUR |
| 1 | 234 | | Hide(); |
| | 235 | |
|
| 1 | 236 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 1 | 237 | | } |
| | 238 | |
|
| | 239 | | private void OnReportUserButtonPressed() |
| | 240 | | { |
| 1 | 241 | | OnReport?.Invoke(userId); |
| 1 | 242 | | WebInterface.SendReportPlayer(userId, UserProfileController.userProfilesCatalog.Get(userId)?.userName); |
| 1 | 243 | | GetSocialAnalytics().SendPlayerReport(PlayerReportIssueType.None, 0, PlayerActionSource.ProfileContextMenu, user |
| 1 | 244 | | Hide(); |
| 1 | 245 | | } |
| | 246 | |
|
| | 247 | | private void OnDeleteUserButtonPressed() |
| | 248 | | { |
| 0 | 249 | | DataStore.i.notifications.GenericConfirmation.Set(GenericConfirmationNotificationData.CreateUnFriendData( |
| | 250 | | UserProfileController.userProfilesCatalog.Get(userId)?.userName, |
| | 251 | | () => |
| | 252 | | { |
| 0 | 253 | | friendOperationsCancellationToken = friendOperationsCancellationToken.SafeRestart(); |
| 0 | 254 | | friendsController.RemoveFriendAsync(userId, friendOperationsCancellationToken.Token).Forget(); |
| 0 | 255 | | OnUnfriend?.Invoke(userId); |
| 0 | 256 | | }), true); |
| | 257 | |
|
| 0 | 258 | | GetSocialAnalytics().SendFriendDeleted(UserProfile.GetOwnUserProfile().userId, userId, PlayerActionSource.Profil |
| 0 | 259 | | Hide(); |
| 0 | 260 | | } |
| | 261 | |
|
| | 262 | | private void OnAddFriendButtonPressed() |
| | 263 | | { |
| | 264 | | // NOTE: if we don't add this, the friend request has strange behaviors |
| 0 | 265 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 266 | | { |
| | 267 | | userId = userId, |
| | 268 | | name = UserProfileController.userProfilesCatalog.Get(userId)?.userName |
| | 269 | | }); |
| | 270 | |
|
| 0 | 271 | | DataStore.i.HUDs.sendFriendRequest.Set(userId, true); |
| 0 | 272 | | DataStore.i.HUDs.sendFriendRequestSource.Set((int)PlayerActionSource.ProfileContextMenu); |
| 0 | 273 | | } |
| | 274 | |
|
| | 275 | | private void OnCancelFriendRequestButtonPressed() |
| | 276 | | { |
| | 277 | | async UniTaskVoid CancelFriendRequestAsync(string userId, CancellationToken cancellationToken = default) |
| | 278 | | { |
| | 279 | | try |
| | 280 | | { |
| 0 | 281 | | FriendRequest request = await friendsController.CancelRequestByUserIdAsync(userId, cancellationToken); |
| | 282 | |
|
| 0 | 283 | | GetSocialAnalytics() |
| | 284 | | .SendFriendRequestCancelled(request.From, request.To, |
| | 285 | | PlayerActionSource.ProfileContextMenu.ToString(), request.FriendRequestId); |
| 0 | 286 | | } |
| 0 | 287 | | catch (Exception e) when (e is not OperationCanceledException) |
| | 288 | | { |
| 0 | 289 | | e.ReportFriendRequestErrorToAnalyticsByUserId(userId, PlayerActionSource.ProfileContextMenu.ToString(), |
| | 290 | | friendsController, socialAnalytics); |
| | 291 | |
|
| 0 | 292 | | throw; |
| | 293 | | } |
| 0 | 294 | | } |
| | 295 | |
|
| 0 | 296 | | friendOperationsCancellationToken = friendOperationsCancellationToken.SafeRestart(); |
| 0 | 297 | | CancelFriendRequestAsync(userId, friendOperationsCancellationToken.Token).Forget(); |
| 0 | 298 | | } |
| | 299 | |
|
| | 300 | | private void OnMessageButtonPressed() |
| | 301 | | { |
| 0 | 302 | | OnOpenPrivateChatRequest?.Invoke(userId); |
| 0 | 303 | | Hide(); |
| 0 | 304 | | } |
| | 305 | |
|
| | 306 | | private void OnBlockUserButtonPressed() |
| | 307 | | { |
| 1 | 308 | | bool blockUser = !isBlocked; |
| | 309 | |
|
| 1 | 310 | | if (blockUser) |
| | 311 | | { |
| 1 | 312 | | DataStore.i.notifications.GenericConfirmation.Set(GenericConfirmationNotificationData.CreateBlockUserData( |
| | 313 | | UserProfileController.userProfilesCatalog.Get(userId)?.userName, |
| | 314 | | () => |
| | 315 | | { |
| 1 | 316 | | WebInterface.SendBlockPlayer(userId); |
| 1 | 317 | | GetSocialAnalytics().SendPlayerBlocked(friendsController.IsFriend(userId), PlayerActionSource.Profil |
| 1 | 318 | | OnBlock?.Invoke(userId, blockUser); |
| 1 | 319 | | }), true); |
| | 320 | | } |
| | 321 | | else |
| | 322 | | { |
| 0 | 323 | | WebInterface.SendUnblockPlayer(userId); |
| 0 | 324 | | GetSocialAnalytics().SendPlayerUnblocked(friendsController.IsFriend(userId), PlayerActionSource.ProfileConte |
| 0 | 325 | | OnBlock?.Invoke(userId, blockUser); |
| | 326 | | } |
| | 327 | |
|
| 1 | 328 | | Hide(); |
| 1 | 329 | | } |
| | 330 | |
|
| | 331 | | private void OnMentionButtonPressed() |
| | 332 | | { |
| 0 | 333 | | DataStore.i.mentions.someoneMentionedFromContextMenu.Set($"@{userName.text}", true); |
| 0 | 334 | | GetSocialAnalytics().SendMentionCreated(MentionCreationSource.ProfileContextMenu, userId); |
| 0 | 335 | | Hide(); |
| 0 | 336 | | } |
| | 337 | |
|
| | 338 | | private void ProcessActiveElements(MenuConfigFlags flags) |
| | 339 | | { |
| 25 | 340 | | bool isOwnUser = UserProfile.GetOwnUserProfile().userId == userId; |
| | 341 | |
|
| 25 | 342 | | headerContainer.SetActive((flags & HEADER_FLAGS) != 0); |
| 25 | 343 | | userName.gameObject.SetActive((flags & MenuConfigFlags.Name) != 0); |
| 25 | 344 | | friendshipContainer.SetActive((flags & MenuConfigFlags.Friendship) != 0 && isFriendsEnabled && !isOwnUser); |
| 25 | 345 | | deleteFriendButton.gameObject.SetActive((flags & MenuConfigFlags.Friendship) != 0 && isFriendsEnabled && !isOwnU |
| 25 | 346 | | passportButton.gameObject.SetActive((flags & MenuConfigFlags.Passport) != 0); |
| 25 | 347 | | blockButton.gameObject.SetActive((flags & MenuConfigFlags.Block) != 0 && !isOwnUser); |
| 25 | 348 | | reportButton.gameObject.SetActive((flags & MenuConfigFlags.Report) != 0 && !isOwnUser); |
| 25 | 349 | | messageButton.gameObject.SetActive((flags & MenuConfigFlags.Message) != 0 && !isBlocked && enableSendMessage && |
| | 350 | |
|
| 25 | 351 | | if (mentionButton != null) |
| 25 | 352 | | mentionButton.gameObject.SetActive((flags & MenuConfigFlags.Mention) != 0 && DataStore.i.HUDs.chatInputVisib |
| 25 | 353 | | } |
| | 354 | |
|
| | 355 | | private bool Setup(string userId, MenuConfigFlags configFlags) |
| | 356 | | { |
| 6 | 357 | | this.userId = userId; |
| | 358 | |
|
| 6 | 359 | | UserProfile profile = UserProfileController.userProfilesCatalog.Get(userId); |
| | 360 | |
|
| 6 | 361 | | if (profile == null) |
| | 362 | | { |
| 0 | 363 | | ShowUserNotificationError(userId); |
| 0 | 364 | | return false; |
| | 365 | | } |
| | 366 | |
|
| 6 | 367 | | if (profile.isGuest || !UserProfile.GetOwnUserProfile().hasConnectedWeb3) |
| 0 | 368 | | configFlags &= ~USES_FRIENDS_API_FLAGS; |
| | 369 | |
|
| 6 | 370 | | currentConfigFlags = configFlags; |
| 6 | 371 | | ProcessActiveElements(configFlags); |
| | 372 | |
|
| 6 | 373 | | if ((configFlags & MenuConfigFlags.Block) != 0) |
| | 374 | | { |
| 4 | 375 | | isBlocked = UserProfile.GetOwnUserProfile().blocked.Contains(userId); |
| 4 | 376 | | blockText.text = isBlocked ? BLOCK_BTN_UNBLOCK_TEXT : BLOCK_BTN_BLOCK_TEXT; |
| | 377 | | } |
| | 378 | |
|
| 6 | 379 | | if ((configFlags & MenuConfigFlags.Name) != 0) |
| | 380 | | { |
| 4 | 381 | | string name = profile?.userName; |
| 4 | 382 | | userName.text = name; |
| | 383 | | } |
| | 384 | |
|
| 6 | 385 | | if ((configFlags & USES_FRIENDS_API_FLAGS) != 0) |
| | 386 | | { |
| 6 | 387 | | UserStatus status = friendsController.GetUserStatus(userId); |
| 6 | 388 | | SetupFriendship(status?.friendshipStatus ?? FriendshipStatus.NOT_FRIEND); |
| 6 | 389 | | friendsController.OnUpdateFriendship -= OnFriendActionUpdate; |
| 6 | 390 | | friendsController.OnUpdateFriendship += OnFriendActionUpdate; |
| | 391 | | } |
| | 392 | |
|
| 6 | 393 | | return true; |
| | 394 | | } |
| | 395 | |
|
| | 396 | | private void SetupFriendship(FriendshipStatus friendshipStatus) |
| | 397 | | { |
| 12 | 398 | | bool friendshipEnabled = (currentConfigFlags & MenuConfigFlags.Friendship) != 0 && isFriendsEnabled; |
| 12 | 399 | | bool messageEnabled = (currentConfigFlags & MenuConfigFlags.Message) != 0 && isFriendsEnabled; |
| | 400 | |
|
| 12 | 401 | | if (friendshipStatus == FriendshipStatus.FRIEND) |
| | 402 | | { |
| 2 | 403 | | if (friendshipEnabled) |
| | 404 | | { |
| 1 | 405 | | friendAddContainer.SetActive(false); |
| 1 | 406 | | friendRemoveContainer.SetActive(true); |
| 1 | 407 | | friendRequestedContainer.SetActive(false); |
| 1 | 408 | | deleteFriendButton.gameObject.SetActive(true); |
| | 409 | | } |
| | 410 | |
|
| 3 | 411 | | if (messageEnabled) { messageButton.gameObject.SetActive(!isBlocked && enableSendMessage); } |
| | 412 | | } |
| 10 | 413 | | else if (friendshipStatus == FriendshipStatus.REQUESTED_TO) |
| | 414 | | { |
| 2 | 415 | | if (friendshipEnabled) |
| | 416 | | { |
| 1 | 417 | | friendAddContainer.SetActive(false); |
| 1 | 418 | | friendRemoveContainer.SetActive(false); |
| 1 | 419 | | friendRequestedContainer.SetActive(true); |
| 1 | 420 | | deleteFriendButton.gameObject.SetActive(false); |
| | 421 | | } |
| | 422 | |
|
| 3 | 423 | | if (messageEnabled) { messageButton.gameObject.SetActive(false); } |
| | 424 | | } |
| 8 | 425 | | else if (friendshipStatus == FriendshipStatus.NOT_FRIEND) |
| | 426 | | { |
| 8 | 427 | | if (friendshipEnabled) |
| | 428 | | { |
| 6 | 429 | | friendAddContainer.SetActive(true); |
| 6 | 430 | | friendRemoveContainer.SetActive(false); |
| 6 | 431 | | friendRequestedContainer.SetActive(false); |
| 6 | 432 | | deleteFriendButton.gameObject.SetActive(false); |
| | 433 | | } |
| | 434 | |
|
| 14 | 435 | | if (messageEnabled) { messageButton.gameObject.SetActive(false); } |
| | 436 | | } |
| 0 | 437 | | else if (friendshipStatus == FriendshipStatus.REQUESTED_FROM) |
| | 438 | | { |
| 0 | 439 | | if (friendshipEnabled) |
| | 440 | | { |
| 0 | 441 | | friendAddContainer.SetActive(true); |
| 0 | 442 | | friendRemoveContainer.SetActive(false); |
| 0 | 443 | | friendRequestedContainer.SetActive(false); |
| 0 | 444 | | deleteFriendButton.gameObject.SetActive(false); |
| | 445 | | } |
| | 446 | |
|
| 0 | 447 | | if (messageEnabled) { messageButton.gameObject.SetActive(false); } |
| | 448 | | } |
| 4 | 449 | | } |
| | 450 | |
|
| | 451 | | private void OnFriendActionUpdate(string userId, FriendshipAction action) |
| | 452 | | { |
| 6 | 453 | | if (this.userId != userId) { return; } |
| | 454 | |
|
| | 455 | | switch (action) |
| | 456 | | { |
| | 457 | | case FriendshipAction.APPROVED: |
| 2 | 458 | | SetupFriendship(FriendshipStatus.FRIEND); |
| 2 | 459 | | break; |
| | 460 | | case FriendshipAction.REQUESTED_TO: |
| 2 | 461 | | SetupFriendship(FriendshipStatus.REQUESTED_TO); |
| 2 | 462 | | break; |
| | 463 | | case FriendshipAction.DELETED: |
| | 464 | | case FriendshipAction.CANCELLED: |
| | 465 | | case FriendshipAction.REJECTED: |
| | 466 | | case FriendshipAction.NONE: |
| 2 | 467 | | SetupFriendship(FriendshipStatus.NOT_FRIEND); |
| 2 | 468 | | break; |
| | 469 | | case FriendshipAction.REQUESTED_FROM: |
| 0 | 470 | | SetupFriendship(FriendshipStatus.REQUESTED_FROM); |
| | 471 | | break; |
| | 472 | | } |
| 0 | 473 | | } |
| | 474 | |
|
| | 475 | | private ISocialAnalytics GetSocialAnalytics() |
| | 476 | | { |
| 2 | 477 | | if (socialAnalytics == null) |
| | 478 | | { |
| 0 | 479 | | socialAnalytics = new SocialAnalytics( |
| | 480 | | Environment.i.platform.serviceProviders.analytics, |
| | 481 | | new UserProfileWebInterfaceBridge()); |
| | 482 | | } |
| | 483 | |
|
| 2 | 484 | | return socialAnalytics; |
| | 485 | | } |
| | 486 | |
|
| | 487 | | private static void ShowUserNotificationError(string userIdOrName) |
| | 488 | | { |
| 0 | 489 | | DataStore.i.notifications.DefaultErrorNotification.Set("This user was not found.", true); |
| 0 | 490 | | Debug.LogError($"User {userIdOrName} was not found in the catalog!"); |
| 0 | 491 | | } |
| | 492 | |
|
| | 493 | | private void OnCopyNameButtonPressed() |
| | 494 | | { |
| 0 | 495 | | clipboard.WriteText($"@{userName.text}"); |
| 0 | 496 | | nameCopiedToast.gameObject.SetActive(true); |
| 0 | 497 | | nameCopiedToast.ShowDelayHide(3); |
| 0 | 498 | | copyPasteAnalyticsService.Copy("name"); |
| 0 | 499 | | } |
| | 500 | |
|
| | 501 | | private IEnumerator ClampPositionToScreenBordersOnNextFrame() |
| | 502 | | { |
| 6 | 503 | | yield return null; |
| 0 | 504 | | ClampPositionToScreenBorders(transform.position); |
| 0 | 505 | | } |
| | 506 | |
|
| | 507 | | #if UNITY_EDITOR |
| | 508 | |
|
| | 509 | | //This is just to process buttons and container visibility on editor |
| | 510 | | private void OnValidate() |
| | 511 | | { |
| 13 | 512 | | if (headerContainer == null) |
| 0 | 513 | | return; |
| | 514 | |
|
| 13 | 515 | | ProcessActiveElements(menuConfigFlags); |
| 13 | 516 | | } |
| | 517 | | #endif |
| | 518 | | } |