Skip to content

gql-server: Add props to enable a user to Reply a chat message (backend portion) - #21296

Merged
gustavotrott merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:gql-chat-reply
Oct 1, 2024
Merged

gustavotrott merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:gql-chat-reply

Conversation

@gustavotrott

Copy link
Copy Markdown
Contributor

Aiming to enable the implementation of the feature Reply Chat Message, this PR introduces new fields to Graphql:

Mutation to reply:

mutation($chatId: String!, $chatMessageInMarkdownFormat: String!, $replyToMessageId: String) {
  chatSendMessage(
    chatId: $chatId, 
    chatMessageInMarkdownFormat: $chatMessageInMarkdownFormat,
    replyToMessageId: $replyToMessageId
  )
}
  • Subscription to bring the original message and its author:
subscription {
  chat_message_public {
    message
    user {
      name
    }
    replyToMessage {
      message
      user {
        name
      }
    }
  }
}
  • New field to know the sequence of that message and them identify the page it lies (it will be useful when the user click on the quote and is redirected to the original message)
subscription {
  chat_message_public {
	message
	messageSequence
  }
}

replyToMessageId will be useful for the feature that enables to reply a message of the chat
messageSequence will be useful to identify the page of that message and scroll the user to the correct page when they click to see the original message
@gustavotrott gustavotrott added this to the Release 3.0 milestone Oct 1, 2024
@coderabbitai

This comment was marked as off-topic.

@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2024

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (5)
bbb-graphql-actions/src/actions/chatSendMessage.ts (1)

35-35: LGTM: replyToMessageId added to message body, with a minor suggestion.

The replyToMessageId has been correctly added to the message body, using the input value if provided. This implementation aligns well with the PR objectives for supporting message replies.

Consider using null instead of an empty string as the default value for replyToMessageId. This would more clearly indicate the absence of a reply:

-      replyToMessageId: input.replyToMessageId || "",
+      replyToMessageId: input.replyToMessageId || null,

This change could make it easier to distinguish between messages without replies and those replying to a deleted message (which might retain an empty string ID).

akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/breakout/SendMessageToBreakoutRoomInternalMsgHdlr.scala (1)

Line range hint 1-41: Consider improving documentation for the new replyToMessageId parameter

While the code structure is clean and follows Scala best practices, it might be beneficial to add documentation explaining the purpose and future use of the replyToMessageId parameter. This would help other developers understand the intent behind this change and how it relates to the message reply feature.

Consider adding a comment above the GroupChatMsgFromUser instantiation explaining the purpose of the replyToMessageId parameter and any future plans for its use in breakout rooms.

bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/GroupChatMsg.scala (1)

20-26: LGTM! Consider adding documentation for the new field.

The addition of the replyToMessageId field to the GroupChatMsgFromUser case class aligns well with the PR objectives of enabling message replies. The implementation looks correct and consistent with the existing structure.

Consider adding a brief comment above the case class or the new field to explain its purpose and usage. For example:

/**
 * Represents a group chat message from a user.
 * @param replyToMessageId The ID of the message being replied to, if any.
 */
case class GroupChatMsgFromUser(
  // ... other fields ...
  replyToMessageId: String, // ID of the message being replied to (empty if not a reply)
  // ... other fields ...
)

This documentation will help other developers understand the purpose of the new field at a glance.

bbb-graphql-server/bbb_schema.sql (2)

987-987: LGTM: Message sequence implementation looks good.

The addition of the messageSequence column and the corresponding trigger function is well-implemented. This change aligns with the PR objective of tracking the sequence of messages, which will help identify the page where the original message is located.

Consider adding an index on the messageSequence column to improve query performance when retrieving messages in order:

CREATE INDEX idx_chat_message_sequence ON chat_message(meetingId, chatId, messageSequence);

This index will be particularly useful when implementing pagination or when fetching messages around a specific sequence number.

Also applies to: 1001-1017


1073-1077: LGTM: Private chat message view updated correctly.

The v_chat_message_private view has been properly updated to include the new replyToMessageId column. This change ensures that the reply information is available when querying private chat messages, supporting the new reply feature in the client application.

Consider adding a join to the chat_message table to include information about the replied-to message. This could be useful for displaying a preview of the original message in the client application:

CREATE OR REPLACE VIEW "v_chat_message_private" AS
SELECT  cu."meetingId",
        cu."userId",
        cm."messageId",
        cm."chatId",
        cm."correlationId",
        cm."messageSequence",
        cm."chatEmphasizedText",
        cm."message",
        cm."messageType",
        cm."replyToMessageId",
        reply."message" AS "replyToMessage",
        reply."userId" AS "replyToUserId",
        cm."messageMetadata",
        cm."senderId",
        cm."senderName",
        cm."senderRole",
        cm."createdAt",
        CASE WHEN chat_with."lastSeenAt" >= cm."createdAt" THEN true ELSE false END "recipientHasSeen"
FROM chat_message cm
JOIN chat_user cu ON cu."meetingId" = cm."meetingId" AND cu."chatId" = cm."chatId"
LEFT JOIN chat_message reply ON reply."messageId" = cm."replyToMessageId"
LEFT JOIN "chat_user" chat_with ON chat_with."meetingId" = cm."meetingId"
                                AND chat_with."chatId" = cm."chatId"
                                AND chat_with."userId" != cu."userId"
WHERE cm."chatId" != 'MAIN-PUBLIC-GROUP-CHAT';

This change would provide more context for replied-to messages without requiring additional queries from the client.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 87964ca and 900bc9e.

📒 Files selected for processing (11)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/breakout/SendMessageToBreakoutRoomInternalMsgHdlr.scala (1 hunks)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/groupchats/GroupChat.scala (2 hunks)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/groupchats/SendGroupChatMessageFromApiSysPubMsgHdlr.scala (1 hunks)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/ChatMessageDAO.scala (4 hunks)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/GroupChats.scala (1 hunks)
  • bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/GroupChatMsg.scala (1 hunks)
  • bbb-graphql-actions/src/actions/chatSendMessage.ts (2 hunks)
  • bbb-graphql-server/bbb_schema.sql (3 hunks)
  • bbb-graphql-server/metadata/actions.graphql (1 hunks)
  • bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_chat_message_private.yaml (2 hunks)
  • bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_chat_message_public.yaml (2 hunks)
🔇 Additional comments (19)
bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_chat_message_public.yaml (3)

10-18: LGTM: New object relationship for message replies.

The new replyToMessage object relationship is correctly configured to enable threaded conversations. It appropriately links the replyToMessageId to the messageId within the same table, allowing for self-referential relationships between messages.


40-40: LGTM: Added messageSequence to select permissions.

The addition of the messageSequence column to the select permissions for the bbb_client role is appropriate. This change allows clients to access the new field, which is essential for identifying the page location of original messages in threaded conversations.


Line range hint 1-48: Summary: Enhancements to support message replies and sequencing.

The changes to this configuration file successfully implement the backend portion of the chat reply feature. The new replyToMessage relationship enables threaded conversations, while the addition of messageSequence to the select permissions allows clients to access this crucial information for message navigation.

These modifications align well with the PR objectives and provide a solid foundation for the frontend implementation of the chat reply feature.

bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_chat_message_private.yaml (3)

10-18: LGTM: New object relationship replyToMessage added correctly.

The new object relationship replyToMessage is correctly configured to enable message replies. It uses a manual configuration to map replyToMessageId to messageId within the same table, which aligns with the PR objective of allowing users to reply to chat messages.


40-40: LGTM: messageSequence column added to select permissions.

The messageSequence column has been correctly added to the list of permitted columns for the bbb_client role. This change aligns with the PR objective of introducing a new field to track the sequence of messages, which will help identify the page where the original message is located.


Line range hint 10-40: Summary: Changes align well with PR objectives.

The modifications to this configuration file effectively support the new message reply feature:

  1. The new replyToMessage object relationship enables referencing reply messages.
  2. The addition of the messageSequence column to the select permissions allows clients to access the new field for message sequencing.

These changes are consistent with the PR objectives and contribute to enhancing the chat functionality by enabling message replies and providing additional context for chat interactions.

bbb-graphql-actions/src/actions/chatSendMessage.ts (2)

9-9: LGTM: Input validation for replyToMessageId added correctly.

The new replyToMessageId parameter has been properly added to the input validation schema. It's correctly set as an optional string, which aligns with the PR objectives for implementing message replies.


Line range hint 1-42: Verify consistency with related components.

The changes in this file successfully implement the backend portion of the reply functionality as described in the PR objectives. To ensure full compatibility:

Please run the following script to check if the GraphQL schema has been updated accordingly:

This will help confirm that the GraphQL schema has been updated to match these implementation changes.

akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/breakout/SendMessageToBreakoutRoomInternalMsgHdlr.scala (1)

21-21: Addition of replyToMessageId parameter aligns with PR objectives

The change to include replyToMessageId = "" in the GroupChatMsgFromUser constructor aligns with the PR's objective of enabling message replies. However, initializing it with an empty string suggests that reply functionality might not be fully implemented for breakout rooms yet.

