Message

The SDK displays messages as stream-chat stores them: every message (in ChannelService observables, component inputs and template contexts) is a LocalMessage, the message type of stream-chat (the Stream message format with a status field). The SDK doesn't add any fields to the message, and it emits the same objects that stream-chat holds in the channel's message paginator (channel.messagePaginator).

StreamMessage (the SDK's own message type in v7) was removed in v8. The data it added to the message is available elsewhere:

v7 StreamMessage field v8
readBy ReadStatusContext.readBy in a custom read status template, or MessageComponent.readBy. Elsewhere getReadBy(message, channel), or watchReadBy(message, channel, callback) (see Read receipts)
translation, quoted_message.translation MessageTextContext.translation in a custom message text template. Elsewhere getMessageTranslation(message, language, currentUserId) (see Translations)
errorStatusCode message.error?.status (see Failed messages)

Date fields

The date fields of messages use the format of stream-chat: TimestampNS (unix nanoseconds, a branded number).

Name Type
created_at TimestampNS
updated_at TimestampNS
deleted_at TimestampNS | undefined
pinned_at TimestampNS | undefined
pin_expires TimestampNS | undefined
message_text_updated_at TimestampNS | undefined

Optional date fields are undefined (never null) if they aren't set. To get a Date, use the nsToDate helper exported by stream-chat (and dateToNs for the other direction). Don't pass a TimestampNS to new Date() or Angular's date pipe: both treat numbers as milliseconds.

Custom fields

Custom message fields are stored under message.custom (for example message.custom.priority). To type them, see custom types.

Moderation

The moderation result of a message is available in message.moderation (for example, message.moderation?.action is 'bounce' for bounced and 'remove' for blocked messages).

Failed messages

Messages are sent, edited and deleted with the message operations of stream-chat (channel.messageOperations). If sending or editing a message fails, the message has the failed status, and message.error is the error of the request: a StreamAPIError for API errors (its status is the HTTP status code), or the original error (for example a network error). The Message component lets the user retry failed messages, except if the request failed with 403 (the user isn't allowed to send or edit the message).

Read receipts

The Message component displays read receipts for the last message sent by the current user. If you display read receipts yourself, use the getReadBy and watchReadBy helpers exported by the SDK. They read the read state of stream-chat (channel.messageReceiptsTracker), and leave out the author of the message:

import { getReadBy, watchReadBy } from "stream-chat-angular";

// The users who read the message
const readBy = getReadBy(message, channel);

// Get notified when the read state changes
const stopWatching = watchReadBy(message, channel, (readBy) => {
  console.log(readBy.map((u) => u.name ?? u.id));
});
// Call it when you no longer need the updates (for example in ngOnDestroy)
stopWatching();

Translations

If the auto translation of messages is enabled, the translations are in message.i18n. The SDK displays them in the language of the current user (user.language), or the auto_translation_language of the channel if the user has no language. ChannelService.activeChannelTranslationLanguage$ emits this language for the active channel. The messages of the current user aren't translated.

import { getMessageTranslation } from "stream-chat-angular";

this.channelService.activeChannelTranslationLanguage$.subscribe((language) => {
  this.translation = getMessageTranslation(
    this.message,
    language,
    this.chatClientService.chatClient.user?.id,
  );
});

Example

Reading the messages of the active channel:

import { nsToDate } from "stream-chat";

this.channelService.activeChannelMessages$.subscribe((messages) => {
  const message = messages[messages.length - 1];
  if (message) {
    console.log(
      nsToDate(message.created_at).toISOString(),
      message.status,
      message.error?.status,
      message.custom,
      message.moderation?.action,
    );
  }
});