Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutations to mark chat messages as read, update message, update group chat info, add user to group chat, share images in chats, and create dedicated group chats for events #2625

Merged
merged 82 commits into from
Dec 28, 2024

Conversation

disha1202
Copy link
Contributor

@disha1202 disha1202 commented Oct 29, 2024

What kind of change does this PR introduce?
Feature

Issue Number:

Fixes #2624

Did you add tests for your changes?
Yes

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced chat functionality with new fields for tracking unseen messages and media in chat messages.
    • New mutations for adding users to group chats, marking messages as read, and updating chat/message details.
    • New queries for retrieving group chats and unread chats by user ID.
    • Introduced new input types for better filtering and chat creation options.
  • Bug Fixes

    • Improved error handling in various mutation resolvers.
  • Documentation

    • Updated GraphQL schema definitions to reflect new input types and mutations.
  • Tests

    • Expanded test coverage for chat-related functionalities, including new tests for group chats and unread messages.

@Cioppolo14
Copy link
Contributor

Closing this as inactive.

@Cioppolo14 Cioppolo14 closed this Dec 13, 2024
@palisadoes
Copy link
Contributor

Reopening. GSoC

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
src/resolvers/Mutation/sendMessageToChat.ts (1)

90-93: Consider atomic update for unseenMessagesByUsers

The current implementation might lead to race conditions when multiple users send messages simultaneously.

Consider using MongoDB's atomic operators:

-      $set: {
-        unseenMessagesByUsers: JSON.stringify(unseenMessagesByUsers),
-        updatedAt: now,
-      },
+      $set: { updatedAt: now },
+      $inc: {
+        'unseenMessagesByUsers': {
+          [context.userId]: 0,
+          ...Object.fromEntries(
+            Object.keys(unseenMessagesByUsers)
+              .filter(id => id !== context.userId)
+              .map(id => [`${id}`, 1])
+          )
+        }
+      }
src/typeDefs/inputs.ts (1)

33-36: Enhance chat search capabilities

The ChatWhereInput could be expanded to include more useful search criteria.

