Rhymen / go-whatsapp

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

Error send first message #542

Closed danielspk closed 3 years ago

danielspk commented 3 years ago

Hello. I see the WASendWithMutex() method use a scope assignment which is not correct:

Original

func WASendWithMutex(jid string, content interface{}) (string, error) {
    mutex, ok := wacMutex[jid]

    if !ok {
        mutex := &sync.Mutex{} // <-- FIX?
        wacMutex[jid] = mutex
    }

    mutex.Lock() // <-- error if ok is false

    // ...
}

Proposal:

func WASendWithMutex(jid string, content interface{}) (string, error) {
    mutex, ok := wacMutex[jid]

    if !ok {
        mutex = &sync.Mutex{} // <-- CHANGE
        wacMutex[jid] = mutex
    }

    mutex.Lock() // <-- work is ok is false

    // ...
}

I am right?

danielspk commented 3 years ago

Sorry, wrong repository