| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using TMPro; |
| | 7 | | using UIComponents.CollapsableSortedList; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | namespace DCL.Chat.HUD |
| | 12 | | { |
| | 13 | | public class WorldChatWindowComponentView : BaseComponentView, IWorldChatWindowView, IComponentModelConfig<WorldChat |
| | 14 | | { |
| | 15 | | private const int CREATION_AMOUNT_PER_FRAME = 5; |
| | 16 | | private const int AVATAR_SNAPSHOTS_PER_FRAME = 5; |
| | 17 | | private const string NEARBY_CHANNEL = "nearby"; |
| | 18 | | private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.005f; |
| | 19 | | private const float MIN_TIME_TO_REQUIRE_MORE_ENTRIES = 0.5f; |
| | 20 | |
|
| | 21 | | [SerializeField] internal CollapsablePublicChannelListComponentView publicChannelList; |
| | 22 | | [SerializeField] internal CollapsableDirectChatListComponentView directChatList; |
| | 23 | | [SerializeField] internal CollapsableChatSearchListComponentView searchResultsList; |
| | 24 | | [SerializeField] internal GameObject searchLoading; |
| | 25 | | [SerializeField] internal Button closeButton; |
| | 26 | | [SerializeField] internal GameObject channelsLoadingContainer; |
| | 27 | | [SerializeField] internal GameObject directChatsLoadingContainer; |
| | 28 | | [SerializeField] internal GameObject emptyDirectChatsContainer; |
| | 29 | | [SerializeField] internal GameObject channelsHeader; |
| | 30 | | [SerializeField] internal GameObject directChannelHeader; |
| | 31 | | [SerializeField] internal GameObject searchResultsHeader; |
| | 32 | | [SerializeField] internal TMP_Text channelsHeaderLabel; |
| | 33 | | [SerializeField] internal TMP_Text directChatsHeaderLabel; |
| | 34 | | [SerializeField] internal TMP_Text searchResultsHeaderLabel; |
| | 35 | | [SerializeField] internal ScrollRect scroll; |
| | 36 | | [SerializeField] internal SearchBarComponentView searchBar; |
| | 37 | | [SerializeField] internal GameObject searchAndCreateContainer; |
| | 38 | | [SerializeField] internal Button openChannelSearchButton; |
| | 39 | | [SerializeField] internal ChannelContextualMenu channelContextualMenu; |
| | 40 | | [SerializeField] internal Button createChannelButton; |
| | 41 | | [SerializeField] internal GameObject searchBarContainer; |
| | 42 | | [SerializeField] internal CollapsableListToggleButton directChatsCollapseButton; |
| | 43 | | [SerializeField] internal CollapsableListToggleButton publicChatsChatsCollapseButton; |
| | 44 | | [SerializeField] private WorldChatWindowModel model; |
| | 45 | | [SerializeField] private GameObject channelsPromoteLabel; |
| | 46 | |
|
| | 47 | | [Header("Load More Entries")] |
| | 48 | | [SerializeField] internal GameObject loadMoreEntriesContainer; |
| | 49 | | [SerializeField] internal TMP_Text loadMoreEntriesLabel; |
| | 50 | | [SerializeField] internal GameObject loadMoreEntriesLoading; |
| | 51 | |
|
| | 52 | | [Header("Guest")] |
| | 53 | | [SerializeField] internal GameObject connectWalletContainer; |
| | 54 | | [SerializeField] internal GameObject walletConnectedContainer; |
| | 55 | | [SerializeField] internal Button connectWalletButton; |
| | 56 | | [SerializeField] internal Button whatIsWalletButton; |
| | 57 | |
|
| 42 | 58 | | private readonly Dictionary<string, PrivateChatModel> privateChatsCreationQueue = |
| | 59 | | new Dictionary<string, PrivateChatModel>(); |
| | 60 | |
|
| 42 | 61 | | private readonly Dictionary<string, PublicChatModel> publicChatsCreationQueue = |
| | 62 | | new Dictionary<string, PublicChatModel>(); |
| | 63 | |
|
| | 64 | | private bool isSortingDirty; |
| | 65 | | private bool isLayoutDirty; |
| | 66 | | private int currentAvatarSnapshotIndex; |
| | 67 | | private bool isLoadingPrivateChannels; |
| | 68 | | private bool isSearchMode; |
| | 69 | | private string optionsChannelId; |
| | 70 | | private Vector2 lastScrollPosition; |
| | 71 | | private float loadMoreEntriesRestrictionTime; |
| | 72 | | private Coroutine requireMoreEntriesRoutine; |
| | 73 | | private bool isConnectWalletMode; |
| | 74 | |
|
| | 75 | | public event Action OnClose; |
| | 76 | | public event Action<string> OnOpenPrivateChat; |
| | 77 | | public event Action<string> OnOpenPublicChat; |
| | 78 | | public event Action<string> OnSearchChatRequested; |
| | 79 | | public event Action OnRequireMorePrivateChats; |
| | 80 | | public event Action OnOpenChannelSearch; |
| | 81 | | public event Action<string> OnLeaveChannel; |
| | 82 | | public event Action OnCreateChannel; |
| | 83 | | public event Action OnSignUp; |
| | 84 | | public event Action OnRequireWalletReadme; |
| | 85 | |
|
| 0 | 86 | | public RectTransform Transform => (RectTransform) transform; |
| 0 | 87 | | public bool IsActive => gameObject.activeInHierarchy; |
| | 88 | |
|
| | 89 | | public static WorldChatWindowComponentView Create() |
| | 90 | | { |
| 34 | 91 | | return Instantiate(Resources.Load<WorldChatWindowComponentView>("SocialBarV1/ConversationListHUD")); |
| | 92 | | } |
| | 93 | |
|
| | 94 | | public override void Awake() |
| | 95 | | { |
| 40 | 96 | | base.Awake(); |
| | 97 | |
|
| | 98 | | int SortByAlphabeticalOrder(PublicChatEntry u1, PublicChatEntry u2) |
| | 99 | | { |
| 1 | 100 | | if (u1.Model.name == NEARBY_CHANNEL) |
| 1 | 101 | | return -1; |
| 0 | 102 | | if (u2.Model.name == NEARBY_CHANNEL) |
| 0 | 103 | | return 1; |
| | 104 | |
|
| 0 | 105 | | return string.Compare(u1.Model.name, u2.Model.name, StringComparison.InvariantCultureIgnoreCase); |
| | 106 | | } |
| | 107 | |
|
| 40 | 108 | | openChannelSearchButton.onClick.AddListener(() => OnOpenChannelSearch?.Invoke()); |
| 41 | 109 | | closeButton.onClick.AddListener(() => OnClose?.Invoke()); |
| 86 | 110 | | directChatList.SortingMethod = (a, b) => b.Model.lastMessageTimestamp.CompareTo(a.Model.lastMessageTimestamp |
| 41 | 111 | | directChatList.OnOpenChat += entry => OnOpenPrivateChat?.Invoke(entry.Model.userId); |
| 40 | 112 | | searchResultsList.OnOpenPrivateChat += entry => OnOpenPrivateChat?.Invoke(entry.Model.userId); |
| 40 | 113 | | searchResultsList.OnOpenPublicChat += entry => OnOpenPublicChat?.Invoke(entry.Model.channelId); |
| 40 | 114 | | publicChannelList.SortingMethod = SortByAlphabeticalOrder; |
| 41 | 115 | | publicChannelList.OnOpenChat += entry => OnOpenPublicChat?.Invoke(entry.Model.channelId); |
| 41 | 116 | | searchBar.OnSearchText += text => OnSearchChatRequested?.Invoke(text); |
| 40 | 117 | | scroll.onValueChanged.AddListener(RequestMorePrivateChats); |
| 41 | 118 | | channelContextualMenu.OnLeave += () => OnLeaveChannel?.Invoke(optionsChannelId); |
| 40 | 119 | | createChannelButton.onClick.AddListener(() => OnCreateChannel?.Invoke()); |
| 41 | 120 | | connectWalletButton.onClick.AddListener(() => OnSignUp?.Invoke()); |
| 41 | 121 | | whatIsWalletButton.onClick.AddListener(() => OnRequireWalletReadme?.Invoke()); |
| 40 | 122 | | UpdateHeaders(); |
| 40 | 123 | | } |
| | 124 | |
|
| | 125 | | public override void OnEnable() |
| | 126 | | { |
| 41 | 127 | | base.OnEnable(); |
| 41 | 128 | | UpdateLayout(); |
| 41 | 129 | | } |
| | 130 | |
|
| | 131 | | public void Initialize(IChatController chatController) |
| | 132 | | { |
| 34 | 133 | | directChatList.Initialize(chatController); |
| 34 | 134 | | publicChannelList.Initialize(chatController); |
| 34 | 135 | | searchResultsList.Initialize(chatController); |
| 34 | 136 | | } |
| | 137 | |
|
| | 138 | | public override void Update() |
| | 139 | | { |
| 245 | 140 | | base.Update(); |
| | 141 | |
|
| 245 | 142 | | SetQueuedEntries(); |
| | 143 | |
|
| 245 | 144 | | if (isSortingDirty) |
| | 145 | | { |
| 26 | 146 | | directChatList.Sort(); |
| 26 | 147 | | searchResultsList.Sort(); |
| 26 | 148 | | publicChannelList.Sort(); |
| | 149 | | } |
| | 150 | |
|
| 245 | 151 | | isSortingDirty = false; |
| | 152 | |
|
| 245 | 153 | | if (isLayoutDirty) |
| 41 | 154 | | ((RectTransform) scroll.transform).ForceUpdateLayout(); |
| 245 | 155 | | isLayoutDirty = false; |
| | 156 | |
|
| 245 | 157 | | FetchProfilePicturesForVisibleEntries(); |
| 245 | 158 | | } |
| | 159 | |
|
| 2 | 160 | | public void Show() => gameObject.SetActive(true); |
| | 161 | |
|
| 2 | 162 | | public void Hide() => gameObject.SetActive(false); |
| | 163 | |
|
| 38 | 164 | | public void SetPrivateChat(PrivateChatModel model) => privateChatsCreationQueue[model.user.userId] = model; |
| | 165 | |
|
| | 166 | | public void RemovePrivateChat(string userId) |
| | 167 | | { |
| 1 | 168 | | privateChatsCreationQueue.Remove(userId); |
| 1 | 169 | | directChatList.Remove(userId); |
| 1 | 170 | | searchResultsList.Remove(userId); |
| 1 | 171 | | UpdateHeaders(); |
| 1 | 172 | | UpdateLayout(); |
| 1 | 173 | | } |
| | 174 | |
|
| 21 | 175 | | public void SetPublicChat(PublicChatModel model) => publicChatsCreationQueue[model.channelId] = model; |
| | 176 | |
|
| | 177 | | public void RemovePublicChat(string channelId) |
| | 178 | | { |
| 0 | 179 | | publicChatsCreationQueue.Remove(channelId); |
| 0 | 180 | | publicChannelList.Remove(channelId); |
| 0 | 181 | | UpdateHeaders(); |
| 0 | 182 | | UpdateLayout(); |
| 0 | 183 | | } |
| | 184 | |
|
| | 185 | | public void Configure(WorldChatWindowModel newModel) |
| | 186 | | { |
| 0 | 187 | | model = newModel; |
| 0 | 188 | | RefreshControl(); |
| 0 | 189 | | } |
| | 190 | |
|
| 1 | 191 | | public void ShowChannelsLoading() => SetChannelsLoadingVisibility(true); |
| | 192 | |
|
| 2 | 193 | | public void HideChannelsLoading() => SetChannelsLoadingVisibility(false); |
| | 194 | |
|
| 2 | 195 | | public void ShowPrivateChatsLoading() => SetPrivateChatLoadingVisibility(true); |
| | 196 | |
|
| 1 | 197 | | public void HidePrivateChatsLoading() => SetPrivateChatLoadingVisibility(false); |
| | 198 | |
|
| | 199 | | public void RefreshBlockedDirectMessages(List<string> blockedUsers) |
| | 200 | | { |
| 0 | 201 | | if (blockedUsers == null) return; |
| 0 | 202 | | directChatList.RefreshBlockedEntries(blockedUsers); |
| 0 | 203 | | } |
| | 204 | |
|
| | 205 | | public void HideMoreChatsToLoadHint() |
| | 206 | | { |
| 1 | 207 | | loadMoreEntriesContainer.SetActive(false); |
| 1 | 208 | | emptyDirectChatsContainer.SetActive(directChatList.Count() == 0); |
| 1 | 209 | | UpdateLayout(); |
| 1 | 210 | | } |
| | 211 | |
|
| | 212 | | public void ShowMoreChatsToLoadHint(int count) |
| | 213 | | { |
| 2 | 214 | | loadMoreEntriesLabel.SetText( |
| | 215 | | $"{count} chats hidden. Use the search bar to find them or click below to show more."); |
| 2 | 216 | | loadMoreEntriesContainer.SetActive(true); |
| 2 | 217 | | emptyDirectChatsContainer.SetActive(false); |
| 2 | 218 | | UpdateLayout(); |
| 2 | 219 | | } |
| | 220 | |
|
| | 221 | | public void HideMoreChatsLoading() |
| | 222 | | { |
| 247 | 223 | | loadMoreEntriesLoading.SetActive(false); |
| 247 | 224 | | } |
| | 225 | |
|
| | 226 | | public void ShowMoreChatsLoading() |
| | 227 | | { |
| 2 | 228 | | loadMoreEntriesLoading.SetActive(true); |
| 2 | 229 | | } |
| | 230 | |
|
| | 231 | | public void HideSearchLoading() |
| | 232 | | { |
| 1 | 233 | | searchLoading.SetActive(false); |
| 1 | 234 | | } |
| | 235 | |
|
| | 236 | | public void ShowSearchLoading() |
| | 237 | | { |
| 1 | 238 | | searchLoading.SetActive(true); |
| 1 | 239 | | searchLoading.transform.SetAsLastSibling(); |
| 1 | 240 | | } |
| | 241 | |
|
| | 242 | | public void DisableSearchMode() |
| | 243 | | { |
| 4 | 244 | | isSearchMode = false; |
| 4 | 245 | | searchResultsList.Hide(); |
| 4 | 246 | | publicChannelList.Show(); |
| 4 | 247 | | publicChannelList.Sort(); |
| | 248 | |
|
| 4 | 249 | | if (!isLoadingPrivateChannels) |
| | 250 | | { |
| 3 | 251 | | directChatList.Show(); |
| 3 | 252 | | directChatList.Sort(); |
| 3 | 253 | | channelsHeader.SetActive(true); |
| 3 | 254 | | directChannelHeader.SetActive(true); |
| | 255 | | } |
| | 256 | |
|
| 4 | 257 | | searchResultsHeader.SetActive(false); |
| 4 | 258 | | searchResultsList.Clear(); |
| 4 | 259 | | searchBar.ClearSearch(false); |
| | 260 | |
|
| 4 | 261 | | UpdateHeaders(); |
| 4 | 262 | | } |
| | 263 | |
|
| | 264 | | public void EnableSearchMode() |
| | 265 | | { |
| 6 | 266 | | isSearchMode = true; |
| | 267 | |
|
| 6 | 268 | | searchResultsList.Clear(); |
| 6 | 269 | | searchResultsList.Show(); |
| 6 | 270 | | searchResultsList.Sort(); |
| 6 | 271 | | publicChannelList.Hide(); |
| 6 | 272 | | directChatList.Hide(); |
| 6 | 273 | | channelsHeader.SetActive(false); |
| 6 | 274 | | directChannelHeader.SetActive(false); |
| 6 | 275 | | searchResultsHeader.SetActive(true); |
| | 276 | |
|
| 6 | 277 | | UpdateHeaders(); |
| 6 | 278 | | searchLoading.transform.SetAsLastSibling(); |
| 6 | 279 | | } |
| | 280 | |
|
| 0 | 281 | | public bool ContainsPrivateChannel(string userId) => privateChatsCreationQueue.ContainsKey(userId) |
| | 282 | | || directChatList.Get(userId) != null; |
| | 283 | |
|
| 0 | 284 | | public void SetCreateChannelButtonActive(bool isActive) => createChannelButton.gameObject.SetActive(isActive); |
| | 285 | |
|
| 1 | 286 | | public void SetSearchAndCreateContainerActive(bool isActive) => searchAndCreateContainer.SetActive(isActive); |
| | 287 | |
|
| | 288 | | public void ShowConnectWallet() |
| | 289 | | { |
| 1 | 290 | | isConnectWalletMode = true; |
| 1 | 291 | | connectWalletContainer.SetActive(true); |
| 1 | 292 | | walletConnectedContainer.SetActive(false); |
| 1 | 293 | | searchBarContainer.SetActive(false); |
| 1 | 294 | | directChatsCollapseButton.SetInteractability(false); |
| 1 | 295 | | publicChatsChatsCollapseButton.SetInteractability(false); |
| 1 | 296 | | } |
| | 297 | |
|
| | 298 | | public void HideConnectWallet() |
| | 299 | | { |
| 2 | 300 | | isConnectWalletMode = false; |
| 2 | 301 | | connectWalletContainer.SetActive(false); |
| 2 | 302 | | walletConnectedContainer.SetActive(true); |
| 2 | 303 | | searchBarContainer.SetActive(true); |
| 2 | 304 | | directChatsCollapseButton.SetInteractability(true); |
| 2 | 305 | | publicChatsChatsCollapseButton.SetInteractability(true); |
| 2 | 306 | | } |
| | 307 | |
|
| 1 | 308 | | public void SetChannelsPromoteLabelVisible(bool isVisible) => channelsPromoteLabel.SetActive(isVisible); |
| | 309 | |
|
| | 310 | | public override void RefreshControl() |
| | 311 | | { |
| 0 | 312 | | publicChannelList.Clear(); |
| 0 | 313 | | foreach (var entry in model.publicChannels) |
| 0 | 314 | | publicChannelList.Set(entry.channelId, entry); |
| 0 | 315 | | SetChannelsLoadingVisibility(model.isLoadingChannels); |
| | 316 | |
|
| 0 | 317 | | directChatList.Clear(); |
| 0 | 318 | | foreach (var entry in model.privateChats) |
| 0 | 319 | | directChatList.Set(entry.userId, entry); |
| 0 | 320 | | SetPrivateChatLoadingVisibility(model.isLoadingDirectChats); |
| 0 | 321 | | } |
| | 322 | |
|
| | 323 | | private void Set(PrivateChatModel model) |
| | 324 | | { |
| 37 | 325 | | var user = model.user; |
| 37 | 326 | | var userId = user.userId; |
| | 327 | |
|
| 37 | 328 | | var entry = new PrivateChatEntryModel( |
| | 329 | | user.userId, |
| | 330 | | user.userName, |
| | 331 | | model.recentMessage != null ? model.recentMessage.body : string.Empty, |
| | 332 | | user.face256SnapshotURL, |
| | 333 | | model.isBlocked, |
| | 334 | | model.isOnline, |
| | 335 | | model.recentMessage != null ? model.recentMessage.timestamp : 0); |
| | 336 | |
|
| 37 | 337 | | if (isSearchMode) |
| 18 | 338 | | searchResultsList.Set(entry); |
| | 339 | | else |
| 19 | 340 | | directChatList.Set(userId, entry); |
| | 341 | |
|
| 37 | 342 | | UpdateHeaders(); |
| 37 | 343 | | UpdateLayout(); |
| 37 | 344 | | SortLists(); |
| 37 | 345 | | } |
| | 346 | |
|
| | 347 | | private void Set(PublicChatModel model) |
| | 348 | | { |
| 21 | 349 | | var channelId = model.channelId; |
| 21 | 350 | | var entryModel = new PublicChatEntryModel(channelId, model.name, model.joined, model.memberCount, showOnlyOn |
| | 351 | | PublicChatEntry entry; |
| | 352 | |
|
| 21 | 353 | | if (isSearchMode) |
| | 354 | | { |
| 8 | 355 | | searchResultsList.Set(entryModel); |
| 8 | 356 | | entry = (PublicChatEntry) searchResultsList.Get(channelId); |
| 8 | 357 | | } |
| | 358 | | else |
| | 359 | | { |
| 13 | 360 | | publicChannelList.Set(channelId, entryModel); |
| 13 | 361 | | entry = publicChannelList.Get(channelId); |
| | 362 | | } |
| | 363 | |
|
| 21 | 364 | | entry.OnOpenOptions -= OpenChannelOptions; |
| 21 | 365 | | entry.OnOpenOptions += OpenChannelOptions; |
| | 366 | |
|
| 21 | 367 | | UpdateHeaders(); |
| 21 | 368 | | UpdateLayout(); |
| 21 | 369 | | SortLists(); |
| 21 | 370 | | } |
| | 371 | |
|
| | 372 | | private void OpenChannelOptions(PublicChatEntry entry) |
| | 373 | | { |
| 1 | 374 | | optionsChannelId = entry.Model.channelId; |
| 1 | 375 | | entry.Dock(channelContextualMenu); |
| 1 | 376 | | channelContextualMenu.SetHeaderTitle($"#{entry.Model.name.ToLower()}"); |
| 1 | 377 | | channelContextualMenu.Show(); |
| 1 | 378 | | } |
| | 379 | |
|
| 0 | 380 | | private void SortLists() => isSortingDirty = true; |
| | 381 | |
|
| | 382 | | private void SetChannelsLoadingVisibility(bool visible) |
| | 383 | | { |
| 3 | 384 | | model.isLoadingChannels = visible; |
| 3 | 385 | | channelsLoadingContainer.SetActive(visible); |
| 3 | 386 | | publicChannelList.gameObject.SetActive(!visible); |
| 3 | 387 | | } |
| | 388 | |
|
| | 389 | | private void SetPrivateChatLoadingVisibility(bool visible) |
| | 390 | | { |
| 3 | 391 | | model.isLoadingDirectChats = visible; |
| 3 | 392 | | directChatsLoadingContainer.SetActive(visible); |
| | 393 | |
|
| 3 | 394 | | if (visible) |
| 2 | 395 | | directChatList.Hide(); |
| 1 | 396 | | else if (!isSearchMode) |
| 1 | 397 | | directChatList.Show(); |
| | 398 | |
|
| 3 | 399 | | scroll.enabled = !visible; |
| 3 | 400 | | isLoadingPrivateChannels = visible; |
| 3 | 401 | | } |
| | 402 | |
|
| | 403 | | private void UpdateHeaders() |
| | 404 | | { |
| 109 | 405 | | directChatsHeaderLabel.text = $"Direct Messages ({directChatList.Count()})"; |
| 109 | 406 | | searchResultsHeaderLabel.text = $"Results ({searchResultsList.Count()})"; |
| 109 | 407 | | searchResultsHeader.SetActive(searchResultsList.Count() > 0); |
| 109 | 408 | | channelsHeaderLabel.text = $"Channels ({publicChannelList.Count()})"; |
| 109 | 409 | | } |
| | 410 | |
|
| 0 | 411 | | private void UpdateLayout() => isLayoutDirty = true; |
| | 412 | |
|
| | 413 | | private void SetQueuedEntries() |
| | 414 | | { |
| 245 | 415 | | if (privateChatsCreationQueue.Count > 0) |
| | 416 | | { |
| 110 | 417 | | for (var i = 0; i < CREATION_AMOUNT_PER_FRAME && privateChatsCreationQueue.Count > 0; i++) |
| | 418 | | { |
| 37 | 419 | | var (userId, model) = privateChatsCreationQueue.First(); |
| 37 | 420 | | privateChatsCreationQueue.Remove(userId); |
| 37 | 421 | | Set(model); |
| | 422 | | } |
| | 423 | | } |
| | 424 | |
|
| 532 | 425 | | for (var i = 0; i < CREATION_AMOUNT_PER_FRAME && publicChatsCreationQueue.Count > 0; i++) |
| | 426 | | { |
| 21 | 427 | | var (userId, model) = publicChatsCreationQueue.First(); |
| 21 | 428 | | publicChatsCreationQueue.Remove(userId); |
| 21 | 429 | | Set(model); |
| | 430 | | } |
| | 431 | |
|
| 245 | 432 | | HideMoreChatsLoading(); |
| 245 | 433 | | } |
| | 434 | |
|
| | 435 | | private void FetchProfilePicturesForVisibleEntries() |
| | 436 | | { |
| 253 | 437 | | if (isSearchMode) return; |
| | 438 | |
|
| 512 | 439 | | foreach (var entry in directChatList.Entries.Values.Skip(currentAvatarSnapshotIndex) |
| | 440 | | .Take(AVATAR_SNAPSHOTS_PER_FRAME)) |
| | 441 | | { |
| 19 | 442 | | if (entry.IsVisible((RectTransform) scroll.transform)) |
| 3 | 443 | | entry.EnableAvatarSnapshotFetching(); |
| | 444 | | else |
| 16 | 445 | | entry.DisableAvatarSnapshotFetching(); |
| | 446 | | } |
| | 447 | |
|
| 237 | 448 | | currentAvatarSnapshotIndex += AVATAR_SNAPSHOTS_PER_FRAME; |
| | 449 | |
|
| 237 | 450 | | if (currentAvatarSnapshotIndex >= directChatList.Entries.Count) |
| 237 | 451 | | currentAvatarSnapshotIndex = 0; |
| 237 | 452 | | } |
| | 453 | |
|
| | 454 | | private void RequestMorePrivateChats(Vector2 position) |
| | 455 | | { |
| 24 | 456 | | if (!loadMoreEntriesContainer.activeInHierarchy |
| | 457 | | || loadMoreEntriesLoading.activeInHierarchy |
| | 458 | | || Time.realtimeSinceStartup - loadMoreEntriesRestrictionTime < MIN_TIME_TO_REQUIRE_MORE_ENTRIES |
| 22 | 459 | | || isConnectWalletMode) return; |
| | 460 | |
|
| 2 | 461 | | if (position.y < REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD && lastScrollPosition.y >= REQUEST_MORE_ENTRIES_SCROL |
| | 462 | | { |
| 1 | 463 | | if (requireMoreEntriesRoutine != null) |
| 0 | 464 | | StopCoroutine(requireMoreEntriesRoutine); |
| | 465 | |
|
| 1 | 466 | | ShowMoreChatsLoading(); |
| 1 | 467 | | requireMoreEntriesRoutine = StartCoroutine(WaitThenRequireMoreEntries()); |
| | 468 | |
|
| 1 | 469 | | loadMoreEntriesRestrictionTime = Time.realtimeSinceStartup; |
| | 470 | | } |
| | 471 | |
|
| 2 | 472 | | lastScrollPosition = position; |
| 2 | 473 | | } |
| | 474 | |
|
| | 475 | | private IEnumerator WaitThenRequireMoreEntries() |
| | 476 | | { |
| 1 | 477 | | yield return new WaitForSeconds(1f); |
| 1 | 478 | | OnRequireMorePrivateChats?.Invoke(); |
| 1 | 479 | | } |
| | 480 | | } |
| | 481 | | } |