xmtp / xmtp-web

XMTP web SDKs and examples, including a React SDK and quickstart example app

Home Page:https://xmtp.github.io/xmtp-web/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: message.sent and message.sentAt

fabriguespe opened this issue · comments

Describe the bug

Messages loaded using display date with sentAt field

const { messages, isLoading } = useMessages(conversation);

CleanShot 2024-02-29 at 13 38 20@2x

While messages loaded via a stream show the date with the sent field

  const onMessage = useCallback(
    (message) => {
      console.log("onMessage", message.content);
      setStreamedMessages((prev) => [...prev, message]);
    },
    [streamedMessages]
  );

CleanShot 2024-02-29 at 13 38 33@2x

Expected behavior

No response

Steps to reproduce the bug

No response

thanks for the report! yes, the onMessage callback references the DecodedMessage in its callback rather than the CachedMessage.

this is intentional for developers who want to access the original DecodedMessage. it's easy to convert to a cached message with the toCachedMessage export from the React SDK.

Thks! adding the code for reference

// callback to handle incoming messages
  const onMessage = useCallback(
    (message: DecodedMessage) => {
      // Convert into cached message format
      const cached = toCachedMessage(message);
      //Add it to the array
      setStreamedMessages((prev) => [...prev, cached]);
    },
    [streamedMessages],
  );