GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
856 stars 208 forks source link

Public Init for ChatMessage and ChatUser #2244

Closed moubry closed 2 years ago

moubry commented 2 years ago

This is a nice to have.

What are you trying to achieve?

I would like to create a SwiftUI Preview for my custom message view, to test what my message view looks like in a variety of different scenarios — with and without attachments, mentions, varying user info, varying text lengths, etc.

If possible, how can you achieve this currently?

I can do this by re-creating ChatMessage in the form of a custom proxy struct (ChatMessageForView) that only contains the properties that I need in order for my views to work, but this is kind of a pain, and I lose out on SwiftUI features that require passing-in a real ChatMessage like .messageBubble(for:).

What would be the better way?

I would like if the init for ChatMessage were marked as public instead of internal so that I can create fake chat messages for the purpose of testing my SwiftUI views.

This would make it possible for me to re-use SwiftUI view features like .messageBubble(for:) in my custom views, so that my custom message views match the style of the StreamSwiftUI default style ones, without needing to duplicate style.

GetStream Environment

GetStream Chat version: 4.20.0 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 15.6 Swift version: latest Xcode version: Version 14.0 beta 4 (14A5284g)

nuno-vieira commented 2 years ago

Hi @moubry!

We have this internal because we don't want developers to think they can create a chat message or chat user model with the initializer. This can open up for bad usage of the SDK. Either way, we understand that this can be a problem for testing and for mocking data. We will discuss this internally and will get back to you as soon as possible.

Best, Nuno

nuno-vieira commented 2 years ago

Btw @moubry, keep in mind you can use our StreamChatTestTools dependency that includes mocks for those models. This is useful for testing, but for previews, it could be a little bit tricky since it doesn't make sense for your app to depend on a testing framework. Unless your previews belong to a different target, which I guess is not ideal right?

moubry commented 2 years ago

We actually already have a separate target in Xcode for running SwiftUI Previews to work around an unrelated issue with another package, so I’ll try StreamChatTestTools to see if that works.

nuno-vieira commented 2 years ago

Awesome 👍 @moubry, Let me know how that goes.

nuno-vieira commented 2 years ago

Hi @moubry!

I'm converting this one to a discussion to see if there are future requests for this.

Best, Nuno