Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.07k stars 492 forks source link

Add Block/Unblock Contact Function #497

Closed jeremia49 closed 3 years ago

jeremia49 commented 3 years ago

as the title said

jeremia49 commented 3 years ago

Let me know what you think 😄

rhsobr commented 3 years ago

i really suggest something like that:


func (wac *Conn) BlockContact(jid string) (<-chan string, error) {
   return wac.handleBlockContact("add", jid)
}

func (wac *Conn) UnblockContact(jid string) (<-chan string, error) {
   return wac.handleBlockContact("remove", jid)
}

func (wac *Conn) handleBlockContact(action, jid string) (<-chan string, error) {
    ts := time.Now().Unix()
    tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount)

    netsplit := strings.Split(jid, "@")
    cusjid := netsplit[0] + "@c.us"

    n := binary.Node{
        Description: "action",
        Attributes: map[string]string{
            "type":  "set",
            "epoch": strconv.Itoa(wac.msgCount),
        },
        Content: []interface{}{
            binary.Node{
                Description: "block",
                Attributes: map[string]string{
                    "type": action,
                },
                Content: []binary.Node{
                    {
                        Description: "user",
                        Attributes: map[string]string{
                            "jid": cusjid,
                        },
                        Content: nil,
                    },
                },
            },
        },
    }

    return wac.writeBinary(n, contact, ignore, tag)
}
jeremia49 commented 3 years ago

Hi there, thanks for your suggestion , I will refactor my code.

Pada tanggal Jum, 18 Des 2020 pukul 00.53 Rafael Henrique < notifications@github.com> menulis:

i really suggest something like that:

func (wac *Conn) BlockContact(jid string) (<-chan string, error) { return wac.handleBlockContact("add", jid) }

func (wac *Conn) UnblockContact(jid string) (<-chan string, error) { return wac.handleBlockContact("remove", jid) }

func (wac *Conn) handleBlockContact(action, jid string) (<-chan string, error) { ts := time.Now().Unix() tag := fmt.Sprintf("%d.--%d", ts, wac.msgCount)

netsplit := strings.Split(jid, "@") cusjid := netsplit[0] + "@c.us"

n := binary.Node{ Description: "action", Attributes: map[string]string{ "type": "set", "epoch": strconv.Itoa(wac.msgCount), }, Content: []interface{}{ binary.Node{ Description: "block", Attributes: map[string]string{ "type": action, }, Content: []binary.Node{ { Description: "user", Attributes: map[string]string{ "jid": cusjid, }, Content: nil, }, }, }, }, }

return wac.writeBinary(n, contact, ignore, tag) }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Rhymen/go-whatsapp/pull/497#issuecomment-747598099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJQBE7KDQBEGW2IHY54OH23SVJAQNANCNFSM4UZFI2YA .

jeremia49 commented 3 years ago

Done 😃

beshoo commented 3 years ago

I like this PL, but we need to get more approval from the community, I don't have time to test it, but it seems fine for me. Let's wait and see who thumps up will be.

Happy Christmases

jeremia49 commented 3 years ago

Ok, thanks 😊

Merry Christmas

On Sun, Dec 27, 2020, 12:12 AM beshoo notifications@github.com wrote:

I like this PL, but we need to get more approval from the community, I don't have time to test it, but it seems fine for me. Let's wait and see who thumps up will be.

Happy Christmases

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Rhymen/go-whatsapp/pull/497#issuecomment-751370426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJQBE7KOF4HK4Q3K57VT23LSWYDQBANCNFSM4UZFI2YA .

DonovanDiamond commented 3 years ago

I think this is great!

beshoo commented 3 years ago

I still have no time to test this PL. @DonovanDiamond @Diden05 did you test it?

jeremia49 commented 3 years ago

I have tested it several times and it's working fine

(sorry for my bad English)