Conversation
|
@kavalerov is attempting to deploy a commit to the ably Team on Vercel. A member of the Team first needs to authorize it. |
components/ChatBox.jsx
Outdated
| setMessages([...history, message]); | ||
| const { send: sendMessage } = useMessages({ | ||
| listener: (payload) => { | ||
| setMessages((prevMessages) => [...prevMessages, payload.message]); |
There was a problem hiding this comment.
This is probably good enough for a demo, but its not entirely correct. Messages can arrive out of order, so the correct way to store them is to use the message.before()/after() funcs to ensure each message coming in is in the correct order first. Its very unlikely you'll experience this edge case if just playing around with the demo though.
There was a problem hiding this comment.
Yeh that'll do! We do have an isSameAs() function too though, perhaps use that instead of directly comparing serials? :)
There was a problem hiding this comment.
100%, give me a moment
components/ChatBox.jsx
Outdated
| const messages = receivedMessages.map((message, index) => { | ||
| const author = message.connectionId === ably.connection.id ? 'me' : 'other'; | ||
| const messageElements = messages.map((message, index) => { | ||
| const key = message.id ?? index; |
There was a problem hiding this comment.
What is the message.id field? Are you sure this is exposed by the message object? If its a chat message, we should use serial instead perhaps?
There was a problem hiding this comment.
Ah yes, my bad, leftover from some other stuff. Will fix shortly.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@splindsay-92 @kavalerov before merge, I noticed one thing:
when I was testing this didn't work, presumably something to do with server side. shouldn't we edit it to a direct import: |
What was the error you are getting? 👀 I've pulled and tested locally, but I can't seem to reproduce any errors |
From Slack discussion:
it's ready to be merged. |
This pull request refactors the chat components to use the new
@ably/chatlibrary, replacing the olderably/reactintegration. It also includes several improvements to the code structure and functionality, such as migrating touseReffor managing DOM elements, updating the message handling logic, and enhancing keyboard interaction. Additionally, thepackage.jsonfile is updated to include the new dependency.Migration to
@ably/chat:components/Chat.jsx: ReplacedAblyProviderandChannelProviderwithChatClientProviderandChatRoomProviderfrom@ably/chat/react. Introduced a newChatClientinstance and configured room options for message history.components/ChatBox.jsx: ReplaceduseChannelwithuseMessagesfrom@ably/chat/reactfor handling message sending and receiving. Updated the message listener and sending logic to align with the new API.Code structure improvements:
components/ChatBox.jsx: Replaced mutable DOM element variables (inputBox,messageEnd) withuseReffor better React practices. UpdateduseEffectto handle smooth scrolling usingmessageEndRef. [1] [2]Enhanced message handling:
components/ChatBox.jsx: Improved message mapping by usingmessage.idas a key when available. Updated the message data structure to usemessage.textinstead ofmessage.data.Keyboard interaction improvements:
components/ChatBox.jsx: ModifiedhandleKeyPressto prevent sending messages when the "Enter" key is pressed with the Shift key held, enabling multi-line input.Dependency updates:
package.json: Added@ably/chatversion^0.6.0and upgradedablyto version2.8.0to support the new chat functionality.