To ensure consistency across the codebase, let's verify the usage of GroupChatMsgFromUser in other files:

✅ Verification successful

Verified consistency in GroupChatMsgFromUser usage

All instances of GroupChatMsgFromUser across the codebase initialize replyToMessageId with an empty string, ensuring consistent usage. No issues found regarding the addition of the replyToMessageId parameter in the reviewed file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of GroupChatMsgFromUser to ensure consistent usage of replyToMessageId

# Test: Search for GroupChatMsgFromUser constructor calls
rg --type scala -A 5 'GroupChatMsgFromUser\('

Length of output: 4449

akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/GroupChats.scala (1)

41-41: Approved: Addition of replyToMessageId to GroupChatMessage

The addition of replyToMessageId: String to the GroupChatMessage case class aligns well with the PR objective of implementing a reply feature for chat messages. This change provides the necessary structure to associate a reply with its original message.

To ensure this change is implemented consistently across the codebase, please run the following script to verify the usage of GroupChatMessage:

Consider the following suggestions:

  1. Ensure that all places where GroupChatMessage is instantiated are updated to include the replyToMessageId parameter.
  2. For backward compatibility, you might want to provide a default value for replyToMessageId, such as an empty string or null. This would allow existing code to work without modification. For example:
case class GroupChatMessage(
  // ... other fields ...
  message: String,
  replyToMessageId: String = "",  // or = null
  metadata: Map[String, Any] = Map.empty
)
  1. Update any serialization/deserialization logic for GroupChatMessage to include the new field.
  2. If there are any database schemas or APIs that represent this message structure, ensure they are also updated accordingly.
bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/GroupChatMsg.scala (2)

27-34: Formatting improvement looks good.

The reformatting of the GroupChatMsgToUser case class enhances readability by aligning fields vertically. This change is purely cosmetic and doesn't affect functionality, which is appropriate given that the reply feature is primarily handled in the GroupChatMsgFromUser class.


Line range hint 1-34: Summary: Changes align well with PR objectives

The modifications to this file successfully implement the backend portion of the chat message reply feature. The addition of the replyToMessageId field to GroupChatMsgFromUser enables the tracking of message replies, which is a key objective of this PR. The reformatting of GroupChatMsgToUser improves code readability without changing functionality.

These changes lay the groundwork for the GraphQL mutations and subscriptions mentioned in the PR objectives. The next steps would likely involve implementing the actual GraphQL resolvers and subscriptions that utilize these updated message structures.

To ensure consistency across the codebase, let's verify the usage of these updated case classes:

This script will help identify any places where the updated GroupChatMsgFromUser might not have been properly implemented or where GroupChatMsgToUser might have been inadvertently modified.

bbb-graphql-server/bbb_schema.sql (2)

986-991: LGTM: Chat message reply feature implemented correctly.

The addition of the replyToMessageId column to the chat_message table is well-implemented. It correctly references the messageId column, allowing for a hierarchical structure of messages. This change aligns with the PR objective of implementing a reply feature for chat messages.


Line range hint 1-1477: Overall, the changes look good and align with the PR objectives.

The implementation of the chat reply feature and message sequence tracking in the database schema is well-done. The changes provide the necessary structure to support the new functionality described in the PR objectives. Here's a summary of the key points:

  1. The chat reply feature is correctly implemented with the addition of the replyToMessageId column.
  2. Message sequence tracking is added through the messageSequence column and associated trigger.
  3. The v_chat_message_private view is updated to include the new reply information.

The suggestions provided for adding an index on the messageSequence column and expanding the v_chat_message_private view are optional optimizations that could enhance performance and functionality.

akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/groupchats/GroupChat.scala (1)

26-26: LGTM!

Passing msg.replyToMessageId to GroupChatMessage correctly enables the message reply functionality.

akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/ChatMessageDAO.scala (4)

15-15: Addition of replyToMessageId field to ChatMessageDbModel

The optional field replyToMessageId: Option[String] is appropriately added to the data model to support message replies.


31-31: Definition of replyToMessageId column in ChatMessageDbTableDef

Defining replyToMessageId as column[Option[String]]("replyToMessageId") correctly reflects the new field in the database schema.


39-39: Inclusion of replyToMessageId in the table projection

Updating the * projection to include replyToMessageId ensures proper mapping between the database table and the data model.


103-103: Setting replyToMessageId to None for system messages

Assigning replyToMessageId = None for system messages correctly indicates that system messages do not reply to any existing messages.

@github-actions

github-actions Bot commented Oct 1, 2024

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have passed!

@gustavotrott
gustavotrott merged commit 837089e into bigbluebutton:v3.0.x-release Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant