diff --git a/ably.d.ts b/ably.d.ts index c02d62fa4..d6d597650 100644 --- a/ably.d.ts +++ b/ably.d.ts @@ -2432,7 +2432,7 @@ export type MessageAction = /** * A message received from Ably. */ -export type InboundMessage = Message & Required>; +export type InboundMessage = Message & Required>; /** * Static utilities related to messages. diff --git a/src/common/lib/client/realtimechannel.ts b/src/common/lib/client/realtimechannel.ts index f3cd2bd86..24ffe62cf 100644 --- a/src/common/lib/client/realtimechannel.ts +++ b/src/common/lib/client/realtimechannel.ts @@ -8,13 +8,13 @@ import * as Utils from '../util/utils'; import Logger from '../util/logger'; import RealtimePresence from './realtimepresence'; import Message, { + fromValues as messageFromValues, + fromValuesArray as messagesFromValuesArray, encodeArray as encodeMessagesArray, decode as decodeMessage, getMessagesSize, CipherOptions, EncodingDecodingContext, - messageFromValuesArrayWithAction, - messageFromValuesWithAction, } from '../types/message'; import ChannelStateChange from './channelstatechange'; import ErrorInfo, { PartialErrorInfo } from '../types/errorinfo'; @@ -234,9 +234,8 @@ class RealtimeChannel extends EventEmitter { throw this.connectionManager.getError(); } if (argCount == 1) { - // setting the action to `message_create` because this is a standard publish - if (Utils.isObject(messages)) messages = [messageFromValuesWithAction(messages, 'message_create')]; - else if (Array.isArray(messages)) messages = messageFromValuesArrayWithAction(messages, 'message_create'); + if (Utils.isObject(messages)) messages = [messageFromValues(messages)]; + else if (Array.isArray(messages)) messages = messagesFromValuesArray(messages); else throw new ErrorInfo( 'The single-argument form of publish() expects a message object or an array of message objects', @@ -244,7 +243,7 @@ class RealtimeChannel extends EventEmitter { 400, ); } else { - messages = [messageFromValuesWithAction({ name: args[0], data: args[1] }, 'message_create')]; + messages = [messageFromValues({ name: args[0], data: args[1] })]; } const maxMessageSize = this.client.options.maxMessageSize; await encodeMessagesArray(messages, this.channelOptions as CipherOptions); diff --git a/src/common/lib/client/restchannel.ts b/src/common/lib/client/restchannel.ts index 31f45d1ee..e27133c6e 100644 --- a/src/common/lib/client/restchannel.ts +++ b/src/common/lib/client/restchannel.ts @@ -6,8 +6,8 @@ import Message, { serialize as serializeMessage, getMessagesSize, CipherOptions, - messageFromValuesWithAction, - messageFromValuesArrayWithAction, + fromValues as messageFromValues, + fromValuesArray as messagesFromValuesArray, } from '../types/message'; import ErrorInfo from '../types/errorinfo'; import { PaginatedResult } from './paginatedresource'; @@ -74,13 +74,13 @@ class RestChannel { if (typeof first === 'string' || first === null) { /* (name, data, ...) */ - messages = [messageFromValuesWithAction({ name: first, data: second }, 'message_create')]; + messages = [messageFromValues({ name: first, data: second })]; params = args[2]; } else if (Utils.isObject(first)) { - messages = [messageFromValuesWithAction(first, 'message_create')]; + messages = [messageFromValues(first)]; params = args[1]; } else if (Array.isArray(first)) { - messages = messageFromValuesArrayWithAction(first, 'message_create'); + messages = messagesFromValuesArray(first); params = args[1]; } else { throw new ErrorInfo( diff --git a/src/common/lib/types/message.ts b/src/common/lib/types/message.ts index f62622c27..ee3324f1e 100644 --- a/src/common/lib/types/message.ts +++ b/src/common/lib/types/message.ts @@ -294,33 +294,6 @@ export async function fromResponseBody( return body; } -/** - * This is used to return a new message with a given action type set. - * @param values - This is a message-like object, with the values to be set on the new message object. - * @param action - This is the action type that will be applied to the message - * @returns {Message} - This is a new message, with the provided action type set. - */ -export function messageFromValuesWithAction( - values: Message | Record, - action: API.MessageAction, -): Message { - return fromValues({ ...values, action: action }); -} - -/** - * This is used to return an array of new messages, each set with the provided action type. - * It will apply the same action type to ALL messages. - * @param values - This is the array of message-like objects, with the values to be set on the new messages. - * @param action - This is the action type, applied to each message in the array. - * @returns {Message[]} - This is an array of new messages, each with the provided action type set. - */ -export function messageFromValuesArrayWithAction(values: unknown[], action: API.MessageAction): Message[] { - const count = values.length, - result = new Array(count); - for (let i = 0; i < count; i++) result[i] = messageFromValuesWithAction(values[i] as Record, action); - return result; -} - export function fromValues( values: Message | Record, options?: { stringifyAction?: boolean },