import { ChatMessageAction, ChatMessageEvent, MessageReactionSummaryEvent } from './events.js'; import { Headers } from './headers.js'; import { Metadata } from './metadata.js'; import { OperationMetadata } from './operation-metadata.js'; import * as Ably from '@ably/pubsub-core'; /** * {@link Headers} type for chat messages. */ export type MessageHeaders = Headers; /** * {@link Metadata} type for chat messages. */ export type MessageMetadata = Metadata; /** * {@link OperationMetadata} type for a chat message. Contains information about an update or deletion operation. */ export type MessageOperationMetadata = OperationMetadata; /** * Represents the detail of a message deletion or update. */ export interface MessageVersion { /** * A unique identifier for the latest version of this message. */ serial: string; /** * The timestamp at which this version was updated, deleted, or created. */ timestamp: Date; /** * The optional clientId of the user who performed an update or deletion. */ clientId?: string; /** * The optional description for an update or deletion. */ description?: string; /** * The optional metadata associated with an update or deletion. */ metadata?: MessageOperationMetadata; } /** * Represents a single message in a chat room. */ export interface Message { /** * The unique identifier of the message. */ readonly serial: string; /** * The clientId of the user who created the message. */ readonly clientId: string; /** * The text of the message. */ readonly text: string; /** * The timestamp at which the message was created. */ readonly timestamp: Date; /** * The metadata of a chat message. Allows for attaching extra info to a message, * which can be used for various features such as animations, effects, or simply * to link it to other resources such as images, relative points in time, etc. * * Metadata is part of the Ably Pub/sub message content and is not read by Ably. * * This value is always set. If there is no metadata, this is an empty object. * * Do not use metadata for authoritative information. There is no server-side * validation. When reading the metadata treat it like user input. * * If you need per-room authoritative information on messages, consider using * {@link userClaim} via JWT user claims instead. */ readonly metadata: MessageMetadata; /** * The headers of a chat message. Headers enable attaching extra info to a message, * which can be used for various features such as linking to a relative point in * time of a livestream video or flagging this message as important or pinned. * * Headers are part of the Ably realtime message extras.headers and they can be used * for Filtered Subscriptions and similar. * * This value is always set. If there are no headers, this is an empty object. * * Do not use the headers for authoritative information. There is no server-side * validation. When reading the headers, treat them like user input. * * If you need per-room authoritative information on messages, consider using * {@link userClaim} via JWT user claims instead. */ readonly headers: MessageHeaders; /** * The user claim attached to this message by the server. This is set automatically * by the Ably server when a JWT contains a matching `ably.room.` claim. * * This value is only present if the publishing user's token contained a claim * for the room in which this message was published. */ readonly userClaim?: string; /** * The action type of the message. This can be used to determine if the message was created, updated, or deleted. */ readonly action: ChatMessageAction; /** * Information about the latest version of this message. */ readonly version: MessageVersion; /** * The reactions summary for this message. */ readonly reactions: MessageReactionSummary; /** * Creates a new message instance with the event applied. * * **NOTE**: This method will not replace the message reactions if the event is of type `Message`. * @param event The event to be applied to the returned message. * @throws An {@link Ably.ErrorInfo} if the event is for a different message. * @throws An {@link Ably.ErrorInfo} if the event is a {@link ChatMessageEventType.Created}. * @returns A new message instance with the event applied. If the event is a no-op, such * as an event for an old version, the same message is returned (not a copy). */ with(event: Message | ChatMessageEvent | MessageReactionSummaryEvent): Message; /** * Creates a copy of the message with fields replaced per the parameters. * @param params The parameters to replace in the message. * @returns The message copy. */ copy(params?: MessageCopyParams): Message; } /** * Parameters for copying a message. */ export interface MessageCopyParams { /** * The text of the copied message. */ text?: string; /** * The metadata of the copied message. */ metadata?: MessageMetadata; /** * The headers of the copied message. */ headers?: MessageHeaders; } /** * Represents a summary of all reactions on a message. */ export interface MessageReactionSummary { /** * Map of reaction to the summary (total and clients) for reactions of type {@link MessageReactionType.Unique}. */ unique: Ably.SummaryUniqueValues; /** * Map of reaction to the summary (total and clients) for reactions of type {@link MessageReactionType.Distinct}. */ distinct: Ably.SummaryDistinctValues; /** * Map of reaction to the summary (total and clients) for reactions of type {@link MessageReactionType.Multiple}. */ multiple: Ably.SummaryMultipleValues; } /** * Parameters for creating a new DefaultMessage instance. */ export interface DefaultMessageParams { serial: string; clientId: string; text: string; metadata: MessageMetadata; headers: MessageHeaders; userClaim?: string; action: ChatMessageAction; version: MessageVersion; timestamp: Date; reactions: MessageReactionSummary; } /** * An implementation of the Message interface for chat messages. * * Allows for comparison of messages based on their serials. */ export declare class DefaultMessage implements Message { readonly serial: string; readonly clientId: string; readonly text: string; readonly metadata: MessageMetadata; readonly headers: MessageHeaders; readonly userClaim?: string; readonly action: ChatMessageAction; readonly version: MessageVersion; readonly timestamp: Date; readonly reactions: MessageReactionSummary; constructor({ serial, clientId, text, metadata, headers, userClaim, action, version, timestamp, reactions, }: DefaultMessageParams); with(event: Message | ChatMessageEvent | MessageReactionSummaryEvent): Message; /** * Get the latest message version, based on the event. * If "this" is the latest version, return "this", otherwise clone the message and apply the reactions. * @param message The message to get the latest version of * @returns The latest message version */ private _getLatestMessageVersion; private static _clone; copy(params?: MessageCopyParams): Message; } /** * Creates an empty MessageReactionSummary object with empty unique and distinct reaction collections. * @returns An empty MessageReactionSummary object. */ export declare const emptyMessageReactions: () => MessageReactionSummary;