Skip to content

Commit 4d63d5e

Browse files
authored
Merge pull request #266 from ably/chat-update-materialisation-fields
Update chat message materialisation fields
2 parents dcec5a7 + 5ecba46 commit 4d63d5e

1 file changed

Lines changed: 40 additions & 32 deletions

File tree

textile/chat-features.textile

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,15 @@ Broadly speaking, messages are published via REST calls to the Chat HTTP API and
256256
** @(CHA-M2e)@ @[Testable]@ In global ordering, a @Message@ is considered to occur before another @Message@ if the @serial@ of the first @Message@ is before the latter when lexicographically sorted.
257257
** @(CHA-M2f)@ @[Testable]@ In global ordering, a @Message@ is considered after another @Message@ if the @serial@ of the first @Message@ is after the latter when lexicographically sorted.
258258
** @(CHA-M2g)@ @[Testable]@ Two @Messages@ are considered to be the same if they have the same @serial@, that is to say, both @Serial@ strings are identical.
259-
* @(CHA-M10)@ A @Message@ can be modified by applying a new @action@ to it, such as an update or delete. Applying an @action@ generates a new @Message@ instance with an updated @latestActionSerial@, while the original Message’s @serial@ remains unchanged.
260-
** @(CHA-M10a)@ @[Testable]@ The @latestActionSerial@ of a @Message@ is a lexicographically sortable, unique identifier for each action applied to the @Message@. Unlike @serial@, @latestActionSerial@ is mutable and is updated each time an @action@ is applied.
261-
** @(CHA-M10b)@ @[Testable]@ In global ordering, an @action@ is considered to occur before another @action@ if the @latestActionSerial@ of the first @action@ is before the latter when lexicographically sorted.
262-
** @(CHA-M10c)@ @[Testable]@ In global ordering, an @action@ is considered to occur after another @action@ if the @latestActionSerial@ of the first @action@ is after the latter when lexicographically sorted.
263-
** @(CHA-M10d)@ @[Testable]@ Two @actions@ are considered to be the same if they have the same @latestActionSerial@, that is to say, both @latestActionSerial@ strings are identical.
259+
* @(CHA-M10)@ A @Message@ can be modified by applying a new @action@ to it, such as an update or delete. Applying an @action@ must generate a new @Message@ instance with the same @serial@ and an updated @version@.
260+
** @(CHA-M10a)@ @[Testable]@ The @version@ of a @Message@ is a lexicographically sortable, unique identifier for each version of the @Message@.
261+
** @(CHA-M10b)@ This clause has been deleted.
262+
** @(CHA-M10c)@ This clause has been deleted.
263+
** @(CHA-M10d)@ This clause has been deleted.
264+
** @(CHA-M10e)@ @[Testable]@ To sort @Message@ @versions@ of the same @Message@ (instances with the same @serial@) in global order, sort @Message@ instances lexicographically by their @version@ property.
265+
*** @(CHA-M10e1)@ @[Testable]@ Two @Message@ instances of the same @serial@ are considered the same version if they have the same @version@ property.
266+
*** @(CHA-M10e2)@ @[Testable]@ Among @Message@ instances of the same @serial@, the one with a lexicographically higher @version@ is newer.
267+
*** @(CHA-M10e3)@ @[Testable]@ Among @Message@ instances of the same @serial@, the one with a lexicographically lower @version@ is older.
264268
* @(CHA-M3)@ A client must be able to send a message to a room.
265269
** @(CHA-M3f)@ @[Testable]@ A client may send a message via the Chat REST API.
266270
** @(CHA-M3a)@ @[Testable]@ When a message is sent successfully via the Chat REST API, the caller shall receive a struct representing the "@Message@":#chat-structs-message in response, as if it were received via Realtime event.
@@ -557,16 +561,16 @@ h4(#rest-sending-messages-request-v2). Corresponding Realtime Event V2
557561
}
558562
}
559563
},
560-
"timestamp": "1726232498871",
564+
"timestamp": 1726232498871,
565+
"createdAt": 1726232498871,
561566
"extras": {
562567
"headers": {
563568
"baz": "qux"
564569
},
565570
},
566-
"serial": "01726585978590-001@abcdefghij:001"
567-
"action": "message.create"
568-
"updatedAt": undefined
569-
"updateSerial": undefined
571+
"serial": "01726585978590-001@abcdefghij:001",
572+
"action": "message.create",
573+
"version": "01726585978590-001@abcdefghij:001",
570574
"operation": {}
571575
}
572576
</pre>
@@ -606,13 +610,11 @@ The response body is as follows.
606610

