Commit e5746015 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

avatar: use profile name

This patch uses profile name instead of ring username to create
fallback avatar.

Change-Id: I94b72eee4fdd8973d040d5c8c10cd44d6c8bd55d
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent f5fb6fa3
......@@ -67,7 +67,7 @@ class ContactViewController: UIViewController, StoryboardBased, ViewModelBased {
// avatar
Observable<(Data?, String)>.combineLatest(self.viewModel.profileImageData.asObservable(),
self.viewModel.userName.asObservable()) { profileImage, username in
self.viewModel.displayName.asObservable()) { profileImage, username in
return (profileImage, username)
}
.observeOn(MainScheduler.instance)
......
......@@ -55,7 +55,11 @@ class ContactRequestCell: UITableViewCell, NibReusable {
func configureFromItem(_ item: ContactRequestItem) {
// avatar
Observable<(Data?, String)>.combineLatest(item.profileImageData.asObservable(),
item.userName.asObservable()) { profileImage, username in
item.userName.asObservable(),
item.profileName.asObservable()) { profileImage, username, profileName in
if !profileName.isEmpty {
return (profileImage, profileName)
}
return (profileImage, username)
}
.observeOn(MainScheduler.instance)
......
......@@ -27,6 +27,7 @@ class ContactRequestItem {
let contactRequest: ContactRequestModel
let userName = Variable("")
let profileName = Variable("")
let profileImageData = Variable<Data?>(nil)
let disposeBag = DisposeBag()
......@@ -36,11 +37,14 @@ class ContactRequestItem {
self.userName.value = contactRequest.ringId
self.profileImageData.value = self.contactRequest.vCard?.imageData
profileService.getProfile(ringId: contactRequest.ringId, createIfNotexists: false)
.subscribe(onNext: { [unowned self] profile in
.subscribe(onNext: { [weak self] profile in
if let photo = profile.photo,
let data = NSData(base64Encoded: photo,
options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) as Data? {
self.profileImageData.value = data
self?.profileImageData.value = data
if let name = profile.alias, !name.isEmpty {
self?.profileName.value = name
}
}
}).disposed(by: self.disposeBag)
}
......
......@@ -316,7 +316,11 @@ class MessageCell: UITableViewCell, NibReusable {
} else if item.bubblePosition() == .received {
// received message avatar
Observable<(Data?, String)>.combineLatest(conversationViewModel.profileImageData.asObservable(),
conversationViewModel.userName.asObservable()) { profileImage, username in
conversationViewModel.userName.asObservable(),
conversationViewModel.displayName.asObservable()) { profileImage, username, displayName in
if let displayName = displayName, !displayName.isEmpty {
return (profileImage, displayName)
}
return (profileImage, username)
}
.observeOn(MainScheduler.instance)
......
......@@ -279,7 +279,10 @@ class ConversationViewController: UIViewController, UITextFieldDelegate,
profileImageView.frame = CGRect.init(x: 0, y: 0, width: imageSize, height: imageSize)
profileImageView.center = CGPoint.init(x: imageSize / 2, y: titleView.center.y)
if let bestId = username {
if let profileName = displayName, !profileName.isEmpty {
profileImageView.addSubview(AvatarView(profileImageData: profileImageData, username: profileName, size: 36))
titleView.addSubview(profileImageView)
} else if let bestId = username {
profileImageView.addSubview(AvatarView(profileImageData: profileImageData, username: bestId, size: 36))
titleView.addSubview(profileImageView)
}
......
......@@ -57,8 +57,12 @@ class ConversationCell: UITableViewCell, NibReusable {
func configureFromItem(_ item: ConversationSection.Item) {
// avatar
Observable<(Data?, String)>.combineLatest(item.profileImageData.asObservable(),
item.userName.asObservable()) { profileImage, username in
return (profileImage, username)
item.userName.asObservable(),
item.displayName.asObservable()) { profileImage, username, displayName in
if let displayName = displayName, !displayName.isEmpty {
return (profileImage, displayName)
}
return (profileImage, username)
}
.observeOn(MainScheduler.instance)
.startWith((item.profileImageData.value, item.userName.value))
......
......@@ -41,7 +41,7 @@ class BannedContactCell: UITableViewCell, NibReusable {
// avatar
self.profileImageView.subviews.forEach({ $0.removeFromSuperview() })
self.profileImageView.addSubview(AvatarView(profileImageData: item.image,
username: item.contact.userName ?? item.contact.ringId,
username: item.displayName ?? (item.contact.userName ?? item.contact.ringId),
size: 40))
if let displayName = item.displayName {
......
......@@ -64,6 +64,7 @@ class BlockListViewModel: ViewModel {
var item = BannedContactItem(withContact: contact)
self.contactService.getProfileForUri(uri: contact.ringId)
.subscribe(onNext: { (profile) in
item.displayName = profile.alias
guard let photo = profile.photo else {
return
}
......@@ -72,7 +73,6 @@ class BlockListViewModel: ViewModel {
.ignoreUnknownCharacters) as Data? else {
return
}
item.displayName = profile.alias
item.image = data
}).disposed(by: self.disposeBag)
if contact.userName == nil || contact.userName! == "" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment