Update dependencies

This commit is contained in:
Tulir Asokan 2018-08-30 01:10:03 +03:00
parent 5a1a6f9c3c
commit 347854dc8c
5 changed files with 42 additions and 12 deletions

8
Gopkg.lock generated
View file

@ -2,7 +2,7 @@
[[projects]] [[projects]]
branch = "master" branch = "develop"
name = "github.com/Rhymen/go-whatsapp" name = "github.com/Rhymen/go-whatsapp"
packages = [ packages = [
".", ".",
@ -13,7 +13,7 @@
"crypto/curve25519", "crypto/curve25519",
"crypto/hkdf" "crypto/hkdf"
] ]
revision = "82b902133ab6093f864dfc11fb9c5648f82f0ee9" revision = "00ef431f94f17f125f842d0c7d4e9b68294c6559"
source = "github.com/tulir/go-whatsapp" source = "github.com/tulir/go-whatsapp"
[[projects]] [[projects]]
@ -123,7 +123,7 @@
".", ".",
"format" "format"
] ]
revision = "42a3133c4980e4b1ea5fb52329d977f592d67cf0" revision = "b018830e10612c04065723de7aa49f35b37864a6"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -146,6 +146,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "8b494649cb598fd6a3862d4de5946f464288424b6e6e561e2b32c8d0ea1cb634" inputs-digest = "16c945243c327e861a6dc4fa2b43010d00453b8ee71427b95fb5dfcc6cb6ebee"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -26,7 +26,7 @@
[[constraint]] [[constraint]]
branch = "master" branch = "develop"
name = "github.com/Rhymen/go-whatsapp" name = "github.com/Rhymen/go-whatsapp"
source = "github.com/tulir/go-whatsapp" source = "github.com/tulir/go-whatsapp"

View file

@ -89,6 +89,9 @@ type Conn struct {
Info *Info Info *Info
Store *Store Store *Store
ServerLastSeen time.Time ServerLastSeen time.Time
longClientName string
shortClientName string
} }
type wsMsg struct { type wsMsg struct {
@ -122,6 +125,9 @@ func NewConn(timeout time.Duration) (*Conn, error) {
msgCount: 0, msgCount: 0,
msgTimeout: timeout, msgTimeout: timeout,
Store: newStore(), Store: newStore(),
longClientName: "github.com/rhymen/go-whatsapp",
shortClientName: "go-whatsapp",
} }
go wac.readPump() go wac.readPump()

View file

@ -84,6 +84,18 @@ func newInfoFromReq(info map[string]interface{}) *Info {
return ret 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 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 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) session.ClientId = base64.StdEncoding.EncodeToString(clientId)
//oldVersion=8691 //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) loginChan, err := wac.write(login)
if err != nil { if err != nil {
return session, fmt.Errorf("error writing login: %v\n", err) 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) wac.listener["s1"] = make(chan string, 1)
//admin init //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) initChan, err := wac.write(init)
if err != nil { if err != nil {
wac.session = nil wac.session = nil

View file

@ -11,7 +11,19 @@ type EventType struct {
} }
func (et *EventType) UnmarshalJSON(data []byte) error { 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) { func (et *EventType) MarshalJSON() ([]byte, error) {
@ -199,7 +211,7 @@ type PowerLevels struct {
UsersDefault int `json:"users_default,omitempty"` UsersDefault int `json:"users_default,omitempty"`
eventsLock sync.RWMutex `json:"-"` eventsLock sync.RWMutex `json:"-"`
Events map[EventType]int `json:"events,omitempty"` Events map[string]int `json:"events,omitempty"`
EventsDefault int `json:"events_default,omitempty"` EventsDefault int `json:"events_default,omitempty"`
StateDefaultPtr *int `json:"state_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 { func (pl *PowerLevels) GetEventLevel(eventType EventType) int {
pl.eventsLock.RLock() pl.eventsLock.RLock()
defer pl.eventsLock.RUnlock() defer pl.eventsLock.RUnlock()
level, ok := pl.Events[eventType] level, ok := pl.Events[eventType.String()]
if !ok { if !ok {
if eventType.IsState { if eventType.IsState {
return pl.StateDefault() return pl.StateDefault()
@ -291,9 +303,9 @@ func (pl *PowerLevels) SetEventLevel(eventType EventType, level int) {
pl.eventsLock.Lock() pl.eventsLock.Lock()
defer pl.eventsLock.Unlock() defer pl.eventsLock.Unlock()
if (eventType.IsState && level == pl.StateDefault()) || (!eventType.IsState && level == pl.EventsDefault) { if (eventType.IsState && level == pl.StateDefault()) || (!eventType.IsState && level == pl.EventsDefault) {
delete(pl.Events, eventType) delete(pl.Events, eventType.String())
} else { } else {
pl.Events[eventType] = level pl.Events[eventType.String()] = level
} }
} }