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/external/external.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'connector/external') 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