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 Draft Messages Support #775

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

Add Draft Messages Support #775

wants to merge 18 commits into from

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Mar 6, 2025

🔗 Issue Link

https://linear.app/stream/issue/IOS-720/drafts-support-for-swiftui

🎯 Goal

Adds draft messages support.

🛠 Implementation

Summary

  1. Adds support for creating and deleting draft messages
  2. Adds support for filling the composer with a draft message
  3. Improves the commands parsing logic
  4. Adds Draft preview message to both Channel List Item and Thread List Item

Details

Filling the composer with a draft message:
Editing of messages in SwiftUI is still not implemented, so I had to implement this from scratch. The good thing is that this will make it easier to implement IOS-648.

Improves the commands parsing logic:
This was required in order to fill a command message in the composer from a draft. With this, we can now paste a command ex: "/giphy hey" in the composer, and it will correctly parse the full command.

MessageComposerViewModel.quotedMessage:
Initially, I added the ChatChannelViewModel to the MessageComposerView to have access to the quotedMessage (1st commit). But then realised I could pass a binding quoted message to the MessageComposerViewModel. So, I decided on the latter solution since it is less hacky.

New APIs

  • Utils.messageListConfig.draftMessagesEnabled
  • MessageComposerViewModel.updateDraftMessage()
  • MessageComposerViewModel.draftMessage
  • MessageComposerViewModel.fillDraftMessage()
  • MessageComposerViewModel.updateDraftMessage()
  • ChatThreadListItemViewModel.draftReplyText
  • ChatChannel.draftMessageText

User Flow

flowchart LR
    A[User Action]
    A -->|Leave Chat| F[Update Channel Draft]
    A -->|Leave Thread| E[Update Thread Draft]
    A -->|Erase Input Message| D[Delete Draft]
    A -->|Publish Message| D[Delete Draft]
Loading

🧪 Testing

Pre-condition:
Apply the following git patch to change the environment:
c2env.patch

Note: Draft List has not been implemented on SwiftUI Demo App since it has already been tested by UIKit.

Update a Channel Draft Message

  1. Open a Channel
  2. Input some text in the composer (Optional: Include attachments, commands)
  3. Leave the Channel
  4. Comeback to the channel
  5. The composer should have the same content as the composer
  6. When going to the Channel List, the channel preview should have the draft message
  7. Open the channel on another device
  8. The composer should have the same content (Besides the attachments)

Update a Thread Draft Reply

  1. Open a Thread
  2. Input some text in the composer (Optional: Include attachments, commands)
  3. Leave the Thread
  4. Comeback to the Thread
  5. The composer should have the same content as the composer
  6. When going to the Thread List, the thread preview should have the draft message
  7. Open the thread on another device
  8. The composer should have the same content (Besides the attachments)

Deleting a Draft (Channel + Thread)

  1. Open a Channel/Thread
  2. Input some text in the composer (Optional: Include attachments, commands)
  3. Leave the Channel/Thread
  4. Comeback to the Channel/Thread
  5. The composer should have the same content as the composer
  6. Erase the content of the composer
  7. Leave the Channel/Thread
  8. When coming back to the Channel/Thread the composer should be empty
  9. When coming back to the Channel List/Thread List the preview should not include the draft
  10. The draft should disappear from the Draft List.
  11. The draft should disappear on the other devices as well. (Previews and Thread List)

Updating a draft with composer open on another device

  1. Open the same channel with the same user on two devices (A,B)
  2. Write content in the composer on Device A
  3. Leave the channel on Device A
  4. Device B should have the composer updated with the draft from Device A

Offline Support

  1. Open a Channel
  2. Go Offline
  3. Type a message
  4. Leave the channel ( Go to the Channel List)
  5. Go Online
  6. Reload The Channel List (Connect again)
  7. The draft from 3. should be present

Note: On iOS, we added draft requests to our Offline Queue. So when the connection is back online, the Draft requests will be retried.

Drafts for Threads that do not exist yet

  1. Open a new Thread Reply (Without replies)
  2. Type a message
  3. Leave the thread
  4. Open the Drafts List
  5. The draft should be there even if the Thread doesn't exist
  6. When tapping the thread it should load the draft

☑️ Checklist

  • I have signed the Stream CLA (required)
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Affected documentation updated (docusaurus, tutorial, CMS (task created)

@nuno-vieira nuno-vieira requested a review from a team as a code owner March 6, 2025 15:03
Copy link

github-actions bot commented Mar 6, 2025

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Mar 6, 2025

SDK Size

title develop branch diff status
StreamChatSwiftUI 8.16 MB 8.2 MB +36 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 so far, left few comments

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 ✅ Feature An issue or PR related to a feature 🤞 Ready for QA labels Mar 7, 2025
Copy link
Contributor

@laevandus laevandus 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

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 🤞 Ready for QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants