Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to show avatar image for messages #55

Merged
merged 4 commits into from
Mar 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change to show avatar for both incoming and outgoing message for demo…
… purpose
  • Loading branch information
Zhao Wang committed Mar 10, 2016
commit 6c09805fb9f668643ae7544c21805713505d9e45
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import ChattoAdditions

class BaseMessageCollectionViewCellAvatarStyle: BaseMessageCollectionViewCellDefaultStyle {
override func getAvatarImageSize(messageViewModel: MessageViewModelProtocol) -> CGSize {
// Display avatar for both incoming and outgoing messages for demo purpose
if messageViewModel.isIncoming {
// Only display avatar for incoming message
return CGSize(width: 35, height: 35)
} else {
return CGSize.zero
return CGSize(width: 35, height: 35)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to remove the if/else

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public class DemoTextMessageViewModelBuilder: ViewModelBuilderProtocol {
public func createViewModel(textMessage: DemoTextMessageModel) -> DemoTextMessageViewModel {
let messageViewModel = self.messageViewModelBuilder.createMessageViewModel(textMessage)
let textMessageViewModel = DemoTextMessageViewModel(textMessage: textMessage, messageViewModel: messageViewModel)
if textMessage.isIncoming {
// Best place to decide whether user having avart might be in the presenter. Here just for demo purpose
// Because we might only want to display avatar when showTail in the nessage bubble
textMessageViewModel.avatarImage = UIImage(named: "userAvatar")
}
// Best place to decide whether user having avart might be in the presenter. Here just for demo purpose
// Because we might only want to display avatar when showTail in the nessage bubble
textMessageViewModel.avatarImage = UIImage(named: "userAvatar")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm... Haven't thought of this. You're right, trying to implement some kind of logic in which the avatar is not shown in every cell looks complicated as it is now. I'd rather add a new attribute ChatItemDecorationAttributes.canShowAvatar and replicate what it's done with the tail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how adding canShowAvatar to the ChatItemDecorationAttributes can make things easier yet. I need to look into the code to see more use cases of ChatItemDecorationAttributes. So if it makes sense, I will add this to the decorator attributes later. :)

I think user can also do this by themselves by subclassing ChatItemDecorationAttributes?

However for now, I will suggest to do this in the presenter based on the actual logic of view model and business requirements. User need to create an custom presenter.

return textMessageViewModel
}

Expand Down