Consider adding more search fields:

 input ChatWhereInput {
   user: UserWhereInput
   name_contains: String
+  isGroup: Boolean
+  createdAt_gte: DateTime
+  createdAt_lte: DateTime
+  hasUnreadMessages: Boolean
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac4256c and d3375de.

📒 Files selected for processing (16)
  • schema.graphql (10 hunks)
  • src/models/Chat.ts (3 hunks)
  • src/models/ChatMessage.ts (2 hunks)
  • src/models/Event.ts (3 hunks)
  • src/resolvers/Mutation/index.ts (3 hunks)
  • src/resolvers/Mutation/sendMessageToChat.ts (3 hunks)
  • src/resolvers/Query/chatsByUserId.ts (2 hunks)
  • src/resolvers/Query/helperFunctions/getWhere.ts (3 hunks)
  • src/resolvers/Query/index.ts (2 hunks)
  • src/typeDefs/inputs.ts (2 hunks)
  • src/typeDefs/mutations.ts (2 hunks)
  • src/typeDefs/queries.ts (1 hunks)
  • src/typeDefs/types.ts (2 hunks)
  • src/types/generatedGraphQLTypes.ts (24 hunks)
  • tests/resolvers/Mutation/sendMessageToChat.spec.ts (1 hunks)
  • tests/resolvers/Query/eventsByOrganizationConnection.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/resolvers/Query/index.ts
  • src/models/Event.ts
  • src/resolvers/Mutation/index.ts
  • tests/resolvers/Mutation/sendMessageToChat.spec.ts
  • tests/resolvers/Query/eventsByOrganizationConnection.spec.ts
  • src/typeDefs/queries.ts
  • src/models/ChatMessage.ts
  • src/resolvers/Query/chatsByUserId.ts
  • src/models/Chat.ts
  • src/typeDefs/mutations.ts
👮 Files not reviewed due to content moderation or server errors (3)
  • src/resolvers/Query/helperFunctions/getWhere.ts
  • schema.graphql
  • src/types/generatedGraphQLTypes.ts
🔇 Additional comments (2)
src/typeDefs/inputs.ts (1)

157-157: LGTM: Event chat creation flag added

The createChat boolean field is a good addition to control chat creation for events.

src/typeDefs/types.ts (1)

828-828: LGTM: Media field added to ChatMessage

The media field addition aligns well with the new file upload functionality.

src/resolvers/Mutation/sendMessageToChat.ts Outdated Show resolved Hide resolved
src/resolvers/Mutation/sendMessageToChat.ts Show resolved Hide resolved
src/typeDefs/inputs.ts Show resolved Hide resolved
src/typeDefs/types.ts Show resolved Hide resolved
src/typeDefs/types.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
src/resolvers/Mutation/markChatMessagesAsRead.ts (2)

10-19: Update JSDoc remarks to include all validation checks.

The remarks section is missing the user authorization check that verifies if the user is a member of the chat.

 * @remarks The following checks are done:
 * 1. If the direct chat exists.
 * 2. If the user exists
+ * 3. If the user is a member of the chat

83-89: Remove redundant chat existence check.

The chat existence is already verified at the beginning of the function, making this check redundant.

-    if (!updatedChat) {
-      throw new errors.NotFoundError(
-        requestContext.translate(CHAT_NOT_FOUND_ERROR.MESSAGE),
-        CHAT_NOT_FOUND_ERROR.CODE,
-        CHAT_NOT_FOUND_ERROR.PARAM,
-      );
-    }
schema.graphql (3)

213-214: Consider using a structured type instead of JSON for unseenMessagesByUsers.

Using JSON type for unseenMessagesByUsers reduces type safety and makes validation harder. Consider creating a dedicated type.

type UnseenMessages {
  userId: ID!
  count: Int!
}

type Chat {
  # ...other fields
  unseenMessagesByUsers: [UnseenMessages!]
}

223-223: Use URL scalar type for media field and add documentation.

The media field would benefit from using the URL scalar type and having documentation about supported media types/sizes.

-  media: String
+  """
+  URL to the media attachment. Supported types: image/*, video/*
+  Max size: 10MB
+  """
+  media: URL

2228-2232: Add documentation and validation directives to createGroupChatInput.

The input type would benefit from documentation and validation directives.

+"""
+Input for creating a new group chat.
+"""
 input createGroupChatInput {
+  "ID of the organization this chat belongs to"
   organizationId: ID!
+  "Title of the group chat (3-50 characters)"
-  title: String!
+  title: String! @constraint(minLength: 3, maxLength: 50)
+  "List of user IDs to add to the chat (minimum 2 users)"
-  userIds: [ID!]!
+  userIds: [ID!]! @constraint(minItems: 2)
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be794e4 and 95b1add.

📒 Files selected for processing (5)
  • schema.graphql (11 hunks)
  • src/resolvers/Mutation/markChatMessagesAsRead.ts (1 hunks)
  • src/resolvers/Query/chatsByUserId.ts (2 hunks)
  • src/typeDefs/mutations.ts (2 hunks)
  • src/types/generatedGraphQLTypes.ts (27 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/resolvers/Query/chatsByUserId.ts
  • src/typeDefs/mutations.ts
🔇 Additional comments (3)
src/resolvers/Mutation/markChatMessagesAsRead.ts (2)

1-4: LGTM! Imports are well structured.


22-32: LGTM! Proper error handling with performance optimization.

src/types/generatedGraphQLTypes.ts (1)

Line range hint 1-5089: LGTM! Auto-generated types file.

This file is automatically generated from the GraphQL schema, no manual review needed.

src/resolvers/Mutation/markChatMessagesAsRead.ts Outdated Show resolved Hide resolved
@palisadoes
Copy link
Contributor

  1. Please fix the failing tests. Click on the Details links for more information.
  2. Please make sure that CodeRabbit.ai approves your changes

@disha1202
Copy link
Contributor Author

  1. Please fix the failing tests. Click on the Details links for more information.
  2. Please make sure that CodeRabbit.ai approves your changes

Hi @palisadoes
The typecheck test is failing which is not related to the changes in this PR and is fixed in
#2770

@palisadoes palisadoes added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Dec 20, 2024
@palisadoes
Copy link
Contributor

@disha1202 The PR was merged and the failed tests persist

@palisadoes
Copy link
Contributor

@disha1202 Can we merge this now? Can you make changes so that coderabbit.ai approves?

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 28, 2024
palisadoes
palisadoes previously approved these changes Dec 28, 2024
@palisadoes
Copy link
Contributor

Please fix the conflicting files

@disha1202 disha1202 dismissed stale reviews from palisadoes and coderabbitai[bot] December 28, 2024 18:25

The merge-base changed after approval.

@palisadoes palisadoes merged commit 3a5276a into PalisadoesFoundation:develop Dec 28, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Priority ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants