Rhymen / go-whatsapp

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

Get a Message Id for the very last message in a conversation #199

Open mario7lorenzo opened 5 years ago

mario7lorenzo commented 5 years ago

Hi, I would like to ask regarding to getting the messageId value of the very last message in a particular conversation. I want to do this since I want to do a syncing process daily and I think that it is more efficient to get all messages before the last message Id rather than get all messages after the very first message because our message will continuously grow and at a certain big number, we won't be able to fetch more data if we start from the beginning. Are there any suggestions? Thanks.

b4-io commented 5 years ago

not the exact solution but in echo example they add the startime as a variable to the handler. What i do is remove and add handler with current time every time i connect and disconnect.

type waHandler struct{
    c   *whatsapp.Conn
    startTime uint64
}
wac.RemoveHandlers()
wac.AddHandler(&waHandler{wac, uint64(time.Now().Unix())})
session, err := wac.Disconnect()
if err == nil {
//restore session
          fmt.Println("Desconectado")
}
<-time.After(30 * time.Second)
session, err = wac.RestoreWithSession(session)
if err == nil {
    fmt.Println("Conectado")
}
<-time.After(30 * time.Second)