Skip to content

Commit 1c12177

Browse files
DOC-2728: Documentation Enhancement: Comments callback. (#3860)
* DOC-2728: Documentation Enhancement: Comments callback. * Update modules/ROOT/pages/comments-callback-mode.adoc Co-authored-by: Mitchell Crompton <[email protected]> * Update modules/ROOT/partials/commands/comments-cmds.adoc Co-authored-by: Mitchell Crompton <[email protected]> * DOC-2728: Update tinycomments_reply callback example and demo code. * Update modules/ROOT/pages/comments-callback-mode.adoc --------- Co-authored-by: Mitchell Crompton <[email protected]>
1 parent 9abba72 commit 1c12177

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

modules/ROOT/examples/live-demos/comments-callback/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ const tinycomments_create = (req, done, fail) => {
6969
};
7070

7171
const tinycomments_reply = (req, done) => {
72-
const replyUid = 'annotation-' + randomString();
72+
const commentUid = 'annotation-' + randomString();
7373
conversationDb[req.conversationUid].comments.push({
74-
uid: replyUid,
74+
uid: commentUid,
7575
author: user_id,
7676
authorName: 'James Wilson',
7777
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_james-wilson_128_52f19412.jpg',
7878
content: req.content,
7979
createdAt: req.createdAt,
8080
modifiedAt: req.createdAt
8181
});
82-
setTimeout(() => done({ commentUid: replyUid }), fakeDelay);
82+
setTimeout(() => done({ commentUid: commentUid }), fakeDelay);
8383
};
8484

8585
const tinycomments_delete = (req, done) => {

modules/ROOT/pages/comments-callback-mode.adoc

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,36 @@
66
:plugincode: comments
77
:commentsMode: callback
88

9-
*Callback mode* is the default mode for the {pluginname} plugin. In the callback mode, callback functions are required to save user comments on a server. The {pluginname} functions (create, reply, edit, delete comment, delete all conversations, resolve, lookup, and fetch conversations) are configured differently depending upon the server-side storage configuration.
9+
*Callback mode* is the default mode for the {pluginname} plugin. In callback mode, callback functions are required to save user comments on a server. The {pluginname} functions (create, reply, edit, delete comment, delete all conversations, resolve, lookup, and fetch conversations) are configured differently depending upon the server-side storage configuration.
10+
11+
[NOTE]
12+
====
13+
Callback mode provides the most flexibility for integrating with custom backend systems. All comment operations are handled through custom callback functions that communicate with your server.
14+
====
1015

1116
== How the {pluginname} plugin works in callback mode
1217

13-
All options accept functions incorporating `+done+` and `+fail+` callbacks as parameters. The function return type is not important, but all functions must call exactly one of these two callbacks: `+fail+` or `+done+`.
18+
All callback functions accept three parameters: a request object (or array for `+tinycomments_fetch+`), a `+done+` callback, and a `+fail+` callback. The function return type is not important, but all functions must call exactly one of these two callbacks: `+fail+` or `+done+`.
1419

15-
* The `+fail+` callback takes either a string or a JavaScript Error type.
16-
* The `+done+` callback takes an argument specific to each function.
20+
* The `+fail+` callback takes an argument specific to each function.
21+
* The `+done+` callback takes an argument specific to each function to indicate successful completion.
1722

18-
Most functions (create, reply, and edit) require an +id+ identifying the current author. This can be provided directly within the callbacks or dynamically via the `+tinycomments_fetch_author_info+` option.
23+
Most functions (create, reply, and edit) require an `+id+` identifying the current author. This can be provided directly within the callbacks or dynamically via the `+tinycomments_fetch_author_info+` option.
1924

2025
[NOTE]
21-
**Current author**: By default, the **Comments** plugin does not know the name of the current user. To display the correct author information when creating a new conversation, integrators can now use the `+tinycomments_fetch_author_info+` option to supply author details dynamically through a callback.
26+
====
27+
**Current author**: By default, the **Comments** plugin does not know the name of the current user. To display the correct author information when creating a new conversation, integrators can use the `+tinycomments_fetch_author_info+` option to supply author details dynamically through a callback.
28+
29+
**Author display names**: The `+authorName+` field is optional in comment objects. If not provided, the plugin will default to using the `+author+` field value.
30+
====
31+
32+
=== Initial conversation loading
33+
34+
During the initial editor load, the {pluginname} uses the `+tinycomments_fetch+` callback to retrieve existing conversations in the document. If not configured, the {pluginname} will fallback to `+tinycomments_lookup+`.
2235

23-
During the initial editor load, the {pluginname} uses `+tinycomments_fetch+` callback to retrieve the existing conversations in the document. If not configured, the {pluginname} will fallback to `+tinycomments_lookup+`.
36+
=== Comment interaction flow
2437

25-
When a user adds a comment or a reply, the {pluginname} plugin uses the `+tinycomments_lookup+` callback to retrieve the selected conversation.
38+
When a user adds a comment or a reply, the {pluginname} plugin uses the `+tinycomments_lookup+` callback to retrieve the selected conversation. This ensures that the latest conversation data is always displayed to users.
2639

2740
[[comments-callback-live-demo]]
2841
== Interactive example
@@ -31,17 +44,17 @@ liveDemo::comments-callback[]
3144

3245
== Options
3346

34-
=== Required options
47+
=== Required callback functions
3548

36-
When using callback mode, the {pluginname} plugin requires callback functions for the following options:
49+
When using callback mode, the {pluginname} plugin requires callback functions for the following operations:
3750

38-
* xref:tinycomments_create[`+tinycomments_create+`]
39-
* xref:tinycomments_reply[`+tinycomments_reply+`]
40-
* xref:tinycomments_edit_comment[`+tinycomments_edit_comment+`]
41-
* xref:tinycomments_delete_comment[`+tinycomments_delete_comment+`]
42-
* xref:tinycomments_delete[`+tinycomments_delete+`]
43-
* xref:tinycomments_delete_all[`+tinycomments_delete_all+`]
44-
* xref:tinycomments_lookup[`+tinycomments_lookup+`]
51+
* xref:tinycomments_create[`+tinycomments_create+`] - Creates new comment conversations
52+
* xref:tinycomments_reply[`+tinycomments_reply+`] - Adds replies to existing conversations
53+
* xref:tinycomments_edit_comment[`+tinycomments_edit_comment+`] - Edits existing comments
54+
* xref:tinycomments_delete_comment[`+tinycomments_delete_comment+`] - Deletes individual comments
55+
* xref:tinycomments_delete[`+tinycomments_delete+`] - Deletes entire conversation threads
56+
* xref:tinycomments_delete_all[`+tinycomments_delete_all+`] - Deletes all conversations
57+
* xref:tinycomments_lookup[`+tinycomments_lookup+`] - Retrieves specific conversations
4558

4659
include::partial$configuration/tinycomments_create.adoc[leveloffset=+1]
4760

@@ -57,11 +70,8 @@ include::partial$configuration/tinycomments_delete_all.adoc[leveloffset=+1]
5770

5871
include::partial$configuration/tinycomments_lookup.adoc[leveloffset=+1]
5972

60-
== Optional options
73+
=== Optional callback functions
6174

62-
* xref:tinycomments_resolve[`+tinycomments_resolve+`]
63-
* xref:tinycomments_fetch[`+tinycomments_fetch+`]
64-
* xref:tinycomments_fetch_author_info[`+tinycomments_fetch_author_info+`]
6575

6676
include::partial$configuration/tinycomments_resolve.adoc[leveloffset=+1]
6777

modules/ROOT/partials/commands/comments-cmds.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
|Command |Description
44
|tc-delete-conversation-at-cursor |Attempts to delete the comment at the current cursor position. A confirmation dialog will be shown prior to deletion.
55
|tc-try-delete-all-conversations |Attempts to delete all comments in the editor. A confirmation dialog will be shown prior to deletion.
6+
|ToggleSidebar |Toggles the specified sidebar open or closed. When used with the 'showcomments' parameter, this opens the comments sidebar.
67
|===
78

89
.Examples
910
[source,js]
1011
----
1112
tinymce.activeEditor.execCommand('tc-delete-conversation-at-cursor');
1213
tinymce.activeEditor.execCommand('tc-try-delete-all-conversations');
14+
tinymce.activeEditor.execCommand('ToggleSidebar', false, 'showcomments');
1315
----

modules/ROOT/partials/configuration/tinycomments_reply.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ const reply_comment = (ref, done, fail) => {
4343
return response.json();
4444
})
4545
.then((ref2) => {
46-
let commentUid = ref2.commentUid;
46+
const commentUid = ref2.commentUid;
4747
done({
48-
commentUid: replyUid,
48+
commentUid: commentUid,
4949
author: currentUser.id,
5050
authorName: currentUser.fullName
5151
});

modules/ROOT/partials/plugins/comments-open-sidebar.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
== Show the {pluginname} sidebar when {productname} loads
1+
== Show sidebar on editor load
22

33
The xref:customsidebar.adoc#sidebar_show[`sidebar_show`] option can be used to show the {pluginname} sidebar when the editor is loaded.
44

0 commit comments

Comments
 (0)