From 347854dc8cffe1deb745a11f4dcf20d547bd782f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 30 Aug 2018 01:10:03 +0300 Subject: [PATCH] Update dependencies --- Gopkg.lock | 8 +++---- Gopkg.toml | 2 +- vendor/github.com/Rhymen/go-whatsapp/conn.go | 6 +++++ .../github.com/Rhymen/go-whatsapp/session.go | 16 ++++++++++++-- vendor/maunium.net/go/gomatrix/events.go | 22 ++++++++++++++----- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 41db0d9..5334d34 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,7 +2,7 @@ [[projects]] - branch = "master" + branch = "develop" name = "github.com/Rhymen/go-whatsapp" packages = [ ".", @@ -13,7 +13,7 @@ "crypto/curve25519", "crypto/hkdf" ] - revision = "82b902133ab6093f864dfc11fb9c5648f82f0ee9" + revision = "00ef431f94f17f125f842d0c7d4e9b68294c6559" source = "github.com/tulir/go-whatsapp" [[projects]] @@ -123,7 +123,7 @@ ".", "format" ] - revision = "42a3133c4980e4b1ea5fb52329d977f592d67cf0" + revision = "b018830e10612c04065723de7aa49f35b37864a6" [[projects]] branch = "master" @@ -146,6 +146,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "8b494649cb598fd6a3862d4de5946f464288424b6e6e561e2b32c8d0ea1cb634" + inputs-digest = "16c945243c327e861a6dc4fa2b43010d00453b8ee71427b95fb5dfcc6cb6ebee" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 926c998..6d31530 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -26,7 +26,7 @@ [[constraint]] - branch = "master" + branch = "develop" name = "github.com/Rhymen/go-whatsapp" source = "github.com/tulir/go-whatsapp" diff --git a/vendor/github.com/Rhymen/go-whatsapp/conn.go b/vendor/github.com/Rhymen/go-whatsapp/conn.go index de9720e..1038f63 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/conn.go +++ b/vendor/github.com/Rhymen/go-whatsapp/conn.go @@ -89,6 +89,9 @@ type Conn struct { Info *Info Store *Store ServerLastSeen time.Time + + longClientName string + shortClientName string } type wsMsg struct { @@ -122,6 +125,9 @@ func NewConn(timeout time.Duration) (*Conn, error) { msgCount: 0, msgTimeout: timeout, Store: newStore(), + + longClientName: "github.com/rhymen/go-whatsapp", + shortClientName: "go-whatsapp", } go wac.readPump() diff --git a/vendor/github.com/Rhymen/go-whatsapp/session.go b/vendor/github.com/Rhymen/go-whatsapp/session.go index 34693d4..1a8c8f3 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/session.go +++ b/vendor/github.com/Rhymen/go-whatsapp/session.go @@ -84,6 +84,18 @@ func newInfoFromReq(info map[string]interface{}) *Info { return ret } +/* +SetClientName sets the long and short client names that are sent to WhatsApp when logging in and displayed in the +WhatsApp Web device list. As the values are only sent when logging in, changing them after logging in is not possible. + */ +func (wac *Conn) SetClientName(long, short string) error { + if wac.session != nil && (wac.session.EncKey != nil || wac.session.MacKey != nil) { + return fmt.Errorf("cannot change client name after logging in") + } + wac.longClientName, wac.shortClientName = long, short + return nil +} + /* Login is the function that creates a new whatsapp session and logs you in. If you do not want to scan the qr code every time, you should save the returned session and use RestoreSession the next time. Login takes a writable channel @@ -122,7 +134,7 @@ func (wac *Conn) Login(qrChan chan<- string) (Session, error) { session.ClientId = base64.StdEncoding.EncodeToString(clientId) //oldVersion=8691 - login := []interface{}{"admin", "init", []int{0, 3, 225}, []string{"github.com/rhymen/go-whatsapp", "go-whatsapp"}, session.ClientId, true} + login := []interface{}{"admin", "init", []int{0, 3, 225}, []string{wac.longClientName, wac.shortClientName}, session.ClientId, true} loginChan, err := wac.write(login) if err != nil { return session, fmt.Errorf("error writing login: %v\n", err) @@ -235,7 +247,7 @@ func (wac *Conn) RestoreSession(session Session) (Session, error) { wac.listener["s1"] = make(chan string, 1) //admin init - init := []interface{}{"admin", "init", []int{0, 3, 225}, []string{"github.com/rhymen/go-whatsapp", "go-whatsapp"}, session.ClientId, true} + init := []interface{}{"admin", "init", []int{0, 3, 225}, []string{wac.longClientName, wac.shortClientName}, session.ClientId, true} initChan, err := wac.write(init) if err != nil { wac.session = nil diff --git a/vendor/maunium.net/go/gomatrix/events.go b/vendor/maunium.net/go/gomatrix/events.go index 9b4ef3e..b9f98f7 100644 --- a/vendor/maunium.net/go/gomatrix/events.go +++ b/vendor/maunium.net/go/gomatrix/events.go @@ -11,7 +11,19 @@ type EventType struct { } func (et *EventType) UnmarshalJSON(data []byte) error { - return json.Unmarshal(data, &et.Type) + err := json.Unmarshal(data, &et.Type) + if err != nil { + return err + } + + switch et.Type { + case StateAliases.Type, StateCanonicalAlias.Type, StateCreate.Type, StateJoinRules.Type, StateMember.Type, + StatePowerLevels.Type, StateRoomName.Type, StateRoomAvatar.Type, StateTopic.Type, StatePinnedEvents.Type: + et.IsState = true + default: + et.IsState = false + } + return nil } func (et *EventType) MarshalJSON() ([]byte, error) { @@ -199,7 +211,7 @@ type PowerLevels struct { UsersDefault int `json:"users_default,omitempty"` eventsLock sync.RWMutex `json:"-"` - Events map[EventType]int `json:"events,omitempty"` + Events map[string]int `json:"events,omitempty"` EventsDefault int `json:"events_default,omitempty"` StateDefaultPtr *int `json:"state_default,omitempty"` @@ -277,7 +289,7 @@ func (pl *PowerLevels) EnsureUserLevel(userID string, level int) bool { func (pl *PowerLevels) GetEventLevel(eventType EventType) int { pl.eventsLock.RLock() defer pl.eventsLock.RUnlock() - level, ok := pl.Events[eventType] + level, ok := pl.Events[eventType.String()] if !ok { if eventType.IsState { return pl.StateDefault() @@ -291,9 +303,9 @@ func (pl *PowerLevels) SetEventLevel(eventType EventType, level int) { pl.eventsLock.Lock() defer pl.eventsLock.Unlock() if (eventType.IsState && level == pl.StateDefault()) || (!eventType.IsState && level == pl.EventsDefault) { - delete(pl.Events, eventType) + delete(pl.Events, eventType.String()) } else { - pl.Events[eventType] = level + pl.Events[eventType.String()] = level } }