607611
<pre>
608612
{
609-
"serial": "01826232498871-001@abcdefghij:001",
610-
"updatedAt": 1726232498871
613+
"version": "01726585978590-001@abcdefghij:001",
614+
"timestamp": 1726585978590
611615
}
612616
</pre>
613617

614-
The serial in the body corresponds to the @updateSerial@ of the corresponding realtime event.
615-
616618
h4(#rest-updating-messages-request). Corresponding Realtime Event
617619

618620
<pre>
@@ -627,22 +629,22 @@ h4(#rest-updating-messages-request). Corresponding Realtime Event
627629
}
628630
}
629631
},
630-
"timestamp": "1726232498871",
632+
"createdAt": 1726232498871,
633+
"timestamp": 1726585978590,
631634
"extras": {
632635
"headers": {
633636
"baz": "qux"
634-
},
637+
}
635638
}
636-
"serial": "01726585978590-001@abcdefghij:001",
639+
"serial": "01726232498871-001@abcdefghij:001",
640+
"version": "01726585978590-001@abcdefghij:001"
637641
"action": "message.update"
638-
"updatedAt": 1826232498871
639-
"updateSerial": "01826232498871-001@abcdefghij:001"
640642
"operation": {
641643
"clientId": "who-performed-the-action",
642644
"description": "why-the-action-was-performed"
643645
"metadata": {
644646
"foo": "bar"
645-
},
647+
}
646648
}
647649
}
648650
</pre>
@@ -671,13 +673,11 @@ The response body is as follows.
671673

672674
<pre>
673675
{
674-
"serial": "01826232498871-001@abcdefghij:001",
675-
"deletedAt": 1826232498871
676+
"version": "01826232498871-001@abcdefghij:001",
677+
"timestamp": 1826232498871
676678
}
677679
</pre>
678680

679-
The serial in the body corresponds to the @updateSerial@ of the corresponding realtime event.
680-
681681
h4(#rest-deleting-messages-request). Corresponding Realtime Event
682682

683683
<pre>
@@ -700,8 +700,9 @@ h4(#rest-deleting-messages-request). Corresponding Realtime Event
700700
}
701701
"serial": "01726585978590-001@abcdefghij:001",
702702
"action": "message.deleted"
703-
"updatedAt": 1826232498871
704-
"updateSerial": "01826232498871-001@abcdefghij:001",
703+
"timestamp": 1826232498871
704+
"createdAt": 1726585978590,
705+
"version": "01826232498871-001@abcdefghij:001",
705706
"operation": {
706707
"clientId": "who-performed-the-action",
707708
"description": "why-the-action-was-performed"
@@ -841,11 +842,10 @@ h4(#chat-structs-message-v2). Messages V2
841842
"headers": {
842843
"baz": "qux"
843844
}
844-
"latestAction": "message.created",
845-
"latestActionSerial": "01726585978590-001@abcdefghij:001",
846-
"deletedAt": DateTime() | undefined,
847-
"updatedAt": DateTime() | undefined,
848-
"latestActionDetails": {
845+
"action": "message.created",
846+
"version": "01726585978590-001@abcdefghij:001",
847+
"timestamp": DateTime(),
848+
"operation": {
849849
"clientId": "who-performed-the-action",
850850
"description": "why-the-action-was-performed"
851851
"metadata": {
@@ -857,9 +857,17 @@ h4(#chat-structs-message-v2). Messages V2
857857
}
858858
</pre>
859859

860+
There are getters provided in the @Message@ object to provide easy access to updated/deleted information:
861+
* @isUpdated@ returns @true@ if the message is updated
862+
* @isDeleted@ returns @true@ if the message is deleted
863+
* @updatedBy@ returns the clientId from @operation.clientId@ if the message is updated, @undefined@ otherwise
864+
* @deletedBy@ returns the clientId from @operation.clientId@ if the message is deleted, @undefined@ otherwise
865+
* @updatedAt@ returns the @timestamp@ from the operation if the message is updated, @undefined@ otherwise
866+
* @deletedAt@ returns the @timestamp@ from the operation if the message is deleted, @undefined@ otherwise
867+
860868
Determining the global order of messages may be achieved by lexicographically comparing the serials. See @CHA-M2@ for more information.
861869

862-
Determining the global order of message actions may be achieved by lexicographically comparing the @latestActionSerial@. See @CHA-M10@ for more information.
870+
Determining the global order of message versions may be achieved by lexicographically comparing the @version@. See @CHA-M10@ for more information.
863871

864872
h3(#chat-structs-ephemeral-reactions). Ephemeral Room Reactions
865873

0 commit comments

Comments
 (0)