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 Static Location and Live Location Support #3531

Closed
wants to merge 88 commits into from

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Dec 13, 2024

🔗 Issue Links

Resolves https://linear.app/stream/issue/IOS-578/location-attachment

🎯 Goal

Adds support for static and live location attachments in the Low-Level Client SDK.

The UI has been implemented in the Demo App to demonstrate how to use the new location APIs.

📝 Summary

New APIs:

  • ChatChannelController
    • sendStaticLocation() - Sends a static location message to the channel.
    • startLiveLocationSharing() - Starts a live location-sharing message in the channel.
    • stopLiveLocationSharing() - Stops sharing the live location message in the channel.
  • ChatMessageController
    • updateMessage() - Updates the message partially. (It was missing from the SDK)
    • updateLiveLocation() - Updates the message's live location attachment if it has one.
    • stopLiveLocationSharing() - Stops sharing the live location attachment if it has one.
  • CurrentChatUserController
    • updateLiveLocation() - Updates the location of all active live location messages for the current user. Internally, it uses the Message Controller to update each message that has a live location attachment.
  • CurrentChatUserControllerDelegate
    • didStartSharingLiveLocation() - Notifies whenever the current user is sharing a live location.
    • didStopSharingLiveLocation() - Notifies whenever the current user stops sharing a live location.
    • didChangeActiveLiveLocationMessages() - Notifies whenever the live location messages update.
  • Throttler
    • The Throttler was part of the UI SDK somehow, so it was moved to the LLC and made public like the Debouncer.
  • ChatMessage
    • staticLocationAttachments - Returns the attachments of .staticLocation type.
    • liveLocationAttachments - Returns the attachments of .liveLocation type.
  • AttachmentType
    • .staticLocation
    • .liveLocation
  • ChatMessageLiveLocationAttachment & LiveLocationAttachmentPayload
  • ChatMessageStaticLocationAttachment & StaticLocationAttachmentPayload

Out of Scope

  • End Time: The backend does not support this out of the box yet, and there's no contract yet for this. But we should add this as soon as possible since all of the common apps have this feature.
  • Multi-Device: At the moment, there is no protection against the user sharing the location between multiple devices. The location will be shared from both devices since, at the moment, we don't have a way to attach the device ID or the device model to an attachment. Since this is an edge case, it can be left for future improvement.

🛠 Implementation

The SDK at the moment only handles updating the location attachments. The location tracking should be provided by the App. Something like the LocationProvider in the Demo App should be implemented by the customer.

Creating a location attachment

In order to create a new message with a location attachment, the developer can use the ChannelController.sendStaticLocation() or the ChannelController.startSharingLiveLocation(). If more fine control is needed, it is also possible to add the attachments by using the ChannelController.createNewMessage() and pass the location attachment payload as an argument.

Sending location updates (Live Location)

The customer is responsible for sending new location updates to the SDK. This is done through the CurrentChatUserController.updateLiveLocation() method. This method will update all the current user's active location attachments. Internally, it uses a activeLiveLocationMessagesObserver that keeps track of the active location attachments of the current user. These changes are also available to the customer through the CurrentChatUserControllerDelegate to make it easier for the developer to know when it should track location updates and when it can turn them off.

Stopping live location attachment

To stop a live location attachment, it can be done through 2 methods:

  • ChatChannelController.stopLiveLocationSharing(): This one will automatically get the current active location attachment in that channel and stop it.
  • ChatMessageController.stopLiveLocationSharing(): Directly tries to stop a live location attachment in the given message if it has an active location attachment. This is especially useful in Message Actions, where having the ChannelController is not possible or difficult.

Overall Data Flow

