Skip to content

Add SendMessageInterceptor to intercept send message request #3671

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

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

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented May 19, 2025

🔗 Issue Links

IOS-857

🎯 Goal

Add a way to intercept our send message request

📝 Summary

  • Add SendMessageInterceptor
  • Add SendMessageInterceptorFactory
  • Add ChatMessage.changing()
  • Improve documentation of ChatMessage.replacing()

🛠 Implementation

SendMessageInterceptor

A new protocol has been introduced, SendMessageInterceptor. This will only be used if the customer provides an interceptor. If no interceptor is provided, nothing is changed.

The SendMessageInterceptor is not exposed directly in the ChatClientConfig. Instead, it can be injected through a SendMessageInterceptorFactory. The factory gives us more flexibility, especially to make it possible to inject the ChatClient, which can be useful in case a customer wants to use the interceptor but still wants to use our internal APIClient to make the request. I created an example on how, in the future, we can provide this to customers here. For now, I reverted it, but if any customer needs to use our APIClient, it will be easy to provide it. It can be useful for customers who might want to intercept our message requests, but only for a certain type of messages, or simply want to override some data.

ChatMessage.changing() vs ChatMessage.replacing()

I added documentation to ChatMessage.replacing() since it was lacking, and it could be misleading on how to use it. The replacing() function is useful when overriding data, especially if the customer wants to delete some of it. For example, providing the state with nil will make the message state as published. Since this behaviour might not be what some customers need, a changing() function has been introduced for the case where customers just want to change some data, but the rest should be left unchanged (It is different from replacing() because in this case it is not possible to erase data, since nil will fallback to the original data).

🧪 Manual Testing Notes

N/A. Covered by unit tests.

☑️ 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

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented May 19, 2025

SDK Size

title develop branch diff status
StreamChat 7.2 MB 7.2 MB +1 KB 🟢
StreamChatUI 4.72 MB 4.72 MB 0 KB 🟢

@nuno-vieira nuno-vieira force-pushed the add/send-message-interceptor branch from 14b91d7 to 8301b2d Compare May 20, 2025 12:51
@nuno-vieira nuno-vieira changed the title WIP SendMessageInterceptor Add SendMessageInterceptor to intercept send message request May 20, 2025
@nuno-vieira nuno-vieira marked this pull request as ready for review May 20, 2025 14:59
@nuno-vieira nuno-vieira requested a review from a team as a code owner May 20, 2025 14:59
@nuno-vieira nuno-vieira force-pushed the add/send-message-interceptor branch from 6ec6b53 to a278241 Compare May 20, 2025 15:05
@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 3.34 ms 66.6% 🔼 🟢
Duration 2.6 s 2.55 s 1.92% 🔼 🟢
Hitch time ratio 4 ms per s 1.31 ms per s 67.25% 🔼 🟢
Frame rate 75 fps 78.48 fps 4.64% 🔼 🟢
Number of hitches 1 0.4 60.0% 🔼 🟢

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented May 20, 2025

SDK Size

title develop branch diff status
StreamChat 7.2 MB 7.2 MB +1 KB 🟢
StreamChatUI 4.72 MB 4.72 MB 0 KB 🟢

Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants