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