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