From 985732ac2a68cf48cbb1c915888ac414c6dc4945 Mon Sep 17 00:00:00 2001 From: AdityaSingh-02 Date: Sat, 26 Aug 2023 13:29:46 +0530 Subject: [PATCH] Final Commit v6.3.2 --- .tours/3---how-a-message-is-sent.tour | 152 +++++++++++----------- .tours/4---how-to-create-an-endpoint.tour | 2 +- .tours/5---how-to-create-a-db-model.tour | 2 +- 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.tours/3---how-a-message-is-sent.tour b/.tours/3---how-a-message-is-sent.tour index 6553a97e5a82..25fa618a3104 100644 --- a/.tours/3---how-a-message-is-sent.tour +++ b/.tours/3---how-a-message-is-sent.tour @@ -1,76 +1,76 @@ -{ - "$schema": "https://aka.ms/codetour-schema", - "title": "3 - How a Message is sent (The Backend)", - "steps": [ - { - "file": "apps/meteor/client/lib/chats/ChatAPI.ts", - "description": "## The ChatAPI\n\n- **ComposerAPI:** This interface defines methods and properties related to the message composer functionality, such as managing text input, handling selection, wrapping text, inserting text, clearing, focusing, and more. It also includes properties for managing quoted messages, editing mode, recording mode, and microphone permissions.\n\n- **DataAPI:** This interface defines methods for interacting with message and room data. It includes functions for composing and managing messages, finding and getting messages by ID, finding the last and previous own messages, managing drafts, accessing room and subscription information, marking rooms as read, and more.\n\n- **UploadsAPI:** This interface defines methods and properties for managing file uploads. It includes functions for retrieving the list of uploads, subscribing to changes, canceling and wiping failed uploads, and sending files.\n\n- **ChatAPI:** This interface represents the main API object for the Rocket Chat client. It includes properties for user-related information, such as the user ID. It also provides access to the composer, data, uploads, and message editing functionality. Additionally, it exposes methods for performing actions like starting/stopping typing, opening/closing user cards and emoji pickers, and handling various message-related flows (uploading files, sending messages, processing slash commands, editing messages, setting reactions, etc.).", - "line": 106 - }, - { - "file": "apps/meteor/client/lib/chats/ChatAPI.ts", - "description": "## ChatAPI sendMessage\n\n#### Among many properties and functions present in ChatAPI here we have sendMessage.\n\n#### Note that sendMessage is *readonly* implying that it cannot be modified after initialization. Hence Implementing ChatAPI in any class would make it modification possible.\n\n```\n readonly sendMessage: ({ text, tshow }: { text: string; tshow?: boolean }) => Promise;\n```", - "line": 146 - }, - { - "file": "apps/meteor/app/ui/client/lib/ChatMessages.ts", - "description": "## Implementation of ChatAPI\n\n#### Here *class ChatMessages implements ChatAPI* and above it we have a *type DeepWritable* which removes readonly property from ChatAPI and This allows us to modify those properties\n", - "line": 27 - }, - { - "file": "apps/meteor/app/ui/client/lib/ChatMessages.ts", - "description": "## SendMessage -\n\n### Above we have a constructor and here in this.flows we are calling *sendMessage.bind(this,this)* The sendMessage is a function which further makes the meteor call for sending Message Data.", - "line": 160 - }, - { - "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", - "description": "## sendMessage function\n\n### The sendMessage recieves text: string and tshow: boolean properties and returns a Promise, And note that here we are utilizing ChatAPI again.\n\n- Within the sendMessage implementation, there are several checks and actions performed based on the provided parameters and the current state of the chat. These checks ensure that the message is valid and that the necessary actions are taken. The implementation of sendMessage may involve interacting with other methods or properties defined in the ChatAPI interface or its implementation.\n\n- By carefully examining the code and understanding its logic, you can gain a better understanding of how the sendMessage function is modified and what actions it performs in the context of the ChatMessages class.\n\n", - "line": 35, - "selection": { - "start": { - "line": 3, - "character": 5 - }, - "end": { - "line": 3, - "character": 258 - } - } - }, - { - "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", - "description": "## Processing Message Further\n\n### In Rocket.chat Messages are sent to ../api/v1/method.call/sendMessage and this is a meteor method. ", - "line": 62 - }, - { - "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", - "description": "## Calling Meteor method\n\n### This method is taking 2 parameters, one is the route for meteor method(api/v1/method.call/:method) and another parameter is message which is passed on by sendMessage function below.\n\n```\nawait sdk.call('sendMessage', message);\n```", - "line": 32 - }, - { - "file": "apps/meteor/app/utils/client/lib/SDKClient.ts", - "description": "## Meteor.Call\n\n### The sendMessage function in the code triggers a Meteor method by passing a method name and its corresponding parameters. This invocation is responsible for initiating the sendMessage functionality. If by any chance someone calls any other method it would simply throw error.\n\n- There are basically **2 Meteor methods** for sendMessage each of them performing different tasks\n - **The first method is responsible for sending the message data to the database and performing various related tasks. However, there may be a slight delay in the message being rendered in the room or channel. To mitigate this delay, a second Meteor method is executed concurrently in an asynchronous manner.**\n\n - **The second method is specifically designed to facilitate the instant display of the sent message. If this method were disabled or not implemented, there would be a noticeable delay in the message being rendered and visible to the users.**", - "line": 161 - }, - { - "file": "apps/meteor/app/lib/server/methods/sendMessage.ts", - "description": "## Meteor.methods\n\n### In this code, we have defined a ServerMethods interface, which includes a route for the sendMessage method. When the sendMessage action is triggered, an API call is made to the route *api/v1/method.call/sendMessage*. ->\n```\nreturn executeSendMessage(uid, message)\n```\n\n#### This triggers a function *executeSendMessage()* below in a try block which is further responsible for operations", - "line": 110 - }, - { - "file": "apps/meteor/app/lib/server/methods/sendMessage.ts", - "description": "## executeSendMessage\n\n### - Inside the *executeSendMessage* function, we receive the uid (user ID) and message as parameters. This function performs various operations related to the sendMessage action.\n\n### - One of the key operations is triggering the sendMessage() function, which takes the user, message, room, and a boolean value as parameters. This function is responsible for handling the process of sending the message. It may involve additional validations, processing the message content, interacting with the database, and performing any necessary actions related to sending messages.", - "line": 85 - }, - { - "file": "apps/meteor/app/lib/server/functions/sendMessage.js", - "description": "## Sending message to DB\n\n### In the sendMessage.js file, The sendMessage function that is called from the [executeSendMessage()](./apps/meteor/app/lib/server/methods/sendMessage.ts) function. The purpose of the sendMessage function is to handle the actual sending of messages.\n\n#### Within the sendMessage function, there are several important steps:\n\n1. **Validations**: The function performs validations on the message, ensuring that it meets certain criteria or conditions before proceeding. This helps maintain message integrity and prevents any invalid or malicious content from being sent.\n\n2. **URL Parsing**: The function also includes a step to parse URLs within the message for safety purposes. This ensures that any URLs included in the message are properly handled and do not pose a security risk.\n\n3. **Asynchronous Callback**: The function utilizes an asynchronous callback mechanism, which allows it to run asynchronously and not block the execution flow. This is especially useful when dealing with tasks that may involve network requests or other asynchronous operations.\n\n4. **IMessage Object**: The callback returns an IMessage object, which represents the message being sent. This object may contain various properties and metadata associated with the message.\n\n6. **Storage in Database**: Once the message has passed all validations, it is stored in the database. This ensures that the message is persisted and can be retrieved or displayed at a later time.\n\n#### Finally, the function returns the message object, indicating the successful completion of the sending process.\n- You can see code below it's easy to understand and try to play around with them, Best way to understand working of any code is to make changes in them and undestand.", - "line": 206 - }, - { - "file": "apps/meteor/app/lib/client/methods/sendMessage.ts", - "description": "## The Async sendMessage Api call\n\n### - As mentioned earlier, there are two Meteor methods for handling the sendMessage functionality and making API Call. The first method handles processing and validation of the message, while the second method addresses the delay in rendering the message on the frontend.\n\n### - The second Meteor method is designed to ensure instant display of the sent message. When the first method completes successfully, it triggers the execution of the second method in an asynchronous manner. This allows for near-real-time rendering of the message on the user interface, reducing any noticeable delay.\n\n### And in the end there is a similar callback as it was in previous step which helps in message rendering, The callback return IMessage object which is displayed to user\n\n### - By separating these two methods, the application can provide a smooth and responsive user experience. The initial processing and validation are performed without blocking the UI, and once that is completed, the message is promptly displayed to the user.\n\n### You Have now successfully sent Message from composer, Note that there is one more API to sendMessage Which is an REST API, Which is currently not being used, if it would be used in future this tour would be updated. Still you can manually sendMessage by making call here [RestAPI Docs](https://developer.rocket.chat/reference/api/rest-api/endpoints/chat-endpoints/send-message) using -curl command, you can go thorugh the DOCS and try sending message on your own", - "line": 14 - } - ] - } \ No newline at end of file +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "3 - How a Message is sent (The Backend)", + "steps": [ + { + "file": "apps/meteor/client/lib/chats/ChatAPI.ts", + "description": "## The ChatAPI\n\n- **ComposerAPI:** This interface defines methods and properties related to the message composer functionality, such as managing text input, handling selection, wrapping text, inserting text, clearing, focusing, and more. It also includes properties for managing quoted messages, editing mode, recording mode, and microphone permissions.\n\n- **DataAPI:** This interface defines methods for interacting with message and room data. It includes functions for composing and managing messages, finding and getting messages by ID, finding the last and previous own messages, managing drafts, accessing room and subscription information, marking rooms as read, and more.\n\n- **UploadsAPI:** This interface defines methods and properties for managing file uploads. It includes functions for retrieving the list of uploads, subscribing to changes, canceling and wiping failed uploads, and sending files.\n\n- **ChatAPI:** This interface represents the main API object for the Rocket Chat client. It includes properties for user-related information, such as the user ID. It also provides access to the composer, data, uploads, and message editing functionality. Additionally, it exposes methods for performing actions like starting/stopping typing, opening/closing user cards and emoji pickers, and handling various message-related flows (uploading files, sending messages, processing slash commands, editing messages, setting reactions, etc.).", + "line": 106 + }, + { + "file": "apps/meteor/client/lib/chats/ChatAPI.ts", + "description": "## ChatAPI sendMessage\n\n#### Among many properties and functions present in ChatAPI here we have sendMessage.\n\n#### Note that sendMessage is *readonly* implying that it cannot be modified after initialization. Hence Implementing ChatAPI in any class would make it modification possible.\n\n```\n readonly sendMessage: ({ text, tshow }: { text: string; tshow?: boolean }) => Promise;\n```", + "line": 146 + }, + { + "file": "apps/meteor/app/ui/client/lib/ChatMessages.ts", + "description": "## Implementation of ChatAPI\n\n#### Here *class ChatMessages implements ChatAPI* and above it we have a *type DeepWritable* which removes readonly property from ChatAPI and This allows us to modify those properties\n", + "line": 28 + }, + { + "file": "apps/meteor/app/ui/client/lib/ChatMessages.ts", + "description": "## SendMessage -\n\n### Above we have a constructor and here in this.flows we are calling *sendMessage.bind(this,this)* The sendMessage is a function which further makes the meteor call for sending Message Data.", + "line": 176 + }, + { + "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", + "description": "## sendMessage function\n\n### The sendMessage recieves text: string and tshow: boolean properties and returns a Promise, And note that here we are utilizing ChatAPI again.\n\n- Within the sendMessage implementation, there are several checks and actions performed based on the provided parameters and the current state of the chat. These checks ensure that the message is valid and that the necessary actions are taken. The implementation of sendMessage may involve interacting with other methods or properties defined in the ChatAPI interface or its implementation.\n\n- By carefully examining the code and understanding its logic, you can gain a better understanding of how the sendMessage function is modified and what actions it performs in the context of the ChatMessages class.\n\n", + "line": 35, + "selection": { + "start": { + "line": 3, + "character": 5 + }, + "end": { + "line": 3, + "character": 258 + } + } + }, + { + "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", + "description": "## Processing Message Further\n\n### In Rocket.chat Messages are sent to ../api/v1/method.call/sendMessage and this is a meteor method. ", + "line": 62 + }, + { + "file": "apps/meteor/client/lib/chats/flows/sendMessage.ts", + "description": "## Calling Meteor method\n\n### This method is taking 2 parameters, one is the route for meteor method(api/v1/method.call/:method) and another parameter is message which is passed on by sendMessage function below.\n\n```\nawait sdk.call('sendMessage', message);\n```", + "line": 32 + }, + { + "file": "apps/meteor/app/utils/client/lib/SDKClient.ts", + "description": "## Meteor.Call\n\n### The sendMessage function in the code triggers a Meteor method by passing a method name and its corresponding parameters. This invocation is responsible for initiating the sendMessage functionality. If by any chance someone calls any other method it would simply throw error.\n\n- There are basically **2 Meteor methods** for sendMessage each of them performing different tasks\n - **The first method is responsible for sending the message data to the database and performing various related tasks. However, there may be a slight delay in the message being rendered in the room or channel. To mitigate this delay, a second Meteor method is executed concurrently in an asynchronous manner.**\n\n - **The second method is specifically designed to facilitate the instant display of the sent message. If this method were disabled or not implemented, there would be a noticeable delay in the message being rendered and visible to the users.**", + "line": 161 + }, + { + "file": "apps/meteor/app/lib/server/methods/sendMessage.ts", + "description": "## Meteor.methods\n\n### In this code, we have defined a ServerMethods interface, which includes a route for the sendMessage method. When the sendMessage action is triggered, an API call is made to the route *api/v1/method.call/sendMessage*. ->\n```\nreturn executeSendMessage(uid, message)\n```\n\n#### This triggers a function *executeSendMessage()* below in a try block which is further responsible for operations", + "line": 110 + }, + { + "file": "apps/meteor/app/lib/server/methods/sendMessage.ts", + "description": "## executeSendMessage\n\n### - Inside the *executeSendMessage* function, we receive the uid (user ID) and message as parameters. This function performs various operations related to the sendMessage action.\n\n### - One of the key operations is triggering the sendMessage() function, which takes the user, message, room, and a boolean value as parameters. This function is responsible for handling the process of sending the message. It may involve additional validations, processing the message content, interacting with the database, and performing any necessary actions related to sending messages.", + "line": 85 + }, + { + "file": "apps/meteor/app/lib/server/functions/sendMessage.js", + "description": "## Sending message to DB\n\n### In the sendMessage.js file, The sendMessage function that is called from the [executeSendMessage()](./apps/meteor/app/lib/server/methods/sendMessage.ts) function. The purpose of the sendMessage function is to handle the actual sending of messages.\n\n#### Within the sendMessage function, there are several important steps:\n\n1. **Validations**: The function performs validations on the message, ensuring that it meets certain criteria or conditions before proceeding. This helps maintain message integrity and prevents any invalid or malicious content from being sent.\n\n2. **URL Parsing**: The function also includes a step to parse URLs within the message for safety purposes. This ensures that any URLs included in the message are properly handled and do not pose a security risk.\n\n3. **Asynchronous Callback**: The function utilizes an asynchronous callback mechanism, which allows it to run asynchronously and not block the execution flow. This is especially useful when dealing with tasks that may involve network requests or other asynchronous operations.\n\n4. **IMessage Object**: The callback returns an IMessage object, which represents the message being sent. This object may contain various properties and metadata associated with the message.\n\n6. **Storage in Database**: Once the message has passed all validations, it is stored in the database. This ensures that the message is persisted and can be retrieved or displayed at a later time.\n\n#### Finally, the function returns the message object, indicating the successful completion of the sending process.\n- You can see code below it's easy to understand and try to play around with them, Best way to understand working of any code is to make changes in them and undestand.", + "line": 206 + }, + { + "file": "apps/meteor/app/lib/client/methods/sendMessage.ts", + "description": "## The Async sendMessage Api call\n\n### - As mentioned earlier, there are two Meteor methods for handling the sendMessage functionality and making API Call. The first method handles processing and validation of the message, while the second method addresses the delay in rendering the message on the frontend.\n\n### - The second Meteor method is designed to ensure instant display of the sent message. When the first method completes successfully, it triggers the execution of the second method in an asynchronous manner. This allows for near-real-time rendering of the message on the user interface, reducing any noticeable delay.\n\n### And in the end there is a similar callback as it was in previous step which helps in message rendering, The callback return IMessage object which is displayed to user\n\n### - By separating these two methods, the application can provide a smooth and responsive user experience. The initial processing and validation are performed without blocking the UI, and once that is completed, the message is promptly displayed to the user.\n\n### You Have now successfully sent Message from composer, Note that there is one more API to sendMessage Which is an REST API, Which is currently not being used, if it would be used in future this tour would be updated. Still you can manually sendMessage by making call here [RestAPI Docs](https://developer.rocket.chat/reference/api/rest-api/endpoints/chat-endpoints/send-message) using -curl command, you can go thorugh the DOCS and try sending message on your own", + "line": 14 + } + ] +} \ No newline at end of file diff --git a/.tours/4---how-to-create-an-endpoint.tour b/.tours/4---how-to-create-an-endpoint.tour index ddd30fcbce98..d84d2826f041 100644 --- a/.tours/4---how-to-create-an-endpoint.tour +++ b/.tours/4---how-to-create-an-endpoint.tour @@ -5,7 +5,7 @@ { "file": "apps/meteor/app/api/server/index.ts", "description": "## How to Create an Endpoint.\n\n### Rocket.Chat offers two methods for creating endpoints: REST API and Meteor Methods(Realtime API). These methods allow developers to extend Rocket.Chat's functionality by defining custom endpoints that can be accessed externally or internally.\n\n### In this guide, we will explore creating endpoints using the REST API and Meteor Methods in Rocket.Chat. We'll discuss their differences, use cases, and provide step-by-step instructions for implementation. By learning how to create endpoints, you'll be able to integrate external services, expose specific functionalities, and perform custom operations.\n", - "line": 51 + "line": 52 }, { "file": "apps/meteor/app/api/server/api.ts", diff --git a/.tours/5---how-to-create-a-db-model.tour b/.tours/5---how-to-create-a-db-model.tour index 688f8350e8f9..20ad3a54658f 100644 --- a/.tours/5---how-to-create-a-db-model.tour +++ b/.tours/5---how-to-create-a-db-model.tour @@ -14,7 +14,7 @@ { "file": "apps/meteor/server/models/raw/Messages.ts", "description": "## MessageRaw class\n\n- **To register a DB model in Rocket.Chat, it is necessary to create a corresponding class for that model. In our case, as we are creating the Messages Model, we need to define a class specifically for it. This class will serve as the blueprint for the Messages Model and will be used for registering and interacting with the corresponding data in the database.**\n\n- **In order to facilitate the management of the Messages Model in Rocket.Chat's database, we have a class called MessageRaw. This class extends the BaseRaw class and implements the IMessageModel interface, which we discussed earlier. By extending BaseRaw and implementing the IMessageModel interface, MessageRaw inherits necessary functionalities and ensures it adheres to the required structure and behavior of the Messages Model in Rocket.Chat.**", - "line": 42 + "line": 43 }, { "file": "apps/meteor/server/models/raw/Messages.ts",