aboutsummaryrefslogtreecommitdiff
path: root/connector/external
diff options
context:
space:
mode:
Diffstat (limited to 'connector/external')
-rw-r--r--connector/external/external.go29
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,