From 5d143ea2e88895fcb9bf33e682ab91c7771d59e7 Mon Sep 17 00:00:00 2001 From: talksik Date: Tue, 28 Dec 2021 16:49:19 -0800 Subject: [PATCH] fixing logic to make sure there are no duplicates in the friends arr --- nirvana-ios/Services/AuthSessionStore.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nirvana-ios/Services/AuthSessionStore.swift b/nirvana-ios/Services/AuthSessionStore.swift index fe3fb3e..f60989a 100644 --- a/nirvana-ios/Services/AuthSessionStore.swift +++ b/nirvana-ios/Services/AuthSessionStore.swift @@ -288,8 +288,13 @@ extension AuthSessionStore { if updatedReturnedUser != nil { DispatchQueue.main.async { self.relevantUsersDict[userFriend!.friendId] = updatedReturnedUser! - - self.friendsArr.append(userFriend!.friendId) + + // update current friendsArr if the friend is already there + if let indexFriend = self.friendsArr.firstIndex(of: userFriend!.friendId) { + print("friend already in the friends arr, just needed to update the relevantusersdict") + } else { // new friend not in array + self.friendsArr.append(userFriend!.friendId) + } self.objectWillChange.send()