From 7c39436eda59efb033d172dfa03af3782f0acacf Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 9 Mar 2020 18:02:13 +0100 Subject: Save client pickle automatically (messenger) --- connector/connector.go | 3 +++ connector/external/external.go | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'connector') diff --git a/connector/connector.go b/connector/connector.go index c2edda4..fd49c7e 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -76,6 +76,9 @@ type Connector interface { } type Handler interface { + // Called to save updated configuration parameters + SaveConfig(config Configuration) + // Called when a room was joined (automatically or by call to Connector.Join) Joined(roomId RoomID) diff --git a/connector/external/external.go b/connector/external/external.go index c40d55b..9aae0f1 100644 --- a/connector/external/external.go +++ b/connector/external/external.go @@ -54,6 +54,7 @@ const ( CLOSE = "close" // external -> ezbr + SAVE_CONFIG = "save_config" JOINED = "joined" LEFT = "left" USER_INFO_UPDATED = "user_info_updated" @@ -198,6 +199,16 @@ func (m *extMessageWithData) UnmarshalJSON(jj []byte) error { } *m = extMessageWithData{extMessage: c} switch c.MsgType { + case SAVE_CONFIG: + var cf struct { + Data Configuration `json:"data"` + } + err := json.Unmarshal(jj, &cf) + if err != nil { + return err + } + m.Data = cf.Data + return nil case USER_INFO_UPDATED: var ui struct { Data UserInfo `json:"data"` @@ -229,14 +240,14 @@ func (m *extMessageWithData) UnmarshalJSON(jj []byte) error { m.Data = &ev.Data return nil case REP_SEARCH_RESULTS: - var ev struct { + var sr struct { Data []UserSearchResult `json:"data"` } - err := json.Unmarshal(jj, &ev) + err := json.Unmarshal(jj, &sr) if err != nil { return err } - m.Data = ev.Data + m.Data = sr.Data return nil case JOINED, LEFT, CACHE_PUT, CACHE_GET, REP_OK, REP_ERROR: return nil @@ -364,6 +375,8 @@ func (ext *External) Close() { func (ext *External) handleCmd(msg *extMessageWithData) { switch msg.MsgType { + case SAVE_CONFIG: + ext.handler.SaveConfig(msg.Data.(Configuration)) case JOINED: ext.handler.Joined(msg.Room) case LEFT: -- cgit v1.2.3