From 31bba8d946940df4858818f5efcc31cfd5a0a035 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 17 Feb 2020 21:04:21 +0100 Subject: Talking to Easybridge is now possible for some things --- connector/connector.go | 1 + connector/irc/irc.go | 8 ++++++-- connector/xmpp/xmpp.go | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'connector') diff --git a/connector/connector.go b/connector/connector.go index 2b54258..5df010a 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -49,6 +49,7 @@ type Connector interface { Join(roomId RoomID) error // Try to invite someone to a channel + // Or if roomId == "", just try adding them as friends Invite(user UserID, roomId RoomID) error // Leave a channel diff --git a/connector/irc/irc.go b/connector/irc/irc.go index 318c663..aa9723f 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -102,7 +102,7 @@ func (irc *IRC) User() UserID { func (irc *IRC) checkRoomId(id RoomID) (string, error) { x := strings.Split(string(id), "@") - if len(x) != 2 || x[1] != irc.server || x[0][0] != '#' { + if x[0][0] != '#' || (len(x) == 2 && x[1] != irc.server) { return "", fmt.Errorf("Invalid room ID: %s", id) } return x[0], nil @@ -110,7 +110,7 @@ func (irc *IRC) checkRoomId(id RoomID) (string, error) { func (irc *IRC) checkUserId(id UserID) (string, error) { x := strings.Split(string(id), "@") - if len(x) != 2 || x[1] != irc.server || x[0][0] == '#' { + if x[0][0] == '#' || (len(x) == 2 && x[1] != irc.server) { return "", fmt.Errorf("Invalid user ID: %s", id) } return x[0], nil @@ -149,6 +149,10 @@ func (irc *IRC) Join(roomId RoomID) error { } func (irc *IRC) Invite(userId UserID, roomId RoomID) error { + if roomId == "" { + return nil + } + ch, err := irc.checkRoomId(roomId) if err != nil { return err diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index caeb993..b18e670 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -294,6 +294,11 @@ func (xm *XMPP) Join(roomId RoomID) error { } func (xm *XMPP) Invite(userId UserID, roomId RoomID) error { + if roomId == "" { + xm.conn.RequestSubscription(string(userId)) + xm.conn.ApproveSubscription(string(userId)) + return nil + } // TODO return fmt.Errorf("Not implemented") } -- cgit v1.2.3