aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
Diffstat (limited to 'connector')
-rw-r--r--connector/connector.go8
-rw-r--r--connector/external/external.go29
-rw-r--r--connector/irc/irc.go5
-rw-r--r--connector/mattermost/mattermost.go5
-rw-r--r--connector/xmpp/xmpp.go5
5 files changed, 50 insertions, 2 deletions
diff --git a/connector/connector.go b/connector/connector.go
index 48fc9e7..c2edda4 100644
--- a/connector/connector.go
+++ b/connector/connector.go
@@ -59,6 +59,9 @@ type Connector interface {
// Leave a channel
Leave(roomId RoomID)
+ // Search for users
+ SearchForUsers(query string) ([]UserSearchResult, error)
+
// Send an event. Returns the ID of the created remote message.
// This ID is used to deduplicate messages: if it comes back, it should have the same Id
// than the one returned here.
@@ -153,6 +156,11 @@ type RoomInfo struct {
Picture SMediaObject `json:"picture"`
}
+type UserSearchResult struct {
+ ID UserID `json:"id"`
+ DisplayName string `json:"display_name"`
+}
+
type MediaObject interface {
Filename() string
Size() int64
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,
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index bf36dfe..cf93893 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -198,6 +198,11 @@ func (irc *IRC) Leave(roomId RoomID) {
irc.conn.Cmd.Part(ch)
}
+func (irc *IRC) SearchForUsers(query string) ([]UserSearchResult, error) {
+ // TODO
+ return nil, fmt.Errorf("Not implemented")
+}
+
func (irc *IRC) Send(event *Event) (string, error) {
if irc.conn == nil {
return "", fmt.Errorf("Not connected")
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 9410126..4490f2a 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -253,6 +253,11 @@ func (mm *Mattermost) Leave(roomId RoomID) {
// Not supported? TODO
}
+func (mm *Mattermost) SearchForUsers(query string) ([]UserSearchResult, error) {
+ // TODO
+ return nil, fmt.Errorf("Not implemented")
+}
+
func (mm *Mattermost) Send(event *Event) (string, error) {
post := &model.Post{
Message: event.Text,
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go
index 1f77fdf..483c75e 100644
--- a/connector/xmpp/xmpp.go
+++ b/connector/xmpp/xmpp.go
@@ -306,6 +306,11 @@ func (xm *XMPP) Leave(roomId RoomID) {
xm.conn.LeaveMUC(string(roomId))
}
+func (xm *XMPP) SearchForUsers(query string) ([]UserSearchResult, error) {
+ // TODO: search roster
+ return nil, fmt.Errorf("Not implemented")
+}
+
func (xm *XMPP) Send(event *Event) (string, error) {
if event.Attachments != nil && len(event.Attachments) > 0 {
for _, at := range event.Attachments {