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

Added support to block/unblock contacts and receive block/unblock events #423

Closed
wants to merge 6 commits into from

Conversation

emacielxp
Copy link
Contributor

Block/Unblock support

Added support to block/unblock contacts and receive block/unblock events

Changes:

connectionevents.go

  • Sync at the local database the blocked list when successfully connect

mdtest/main.go

  • Included commands to test the block/unblock feature:
    -- listblocked: get the blocked list from whatsapp
    -- syncblockedlist: get the blocked list from whatsapp and update local database
    -- block: block contact
    -- unblock: unblock contact

  • Included contact blocked status changed event listener

notification.go

  • Included function to handle the whatsapp block/unblock event changes

store/sqlstore/store.go

  • Included queries to update database contact block column

  • Included functions to use the above queries

  • Change getContact and GetAllContacts functions to return the blocked flag inside the ContactInfo data

store/sqlstore/upgrade.go

  • Included a new upgrade database function with the alter table with the new column related to the blocked flag

store/store,go

  • Included functions created at: store/sqlstore/store.go

types/events/events.go

  • Created the contact blocked status changed event type definition

types/user.go

  • Changed the ContactInfo included the Blocked field

user.go

  • Created necessary functions to allow list, block and unblock contacts

Notes:

this feature was already tested and works fine at:

  • iphone business
  • iphone normal
  • android business
  • android normal

@tulir
Copy link
Owner

tulir commented Jul 12, 2023

Not sure if it should be stored in the db, might be better to just have the methods for modifying and fetching the list and event types for incoming notifications

@emacielxp
Copy link
Contributor Author

emacielxp commented Jul 12, 2023

i've do this because in some cases my system send messages for blocked contacts and whatsapp return 403 error, but at whatsapp app or whatsapp web you can't send messages when the contact is blocked and i think this may cause problems with whatsapp to clients that use my system (because sending messages that isn't allowed for blocked contacts at official channels)..

i've implemented before i send a message (call SendMessage function) to check at the local database (GetContact function) if the contact is blocked or not and skipping sending if blocked, but thinking now, maybe this control (send or not the message) shoud be implemented inside the whatsmeow SendMessage function, to avoid the problem i mentioned before..

i will do this refactor and update this PR

@emacielxp
Copy link
Contributor Author

according your reply, removed from database the store of contact block data, create a blocked contact memory cache similar to groupParticipantsCache and validate at sendMessage function to return an error when the contact is blocked

@emacielxp
Copy link
Contributor Author

@tulir any news about this PR?

@salman0ansari
Copy link
Contributor

tested this PR and code is working fine
I wonder why it has not been merged yet

@emacielxp
Copy link
Contributor Author

I will open a new PR with this feature

@emacielxp emacielxp closed this Sep 8, 2023
@mateusfmello
Copy link

I will open a new PR with this feature

@emacielxp if possible, enter the URL of the new PR here.

I'm waiting for the merge of this feature.

@emacielxp
Copy link
Contributor Author

@mateusfmello here is: #460

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