-
Notifications
You must be signed in to change notification settings - Fork 76
feat: message composer #1495
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
feat: message composer #1495
Conversation
Size Change: +80.5 kB (+27.42%) 🚨 Total Size: 374 kB
|
3d8c06c
to
e872576
Compare
bb1179a
to
0b1b773
Compare
…iddleware results
b5c6d3f
to
054aa7b
Compare
…/message-composer
…/message-composer
const isActualStateChange = | ||
!!previousValue && | ||
(nextValue.attachments.length !== previousValue.attachments.length || | ||
nextValue.attachments.some( | ||
(attachment, index) => | ||
attachment.localMetadata.id !== | ||
previousValue.attachments[index].localMetadata.id, | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed this pattern a bunch of times here but I don't think this is the route we should take. Any state update emitted by our code should be truly intentional - if we can/have to target specific part of the state, we should do it through the selector which does the value comparation under the hood and the handler gets executed only if the selected values actually changed. It's harder with complex entities (such as arrays or objects) which get constructed anew each time an event comes in with new data and seemingly nothing really changed - but this problem should be tackled at the very top, where the actual state is being changed so that we don't have to re-define these comparisons for every subscription. It's fine like this for now I suppose but we should tackle it at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are logging the state change timestamp. The goal is to be able to determine, whether the draft data coming through a WS should be accepted and also if a draft creation should take place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm trying to say is that the checks should happen here:
on("channel.updated", (event) => {
const { members, membersHash } = state.getLatestValue();
members; // ['john', 'bob', 'jane']
event.members; // also ['john', 'bob', 'jane']
event.members !== members; // true (overriding these would trigger state update for subscribers with selectors pointing at members)
const incomingMembersHash = calculateHash(event.members);
if (membersHash !== incomingMembersHash) { // false (no state change, subscribers won't be notified)
state.partialNext({
members: event.members,
membersHash: incomingMembersHash,
});
}
});
The example using hashes is silly but you get the point.
This way - if I create another subscriber (or hundred more) - I can be sure that each won't have to check whether something changed or not, because if their handler got triggered it should mean that something actually changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here: 1b13f9a
…/message-composer
…/message-composer
…/message-composer
This PR introduces a new message composer system that provides a robust foundation for message composition with support for drafts, middleware, and various composition features. - Message draft support for channels - Text composition middleware system - Command handling with case-insensitive search - Link preview integration - Mentions search with local member support - Notification management system - Local message type for better state management - Introduces `MessageComposer` class for managing message composition - Adds middleware system for text composition with extensible pipeline - Implements draft message handling with proper state management - Adds support for commands with trigger-based activation - Integrates link preview functionality during composition - Provides notification management for composition events - Introduces `LocalMessage` type for improved state handling Introduction of `LocalMessage` type. The `MessageResponse` is automatically transformed into LocalMessage type before being submitted to the state. - Added comprehensive test coverage for: - Message composition middleware - Command handling - Link preview integration - Mentions search - State management - Draft handling - Bundle size increase: +72.3 kB (+24.62%) - dist/cjs/index.browser.cjs: +19.4 kB - dist/cjs/index.node.cjs: +20 kB - dist/esm/index.js: +32.9 kB - Convert message composer into a plugin system - Further optimize bundle size - Add more middleware options for extensibility - Encapsulate interaction with the UI element representing the text editing area - Related to stream-chat-react#2669 - `linkifyjs@^4.2.0` BREAKING CHANGE: Replacement of FormatMessageResponse with LocalMessage type --------- Co-authored-by: Anton Arnautov <arnautov.anton@gmail.com> Co-authored-by: Khushal Agarwal <khushal.agarwal987@gmail.com> Co-authored-by: Zita Szupera <szuperaz@gmail.com> Co-authored-by: Ivan Sekovanikj <ivan.sekovanikj@getstream.io>
## [9.0.0-rc.11](v9.0.0-rc.10...v9.0.0-rc.11) (2025-04-28) ### ⚠ BREAKING CHANGES * Replacement of FormatMessageResponse with LocalMessage type ### Bug Fixes * [REACT-344] remove Agora & 100ms integrations ([#1519](#1519)) ([16cd81a](16cd81a)) * [REACT-350] make archived_at & pinned_at nullable ([#1515](#1515)) ([318825a](318825a)) * [REACT-353] unify pinned_at & archived_at nullish values ([#1516](#1516)) ([a840226](a840226)), closes [#1515](#1515) ### Features * [CHA-794] Add sort and filter param to queryThreads ([#1511](#1511)) ([ea7fe99](ea7fe99)) * [CHA-855] - Refactoring partial update member ([#1517](#1517)) ([e4f7e68](e4f7e68)) * message composer ([#1495](#1495)) ([0c07524](0c07524)), closes [stream-chat-react#2669](GetStream/stream-chat-react#2669)
### 🎯 Goal Provide a message composition API supported by reactive state layer from stream-chat. The message composition logic has been moved to stream-chat. The logic kept in stream-chat-react is related only to the browser event handling. Depends on: - GetStream/stream-chat-js#1495 - GetStream/stream-chat-css#328 ### 🛠 Implementation details The message composition now relies on `MessageComposer `instance. The instance is available for the channel message list, thread message list and for editing a specific message. The `MessageComposer` instance should be accessed via `useMessageComposer` hook, that identifies the correct context (channel, thread, message). ### 🎨 UI Changes No changes BREAKING CHANGE: `Channel` props `dragAndDropWindow` & `optionalMessageInputProps` have been removed, use `WithDragAndDropUpload` component instead (#2688) BREAKING CHANGE: Attachment identity functions moved to stream-chat-js (e.g. isFileAttachment...) BREAKING CHANGE: Remove ChatAutoComplete, AutoCompleteTextarea, DefaultSuggestionList, DefaultSuggestionListItem and introduce TextareaComposer, SuggestionList, SuggestionListItem BREAKING CHANGE: Remove defaultScrollToItem function previously used by SuggestionList BREAKING CHANGE: Removed DefaultTriggerProvider component BREAKING CHANGE: Remove from Channel props - acceptedFiles, enrichURLForPreview, enrichURLForPreviewConfig, maxNumberOfFiles, multipleUploads, TriggerProvider BREAKING CHANGE: Removal of acceptedFiles, debounceURLEnrichmentMs, enrichURLForPreview, findURLFn, multipleUploads, onLinkPreviewDismissed, quotedMessage from ChannelStateContext BREAKING CHANGE: Changed signature for functions sendMessage and editMessage in ChannelActionContext BREAKING CHANGE: Changed signature for handleSubmit BREAKING CHANGE: Removed setQuotedMessage from ChannelActionContext BREAKING CHANGE: Removed types MessageToSend, StreamMessage, UpdatedMessage in favor of LocalMessage or RenderedMessage BREAKING CHANGE: Removed Trigger generics from ChannelProps BREAKING CHANGE: Message input state as well as the API is now kept within MessageComposer instead of MessageInputContext BREAKING CHANGE: Renamed useMessageInputState to useMessageInputControls as it does not handle the composition state anymore BREAKING CHANGE: Removed from MessageInputProps - disabled, disableMentions, doFileUploadRequest, doImageUploadRequest, errorHandler, getDefaultValue, mentionAllAppUsers, mentionQueryParams, message, noFiles, urlEnrichmentConfig, useMentionsTransliteration, additionalTextareaProps do not expect default value anymore BREAKING CHANGE: Changed the signature of MessageInput prop overrideSubmitHandler BREAKING CHANGE: Local attachment and link preview types moved to stream-chat BREAKING CHANGE: The SuggestionListItem UI components for TextareaComposer receive tokenizedDisplayName instead of itemNameParts BREAKING CHANGE: Removed duplicate types SendMessageOptions, UpdateMessageOptions which should be imported from stream-chat instead BREAKING CHANGE: Removed type LinkPreviewListProps - LinkPreviewList does not have any props anymore --------- Co-authored-by: Anton Arnautov <arnautov.anton@gmail.com>
## [9.0.0](v8.60.0...v9.0.0) (2025-05-06) ### ⚠ BREAKING CHANGES * Replacement of FormatMessageResponse with LocalMessage type * `ErrorFromResponse` class constructor now requires second parameter (`status`, `response` and optionally `code`) * dropped jsDelivr bundle (#1468) * dropped `StreamChatGenerics`, use `Custom<Entity>Data` to extend your types * type `InviteOptions` has been renamed to `UpdateChannelOptions` * type `UpdateChannelOptions` has been renamed to `UpdateChannelTypeRequest` * type `ThreadResponseCustomData` has been renamed to `CustomThreadData` * type `MarkAllReadOptions` has been deleted in favour of type `MarkChannelsReadOptions` * type `QueryFilter` no longer supports `$ne` and `$nin` operators * type `ChannelMembership` has been deleted in favour of type `ChannelMemberResponse` * function `formatMessage` (`utils.ts`) no longer returns `__html` property in the formatted message output ### Bug Fixes * [REACT-344] remove Agora & 100ms integrations ([#1519](#1519)) ([16cd81a](16cd81a)) * add image property to UserResponse type ([#1486](#1486)) ([2a57b7f](2a57b7f)) * adjust ChannelResponse, ChannelData & PollResponse ([#1493](#1493)) ([39091c7](39091c7)) * adjust ErrorFromResponse error class ([#1491](#1491)) ([ff32bd2](ff32bd2)) * increase package.json[engines.node] version ([6764bad](6764bad)) * multiple module augmentation fails in Angular ([#1488](#1488)) ([7f8a9a0](7f8a9a0)) * omit name from CustomChannelData for ChannelFilters ([#1494](#1494)) ([d7030c2](d7030c2)) * **qa:** adjust Event & ChannelData types ([#1524](#1524)) ([f1d73fd](f1d73fd)) * remove message composer bugs ([#1521](#1521)) ([8b324eb](8b324eb)) * replace StreamChatGenerics with module augmentation ([#1458](#1458)) ([feb97da](feb97da)) ### Features * add missing configuration parameters for AttachmentManager and TextComposer ([#1520](#1520)) ([44902e7](44902e7)) * disable link previews in message composer ([02cd9a8](02cd9a8)) * improve MessageComposer ergonomics ([2c0c639](2c0c639)) * make MessageComposer middleware executors public ([9aae032](9aae032)) * message composer ([#1495](#1495)) ([0c07524](0c07524)), closes [stream-chat-react#2669](GetStream/stream-chat-react#2669) * middleware handler API improvement ([#1523](#1523)) ([9d8992d](9d8992d))
🎉 This PR is included in version 9.2.0-offline-support-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Message Composer Feature
Overview
This PR introduces a new message composer system that provides a robust foundation for message composition with support for drafts, middleware, and various composition features.
Key Features
Technical Details
MessageComposer
class for managing message compositionLocalMessage
type for improved state handlingBreaking Changes
Introduction of
LocalMessage
type. TheMessageResponse
is automatically transformed into LocalMessage type before being submitted to the state.Testing
Performance Impact
Future Improvements
Related Issues
Dependencies
linkifyjs@^4.2.0
Documentation
TODO: Add documentation for:
BREAKING CHANGE: Replacement of FormatMessageResponse with LocalMessage type