| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using Cysharp.Threading.Tasks; |
| | 4 | | using DCL; |
| | 5 | | using SocialFeaturesAnalytics; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public class FriendsHUDController : IHUD |
| | 9 | | { |
| | 10 | | private const int LOAD_FRIENDS_ON_DEMAND_COUNT = 30; |
| | 11 | | private const int MAX_SEARCHED_FRIENDS = 100; |
| | 12 | |
|
| 44 | 13 | | private readonly Dictionary<string, FriendEntryModel> friends = new Dictionary<string, FriendEntryModel>(); |
| 44 | 14 | | private readonly Dictionary<string, FriendEntryModel> onlineFriends = new Dictionary<string, FriendEntryModel>(); |
| | 15 | | private readonly DataStore dataStore; |
| | 16 | | private readonly IFriendsController friendsController; |
| | 17 | | private readonly IUserProfileBridge userProfileBridge; |
| | 18 | | private readonly ISocialAnalytics socialAnalytics; |
| | 19 | | private readonly IChatController chatController; |
| | 20 | |
|
| | 21 | | private UserProfile ownUserProfile; |
| | 22 | | private bool searchingFriends; |
| | 23 | | private int lastSkipForFriends; |
| | 24 | | private int lastSkipForFriendRequests; |
| | 25 | |
|
| 0 | 26 | | public IFriendsHUDComponentView View { get; private set; } |
| | 27 | |
|
| | 28 | | public event Action<string> OnPressWhisper; |
| | 29 | | public event Action OnOpened; |
| | 30 | | public event Action OnClosed; |
| | 31 | |
|
| 44 | 32 | | public FriendsHUDController(DataStore dataStore, |
| | 33 | | IFriendsController friendsController, |
| | 34 | | IUserProfileBridge userProfileBridge, |
| | 35 | | ISocialAnalytics socialAnalytics, |
| | 36 | | IChatController chatController) |
| | 37 | | { |
| 44 | 38 | | this.dataStore = dataStore; |
| 44 | 39 | | this.friendsController = friendsController; |
| 44 | 40 | | this.userProfileBridge = userProfileBridge; |
| 44 | 41 | | this.socialAnalytics = socialAnalytics; |
| 44 | 42 | | this.chatController = chatController; |
| 44 | 43 | | } |
| | 44 | |
|
| | 45 | | public void Initialize(IFriendsHUDComponentView view = null) |
| | 46 | | { |
| 44 | 47 | | view ??= FriendsHUDComponentView.Create(); |
| 44 | 48 | | View = view; |
| | 49 | |
|
| 44 | 50 | | view.Initialize(chatController, friendsController, socialAnalytics); |
| 44 | 51 | | view.RefreshFriendsTab(); |
| 44 | 52 | | view.OnFriendRequestApproved += HandleRequestAccepted; |
| 44 | 53 | | view.OnCancelConfirmation += HandleRequestCancelled; |
| 44 | 54 | | view.OnRejectConfirmation += HandleRequestRejected; |
| 44 | 55 | | view.OnFriendRequestSent += HandleRequestSent; |
| 44 | 56 | | view.OnWhisper += HandleOpenWhisperChat; |
| 44 | 57 | | view.OnClose += HandleViewClosed; |
| 44 | 58 | | view.OnRequireMoreFriends += DisplayMoreFriends; |
| 44 | 59 | | view.OnRequireMoreFriendRequests += DisplayMoreFriendRequests; |
| 44 | 60 | | view.OnSearchFriendsRequested += SearchFriends; |
| 44 | 61 | | view.OnFriendListDisplayed += DisplayFriendsIfAnyIsLoaded; |
| 44 | 62 | | view.OnRequestListDisplayed += DisplayFriendRequestsIfAnyIsLoaded; |
| | 63 | |
|
| 44 | 64 | | ownUserProfile = userProfileBridge.GetOwn(); |
| 44 | 65 | | ownUserProfile.OnUpdate -= HandleProfileUpdated; |
| 44 | 66 | | ownUserProfile.OnUpdate += HandleProfileUpdated; |
| | 67 | |
|
| 44 | 68 | | if (friendsController != null) |
| | 69 | | { |
| 44 | 70 | | friendsController.OnUpdateFriendship += HandleFriendshipUpdated; |
| 44 | 71 | | friendsController.OnUpdateUserStatus += HandleUserStatusUpdated; |
| 44 | 72 | | friendsController.OnFriendNotFound += OnFriendNotFound; |
| | 73 | |
|
| 44 | 74 | | if (friendsController.IsInitialized) |
| | 75 | | { |
| 2 | 76 | | view.HideLoadingSpinner(); |
| 2 | 77 | | } |
| | 78 | | else |
| | 79 | | { |
| 42 | 80 | | view.ShowLoadingSpinner(); |
| 42 | 81 | | friendsController.OnInitialized -= HandleFriendsInitialized; |
| 42 | 82 | | friendsController.OnInitialized += HandleFriendsInitialized; |
| | 83 | | } |
| | 84 | | } |
| | 85 | |
|
| 44 | 86 | | ShowOrHideMoreFriendsToLoadHint(); |
| 44 | 87 | | ShowOrHideMoreFriendRequestsToLoadHint(); |
| 44 | 88 | | } |
| | 89 | |
|
| | 90 | | public void Dispose() |
| | 91 | | { |
| 45 | 92 | | if (friendsController != null) |
| | 93 | | { |
| 45 | 94 | | friendsController.OnInitialized -= HandleFriendsInitialized; |
| 45 | 95 | | friendsController.OnUpdateFriendship -= HandleFriendshipUpdated; |
| 45 | 96 | | friendsController.OnUpdateUserStatus -= HandleUserStatusUpdated; |
| | 97 | | } |
| | 98 | |
|
| 45 | 99 | | if (View != null) |
| | 100 | | { |
| 45 | 101 | | View.OnFriendRequestApproved -= HandleRequestAccepted; |
| 45 | 102 | | View.OnCancelConfirmation -= HandleRequestCancelled; |
| 45 | 103 | | View.OnRejectConfirmation -= HandleRequestRejected; |
| 45 | 104 | | View.OnFriendRequestSent -= HandleRequestSent; |
| 45 | 105 | | View.OnWhisper -= HandleOpenWhisperChat; |
| 45 | 106 | | View.OnDeleteConfirmation -= HandleUnfriend; |
| 45 | 107 | | View.OnClose -= HandleViewClosed; |
| 45 | 108 | | View.OnRequireMoreFriends -= DisplayMoreFriends; |
| 45 | 109 | | View.OnRequireMoreFriendRequests -= DisplayMoreFriendRequests; |
| 45 | 110 | | View.OnSearchFriendsRequested -= SearchFriends; |
| 45 | 111 | | View.OnFriendListDisplayed -= DisplayFriendsIfAnyIsLoaded; |
| 45 | 112 | | View.OnRequestListDisplayed -= DisplayFriendRequestsIfAnyIsLoaded; |
| 45 | 113 | | View.Dispose(); |
| | 114 | | } |
| | 115 | |
|
| 45 | 116 | | if (ownUserProfile != null) |
| 45 | 117 | | ownUserProfile.OnUpdate -= HandleProfileUpdated; |
| | 118 | |
|
| 45 | 119 | | if (userProfileBridge != null) |
| | 120 | | { |
| 126 | 121 | | foreach (var friendId in friends.Keys) |
| | 122 | | { |
| 18 | 123 | | var profile = userProfileBridge.Get(friendId); |
| 18 | 124 | | if (profile == null) continue; |
| 16 | 125 | | profile.OnUpdate -= HandleFriendProfileUpdated; |
| | 126 | | } |
| | 127 | | } |
| 45 | 128 | | } |
| | 129 | |
|
| | 130 | | public void SetVisibility(bool visible) |
| | 131 | | { |
| 18 | 132 | | if (visible) |
| | 133 | | { |
| 14 | 134 | | lastSkipForFriends = 0; |
| 14 | 135 | | lastSkipForFriendRequests = 0; |
| 14 | 136 | | View.ClearAll(); |
| 14 | 137 | | View.Show(); |
| 14 | 138 | | UpdateNotificationsCounter(); |
| | 139 | |
|
| 28 | 140 | | foreach (var friend in onlineFriends) |
| 0 | 141 | | View.Set(friend.Key, friend.Value); |
| | 142 | |
|
| 14 | 143 | | if (View.IsFriendListActive) |
| 6 | 144 | | DisplayMoreFriends(); |
| 8 | 145 | | else if (View.IsRequestListActive) |
| 5 | 146 | | DisplayMoreFriendRequests(); |
| | 147 | |
|
| 14 | 148 | | OnOpened?.Invoke(); |
| 0 | 149 | | } |
| | 150 | | else |
| | 151 | | { |
| 4 | 152 | | View.Hide(); |
| 4 | 153 | | View.DisableSearchMode(); |
| 4 | 154 | | searchingFriends = false; |
| 4 | 155 | | OnClosed?.Invoke(); |
| | 156 | | } |
| 0 | 157 | | } |
| | 158 | |
|
| 0 | 159 | | private void HandleViewClosed() => SetVisibility(false); |
| | 160 | |
|
| | 161 | | private void HandleFriendsInitialized() |
| | 162 | | { |
| 1 | 163 | | friendsController.OnInitialized -= HandleFriendsInitialized; |
| 1 | 164 | | View.HideLoadingSpinner(); |
| | 165 | |
|
| 1 | 166 | | if (View.IsActive()) |
| | 167 | | { |
| 0 | 168 | | if (View.IsFriendListActive && lastSkipForFriends <= 0) |
| 0 | 169 | | DisplayMoreFriends(); |
| 0 | 170 | | else if (View.IsRequestListActive && lastSkipForFriendRequests <= 0) |
| 0 | 171 | | DisplayMoreFriendRequests(); |
| | 172 | | } |
| | 173 | |
|
| 1 | 174 | | UpdateNotificationsCounter(); |
| 1 | 175 | | } |
| | 176 | |
|
| 2 | 177 | | private void HandleProfileUpdated(UserProfile profile) => UpdateBlockStatus(profile).Forget(); |
| | 178 | |
|
| | 179 | | private async UniTask UpdateBlockStatus(UserProfile profile) |
| | 180 | | { |
| | 181 | | const int iterationsPerFrame = 10; |
| | 182 | |
|
| | 183 | | //NOTE(Brian): HashSet to check Contains quicker. |
| 2 | 184 | | var allBlockedUsers = profile.blocked != null |
| | 185 | | ? new HashSet<string>(profile.blocked) |
| | 186 | | : new HashSet<string>(); |
| | 187 | |
|
| 2 | 188 | | var iterations = 0; |
| | 189 | |
|
| 8 | 190 | | foreach (var friendPair in friends) |
| | 191 | | { |
| 2 | 192 | | var friendId = friendPair.Key; |
| 2 | 193 | | var model = friendPair.Value; |
| | 194 | |
|
| 2 | 195 | | model.blocked = allBlockedUsers.Contains(friendId); |
| 2 | 196 | | await UniTask.SwitchToMainThread(); |
| 2 | 197 | | View.UpdateBlockStatus(friendId, model.blocked); |
| | 198 | |
|
| 2 | 199 | | iterations++; |
| 2 | 200 | | if (iterations > 0 && iterations % iterationsPerFrame == 0) |
| 0 | 201 | | await UniTask.NextFrame(); |
| 2 | 202 | | } |
| 2 | 203 | | } |
| | 204 | |
|
| | 205 | | private void HandleRequestSent(string userNameOrId) |
| | 206 | | { |
| 3 | 207 | | if (AreAlreadyFriends(userNameOrId)) |
| | 208 | | { |
| 1 | 209 | | View.ShowRequestSendError(FriendRequestError.AlreadyFriends); |
| 1 | 210 | | } |
| | 211 | | else |
| | 212 | | { |
| 2 | 213 | | friendsController.RequestFriendship(userNameOrId); |
| | 214 | |
|
| 2 | 215 | | if (ownUserProfile != null) |
| 2 | 216 | | socialAnalytics.SendFriendRequestSent(ownUserProfile.userId, userNameOrId, 0, |
| | 217 | | PlayerActionSource.FriendsHUD); |
| | 218 | |
|
| 2 | 219 | | View.ShowRequestSendSuccess(); |
| | 220 | | } |
| 2 | 221 | | } |
| | 222 | |
|
| | 223 | | private bool AreAlreadyFriends(string userNameOrId) |
| | 224 | | { |
| 3 | 225 | | var userId = userNameOrId; |
| 3 | 226 | | var profile = userProfileBridge.GetByName(userNameOrId); |
| | 227 | |
|
| 3 | 228 | | if (profile != default) |
| 1 | 229 | | userId = profile.userId; |
| | 230 | |
|
| 3 | 231 | | return friendsController != null |
| | 232 | | && friendsController.ContainsStatus(userId, FriendshipStatus.FRIEND); |
| | 233 | | } |
| | 234 | |
|
| | 235 | | private void HandleUserStatusUpdated(string userId, UserStatus status) => |
| 6 | 236 | | UpdateUserStatus(userId, status); |
| | 237 | |
|
| | 238 | | private void UpdateUserStatus(string userId, UserStatus status) |
| | 239 | | { |
| 7 | 240 | | switch (status.friendshipStatus) |
| | 241 | | { |
| | 242 | | case FriendshipStatus.FRIEND: |
| 3 | 243 | | var friend = friends.ContainsKey(userId) |
| | 244 | | ? new FriendEntryModel(friends[userId]) |
| | 245 | | : new FriendEntryModel(); |
| 3 | 246 | | friend.CopyFrom(status); |
| 3 | 247 | | friend.blocked = IsUserBlocked(userId); |
| 3 | 248 | | friends[userId] = friend; |
| 3 | 249 | | View.Set(userId, friend); |
| | 250 | |
|
| 3 | 251 | | if (status.presence == PresenceStatus.ONLINE) |
| 2 | 252 | | onlineFriends[userId] = friend; |
| | 253 | | else |
| 1 | 254 | | onlineFriends.Remove(userId); |
| | 255 | |
|
| 1 | 256 | | break; |
| | 257 | | case FriendshipStatus.NOT_FRIEND: |
| 0 | 258 | | View.Remove(userId); |
| 0 | 259 | | friends.Remove(userId); |
| 0 | 260 | | onlineFriends.Remove(userId); |
| 0 | 261 | | break; |
| | 262 | | case FriendshipStatus.REQUESTED_TO: |
| 2 | 263 | | var sentRequest = friends.ContainsKey(userId) |
| | 264 | | ? new FriendRequestEntryModel(friends[userId], false) |
| | 265 | | : new FriendRequestEntryModel {isReceived = false}; |
| 2 | 266 | | sentRequest.CopyFrom(status); |
| 2 | 267 | | sentRequest.blocked = IsUserBlocked(userId); |
| 2 | 268 | | friends[userId] = sentRequest; |
| 2 | 269 | | onlineFriends.Remove(userId); |
| 2 | 270 | | View.Set(userId, sentRequest); |
| 2 | 271 | | break; |
| | 272 | | case FriendshipStatus.REQUESTED_FROM: |
| 2 | 273 | | var receivedRequest = friends.ContainsKey(userId) |
| | 274 | | ? new FriendRequestEntryModel(friends[userId], true) |
| | 275 | | : new FriendRequestEntryModel {isReceived = true}; |
| 2 | 276 | | receivedRequest.CopyFrom(status); |
| 2 | 277 | | receivedRequest.blocked = IsUserBlocked(userId); |
| 2 | 278 | | friends[userId] = receivedRequest; |
| 2 | 279 | | onlineFriends.Remove(userId); |
| 2 | 280 | | View.Set(userId, receivedRequest); |
| | 281 | | break; |
| | 282 | | } |
| | 283 | |
|
| 7 | 284 | | UpdateNotificationsCounter(); |
| 7 | 285 | | ShowOrHideMoreFriendsToLoadHint(); |
| 7 | 286 | | ShowOrHideMoreFriendRequestsToLoadHint(); |
| 7 | 287 | | } |
| | 288 | |
|
| | 289 | | private void HandleFriendshipUpdated(string userId, FriendshipAction friendshipAction) |
| | 290 | | { |
| 15 | 291 | | var userProfile = userProfileBridge.Get(userId); |
| | 292 | |
|
| 15 | 293 | | if (userProfile == null) |
| | 294 | | { |
| 0 | 295 | | Debug.LogError($"UserProfile is null for {userId}! ... friendshipAction {friendshipAction}"); |
| 0 | 296 | | return; |
| | 297 | | } |
| | 298 | |
|
| 15 | 299 | | userProfile.OnUpdate -= HandleFriendProfileUpdated; |
| | 300 | |
|
| | 301 | | switch (friendshipAction) |
| | 302 | | { |
| | 303 | | case FriendshipAction.NONE: |
| | 304 | | case FriendshipAction.REJECTED: |
| | 305 | | case FriendshipAction.CANCELLED: |
| | 306 | | case FriendshipAction.DELETED: |
| 3 | 307 | | friends.Remove(userId); |
| 3 | 308 | | View.Remove(userId); |
| 3 | 309 | | onlineFriends.Remove(userId); |
| 3 | 310 | | break; |
| | 311 | | case FriendshipAction.APPROVED: |
| 7 | 312 | | var approved = friends.ContainsKey(userId) |
| | 313 | | ? new FriendEntryModel(friends[userId]) |
| | 314 | | : new FriendEntryModel(); |
| 7 | 315 | | approved.CopyFrom(userProfile); |
| 7 | 316 | | approved.blocked = IsUserBlocked(userId); |
| 7 | 317 | | friends[userId] = approved; |
| 7 | 318 | | View.Set(userId, approved); |
| 7 | 319 | | userProfile.OnUpdate += HandleFriendProfileUpdated; |
| 7 | 320 | | break; |
| | 321 | | case FriendshipAction.REQUESTED_FROM: |
| 2 | 322 | | var requestReceived = friends.ContainsKey(userId) |
| | 323 | | ? new FriendRequestEntryModel(friends[userId], true) |
| | 324 | | : new FriendRequestEntryModel {isReceived = true}; |
| 2 | 325 | | requestReceived.CopyFrom(userProfile); |
| 2 | 326 | | requestReceived.blocked = IsUserBlocked(userId); |
| 2 | 327 | | friends[userId] = requestReceived; |
| 2 | 328 | | View.Set(userId, requestReceived); |
| 2 | 329 | | userProfile.OnUpdate += HandleFriendProfileUpdated; |
| 2 | 330 | | break; |
| | 331 | | case FriendshipAction.REQUESTED_TO: |
| 3 | 332 | | var requestSent = friends.ContainsKey(userId) |
| | 333 | | ? new FriendRequestEntryModel(friends[userId], false) |
| | 334 | | : new FriendRequestEntryModel {isReceived = false}; |
| 3 | 335 | | requestSent.CopyFrom(userProfile); |
| 3 | 336 | | requestSent.blocked = IsUserBlocked(userId); |
| 3 | 337 | | friends[userId] = requestSent; |
| 3 | 338 | | View.Set(userId, requestSent); |
| 3 | 339 | | userProfile.OnUpdate += HandleFriendProfileUpdated; |
| | 340 | | break; |
| | 341 | | } |
| | 342 | |
|
| 15 | 343 | | UpdateNotificationsCounter(); |
| 15 | 344 | | ShowOrHideMoreFriendsToLoadHint(); |
| 15 | 345 | | ShowOrHideMoreFriendRequestsToLoadHint(); |
| 15 | 346 | | } |
| | 347 | |
|
| | 348 | | private void HandleFriendProfileUpdated(UserProfile profile) |
| | 349 | | { |
| 1 | 350 | | var userId = profile.userId; |
| 1 | 351 | | if (!friends.ContainsKey(userId)) return; |
| 1 | 352 | | friends[userId].CopyFrom(profile); |
| | 353 | |
|
| 1 | 354 | | var status = friendsController.GetUserStatus(profile.userId); |
| 1 | 355 | | if (status == null) return; |
| | 356 | |
|
| 1 | 357 | | UpdateUserStatus(userId, status); |
| 1 | 358 | | } |
| | 359 | |
|
| | 360 | | private bool IsUserBlocked(string userId) |
| | 361 | | { |
| 19 | 362 | | if (ownUserProfile != null && ownUserProfile.blocked != null) |
| 19 | 363 | | return ownUserProfile.blocked.Contains(userId); |
| 0 | 364 | | return false; |
| | 365 | | } |
| | 366 | |
|
| | 367 | | private void OnFriendNotFound(string name) |
| | 368 | | { |
| 1 | 369 | | View.DisplayFriendUserNotFound(); |
| 1 | 370 | | } |
| | 371 | |
|
| | 372 | | private void UpdateNotificationsCounter() |
| | 373 | | { |
| 37 | 374 | | if (View.IsActive()) |
| 9 | 375 | | dataStore.friendNotifications.seenFriends.Set(View.FriendCount); |
| | 376 | |
|
| 37 | 377 | | dataStore.friendNotifications.pendingFriendRequestCount.Set(friendsController.ReceivedRequestCount); |
| 37 | 378 | | } |
| | 379 | |
|
| 1 | 380 | | private void HandleOpenWhisperChat(FriendEntryModel entry) => OnPressWhisper?.Invoke(entry.userId); |
| | 381 | |
|
| 0 | 382 | | private void HandleUnfriend(string userId) => friendsController.RemoveFriend(userId); |
| | 383 | |
|
| | 384 | | private void HandleRequestRejected(FriendRequestEntryModel entry) |
| | 385 | | { |
| 0 | 386 | | friendsController.RejectFriendship(entry.userId); |
| | 387 | |
|
| 0 | 388 | | UpdateNotificationsCounter(); |
| | 389 | |
|
| 0 | 390 | | if (ownUserProfile != null) |
| 0 | 391 | | socialAnalytics.SendFriendRequestRejected(ownUserProfile.userId, entry.userId, |
| | 392 | | PlayerActionSource.FriendsHUD); |
| 0 | 393 | | } |
| | 394 | |
|
| | 395 | | private void HandleRequestCancelled(FriendRequestEntryModel entry) |
| | 396 | | { |
| 0 | 397 | | friendsController.CancelRequest(entry.userId); |
| | 398 | |
|
| 0 | 399 | | if (ownUserProfile != null) |
| 0 | 400 | | socialAnalytics.SendFriendRequestCancelled(ownUserProfile.userId, entry.userId, |
| | 401 | | PlayerActionSource.FriendsHUD); |
| 0 | 402 | | } |
| | 403 | |
|
| | 404 | | private void HandleRequestAccepted(FriendRequestEntryModel entry) |
| | 405 | | { |
| 0 | 406 | | friendsController.AcceptFriendship(entry.userId); |
| | 407 | |
|
| 0 | 408 | | if (ownUserProfile != null) |
| 0 | 409 | | socialAnalytics.SendFriendRequestApproved(ownUserProfile.userId, entry.userId, |
| | 410 | | PlayerActionSource.FriendsHUD); |
| 0 | 411 | | } |
| | 412 | |
|
| | 413 | | private void DisplayFriendsIfAnyIsLoaded() |
| | 414 | | { |
| 1 | 415 | | if (View.FriendCount > 0) return; |
| 1 | 416 | | if (lastSkipForFriends > 0) return; |
| 1 | 417 | | DisplayMoreFriends(); |
| 1 | 418 | | } |
| | 419 | |
|
| | 420 | | private void DisplayMoreFriends() |
| | 421 | | { |
| 10 | 422 | | if (!friendsController.IsInitialized) return; |
| | 423 | |
|
| 8 | 424 | | friendsController.GetFriends(LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriends); |
| | 425 | |
|
| | 426 | | // We are not handling properly the case when the friends are not fetched correctly from server. |
| | 427 | | // 'lastSkipForFriends' will have an invalid value. |
| 8 | 428 | | lastSkipForFriends += LOAD_FRIENDS_ON_DEMAND_COUNT; |
| | 429 | |
|
| 8 | 430 | | ShowOrHideMoreFriendsToLoadHint(); |
| 8 | 431 | | } |
| | 432 | |
|
| | 433 | | private void DisplayMoreFriendRequests() |
| | 434 | | { |
| 7 | 435 | | if (!friendsController.IsInitialized) return; |
| 7 | 436 | | if (searchingFriends) return; |
| | 437 | |
|
| 7 | 438 | | friendsController.GetFriendRequests( |
| | 439 | | LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests, |
| | 440 | | LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests); |
| | 441 | |
|
| | 442 | | // We are not handling properly the case when the friend requests are not fetched correctly from server. |
| | 443 | | // 'lastSkipForFriendRequests' will have an invalid value. |
| 7 | 444 | | lastSkipForFriendRequests += LOAD_FRIENDS_ON_DEMAND_COUNT; |
| | 445 | |
|
| 7 | 446 | | ShowOrHideMoreFriendRequestsToLoadHint(); |
| 7 | 447 | | } |
| | 448 | |
|
| | 449 | | private void DisplayFriendRequestsIfAnyIsLoaded() |
| | 450 | | { |
| 1 | 451 | | if (View.FriendRequestCount > 0) return; |
| 1 | 452 | | if (lastSkipForFriendRequests > 0) return; |
| 1 | 453 | | DisplayMoreFriendRequests(); |
| 1 | 454 | | } |
| | 455 | |
|
| | 456 | | private void ShowOrHideMoreFriendRequestsToLoadHint() |
| | 457 | | { |
| 73 | 458 | | if (lastSkipForFriendRequests >= friendsController.TotalFriendRequestCount) |
| 72 | 459 | | View.HideMoreRequestsToLoadHint(); |
| | 460 | | else |
| 1 | 461 | | View.ShowMoreRequestsToLoadHint(Mathf.Clamp(friendsController.TotalFriendRequestCount - lastSkipForFriendReq |
| | 462 | | 0, |
| | 463 | | friendsController.TotalFriendRequestCount)); |
| 1 | 464 | | } |
| | 465 | |
|
| | 466 | | private void ShowOrHideMoreFriendsToLoadHint() |
| | 467 | | { |
| 75 | 468 | | if (lastSkipForFriends >= friendsController.TotalFriendCount || searchingFriends) |
| 74 | 469 | | View.HideMoreFriendsToLoadHint(); |
| | 470 | | else |
| 1 | 471 | | View.ShowMoreFriendsToLoadHint(Mathf.Clamp(friendsController.TotalFriendCount - lastSkipForFriends, |
| | 472 | | 0, |
| | 473 | | friendsController.TotalFriendCount)); |
| 1 | 474 | | } |
| | 475 | |
|
| | 476 | | private void SearchFriends(string search) |
| | 477 | | { |
| 3 | 478 | | if (string.IsNullOrEmpty(search)) |
| | 479 | | { |
| 1 | 480 | | View.DisableSearchMode(); |
| 1 | 481 | | searchingFriends = false; |
| 1 | 482 | | ShowOrHideMoreFriendsToLoadHint(); |
| 1 | 483 | | return; |
| | 484 | | } |
| | 485 | |
|
| 2 | 486 | | friendsController.GetFriends(search, MAX_SEARCHED_FRIENDS); |
| | 487 | |
|
| 2 | 488 | | View.EnableSearchMode(); |
| 2 | 489 | | View.HideMoreFriendsToLoadHint(); |
| 2 | 490 | | searchingFriends = true; |
| 2 | 491 | | } |
| | 492 | | } |