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

feat: add group participants #132

Merged
merged 7 commits into from
Apr 19, 2024
Merged

feat: add group participants #132

merged 7 commits into from
Apr 19, 2024

Conversation

aldinokemal
Copy link
Owner

Context

  • Add participants to group
  • Update OpenAPI

Test Results

Screenshot 2024-04-10 at 14 45 56

Copy link
Contributor

coderabbitai bot commented Apr 10, 2024

Walkthrough

This update introduces significant enhancements to group management capabilities within the API, including new endpoints for creating groups and managing participants. The changes streamline group operations such as adding, removing, promoting, and demoting participants. Additionally, the documentation and codebase reflect these advancements, ensuring developers can effectively utilize the new features. This version also includes minor adjustments for improved functionality and user experience.

Changes

File(s) Change Summary
docs/openapi.yaml Updated to version 3.11.0; introduced CreateGroupResponse and GenericResponse; added new endpoints for group operations.
readme.md Updated API documentation to include details on generating an HTTP client and new group management endpoints.
src/config/settings.go Updated AppVersion to "v4.13.0".
src/domains/group/group.go, .../services/group.go, .../validations/group_validation.go Enhanced group management with new methods for adding participants and validations.
src/internal/rest/group.go, src/views/.../GroupAddParticipants.js, src/views/index.html Added functionality for adding participants to a group through the REST API and UI components.
src/pkg/whatsapp/whatsapp.go Optimized code by removing redundant "ephemeral" addition for "view once" events.

"In the land of code and bytes, where groups of chats take flight,
A rabbit hopped, with updates in tow, through the digital night.
🥕 New paths to tread, participants to add, a version fresh and bright,
With every line and function spread, it leaps towards the light.
So here's to groups, both big and small, may they chatter with delight!"
~ @coderabbitai 🐰✨


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b620001 and a8016e7.
Files selected for processing (10)
  • docs/openapi.yaml (4 hunks)
  • readme.md (1 hunks)
  • src/config/settings.go (1 hunks)
  • src/domains/group/group.go (2 hunks)
  • src/internal/rest/group.go (4 hunks)
  • src/pkg/whatsapp/whatsapp.go (1 hunks)
  • src/services/group.go (2 hunks)
  • src/validations/group_validation.go (1 hunks)
  • src/views/components/GroupAddParticipants.js (1 hunks)
  • src/views/index.html (3 hunks)
Files skipped from review due to trivial changes (2)
  • src/config/settings.go
  • src/pkg/whatsapp/whatsapp.go
Additional comments not posted (19)
src/domains/group/group.go (3)

9-9: Consider documenting the AddParticipant method.

Adding comments to public methods and interfaces improves code readability and helps other developers understand the purpose and usage of the method.


25-28: Ensure participant IDs are validated.

Given the security implications of adding participants to groups, it's crucial to validate participant IDs to prevent unauthorized additions. Consider implementing server-side validation if not already done.


30-34: Review the ParticipantStatus structure for extensibility.

The ParticipantStatus structure currently includes Participant, Status, and Message. Consider if additional fields (e.g., timestamp, action performed by) might be needed in the future for audit or logging purposes.

src/validations/group_validation.go (1)

48-60: Ensure comprehensive validation for participant IDs.

While the current validation checks for the presence of GroupID and Participants, consider extending the validation to ensure the format of participant IDs matches expected patterns (e.g., phone numbers with country codes for WhatsApp).

src/internal/rest/group.go (1)

77-93: Validate participant data before processing.

Before proceeding with adding participants, ensure that the participant data received in the request is validated. This can help prevent issues related to invalid data and improve the robustness of the API.

src/services/group.go (2)

76-114: Optimize error handling in AddParticipant.

Consider consolidating error handling in the AddParticipant function to reduce redundancy and improve readability. This could involve creating a helper function for common error responses or using a more structured approach to error handling.


116-130: Verify participant existence before adding.

