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

Corrigindo um bug no endpoint de findChats e permitindo paginação nos endpoints de findChats e findContacts #1334

Conversation

pedro-php
Copy link

@pedro-php pedro-php commented Mar 25, 2025

Fix

Problema

Ao se utilizar o endpoint de findChat para encontrar o nome de um grupo, era retornado o pushname do último usuário que enviou uma mensagem no chat ao invés do nome do chat em si.

O que foi alterado?

Ao receber uma mensagem, o chatName não mais é sobrescrito com o pushname do remetente da mensagem em mensagens provindas de grupo. Também foi adicionado ao retorno do endpoint um parâmetro chatName, que retorna o chatname da tabela de Chats.

Resolução

Agora, ao se chamar o endpoint, um parâmetro extra chatName retorna o campo chatname da tabela de Chats, correspondente ao pushname do usuário em contatos e ao nome do grupo em grupos.

Feature

Problema

Em números com muitos contatos e chats, realizar a chamada à esses endpoints podia ser demorada e algumas vezes impossível.

O que foi alterado

Adicionada a possibilidade de paginar os endpoints de findChats e findContacts atráves dos parâmetros page e offset. No endpoint de findChats, foi adicionada diretamente à rawQuery, e no enddpoint findContacts, foi adicionada aos parâmetros take e skip do prisma.

Resolução

O usuário pode agora, opcionalmente, paginar os resultados de ambos os endpoints, aliviando a carga da requisição.

Summary by Sourcery

Improves the findChats and findContacts endpoints by adding pagination and fixing a bug where the findChat endpoint returned the wrong name for group chats.

New Features:

  • Adds pagination to the findChats and findContacts endpoints using the page and offset parameters, improving performance for users with many contacts and chats.

Bug Fixes:

  • Fixes a bug in the findChat endpoint that caused it to return the pushname of the last user who sent a message in the chat instead of the chat name itself. The chatName is no longer overwritten with the sender's pushname for messages from groups.
  • Adds a chatName parameter to the findChats endpoint response, which returns the chatname from the Chats table, corresponding to the user's pushname in contacts and the group name in groups.

Copy link

sourcery-ai bot commented Mar 25, 2025

Reviewer's Guide by Sourcery

This pull request fixes a bug in the findChats endpoint and implements pagination for the findChats and findContacts endpoints. The bug fix ensures that the correct chat name is returned, while the pagination feature improves performance for users with many contacts and chats.

Sequence diagram for fetching chat name

sequenceDiagram
  participant Client
  participant ChannelStartupService
  participant PrismaRepository

  Client->>ChannelStartupService: Calls findChats endpoint
  ChannelStartupService->>PrismaRepository: Executes raw SQL query to fetch chats
  PrismaRepository-->>ChannelStartupService: Returns chat data including chatName from Chat table
  ChannelStartupService-->>Client: Returns chat data with correct chatName
Loading

Sequence diagram for Contact Pagination

sequenceDiagram
    participant Client
    participant ChannelStartupService
    participant PrismaRepository

    Client->>ChannelStartupService: Calls findContacts endpoint with page and offset
    ChannelStartupService->>PrismaRepository: Calls contact.findMany with take and skip parameters
    PrismaRepository-->>ChannelStartupService: Returns paginated contact data
    ChannelStartupService-->>Client: Returns paginated contact data
Loading

Updated class diagram for ChannelStartupService

classDiagram
    class ChannelStartupService {
        +findContacts(query: any): Promise<Contact[]>
        +findChats(query: any): Promise<Chat[]>
    }

    class Contact {
        id: string
        remoteJid: string
        pushName: string
        chatName: string
        profilePicUrl: string
        updatedAt: Date
        windowStart: Date
    }

    note for Contact "Added chatName attribute"

    class Chat {
        name: string
        createdAt: Date
    }

    ChannelStartupService -- Contact : returns
Loading

File-Level Changes

Change Details Files
Fixed a bug in the findChats endpoint that was returning the push name of the last user who sent a message in the chat instead of the chat name itself.
  • The chat name is no longer overwritten with the sender's push name in messages from groups.
  • Added a chatName parameter to the endpoint's return, which returns the chat name from the Chats table.
src/api/services/channel.service.ts
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Implemented pagination for the findChats and findContacts endpoints.
  • Added the ability to paginate the findChats and findContacts endpoints using the page and offset parameters.
  • In the findChats endpoint, pagination was added directly to the raw query.
  • In the findContacts endpoint, pagination was added to the take and skip parameters of Prisma.
src/api/services/channel.service.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @pedro-php - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding validation to ensure that page and offset are positive integers.
  • It might be worth extracting the pagination logic into a separate helper function to improve readability.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@MateusHirataAW
Copy link

up

1 similar comment
@marcosgalupo
Copy link

up

@DavidsonGomes DavidsonGomes changed the base branch from main to develop March 26, 2025 12:59
@DavidsonGomes DavidsonGomes merged commit b89f114 into EvolutionAPI:develop Mar 26, 2025
1 check passed
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.

4 participants