Skip to content

Commit

Permalink
MessageAction enum changes
Browse files Browse the repository at this point in the history
as agreed in
ably/sdk-api-reference#44 (comment)
and ably/realtime#6810 , plus addition of
summary
  • Loading branch information
SimonWoolf committed Jan 7, 2025
1 parent 98d006d commit cd1fc99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
23 changes: 7 additions & 16 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2387,10 +2387,6 @@ export interface Operation {
* The namespace containing the different types of message actions.
*/
declare namespace MessageActions {
/**
* Message action has not been set.
*/
type MESSAGE_UNSET = 'message.unset';
/**
* Message action for a newly created message.
*/
Expand All @@ -2403,31 +2399,26 @@ declare namespace MessageActions {
* Message action for a deleted message.
*/
type MESSAGE_DELETE = 'message.delete';
/**
* Message action for a newly created annotation.
*/
type ANNOTATION_CREATE = 'annotation.create';
/**
* Message action for a deleted annotation.
*/
type ANNOTATION_DELETE = 'annotation.delete';
/**
* Message action for a meta-message that contains channel occupancy information.
*/
type META_OCCUPANCY = 'meta.occupancy';
/**
* Message action for a message containing the latest rolled-up summary of annotations
* that have been made to this message.
*/
type MESSAGE_SUMMARY = 'message.summary';
}

/**
* Describes the possible action types used on an {@link Message}.
*/
export type MessageAction =
| MessageActions.MESSAGE_UNSET
| MessageActions.MESSAGE_CREATE
| MessageActions.MESSAGE_UPDATE
| MessageActions.MESSAGE_DELETE
| MessageActions.ANNOTATION_CREATE
| MessageActions.ANNOTATION_DELETE
| MessageActions.META_OCCUPANCY;
| MessageActions.META_OCCUPANCY
| MessageActions.MESSAGE_SUMMARY;

/**
* A message received from Ably.
Expand Down
4 changes: 1 addition & 3 deletions src/common/lib/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import type RealtimeChannel from '../client/realtimechannel';
type Channel = RestChannel | RealtimeChannel;

const MessageActionArray: API.MessageAction[] = [
'message.unset',
'message.create',
'message.update',
'message.delete',
'annotation.create',
'annotation.delete',
'meta.occupancy',
'message.summary'
];

const MessageActionMap = new Map<API.MessageAction, number>(MessageActionArray.map((action, index) => [action, index]));
Expand Down
6 changes: 3 additions & 3 deletions test/realtime/message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,15 +1279,15 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
const testCases = [
{
description: 'should stringify the numeric action',
action: 1,
action: 0,
expectedString: '[Message; action=message.create]',
expectedJSON: { action: 1 },
expectedJSON: { action: 0 },
},
{
description: 'should accept an already stringified action',
action: 'message.update',
expectedString: '[Message; action=message.update]',
expectedJSON: { action: 2 },
expectedJSON: { action: 1 },
},
{
description: 'should handle no action provided',
Expand Down

0 comments on commit cd1fc99

Please sign in to comment.