Ensure that the IsOnWhatsapp check in participantToJID accurately verifies the existence of participants on WhatsApp. This is crucial for preventing attempts to add non-existent users to groups.

src/views/components/GroupAddParticipants.js (3)

1-119: Ensure input validation on the client side.

For the GroupAddParticipants component, consider implementing client-side validation for participant phone numbers to ensure they meet WhatsApp's format requirements before submission. This can improve user experience by catching errors early.


39-55: Handle API response errors gracefully.

In the submitApi method, ensure that errors from the API response are handled gracefully, providing clear feedback to the user. This could involve parsing error messages from the API and displaying them in a user-friendly manner.


63-118: Review accessibility of the modal interface.

For the modal interface used to add participants, review and ensure accessibility standards are met. This includes proper labeling of form elements, keyboard navigability, and screen reader support.

src/views/index.html (1)

84-84: Confirm integration of GroupAddParticipants.

Ensure that the GroupAddParticipants component is correctly integrated and functions as expected within the application's UI. This includes verifying that the component is properly loaded and interacts correctly with other components.

readme.md (2)

126-129: Ensure documentation accuracy for participant management endpoints.

Verify that the documentation for the new endpoints related to managing participants in a group (/group/participants, /group/participants/promote, etc.) accurately reflects the implemented API behavior and parameters.


100-100: Encourage the use of the OpenAPI generator.

Consider providing a brief example or a link to a guide on how to use the OpenAPI generator with the provided openapi.yaml file. This can help developers quickly get started with generating client libraries for the API.

docs/openapi.yaml (6)

4-4: Version update to 3.11.0 is appropriate for introducing new features.


776-788: The /group endpoint for creating groups and adding participants is correctly defined.


790-822: The /group/participants endpoint for adding more participants to a group is correctly defined.


906-920: The CreateGroupResponse schema is well-defined and aligns with the expected response for group creation.


921-942: The AddParticipantToGroupResponse schema is appropriately defined for the response when adding participants to a group.


856-856: The usage of GenericResponse schema for standard responses is appropriate and flexible.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 2

err := c.BodyParser(&request)
utils.PanicIfNeeded(err)

whatsapp.SanitizePhone(&request.GroupID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sanitize GroupID to prevent injection attacks.

- whatsapp.SanitizePhone(&request.GroupID)
+ sanitizedGroupID, err := whatsapp.SanitizeGroupID(request.GroupID)
+ if err != nil {
+     return c.Status(fiber.StatusBadRequest).JSON(utils.ResponseError{Message: "Invalid Group ID"})
+ }
+ request.GroupID = sanitizedGroupID

Ensure that GroupID is properly sanitized to prevent potential injection attacks. Consider implementing a dedicated sanitization function if not already available.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
whatsapp.SanitizePhone(&request.GroupID)
sanitizedGroupID, err := whatsapp.SanitizeGroupID(request.GroupID)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(utils.ResponseError{Message: "Invalid Group ID"})
}
request.GroupID = sanitizedGroupID

Comment on lines +56 to +58
participantsJID, err := service.participantToJID(request.Participants)
if err != nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle errors explicitly in participantToJID calls.

- participantsJID, err := service.participantToJID(request.Participants)
- if err != nil {
-     return
- }
+ participantsJID, err := service.participantToJID(request.Participants)
+ if err != nil {
+     return nil, err
+ }

Ensure that errors returned by participantToJID are handled explicitly to avoid silent failures and improve error reporting.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
participantsJID, err := service.participantToJID(request.Participants)
if err != nil {
return
participantsJID, err := service.participantToJID(request.Participants)
if err != nil {
return nil, err

@aldinokemal aldinokemal changed the title Feat/add group participants feat: add group participants Apr 10, 2024
@aldinokemal aldinokemal merged commit e78767d into main Apr 19, 2024
9 checks passed
@aldinokemal aldinokemal deleted the feat/add-group-participants branch April 19, 2024 07:54
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