UNPKG

@cometchat/chat-uikit-react-native

Version:

Ready-to-use Chat UI Components for React Native

219 lines 5.21 kB
import { CometChatUIEventHandler, CometChatUIEvents } from "../events"; /** * CometChatTextFormatter * Abstract class for text formatter. */ export class CometChatTextFormatter { /** * The regex patterns to find specific text pattern in the user input text. */ regexPattern = /(@w+)/g; /** * List of users for suggestion item. */ SuggestionItems = []; /** * The message object in context. */ messageObject; /** * List of searched data. */ searchData = []; /** * The user in context. */ user; /** * The group in context. */ group; /** * The composer ID. */ composerId; /** * The formatter id. */ id; /** * The character to track once typed in the text input field. */ trackCharacter = "#"; /** * The user who is currently logged in. */ loggedInUser; /** * Sets the regex patterns to match. * @param regexPattern - The regex patterns. */ setRegexPatterns(regexPattern) { this.regexPattern = regexPattern; } /** * Gets the regex pattern for matching text. * @returns The regex pattern. */ getRegexPattern = () => { return this.regexPattern; }; /** * Gets the composer ID. * @returns The composer ID. */ getComposerId = () => { return this.composerId; }; /** * Gets the formatter ID. * @returns The formatter ID. */ getId = () => { return this.id; }; /** * Sets the tracking character. * @param trackCharacter - The character to track. */ setTrackingCharacter(trackCharacter) { this.trackCharacter = trackCharacter; } /** * Sets the composer ID. * @param composerId - The composer ID. */ setComposerId(composerId) { this.composerId = composerId; } /** * Sets the formatter ID. * @param id - The formatter ID. */ setId(id) { this.id = id; } /** * Search function used to call an API with searched text. * @param searchKey - The search key. */ search(searchKey) { } /** * Sets the search data. * @param data - The search data. */ setSearchData(data) { this.searchData = [...data]; CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccSuggestionData, { id: this.composerId, data: [...this.searchData], }); } /** * Sets the message object. * @param messageObject - The message object to be set. */ setMessage(messageObject) { this.messageObject = messageObject; } /** * Retrieves the message object. * @returns The current message object. */ getMessage() { return this.messageObject; } /** * Fetches the next set of data. */ fetchNext() { } /** * Sets the user. * @param user - The user to set. */ setUser(user) { this.user = user; } /** * Retrieves the user. * @returns The current user. */ getUser() { return this.user; } /** * Sets the group. * @param group - The group to set. */ setGroup(group) { this.group = group; } /** * Retrieves the group. * @returns The current group. */ getGroup() { return this.group; } /** * Retrieves the currently logged in user. * @returns The currently logged in user. */ getLoggedInUser() { return this.loggedInUser; } /** * Sets the currently logged in user. * @param loggedInUser - The user to set as currently logged in. */ setLoggedInUser(loggedInUser) { this.loggedInUser = loggedInUser; } /** * If the input text is provided, it returns the formatted text. Otherwise, it edits the text using the current cursor position. * @param inputText - The text to format. * @returns The formatted text. */ getFormattedText(inputText) { if (!inputText) { return ""; } return inputText; } /** * Handles the message before sending it. * @param message - The message to handle. * @returns The message after handling. */ handlePreMessageSend(message) { return message; } /** * Handles the message before editing it. * @param message - The message to handle. * @returns The message after handling. */ handleComposerPreview(message) { } /** * Gets the tracking character. * @returns The tracking character. */ getTrackingCharacter() { return this.trackCharacter; } /** * Retrieves the suggestion items. * @returns The current suggestion items. */ getSuggestionItems() { return this.SuggestionItems; } /** * Sets the suggestion items. * @param SuggestionItems - The suggestion items to be set. */ setSuggestionItems(SuggestionItems) { this.SuggestionItems = SuggestionItems; } } //# sourceMappingURL=CometChatTextFormatter.js.map