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 custom location attachment to the Demo App #2947

Merged
merged 22 commits into from
Dec 21, 2023

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Dec 20, 2023

🔗 Issue Links

Resolves https://github.com/GetStream/ios-issues-tracking/issues/684

🎯 Goal

Adds a custom attachment example to the Demo App. This will make it easier to test features for custom attachments. It is also helpful for customers to see how a custom attachment can be implemented. In the future, we should update the documentation to use this example instead of the dummy "workout" example we currently have.

While working on this, I realised it was not easy for custom attachments to support the mixed attachments rendering, so I made some improvements to make it easier.

📝 Summary

  • Adds a custom location attachment to the Demo App
  • Makes it easier for custom attachments to support mixed attachment rendering
  • Adds the possibility to enable/disable background mapping in the demo app.
  • Fixes deleted messages, always showing custom attachments

🛠 Implementation

Adds a custom location attachment to the Demo App

For this attachment, we are just saving the coordinates of a location. Then, the app is responsible for showing that location on a map. For better performance, an image snapshot of the map is generated in the message list, and only when tapping the snapshot we open the actual map. We could also save the generated snapshots upload it to the CDN, and save them in the message. This way, Web could use the generated snapshots from iOS or Android, but this is out of scope right now, especially for a Demo App example.

Makes it easier for custom attachments to support mixed attachment rendering

Previously, in order to support mixed attachments for our custom attachment was quite complex and not intuitive. It was required to override the MixedAttachmentInjector, override the injectors property, make sure we did it lazily and make sure we defined the correct order.

Now, we just need to register our custom attachment to the MixedAttachmentInjector registry, and then when overriding the Catalog, make sure to return the MixedAttachmentInjector when there are multiples attachment types.

Example:

Components.default.mixedAttachmentInjector.register(.location, with: LocationAttachmentViewInjector.self)

class DemoAttachmentViewCatalog: AttachmentViewCatalog {
    override class func attachmentViewInjectorClassFor(message: ChatMessage, components: Components) -> AttachmentViewInjector.Type? {
        let hasMultipleAttachmentTypes = message.attachmentCounts.keys.count > 1
        let hasLocationAttachment = message.attachmentCounts.keys.contains(.location)
        if hasLocationAttachment {
            if hasMultipleAttachmentTypes {
                return MixedAttachmentViewInjector.self
            }
            return LocationAttachmentViewInjector.self
        }

        return super.attachmentViewInjectorClassFor(message: message, components: components)
    }
}

Fixes deleted messages, always showing custom attachments

We returned nil for the attachment injector whenever the message was deleted. But this was done in the incorrect place. Whenever there was a customization, this logic was overriden.

🎨 Showcase

Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-12-21.at.02.34.54.mov

🧪 Manual Testing Notes

Precondition

Location Attachments should be enabled in the Demo App Configuration.

Adds a custom location attachment to the Demo App

Please check the video above

Makes it easier for custom attachments to support mixed attachments rendering

  1. Add a location with another attachment
  2. Both attachments should render in the composer
  3. Both attachments should render in the message list

Fixes deleted messages, always showing custom attachments

  1. Add a location attachment
  2. Delete a message with a location attachment
  3. "Message deleted" text should appear.

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (docusaurus, tutorial, CMS)

@nuno-vieira nuno-vieira added the 🪧 Demo App An Issue or PR related to the Demo App label Dec 20, 2023
Copy link

github-actions bot commented Dec 20, 2023

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@nuno-vieira nuno-vieira added 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK ✅ Feature An issue or PR related to a feature labels Dec 21, 2023
@nuno-vieira nuno-vieira force-pushed the demo-app/custom-location-attachment branch from 37623ba to 5e4220c Compare December 21, 2023 02:12
@nuno-vieira nuno-vieira marked this pull request as ready for review December 21, 2023 02:55
@nuno-vieira nuno-vieira requested a review from a team as a code owner December 21, 2023 02:55
Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

Great stuff @nuno-vieira 👏 Just added few small things, otherwise this is a very nice improvement.

@nuno-vieira nuno-vieira merged commit a26f3c2 into develop Dec 21, 2023
7 checks passed
@nuno-vieira nuno-vieira deleted the demo-app/custom-location-attachment branch December 21, 2023 10:31
@nuno-vieira nuno-vieira mentioned this pull request Dec 21, 2023
Copy link

sonarcloud bot commented Dec 21, 2023

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

47 New issues
0 Security Hotspots
91.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@nuno-vieira nuno-vieira restored the demo-app/custom-location-attachment branch December 21, 2023 15:39
nuno-vieira added a commit that referenced this pull request Dec 21, 2023
This was referenced Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪧 Demo App An Issue or PR related to the Demo App ✅ Feature An issue or PR related to a feature 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants