Skip to content

Commit

Permalink
Fixed a bug with a user following.
Browse files Browse the repository at this point in the history
  • Loading branch information
buh committed May 13, 2019
1 parent 6189f82 commit 75fda88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Expand Up @@ -19,7 +19,6 @@ final class ProfileBuilder {

if let viewController = navigationController.viewControllers.first as? ProfileViewController {
viewController.user = user
viewController.isCurrentUser = true
viewController.builder = self
}

Expand Down
Expand Up @@ -31,11 +31,19 @@ class ProfileViewController: UIViewController, BundledStoryboardLoadable {
@IBOutlet weak var headerViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var feedContainerView: UIView!

var user: User?
var isCurrentUser: Bool = false
var builder: ProfileBuilder?
private var flatFeedViewController: ActivityFeedViewController?

var user: User? {
didSet {
if let user = user, let currentUser = Client.shared.currentUser {
isCurrentUser = user.id == currentUser.id
}
}
}

private(set) var isCurrentUser: Bool = false
private var flatFeedViewController: ActivityFeedViewController?

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
loadAvatar(onlyTabBarItem: true)
Expand Down Expand Up @@ -174,16 +182,15 @@ extension ProfileViewController {
return
}

let button = BarButton(title: "Follow", backgroundColor: UIColor(red:0, green:0.48, blue:1, alpha:1))
let button = BarButton(title: "Follow", backgroundColor: Appearance.Color.blue)
button.setTitle("Updating...", backgroundColor: Appearance.Color.transparentWhite, for: .disabled)
button.setTitle("Following", backgroundColor: Appearance.Color.transparentWhite, for: .selected)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)

button.addTap { [weak flatFeedPresenter] in
if let button = $0 as? BarButton,
let feedId = flatFeedPresenter?.flatFeed.feedId,
let userFeedId = FeedId.user {
let userFeed = Client.shared.flatFeed(userFeedId)
let userFeed = User.current?.feed {
let isFollowing = button.isSelected
button.isEnabled = false

Expand Down
10 changes: 3 additions & 7 deletions Sources/Models/User.swift
Expand Up @@ -24,6 +24,8 @@ public final class User: GetStream.User, UserNameRepresentable, AvatarRepresenta
}

private let dispatchQueue = DispatchQueue(label: "io.getstream.User")
private(set) lazy var feed: FlatFeed = Client.shared.flatFeed(FeedId.user(with: id))

public var avatarImage: UIImage?

init(name: String, id: String) {
Expand Down Expand Up @@ -66,13 +68,7 @@ extension User {
/// Checks if the user feed is following to a target.
public func isFollow(toTarget target: FeedId,
completion: @escaping (_ isFollow: Bool, _ following: Follower?, _ error: Error?) -> Void) {
guard let userFeedId = FeedId.user else {
print("⚠️", #function, "userId not found in the Token")
completion(false, nil, nil)
return
}

Client.shared.flatFeed(userFeedId).following(filter: [target]) {
feed.following(filter: [target]) {
if let response = try? $0.get() {
completion(response.results.first != nil, response.results.first, nil)
} else {
Expand Down

0 comments on commit 75fda88

Please sign in to comment.