-
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
base: rc
Are you sure you want to change the base?
feat: message composer #1495
Conversation
Size Change: +80.8 kB (+27.5%) 🚨 Total Size: 375 kB
|
3d8c06c
to
e872576
Compare
bb1179a
to
0b1b773
Compare
…iddleware results
b5c6d3f
to
054aa7b
Compare
…/message-composer
…/message-composer
…e slots, preserve original attachment id
…/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.
…/message-composer
…/message-composer
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: