-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Corrigindo um bug ao atualizar o push name no evento MESSAGES_UPSERT e MESSAGES_UPDATE #1366
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 ao atualizar o push name no evento MESSAGES_UPSERT e MESSAGES_UPDATE #1366
Conversation
…der to return always the chatname from the user correctly
Reviewer's Guide by SourceryThis pull request fixes a bug where the Sequence diagram for MESSAGES_UPSERT eventsequenceDiagram
participant WhatsApp
participant BaileysService
participant PrismaRepository
participant WebhookService
WhatsApp->>BaileysService: Event: MESSAGES_UPSERT (message received)
BaileysService->>BaileysService: Check if chat exists
alt Chat exists and pushName is valid and fromMe is false and not a group
BaileysService->>PrismaRepository: Update Chat.name with pushName
PrismaRepository-->>BaileysService: Success
BaileysService->>WebhookService: Send CHATS_UPSERT event with updated Chat
WebhookService-->>BaileysService: Acknowledged
else Chat does not exist or pushName is invalid or fromMe is true or is a group
BaileysService->>BaileysService: Do not update Chat.name
end
Updated class diagram for ChatclassDiagram
class Chat {
remoteJid: string
instanceId: string
unreadMessages: number
// name: string - Removed from initial creation
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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:
- The changes look good, but it would be helpful to add a comment explaining why the
name
field is no longer updated during theMESSAGES_UPDATE
event. - Consider adding a test case to specifically verify that the chat name is updated correctly when a new message is received from a contact.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Talvez vc consiga resolver este bug também: #1367 chegou a ocorrer com vc? |
Fix
Problema
Ao enviar uma mensagem via dispositivo, dois comportamentos distintos ocorriam:
MESSAGES_UPSERT
atualizava o camponame
da tabelaChat
com opushname
do remetente.MESSAGES_UPDATE
sobrescrevia o camponame
com uma string vazia de forma consistente, pois tentava fazer umupdate
utilizando uma variável que sequer era definida — já que esse campo não era enviado pelo respectivo evento da Baileys.O que foi alterado?
name
da tabelaChat
não é mais atualizado durante o eventoMESSAGES_UPDATE
. Isto ocorre pois o camponame
sequer é enviado no evento, causando ele sempre ser atualizado como uma string vazia.MESSAGES_UPSERT
, o camponame
só é atualizado quandofromMe
for falso, ou seja, apenas quando a mensagem for recebida (não enviada pelo próprio usuário).Resolução
Agora, ao chamar um endpoint que retorna o campo
name
da tabelaChat
(como o/chat/findChats/
), o valor retornado será o correto — evitando strings vazias ou o nome do próprio remetente. O campo continua sendo atualizado normalmente ao receber mensagens.Summary by Sourcery
Fix the behavior of updating chat names during message events to prevent incorrect name updates
Bug Fixes:
Enhancements: