JavaScript/jQuery Chat - Editing Messages with Functions

You can set the editing.allowDeleting and allowUpdating options to a Boolean value to toggle editing functionality.

Alternatively, you can customize conditions for when users can edit messages. For example, the following code snippet prevents editing or deleting messages that are more than five minutes old:

index.js
  • const restrictEditing = ({ message }) => {
  • if (Date.now() - message.timestamp < 5 * 60 * 1000) {
  • return true;
  • } else {
  • return false;
  • }
  • };
  •  
  • $('#chat').dxChat({
  • // ...
  • editing: {
  • allowUpdating: restrictEditing,
  • allowDeleting: restrictEditing,
  • },
  • });
NOTE
A Boolean value must be returned if allowDeleting or allowUpdating are used as functions.