sequenceDiagram
    participant App
    participant LocationProvider
    participant SDK
    participant Backend

    Note over App,Backend: Start New Location Share
    App->>LocationProvider: getCurrentLocation()
    LocationProvider-->>App: Return current location
    App->>SDK: startLiveLocationSharing(location)
    SDK->>Backend: Create location message
    Backend-->>SDK: Confirm creation
    SDK->>App: onStartLiveLocationSharing()
    App->>LocationProvider: startMonitoring()

    Note over App,Backend: Location Updates
    LocationProvider->>LocationProvider: Monitor location changes
    LocationProvider->>SDK: didUpdateLocation(location)
    SDK->>Backend: updateLiveLocation
    Note over SDK: 3s Throttling

    Note over App,Backend: Stop Location Share
    App->>SDK: stopLiveLocationSharing()
    SDK->>Backend: Stop location sharing
    Backend-->>SDK: Confirm stop
    SDK->>App: onStopLiveLocationSharing()
    App->>LocationProvider: stopMonitoring()
Loading

🎨 Showcase

Static Live
static.mp4
live.mp4

🧪 Manual Testing Notes

Note: To simulate live location updates in the Simulator, with the Simulator selected, Go to Features > Location > City Bicycle Ride in the top bar of the Mac.

Static

  1. Open the Demo App
  2. Tap on Configuration
  3. Enable Location Attachments (Skip this step if Stream Developers scheme is being used)
  4. Open a Channel
  5. Tap on Attachments Icon
  6. Tap "Send Current Location"
  7. It should render an image of the map with a Pin
  8. Tapping the attachment should open the map with the Pin

Live

  1. Open the Demo App
  2. Tap on Configuration
  3. Enable Location Attachments (Skip this step if Stream Developers scheme is being used)
  4. Open a Channel
  5. Tap on Attachments Icon
  6. Tap "Share Live Location"
  7. It should render an image of the map with the avatar of the user
    • The image is static and does not update. It is generated when the channel is opened.
    • The avatar does not have the blue pulse animation. This is due to the fact that we reload the cell on every update, which would restart the animation.
  8. Tapping the attachment should open the map with the user's avatar, and it should follow his location.
  9. Tapping the "Stop Sharing" button should stop sharing the live location.

Make sure to test from the current user's perspective and the other user's perspective.

☑️ 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
  • Comparison screenshots added for visual changes
  • Affected documentation updated (docusaurus, tutorial, CMS)

@nuno-vieira nuno-vieira added 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK ✅ Feature An issue or PR related to a feature labels Dec 18, 2024
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.

Couldn't test a lot, since a had constant crashes (shared details on Slack). Let's figure that out first, then I will do another round.

@nuno-vieira nuno-vieira marked this pull request as ready for review January 3, 2025 17:40
@nuno-vieira nuno-vieira requested a review from a team as a code owner January 3, 2025 17:40
@nuno-vieira nuno-vieira changed the title [WIP] Add Static Location and Live Location Support Add Static Location and Live Location Support Jan 3, 2025
@nuno-vieira nuno-vieira force-pushed the add/location-attachments branch from 5e5a9ab to 70218c2 Compare January 3, 2025 22:01
Copy link

github-actions bot commented Jan 3, 2025

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 3, 2025

SDK Size

title develop branch diff status
StreamChat 6.98 MB 7.07 MB +93 KB 🟢
StreamChatUI 4.77 MB 4.77 MB -1 KB 🚀

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.

Looks good! Left few comments, let me know what you think.

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.

LGTM! ✅

@nuno-vieira nuno-vieira added the 🤞 Ready For QA A PR that is Ready for QA label Jan 9, 2025
@testableapple testableapple added 🧪 QAing 🟢 QAed A PR that was QAed and removed 🤞 Ready For QA A PR that is Ready for QA 🧪 QAing labels Jan 9, 2025
@nuno-vieira nuno-vieira force-pushed the add/location-attachments branch from 502d6b5 to f1a4fac Compare January 9, 2025 22:31
@nuno-vieira nuno-vieira force-pushed the add/location-attachments branch from f1a4fac to 37bd1d1 Compare January 9, 2025 23:00
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 🟢 QAed A PR that was QAed 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants