From f9e0c58f3c0e90b987b7763f020ea5dcbf366779 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 9 Mar 2020 17:41:53 +0100 Subject: Fix revUserId (messenger) and implement search (messenger only for now) --- connector/external/external.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'connector/external') diff --git a/connector/external/external.go b/connector/external/external.go index 637e69e..c40d55b 100644 --- a/connector/external/external.go +++ b/connector/external/external.go @@ -49,6 +49,7 @@ const ( JOIN = "join" INVITE = "invite" LEAVE = "leave" + SEARCH = "search" SEND = "send" CLOSE = "close" @@ -64,8 +65,9 @@ const ( // reply messages // ezbr -> external: all must wait for a reply! // external -> ezbr: only CACHE_GET produces a reply - REP_OK = "rep_ok" - REP_ERROR = "rep_error" + REP_OK = "rep_ok" + REP_SEARCH_RESULTS = "rep_search_results" + REP_ERROR = "rep_error" ) // ---- @@ -226,6 +228,16 @@ func (m *extMessageWithData) UnmarshalJSON(jj []byte) error { } m.Data = &ev.Data return nil + case REP_SEARCH_RESULTS: + var ev struct { + Data []UserSearchResult `json:"data"` + } + err := json.Unmarshal(jj, &ev) + if err != nil { + return err + } + m.Data = ev.Data + return nil case JOINED, LEFT, CACHE_PUT, CACHE_GET, REP_OK, REP_ERROR: return nil default: @@ -428,6 +440,19 @@ func (ext *External) Leave(room RoomID) { } } +func (ext *External) SearchForUsers(query string) ([]UserSearchResult, error) { + rep, err := ext.cmd(extMessage{ + MsgType: SEARCH, + }, query) + if err != nil { + return nil, err + } + if rep.MsgType != REP_SEARCH_RESULTS { + return nil, fmt.Errorf("Invalid result type from external: %s", rep.MsgType) + } + return rep.Data.([]UserSearchResult), nil +} + func (ext *External) Send(event *Event) (string, error) { rep, err := ext.cmd(extMessage{ MsgType: SEND, -- cgit v1.2.3