| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using SocialFeaturesAnalytics; |
| | 7 | | using TMPro; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | public class FriendsTabComponentView : BaseComponentView |
| | 12 | | { |
| | 13 | | private const int CREATION_AMOUNT_PER_FRAME = 5; |
| | 14 | | private const int AVATAR_SNAPSHOTS_PER_FRAME = 5; |
| | 15 | | private const int PRE_INSTANTIATED_ENTRIES = 25; |
| | 16 | | private const string FRIEND_ENTRIES_POOL_NAME_PREFIX = "FriendEntriesPool_"; |
| | 17 | |
|
| | 18 | | [SerializeField] private GameObject enabledHeader; |
| | 19 | | [SerializeField] private GameObject disabledHeader; |
| | 20 | | [SerializeField] private GameObject emptyStateContainer; |
| | 21 | | [SerializeField] private GameObject filledStateContainer; |
| | 22 | | [SerializeField] private FriendEntry entryPrefab; |
| | 23 | | [SerializeField] private FriendListComponents onlineFriendsList; |
| | 24 | | [SerializeField] private FriendListComponents offlineFriendsList; |
| | 25 | | [SerializeField] private FriendListComponents allFriendsList; |
| | 26 | | [SerializeField] private FriendListComponents searchResultsFriendList; |
| | 27 | | [SerializeField] private SearchBarComponentView searchBar; |
| | 28 | | [SerializeField] private UserContextMenu contextMenuPanel; |
| | 29 | | [SerializeField] private Model model; |
| | 30 | | [SerializeField] private RectTransform viewport; |
| | 31 | |
|
| | 32 | | [Header("Load More Entries")] [SerializeField] |
| | 33 | | internal Button loadMoreEntriesButton; |
| | 34 | |
|
| | 35 | | [SerializeField] internal GameObject loadMoreEntriesContainer; |
| | 36 | | [SerializeField] internal TMP_Text loadMoreEntriesLabel; |
| | 37 | |
|
| 24 | 38 | | private readonly Dictionary<string, FriendEntryModel> creationQueue = |
| | 39 | | new Dictionary<string, FriendEntryModel>(); |
| | 40 | |
|
| 24 | 41 | | private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>(); |
| 24 | 42 | | private readonly Dictionary<string, FriendEntry> entries = new Dictionary<string, FriendEntry>(); |
| | 43 | | private Pool entryPool; |
| | 44 | | private int currentAvatarSnapshotIndex; |
| | 45 | | private bool isLayoutDirty; |
| | 46 | | private Dictionary<string, FriendEntryModel> filteredEntries; |
| | 47 | | private IChatController chatController; |
| | 48 | | private ILastReadMessagesService lastReadMessagesService; |
| | 49 | | private IFriendsController friendsController; |
| | 50 | | private ISocialAnalytics socialAnalytics; |
| | 51 | |
|
| 0 | 52 | | public Dictionary<string, FriendEntry> Entries => entries; |
| 18 | 53 | | public int Count => entries.Count + creationQueue.Keys.Count(s => !entries.ContainsKey(s)); |
| | 54 | |
|
| 0 | 55 | | public bool DidDeferredCreationCompleted => creationQueue.Count == 0; |
| | 56 | |
|
| | 57 | | public event Action<string> OnSearchRequested; |
| | 58 | |
|
| | 59 | | public bool ListByOnlineStatus |
| | 60 | | { |
| 0 | 61 | | get => model.listByOnlineStatus; |
| | 62 | | set |
| | 63 | | { |
| 1 | 64 | | model.listByOnlineStatus = value; |
| 1 | 65 | | RefreshControl(); |
| 1 | 66 | | } |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public event Action<FriendEntryModel> OnWhisper; |
| | 70 | | public event Action<string> OnDeleteConfirmation; |
| | 71 | | public event Action OnRequireMoreFriends; |
| | 72 | |
|
| | 73 | | public void Initialize(IChatController chatController, |
| | 74 | | ILastReadMessagesService lastReadMessagesService, |
| | 75 | | IFriendsController friendsController, |
| | 76 | | ISocialAnalytics socialAnalytics) |
| | 77 | | { |
| 23 | 78 | | this.chatController = chatController; |
| 23 | 79 | | this.lastReadMessagesService = lastReadMessagesService; |
| 23 | 80 | | this.friendsController = friendsController; |
| 23 | 81 | | this.socialAnalytics = socialAnalytics; |
| 23 | 82 | | } |
| | 83 | |
|
| | 84 | | public override void OnEnable() |
| | 85 | | { |
| 24 | 86 | | base.OnEnable(); |
| | 87 | |
|
| 24 | 88 | | searchBar.Configure(new SearchBarComponentModel {placeHolderText = "Search friend"}); |
| 24 | 89 | | searchBar.OnSearchText += HandleSearchInputChanged; |
| 24 | 90 | | contextMenuPanel.OnBlock += HandleFriendBlockRequest; |
| 24 | 91 | | contextMenuPanel.OnUnfriend += HandleUnfriendRequest; |
| 24 | 92 | | loadMoreEntriesButton.onClick.AddListener(RequestMoreFriendEntries); |
| | 93 | |
|
| | 94 | | int SortByAlphabeticalOrder(FriendEntryBase u1, FriendEntryBase u2) |
| | 95 | | { |
| 0 | 96 | | return string.Compare(u1.Model.userName, u2.Model.userName, StringComparison.InvariantCultureIgnoreCase); |
| | 97 | | } |
| | 98 | |
|
| 24 | 99 | | onlineFriendsList.list.SortingMethod = SortByAlphabeticalOrder; |
| 24 | 100 | | offlineFriendsList.list.SortingMethod = SortByAlphabeticalOrder; |
| 24 | 101 | | allFriendsList.list.SortingMethod = SortByAlphabeticalOrder; |
| 24 | 102 | | searchResultsFriendList.list.SortingMethod = SortByAlphabeticalOrder; |
| 24 | 103 | | UpdateLayout(); |
| 24 | 104 | | UpdateEmptyOrFilledState(); |
| 24 | 105 | | } |
| | 106 | |
|
| | 107 | | public override void OnDisable() |
| | 108 | | { |
| 24 | 109 | | base.OnDisable(); |
| | 110 | |
|
| 24 | 111 | | searchBar.OnSearchText -= HandleSearchInputChanged; |
| 24 | 112 | | contextMenuPanel.OnBlock -= HandleFriendBlockRequest; |
| 24 | 113 | | contextMenuPanel.OnUnfriend -= HandleUnfriendRequest; |
| 24 | 114 | | loadMoreEntriesButton.onClick.RemoveListener(RequestMoreFriendEntries); |
| 24 | 115 | | } |
| | 116 | |
|
| | 117 | | public void Expand() |
| | 118 | | { |
| 23 | 119 | | if (ListByOnlineStatus) |
| | 120 | | { |
| 0 | 121 | | model.isOfflineFriendsExpanded = true; |
| 0 | 122 | | model.isOnlineFriendsExpanded = true; |
| 0 | 123 | | onlineFriendsList.list.Expand(); |
| 0 | 124 | | offlineFriendsList.list.Expand(); |
| 0 | 125 | | } |
| | 126 | | else |
| 23 | 127 | | allFriendsList.list.Expand(); |
| 23 | 128 | | } |
| | 129 | |
|
| | 130 | | public void Show() |
| | 131 | | { |
| 8 | 132 | | gameObject.SetActive(true); |
| 8 | 133 | | enabledHeader.SetActive(true); |
| 8 | 134 | | disabledHeader.SetActive(false); |
| 8 | 135 | | searchBar.ClearSearch(); |
| 8 | 136 | | } |
| | 137 | |
|
| | 138 | | public void Hide() |
| | 139 | | { |
| 7 | 140 | | gameObject.SetActive(false); |
| 7 | 141 | | enabledHeader.SetActive(false); |
| 7 | 142 | | disabledHeader.SetActive(true); |
| 7 | 143 | | contextMenuPanel.Hide(); |
| 7 | 144 | | } |
| | 145 | |
|
| | 146 | | public override void Update() |
| | 147 | | { |
| 34 | 148 | | base.Update(); |
| | 149 | |
|
| 34 | 150 | | if (isLayoutDirty) |
| 16 | 151 | | Utils.ForceRebuildLayoutImmediate((RectTransform) filledStateContainer.transform); |
| 34 | 152 | | isLayoutDirty = false; |
| | 153 | |
|
| 34 | 154 | | SortDirtyLists(); |
| 34 | 155 | | FetchProfilePicturesForVisibleEntries(); |
| 34 | 156 | | SetQueuedEntries(); |
| 34 | 157 | | } |
| | 158 | |
|
| | 159 | | public void Clear() |
| | 160 | | { |
| 0 | 161 | | entries.ToList().ForEach(pair => Remove(pair.Key)); |
| | 162 | |
|
| 0 | 163 | | if (ListByOnlineStatus) |
| | 164 | | { |
| 0 | 165 | | onlineFriendsList.list.Clear(); |
| 0 | 166 | | offlineFriendsList.list.Clear(); |
| 0 | 167 | | } |
| | 168 | | else |
| 0 | 169 | | allFriendsList.list.Clear(); |
| | 170 | |
|
| 0 | 171 | | searchResultsFriendList.list.Clear(); |
| 0 | 172 | | UpdateEmptyOrFilledState(); |
| 0 | 173 | | UpdateCounterLabel(); |
| 0 | 174 | | } |
| | 175 | |
|
| | 176 | | public void Remove(string userId) |
| | 177 | | { |
| 10 | 178 | | if (creationQueue.ContainsKey(userId)) |
| 1 | 179 | | creationQueue.Remove(userId); |
| | 180 | |
|
| 18 | 181 | | if (!entries.ContainsKey(userId)) return; |
| | 182 | |
|
| 2 | 183 | | if (pooleableEntries.TryGetValue(userId, out var pooleableObject)) |
| | 184 | | { |
| 2 | 185 | | entryPool.Release(pooleableObject); |
| 2 | 186 | | pooleableEntries.Remove(userId); |
| | 187 | | } |
| | 188 | |
|
| 2 | 189 | | entries.Remove(userId); |
| | 190 | |
|
| 2 | 191 | | if (ListByOnlineStatus) |
| | 192 | | { |
| 0 | 193 | | offlineFriendsList.list.Remove(userId); |
| 0 | 194 | | onlineFriendsList.list.Remove(userId); |
| 0 | 195 | | } |
| | 196 | | else |
| 2 | 197 | | allFriendsList.list.Remove(userId); |
| | 198 | |
|
| 2 | 199 | | searchResultsFriendList.list.Remove(userId); |
| | 200 | |
|
| 2 | 201 | | UpdateEmptyOrFilledState(); |
| 2 | 202 | | UpdateCounterLabel(); |
| 2 | 203 | | UpdateLayout(); |
| 2 | 204 | | } |
| | 205 | |
|
| 42 | 206 | | public FriendEntry Get(string userId) => entries.ContainsKey(userId) ? entries[userId] : null; |
| | 207 | |
|
| | 208 | | public void Populate(string userId, FriendEntryModel model) |
| | 209 | | { |
| 5 | 210 | | if (!entries.ContainsKey(userId)) |
| | 211 | | { |
| 0 | 212 | | if (creationQueue.ContainsKey(userId)) |
| 0 | 213 | | creationQueue[userId] = model; |
| 0 | 214 | | return; |
| | 215 | | } |
| | 216 | |
|
| 5 | 217 | | var entry = entries[userId]; |
| 5 | 218 | | entry.Populate(model); |
| | 219 | |
|
| 5 | 220 | | if (filteredEntries?.ContainsKey(userId) ?? false) |
| | 221 | | { |
| 0 | 222 | | offlineFriendsList.list.Remove(userId); |
| 0 | 223 | | onlineFriendsList.list.Remove(userId); |
| 0 | 224 | | searchResultsFriendList.list.Add(userId, entry); |
| 0 | 225 | | searchResultsFriendList.FlagAsPendingToSort(); |
| 0 | 226 | | } |
| | 227 | | else |
| | 228 | | { |
| 5 | 229 | | if (ListByOnlineStatus) |
| | 230 | | { |
| 0 | 231 | | if (model.status == PresenceStatus.ONLINE) |
| | 232 | | { |
| 0 | 233 | | offlineFriendsList.list.Remove(userId); |
| 0 | 234 | | onlineFriendsList.list.Add(userId, entry); |
| 0 | 235 | | onlineFriendsList.FlagAsPendingToSort(); |
| 0 | 236 | | } |
| | 237 | | else |
| | 238 | | { |
| 0 | 239 | | onlineFriendsList.list.Remove(userId); |
| 0 | 240 | | offlineFriendsList.list.Add(userId, entry); |
| 0 | 241 | | offlineFriendsList.FlagAsPendingToSort(); |
| | 242 | | } |
| 0 | 243 | | } |
| | 244 | | else |
| | 245 | | { |
| 5 | 246 | | allFriendsList.list.Add(userId, entry); |
| 5 | 247 | | allFriendsList.FlagAsPendingToSort(); |
| | 248 | | } |
| | 249 | | } |
| | 250 | |
|
| 5 | 251 | | UpdateLayout(); |
| 5 | 252 | | UpdateEmptyOrFilledState(); |
| 5 | 253 | | UpdateCounterLabel(); |
| 5 | 254 | | } |
| | 255 | |
|
| | 256 | | public void Set(string userId, FriendEntryModel model) |
| | 257 | | { |
| 5 | 258 | | if (creationQueue.ContainsKey(userId)) |
| | 259 | | { |
| 0 | 260 | | creationQueue[userId] = model; |
| 0 | 261 | | return; |
| | 262 | | } |
| | 263 | |
|
| 5 | 264 | | if (!entries.ContainsKey(userId)) |
| | 265 | | { |
| 5 | 266 | | CreateEntry(userId); |
| 5 | 267 | | UpdateLayout(); |
| | 268 | | } |
| | 269 | |
|
| 5 | 270 | | Populate(userId, model); |
| 5 | 271 | | } |
| | 272 | |
|
| | 273 | | public override void RefreshControl() |
| | 274 | | { |
| 1 | 275 | | if (ListByOnlineStatus) |
| | 276 | | { |
| 0 | 277 | | onlineFriendsList.Show(); |
| 0 | 278 | | offlineFriendsList.Show(); |
| 0 | 279 | | allFriendsList.Hide(); |
| | 280 | |
|
| 0 | 281 | | if (model.isOnlineFriendsExpanded) |
| 0 | 282 | | onlineFriendsList.list.Expand(); |
| | 283 | | else |
| 0 | 284 | | onlineFriendsList.list.Collapse(); |
| | 285 | |
|
| 0 | 286 | | if (model.isOfflineFriendsExpanded) |
| 0 | 287 | | offlineFriendsList.list.Expand(); |
| | 288 | | else |
| 0 | 289 | | offlineFriendsList.list.Collapse(); |
| 0 | 290 | | } |
| | 291 | | else |
| | 292 | | { |
| 1 | 293 | | onlineFriendsList.Hide(); |
| 1 | 294 | | offlineFriendsList.Hide(); |
| 1 | 295 | | allFriendsList.Show(); |
| | 296 | | } |
| 1 | 297 | | } |
| | 298 | |
|
| | 299 | | public void ClearFilter() |
| | 300 | | { |
| 0 | 301 | | filteredEntries = null; |
| | 302 | |
|
| 0 | 303 | | if (searchResultsFriendList.list.gameObject.activeSelf) |
| | 304 | | { |
| 0 | 305 | | foreach (var pair in entries) |
| | 306 | | { |
| 0 | 307 | | searchResultsFriendList.list.Remove(pair.Key); |
| 0 | 308 | | Populate(pair.Key, pair.Value.Model); |
| | 309 | | } |
| | 310 | | } |
| | 311 | |
|
| 0 | 312 | | searchResultsFriendList.Hide(); |
| | 313 | |
|
| 0 | 314 | | if (ListByOnlineStatus) |
| | 315 | | { |
| 0 | 316 | | offlineFriendsList.Show(); |
| 0 | 317 | | onlineFriendsList.Show(); |
| 0 | 318 | | offlineFriendsList.Sort(); |
| 0 | 319 | | onlineFriendsList.Sort(); |
| 0 | 320 | | offlineFriendsList.list.Filter(entry => true); |
| 0 | 321 | | onlineFriendsList.list.Filter(entry => true); |
| 0 | 322 | | } |
| | 323 | | else |
| | 324 | | { |
| 0 | 325 | | allFriendsList.Show(); |
| 0 | 326 | | allFriendsList.Sort(); |
| 0 | 327 | | allFriendsList.list.Filter(entry => true); |
| | 328 | | } |
| 0 | 329 | | } |
| | 330 | |
|
| | 331 | | public void Filter(Dictionary<string, FriendEntryModel> search) |
| | 332 | | { |
| 0 | 333 | | filteredEntries = search; |
| | 334 | |
|
| 0 | 335 | | if (ListByOnlineStatus) |
| | 336 | | { |
| 0 | 337 | | offlineFriendsList.Hide(); |
| 0 | 338 | | onlineFriendsList.Hide(); |
| 0 | 339 | | } |
| | 340 | | else |
| 0 | 341 | | allFriendsList.Hide(); |
| | 342 | |
|
| 0 | 343 | | if (!searchResultsFriendList.list.gameObject.activeSelf) |
| | 344 | | { |
| 0 | 345 | | foreach (var pair in entries) |
| | 346 | | { |
| 0 | 347 | | searchResultsFriendList.list.Add(pair.Key, pair.Value); |
| | 348 | |
|
| 0 | 349 | | if (ListByOnlineStatus) |
| | 350 | | { |
| 0 | 351 | | offlineFriendsList.list.Remove(pair.Key); |
| 0 | 352 | | onlineFriendsList.list.Remove(pair.Key); |
| 0 | 353 | | } |
| | 354 | | else |
| 0 | 355 | | allFriendsList.list.Remove(pair.Key); |
| | 356 | | } |
| | 357 | | } |
| | 358 | |
|
| 0 | 359 | | searchResultsFriendList.Show(); |
| 0 | 360 | | searchResultsFriendList.Sort(); |
| 0 | 361 | | searchResultsFriendList.list.Filter(entry => search.ContainsKey(entry.Model.userId)); |
| | 362 | |
|
| 0 | 363 | | UpdateCounterLabel(); |
| 0 | 364 | | HideMoreFriendsToLoadHint(); |
| 0 | 365 | | UpdateLayout(); |
| 0 | 366 | | } |
| | 367 | |
|
| 6 | 368 | | public void Enqueue(string userId, FriendEntryModel model) => creationQueue[userId] = model; |
| | 369 | |
|
| | 370 | | public void ShowMoreFriendsToLoadHint(int pendingFriendsCount) |
| | 371 | | { |
| 1 | 372 | | loadMoreEntriesLabel.SetText( |
| | 373 | | $"{pendingFriendsCount} friends hidden. Use the search bar to find them or click below to show more."); |
| 1 | 374 | | ShowMoreFriendsToLoadHint(); |
| 1 | 375 | | } |
| | 376 | |
|
| | 377 | | public void HideMoreFriendsToLoadHint() |
| | 378 | | { |
| 1 | 379 | | loadMoreEntriesContainer.SetActive(false); |
| 1 | 380 | | UpdateLayout(); |
| 1 | 381 | | } |
| | 382 | |
|
| | 383 | | private void ShowMoreFriendsToLoadHint() |
| | 384 | | { |
| 1 | 385 | | loadMoreEntriesContainer.SetActive(true); |
| 1 | 386 | | UpdateLayout(); |
| 1 | 387 | | } |
| | 388 | |
|
| 8 | 389 | | private void HandleSearchInputChanged(string search) => OnSearchRequested?.Invoke(search); |
| | 390 | |
|
| | 391 | | private void SetQueuedEntries() |
| | 392 | | { |
| 63 | 393 | | if (creationQueue.Count == 0) return; |
| | 394 | |
|
| 20 | 395 | | for (var i = 0; i < CREATION_AMOUNT_PER_FRAME && creationQueue.Count != 0; i++) |
| | 396 | | { |
| 5 | 397 | | var pair = creationQueue.FirstOrDefault(); |
| 5 | 398 | | creationQueue.Remove(pair.Key); |
| 5 | 399 | | Set(pair.Key, pair.Value); |
| | 400 | | } |
| 5 | 401 | | } |
| | 402 | |
|
| | 403 | | private void FetchProfilePicturesForVisibleEntries() |
| | 404 | | { |
| 68 | 405 | | foreach (var entry in entries.Values.Skip(currentAvatarSnapshotIndex).Take(AVATAR_SNAPSHOTS_PER_FRAME)) |
| | 406 | | { |
| 0 | 407 | | if (entry.IsVisible(viewport)) |
| 0 | 408 | | entry.EnableAvatarSnapshotFetching(); |
| | 409 | | else |
| 0 | 410 | | entry.DisableAvatarSnapshotFetching(); |
| | 411 | | } |
| | 412 | |
|
| 34 | 413 | | currentAvatarSnapshotIndex += AVATAR_SNAPSHOTS_PER_FRAME; |
| | 414 | |
|
| 34 | 415 | | if (currentAvatarSnapshotIndex >= entries.Count) |
| 34 | 416 | | currentAvatarSnapshotIndex = 0; |
| 34 | 417 | | } |
| | 418 | |
|
| | 419 | | private void UpdateEmptyOrFilledState() |
| | 420 | | { |
| 31 | 421 | | emptyStateContainer.SetActive(entries.Count == 0); |
| 31 | 422 | | filledStateContainer.SetActive(entries.Count > 0); |
| 31 | 423 | | } |
| | 424 | |
|
| | 425 | | private void CreateEntry(string userId) |
| | 426 | | { |
| 5 | 427 | | entryPool = GetEntryPool(); |
| 5 | 428 | | var newFriendEntry = entryPool.Get(); |
| 5 | 429 | | pooleableEntries.Add(userId, newFriendEntry); |
| 5 | 430 | | var entry = newFriendEntry.gameObject.GetComponent<FriendEntry>(); |
| 5 | 431 | | entry.Initialize(chatController, lastReadMessagesService, friendsController, socialAnalytics); |
| 5 | 432 | | entries.Add(userId, entry); |
| | 433 | |
|
| 5 | 434 | | entry.OnMenuToggle -= OnEntryMenuToggle; |
| 5 | 435 | | entry.OnMenuToggle += OnEntryMenuToggle; |
| 5 | 436 | | entry.OnWhisperClick -= OnEntryWhisperClick; |
| 5 | 437 | | entry.OnWhisperClick += OnEntryWhisperClick; |
| 5 | 438 | | } |
| | 439 | |
|
| 0 | 440 | | private void OnEntryWhisperClick(FriendEntry friendEntry) => OnWhisper?.Invoke(friendEntry.Model); |
| | 441 | |
|
| | 442 | | private void OnEntryMenuToggle(FriendEntryBase friendEntry) |
| | 443 | | { |
| 0 | 444 | | contextMenuPanel.Show(friendEntry.Model.userId); |
| 0 | 445 | | friendEntry.Dock(contextMenuPanel); |
| 0 | 446 | | } |
| | 447 | |
|
| | 448 | | private Pool GetEntryPool() |
| | 449 | | { |
| 5 | 450 | | var entryPool = PoolManager.i.GetPool(FRIEND_ENTRIES_POOL_NAME_PREFIX + name + GetInstanceID()); |
| 5 | 451 | | if (entryPool != null) return entryPool; |
| | 452 | |
|
| 5 | 453 | | entryPool = PoolManager.i.AddPool( |
| | 454 | | FRIEND_ENTRIES_POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 455 | | Instantiate(entryPrefab).gameObject, |
| | 456 | | maxPrewarmCount: PRE_INSTANTIATED_ENTRIES, |
| | 457 | | isPersistent: true); |
| 5 | 458 | | entryPool.ForcePrewarm(); |
| | 459 | |
|
| 5 | 460 | | return entryPool; |
| | 461 | | } |
| | 462 | |
|
| | 463 | | private void UpdateCounterLabel() |
| | 464 | | { |
| 7 | 465 | | if (ListByOnlineStatus) |
| | 466 | | { |
| 0 | 467 | | onlineFriendsList.countText.SetText("ONLINE ({0})", onlineFriendsList.list.Count()); |
| 0 | 468 | | offlineFriendsList.countText.SetText("OFFLINE ({0})", offlineFriendsList.list.Count()); |
| 0 | 469 | | } |
| | 470 | | else |
| 7 | 471 | | allFriendsList.countText.SetText("Results ({0})", allFriendsList.list.Count()); |
| | 472 | |
|
| 7 | 473 | | searchResultsFriendList.countText.SetText("Results ({0})", searchResultsFriendList.list.Count()); |
| 7 | 474 | | } |
| | 475 | |
|
| | 476 | | private void HandleFriendBlockRequest(string userId, bool blockUser) |
| | 477 | | { |
| 0 | 478 | | var friendEntryToBlock = Get(userId); |
| 0 | 479 | | if (friendEntryToBlock == null) return; |
| | 480 | | // instantly refresh ui |
| 0 | 481 | | friendEntryToBlock.Model.blocked = blockUser; |
| 0 | 482 | | Set(userId, friendEntryToBlock.Model); |
| 0 | 483 | | } |
| | 484 | |
|
| | 485 | | private void HandleUnfriendRequest(string userId) |
| | 486 | | { |
| 0 | 487 | | var entry = Get(userId); |
| 0 | 488 | | if (entry == null) return; |
| 0 | 489 | | Remove(userId); |
| 0 | 490 | | OnDeleteConfirmation?.Invoke(userId); |
| 0 | 491 | | } |
| | 492 | |
|
| 0 | 493 | | private void UpdateLayout() => isLayoutDirty = true; |
| | 494 | |
|
| | 495 | | private void SortDirtyLists() |
| | 496 | | { |
| 34 | 497 | | if (ListByOnlineStatus) |
| | 498 | | { |
| 0 | 499 | | if (offlineFriendsList.IsSortingDirty) |
| 0 | 500 | | offlineFriendsList.Sort(); |
| 0 | 501 | | if (onlineFriendsList.IsSortingDirty) |
| 0 | 502 | | onlineFriendsList.Sort(); |
| 0 | 503 | | } |
| 34 | 504 | | else if (allFriendsList.IsSortingDirty) |
| 2 | 505 | | allFriendsList.Sort(); |
| | 506 | |
|
| 34 | 507 | | if (searchResultsFriendList.IsSortingDirty) |
| 0 | 508 | | searchResultsFriendList.Sort(); |
| 34 | 509 | | } |
| | 510 | |
|
| 1 | 511 | | private void RequestMoreFriendEntries() => OnRequireMoreFriends?.Invoke(); |
| | 512 | |
|
| | 513 | | [Serializable] |
| | 514 | | private struct FriendListComponents |
| | 515 | | { |
| | 516 | | public CollapsableSortedFriendEntryList list; |
| | 517 | | public TMP_Text countText; |
| | 518 | | public GameObject headerContainer; |
| | 519 | |
|
| 0 | 520 | | public bool IsSortingDirty { get; private set; } |
| | 521 | |
|
| | 522 | | public void Show() |
| | 523 | | { |
| 1 | 524 | | list.Show(); |
| 1 | 525 | | headerContainer.SetActive(true); |
| 1 | 526 | | } |
| | 527 | |
|
| | 528 | | public void Hide() |
| | 529 | | { |
| 2 | 530 | | list.Hide(); |
| 2 | 531 | | headerContainer.SetActive(false); |
| 2 | 532 | | } |
| | 533 | |
|
| 0 | 534 | | public void FlagAsPendingToSort() => IsSortingDirty = true; |
| | 535 | |
|
| | 536 | | public void Sort() |
| | 537 | | { |
| 2 | 538 | | list.Sort(); |
| 2 | 539 | | IsSortingDirty = false; |
| 2 | 540 | | } |
| | 541 | | } |
| | 542 | |
|
| | 543 | | [Serializable] |
| | 544 | | private class Model |
| | 545 | | { |
| | 546 | | public bool isOnlineFriendsExpanded; |
| | 547 | | public bool isOfflineFriendsExpanded; |
| | 548 | | public bool listByOnlineStatus; |
| | 549 | | } |
| | 550 | | } |