diff options
author | Alex Auvolat <alex@adnab.me> | 2020-03-09 17:41:53 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-03-09 17:41:53 +0100 |
commit | f9e0c58f3c0e90b987b7763f020ea5dcbf366779 (patch) | |
tree | da02fdd4d02ec2631736757e3fc2cf8dbbd3e2d5 /connector/external | |
parent | 0d6fa02a782a5679716a0244098697af756d0699 (diff) | |
download | easybridge-f9e0c58f3c0e90b987b7763f020ea5dcbf366779.tar.gz easybridge-f9e0c58f3c0e90b987b7763f020ea5dcbf366779.zip |
Fix revUserId (messenger) and implement search (messenger only for now)
Diffstat (limited to 'connector/external')
-rw-r--r-- | connector/external/external.go | 29 |
1 files changed, 27 insertions, 2 deletions
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, |