Skip to content

Allow customisation of message previews in lists #839

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented May 27, 2025

🔗 Issue Links

Resolves: IOS-895

🎯 Goal

  • Allow overriding message previews in lists (e.g. supporting previews for custom attachments)

📝 Summary

  • Open up the MessagePreviewFormatter

🛠 Implementation

  • Open up existing MessagePreviewFormatter

🎨 Showcase

🧪 Manual Testing Notes

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@laevandus laevandus requested a review from a team as a code owner May 27, 2025 12:19
@laevandus laevandus added the ✅ Feature An issue or PR related to a feature label May 27, 2025
@laevandus laevandus force-pushed the message-preview-customisation branch from 3432039 to 5b21d5f Compare May 27, 2025 12:21
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented May 27, 2025

SDK Size

title develop branch diff status
StreamChatSwiftUI 8.23 MB 8.23 MB +1 KB 🟢

Comment on lines 8 to 16
/// Provides message preview representation for lists.
public protocol MessagePreviewFormatting {
/// Formats the message including the author's name.
func format(_ previewMessage: ChatMessage, in channel: ChatChannel) -> String
/// Formats only the content of the message without the author's name.
func formatContent(for previewMessage: ChatMessage, in channel: ChatChannel) -> String
/// Formats only the attachment content of the message in case it contains attachments.
func formatAttachmentContent(for previewMessage: ChatMessage, in channel: ChatChannel) -> String?
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it is probably better to just use the MessagePreviewFormatter function directly here 🤔 There is a chance we add new function here, for example, for Draft Message etc... and if we introduce a new function, it will be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

The other formatters, we use a protocol, but usually it is just one function, and for one use case. This one is a bit different, since we use it in multiple places, and there is a chance to extend it further

Copy link
Contributor

@martinmitrevski martinmitrevski May 27, 2025

Choose a reason for hiding this comment

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

It's also fine like this, you can add a protocol extension with a default implementation to avoid breaking changes.

Copy link
Contributor Author

@laevandus laevandus May 28, 2025

Choose a reason for hiding this comment

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

I did consider skipping the protocol part completely, but then only added it because many existing types in Utils had it. I guess it makes sense to skip it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, let's go for no protocol here

Copy link
Member

@nuno-vieira nuno-vieira May 28, 2025

Choose a reason for hiding this comment

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

Yeah the default extension is a good point, forgot about it. In that case I'm fine with both approaches 👍

@laevandus laevandus enabled auto-merge (squash) May 28, 2025 08:25
Copy link

@laevandus laevandus merged commit 88bd595 into develop May 28, 2025
11 checks passed
@laevandus laevandus deleted the message-preview-customisation branch May 28, 2025 09:17
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Feature An issue or PR related to a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants