store.go 756 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package whatsapp
  2. import (
  3. "github.com/Rhymen/go-whatsapp/binary"
  4. "strings"
  5. )
  6. type Store struct {
  7. Contacts map[string]Contact
  8. }
  9. type Contact struct {
  10. Jid string
  11. Notify string
  12. Name string
  13. Short string
  14. }
  15. func newStore() *Store {
  16. return &Store{
  17. make(map[string]Contact),
  18. }
  19. }
  20. func (wac *Conn) updateContacts(contacts interface{}) {
  21. c, ok := contacts.([]interface{})
  22. if !ok {
  23. return
  24. }
  25. for _, contact := range c {
  26. contactNode, ok := contact.(binary.Node)
  27. if !ok {
  28. continue
  29. }
  30. jid := strings.Replace(contactNode.Attributes["jid"], "@c.us", "@s.whatsapp.net", 1)
  31. wac.Store.Contacts[jid] = Contact{
  32. jid,
  33. contactNode.Attributes["notify"],
  34. contactNode.Attributes["name"],
  35. contactNode.Attributes["short"],
  36. }
  37. }
  38. }