| | 1 | | using DCL.Social.Chat; |
| | 2 | | using DCL.Social.Friends; |
| | 3 | | using SocialBar.UserThumbnail; |
| | 4 | | using SocialFeaturesAnalytics; |
| | 5 | | using System; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.EventSystems; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler |
| | 12 | | { |
| | 13 | | private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.995f; |
| | 14 | |
|
| | 15 | | [SerializeField] internal Button backButton; |
| | 16 | | [SerializeField] internal Button closeButton; |
| | 17 | | [SerializeField] internal UserThumbnailComponentView userThumbnail; |
| | 18 | | [SerializeField] internal TMP_Text userNameLabel; |
| | 19 | | [SerializeField] internal PrivateChatHUDView chatView; |
| | 20 | | [SerializeField] internal GameObject jumpInButtonContainer; |
| | 21 | | [SerializeField] internal JumpInButton jumpInButton; |
| | 22 | | [SerializeField] internal UserContextMenu userContextMenu; |
| | 23 | | [SerializeField] internal RectTransform userContextMenuReferencePoint; |
| | 24 | | [SerializeField] internal Button optionsButton; |
| | 25 | | [SerializeField] internal GameObject messagesLoading; |
| | 26 | | [SerializeField] internal ScrollRect scroll; |
| | 27 | | [SerializeField] internal GameObject oldMessagesLoadingContainer; |
| | 28 | | [SerializeField] private Model model; |
| | 29 | |
|
| | 30 | | private IFriendsController friendsController; |
| | 31 | | private ISocialAnalytics socialAnalytics; |
| | 32 | | private Coroutine alphaRoutine; |
| | 33 | | private Vector2 originalSize; |
| | 34 | |
|
| | 35 | | public event Action OnPressBack; |
| | 36 | | public event Action OnMinimize; |
| | 37 | | public event Action OnClose; |
| | 38 | | public event Action<string> OnUnfriend |
| | 39 | | { |
| 1 | 40 | | add => userContextMenu.OnUnfriend += value; |
| 1 | 41 | | remove => userContextMenu.OnUnfriend -= value; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public event Action OnRequireMoreMessages; |
| | 45 | | public event Action<bool> OnFocused |
| | 46 | | { |
| 2 | 47 | | add => onFocused += value; |
| 1 | 48 | | remove => onFocused -= value; |
| | 49 | | } |
| | 50 | | public event Action OnClickOverWindow; |
| | 51 | | public event Action<string> OnUnblockUser; |
| | 52 | |
|
| 4 | 53 | | public IChatHUDComponentView ChatHUD => chatView; |
| 2 | 54 | | public bool IsActive => gameObject.activeInHierarchy; |
| 0 | 55 | | public RectTransform Transform => (RectTransform) transform; |
| 0 | 56 | | public bool IsFocused => isFocused; |
| | 57 | |
|
| | 58 | | public override void Awake() |
| | 59 | | { |
| 14 | 60 | | base.Awake(); |
| 14 | 61 | | originalSize = ((RectTransform) transform).sizeDelta; |
| 15 | 62 | | backButton.onClick.AddListener(() => OnPressBack?.Invoke()); |
| 15 | 63 | | closeButton.onClick.AddListener(() => OnClose?.Invoke()); |
| 14 | 64 | | optionsButton.onClick.AddListener(ShowOptions); |
| 14 | 65 | | userContextMenu.OnBlock += HandleBlockFromContextMenu; |
| 14 | 66 | | scroll.onValueChanged.AddListener((scrollPos) => |
| | 67 | | { |
| 0 | 68 | | if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD) |
| 0 | 69 | | OnRequireMoreMessages?.Invoke(); |
| 0 | 70 | | }); |
| | 71 | |
|
| 14 | 72 | | chatView.OnUnblockUser += HandleUnblockFromButtonInChat; |
| 14 | 73 | | } |
| | 74 | |
|
| | 75 | | public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics) |
| | 76 | | { |
| 14 | 77 | | this.friendsController = friendsController; |
| 14 | 78 | | this.socialAnalytics = socialAnalytics; |
| 14 | 79 | | } |
| | 80 | |
|
| | 81 | | public override void Dispose() |
| | 82 | | { |
| 28 | 83 | | if (!this) return; |
| 28 | 84 | | if (!gameObject) return; |
| | 85 | |
|
| 28 | 86 | | if (userContextMenu != null) |
| 28 | 87 | | userContextMenu.OnBlock -= HandleBlockFromContextMenu; |
| | 88 | |
|
| 28 | 89 | | if (chatView!= null) |
| 27 | 90 | | chatView.OnUnblockUser -= HandleUnblockFromButtonInChat; |
| | 91 | |
|
| 28 | 92 | | base.Dispose(); |
| 28 | 93 | | } |
| | 94 | |
|
| | 95 | | public void SetLoadingMessagesActive(bool isActive) |
| | 96 | | { |
| 3 | 97 | | if (messagesLoading == null) |
| 0 | 98 | | return; |
| | 99 | |
|
| 3 | 100 | | messagesLoading.SetActive(isActive); |
| 3 | 101 | | } |
| | 102 | |
|
| | 103 | | public void SetOldMessagesLoadingActive(bool isActive) |
| | 104 | | { |
| 3 | 105 | | if (oldMessagesLoadingContainer == null) |
| 0 | 106 | | return; |
| | 107 | |
|
| 3 | 108 | | oldMessagesLoadingContainer.SetActive(isActive); |
| 3 | 109 | | oldMessagesLoadingContainer.transform.SetAsFirstSibling(); |
| 3 | 110 | | } |
| | 111 | |
|
| | 112 | | public override void RefreshControl() |
| | 113 | | { |
| 2 | 114 | | userThumbnail.Configure(new UserThumbnailComponentModel |
| | 115 | | { |
| | 116 | | faceUrl = model.faceSnapshotUrl, |
| | 117 | | isBlocked = model.isUserBlocked, |
| | 118 | | isOnline = model.isUserOnline |
| | 119 | | }); |
| 2 | 120 | | userNameLabel.SetText(model.userName); |
| 2 | 121 | | jumpInButtonContainer.SetActive(model.isUserOnline); |
| 2 | 122 | | chatView.SetBlockedStatus(model.isUserBlocked); |
| 2 | 123 | | } |
| | 124 | |
|
| | 125 | | public void Setup(UserProfile profile, bool isOnline, bool isBlocked) |
| | 126 | | { |
| 2 | 127 | | model = new Model |
| | 128 | | { |
| | 129 | | userId = profile.userId, |
| | 130 | | faceSnapshotUrl = profile.face256SnapshotURL, |
| | 131 | | userName = profile.userName, |
| | 132 | | isUserOnline = isOnline, |
| | 133 | | isUserBlocked = isBlocked |
| | 134 | | }; |
| 2 | 135 | | RefreshControl(); |
| | 136 | |
|
| 2 | 137 | | jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics); |
| 2 | 138 | | } |
| | 139 | |
|
| 2 | 140 | | public void Show() => gameObject.SetActive(true); |
| | 141 | |
|
| 2 | 142 | | public void Hide() => gameObject.SetActive(false); |
| | 143 | |
|
| 1 | 144 | | public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke(); |
| | 145 | |
|
| | 146 | | private void ShowOptions() |
| | 147 | | { |
| 0 | 148 | | var contextMenuTransform = (RectTransform) userContextMenu.transform; |
| 0 | 149 | | contextMenuTransform.pivot = userContextMenuReferencePoint.pivot; |
| 0 | 150 | | contextMenuTransform.position = userContextMenuReferencePoint.position; |
| 0 | 151 | | userContextMenu.Show(model.userId); |
| 0 | 152 | | } |
| | 153 | |
|
| | 154 | | private void HandleBlockFromContextMenu(string userId, bool isBlocked) |
| | 155 | | { |
| 0 | 156 | | if (userId != model.userId) return; |
| 0 | 157 | | model.isUserBlocked = isBlocked; |
| 0 | 158 | | RefreshControl(); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | private void HandleUnblockFromButtonInChat(string userId) |
| | 162 | | { |
| 0 | 163 | | HandleBlockFromContextMenu(userId, false); |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | |
|
| | 167 | | [Serializable] |
| | 168 | | private struct Model |
| | 169 | | { |
| | 170 | | public string userId; |
| | 171 | | public string userName; |
| | 172 | | public string faceSnapshotUrl; |
| | 173 | | public bool isUserBlocked; |
| | 174 | | public bool isUserOnline; |
| | 175 | | } |
| | 176 | | } |