Skip to main content

Introduction

The ShortcutFormatter class extends the CometChatTextFormatter class to provide a mechanism for handling shortcuts within messages. This guide will walk you through the process of using ShortcutFormatter to implement shortcut extensions in your CometChat application.

Setup

  1. Create the ShortcutFormatter Class: Define the ShortcutFormatter class by extending the CometChatTextFormatter class.
  1. Init: Initialize the messageShortcuts map and shortcuts list in the init().
  1. Prepare Shortcuts: Implement the prepareShortcuts() method to fetch shortcuts from the server using CometChat extension.
  1. Override onChange Method: Override the onChange() method to search for shortcuts based on the entered query.
  1. Handle Scroll to Bottom: Override the onScrollToBottom() method if needed.
  1. Additional Base Class Methods: The CometChatTextFormatter base class provides additional methods you can override for advanced customization:

Usage

The widgets CometChatConversations, CometChatMessageComposer and CometChatMessageList have a property called textFormatters which accepts a list of CometChatTextFormatter to format the text. The code shared below textFormatters consisting of the above created Shortcuts formatter being passed down to CometChatMessageComposer from CometChatConversationsWithMessages with help of configurations.

Example

Here is the complete example for reference: