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

For Group Chat #413

Open
saroar opened this issue Dec 3, 2017 · 10 comments
Open

For Group Chat #413

saroar opened this issue Dec 3, 2017 · 10 comments

Comments

@saroar
Copy link

saroar commented Dec 3, 2017

i am trying to show each user avatar and name on my back-end i did something like this https://github.com/PerfectExamples/Perfect-Chat-Demo/blob/master/Sources/ChatUser.swift

so is it possible if yes please show some code how i can do it thanks advance

i can do something but it does not help me

if textmessageViewModal.isIncoming {
    textmessageViewModal.avatarImage.value = UIImage(named: "avatar")
} else {
     ImageCache.default.retrieveImage(forKey: "\(PerfectLocalAuth.email)", options: nil) 
        image, cacheType in
            if let image = image {
                  textmessageViewModal.avatarImage.value = image
             } else {
                  textmessageViewModal.avatarImage.value = #imageLiteral(resourceName: "avatar1")
            }
      }
 }
@AntonPalich
Copy link
Contributor

@saroar Where did you put this code? Can you share the presenter that manages your message with an avatar?

@saroar
Copy link
Author

saroar commented Dec 5, 2017

@AntonPalich
Copy link
Contributor

@saroar Do you see avatar at all?

If you don't see it, can you check that you set canShowAvatar to true in ChatDecorationAttributes in your ChatDecorator??

If canShowAvatar is true then the issue is in BaseMessageCollectionViewCell that doesn't observe changes in avatarImage property. We don't use it in production, so it can be a bug. Your view model sets image asynchronously. Therefore, if you update avatar image after cell was configured with a view model then your cell doesn't know that avatar image was updated. Cell should observe avatarImage property and update UI on any change.

@saroar
Copy link
Author

saroar commented Dec 6, 2017

@AntonPalich

import Chatto
import ChattoAdditions

class ChatDecorator: ChatItemsDecoratorProtocol {

    func decorateItems(_ chatItems: [ChatItemProtocol]) -> [DecoratedChatItem] {

        var decoratedItems = [DecoratedChatItem]()

        for item in chatItems {

            let decoratedItem = DecoratedChatItem(chatItem: item,
                decorationAttributes: ChatItemDecorationAttributes(bottomMargin: 3,
                                             canShowTail: true,
                                             canShowAvatar: true,
                                             canShowFailedIcon: false)
            )

            decoratedItems.append(decoratedItem)
        }

        return decoratedItems

    }
}```

@saroar
Copy link
Author

saroar commented Dec 6, 2017

if you click this
http://prntscr.com/hjl2sm
http://prntscr.com/hjl4r6

you can see what my i see in my app please see those screen short please

@saroar
Copy link
Author

saroar commented Dec 6, 2017

i need each ur avatar will show my group chat i think it is not possible with Chatto or each user name

@AntonPalich
Copy link
Contributor

@saroar It's possible. You have a full control over the bubble content.

I see that you set avatar placeholder for all incoming messages. If you want to set a user image your message should provide an information that can be used to load an avatar for each incoming message. This information can be a user ID or an URL to an image, it's up to you. The same for outgoing messages.

@saroar
Copy link
Author

saroar commented Dec 6, 2017

Thanks for quick reply
My msg have image URL then I will show it or let do it user id now please can you guide me how i can do it i am very new in swift may be ur little help i can do it then will publish this here to so every one can get help from here or show me some code where i can see @AntonPalich thanks advance

@saroar
Copy link
Author

saroar commented Dec 19, 2017

@AntonPalich how i do know current user id here? so i can show user name or avatar , becz decoratedTextMessage i have one text nothing else

@saroar
Copy link
Author

saroar commented Dec 20, 2017

thanks everything is working great

here is my code working for group chat

        
        let textmessageViewModal = ViewModel(
            textMessage: decoratedTextMessage,
            messageViewModel:defualtBuilder.createMessageViewModel(decoratedTextMessage)
        )

        if textmessageViewModal.isIncoming {
            NetworkignService.shared.fetchHangoutChannelAvatarByOwnerId(ownerId: decoratedTextMessage.senderId) { pictureUrl in
                guard let url = pictureUrl?["picture"].stringValue else {
                    textmessageViewModal.avatarImage.value = #imageLiteral(resourceName: "avatar")
                    return
                }
                
                ImageLoader2.sharedInstance.load(url: url, completion: { image in
                    textmessageViewModal.avatarImage.value = image
                })
                
            }
            
            textmessageViewModal.avatarImage.value = UIImage(named: "avatar")
        } else if let imageUrl = PerfectLocalAuth.userdetails["picture"] as? String {

            ImageLoader2.sharedInstance.load(url: imageUrl, completion: { image in
                textmessageViewModal.avatarImage.value = image
            })

        } else {
            textmessageViewModal.avatarImage.value = #imageLiteral(resourceName: "avatar1")
        }
        
        return textmessageViewModal
    }```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants