From f4d6527d2a4f9be3c93f89b964ea88dfbf4e20e0 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 12 Jan 2016 09:48:00 +0800 Subject: [PATCH] optional avatarURLString in UsernamePrefixMatchedUser --- Yep/Services/YepService.swift | 10 ++++++---- Yep/Views/Mention/MentionView.swift | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index c3aa60d1..61e52588 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -3695,7 +3695,7 @@ struct UsernamePrefixMatchedUser { let userID: String let username: String let nickname: String - let avatarURLString: String + let avatarURLString: String? var mentionUsername: String { return "@" + username @@ -3709,7 +3709,7 @@ func usersMatchWithUsernamePrefix(usernamePrefix: String, failureHandler: ((Reas ] let parse: JSONDictionary -> [UsernamePrefixMatchedUser]? = { data in - //println("usersMatchWithUsernamePrefix: \(data)") + println("usersMatchWithUsernamePrefix: \(data)") if let usersData = data["users"] as? [JSONDictionary] { let users: [UsernamePrefixMatchedUser] = usersData.map({ userInfo in @@ -3717,12 +3717,14 @@ func usersMatchWithUsernamePrefix(usernamePrefix: String, failureHandler: ((Reas userID = userInfo["id"] as? String, username = userInfo["username"] as? String, nickname = userInfo["nickname"] as? String, - avatarInfo = userInfo["avatar"] as? JSONDictionary, - avatarURLString = avatarInfo["thumb_url"] as? String + avatarInfo = userInfo["avatar"] as? JSONDictionary + //avatarURLString = avatarInfo["thumb_url"] as? String else { return nil } + let avatarURLString = avatarInfo["thumb_url"] as? String + return UsernamePrefixMatchedUser(userID: userID, username: username, nickname: nickname, avatarURLString: avatarURLString) }).flatMap({ $0 }) diff --git a/Yep/Views/Mention/MentionView.swift b/Yep/Views/Mention/MentionView.swift index 3aca2d11..a739b749 100644 --- a/Yep/Views/Mention/MentionView.swift +++ b/Yep/Views/Mention/MentionView.swift @@ -72,8 +72,12 @@ private class MentionUserCell: UITableViewCell { func configureWithUsernamePrefixMatchedUser(user: UsernamePrefixMatchedUser) { - let plainAvatar = PlainAvatar(avatarURLString: user.avatarURLString, avatarStyle: picoAvatarStyle) + if let avatarURLString = user.avatarURLString { + let plainAvatar = PlainAvatar(avatarURLString: avatarURLString, avatarStyle: picoAvatarStyle) avatarImageView.navi_setAvatar(plainAvatar, withFadeTransitionDuration: avatarFadeTransitionDuration) + } else { + avatarImageView.image = UIImage(named: "default_avatar_30") + } nicknameLabel.text = user.nickname mentionUsernameLabel.text = user.mentionUsername