Search code examples
iosswiftgetstream-io

Cannot get follower counts GetStream Swift


As the title says retrieving a user using the flag withFollowCounts set to true is still bringing back 0 on the followersCount and followingCount properties. I've set up a follow relationship between my timeline feed and their user feed and I'm lost on how to fix this issue. The documentation doesn't mention much about these properties or what's required to populate them.

func initStreams(){
    Client.shared.setupUser(token: self.token) { result in
        switch result {
        case .success:
            self.userFeed = Client.shared.flatFeed(feedSlug: "User")
            self.timelineFeed = Client.shared.flatFeed(feedSlug: "Timeline")

            Client.shared.get(typeOf: StreamUser.self, userId: self.userID, withFollowCounts: true){ userResult in
                switch userResult {
                case .success(let user):
                    self.streamUser = user
                case .failure(let err):
                    fatalError("Could not find stream user \(err)")
                }
            }

        case .failure(let error):
            fatalError("Error setting up user \(error.localizedDescription)")
        }
    }
}

func FollowUser(user: StreamUser, completion: @escaping (Bool) -> Void){
    let feedID = Client.shared.flatFeed(feedSlug: "User", userId: user.id).feedId
    timelineFeed!.follow(toTarget: feedID) { result in
        switch result{
        case .failure(let err):
            print("Error following user \(err)")
            completion(false)
        case .success:

            user.followersCount = user.followersCount ?? 0 + 1
            self.streamUser?.followingCount = self.streamUser?.followingCount ?? 0 + 1

            completion(true)
        }
    }
}

Solution

  • It's the uppercase first letter in "User" and "Timeline" feed slugs. You need to make it lowercase "user" and "timeline". You need to change it in the dashboard and the code.