From aa6c5628e9b48303826ee0fa5fbb826e2c6cf54f Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 4 May 2020 18:36:55 +0200 Subject: Notify user of stuff going on in backends (not done for FB Messenger) --- connector/connector.go | 3 +++ connector/irc/irc.go | 5 ++--- connector/mattermost/mattermost.go | 2 +- connector/xmpp/xmpp.go | 8 +++----- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'connector') diff --git a/connector/connector.go b/connector/connector.go index fd49c7e..55e0e34 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -79,6 +79,9 @@ type Handler interface { // Called to save updated configuration parameters SaveConfig(config Configuration) + // Called to notify user of stuff going on + SystemMessage(message string) + // Called when a room was joined (automatically or by call to Connector.Join) Joined(roomId RoomID) diff --git a/connector/irc/irc.go b/connector/irc/irc.go index cf93893..bee2bca 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -270,8 +270,7 @@ func (irc *IRC) connectLoop(c *girc.Client) { } if err := c.Connect(); err != nil { irc.connected = false - fmt.Printf("IRC failed to connect / disconnected: %s\n", err) - fmt.Printf("Retrying in %ds\n", irc.timeout) + irc.handler.SystemMessage(fmt.Sprintf("IRC failed to connect / disconnected (%s), reconnecting in %ds", err, irc.timeout)) time.Sleep(time.Duration(irc.timeout) * time.Second) irc.timeout *= 2 if irc.timeout > 600 { @@ -284,7 +283,7 @@ func (irc *IRC) connectLoop(c *girc.Client) { } func (irc *IRC) ircConnected(c *girc.Client, e girc.Event) { - fmt.Printf("ircConnected ^^^^\n") + irc.handler.SystemMessage("Connected to IRC.") irc.timeout = 10 irc.connected = true } diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index 5ec76d0..c42521f 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -345,7 +345,7 @@ func (mm *Mattermost) Close() { } func (mm *Mattermost) handleConnected() { - log.Debugf("(Re-)connected to mattermost: %s@%s ; doing channel sync\n", mm.username, mm.server) + mm.handler.SystemMessage(fmt.Sprintf("(Re-)connected to mattermost (%s@%s), doing channel sync", mm.username, mm.server)) // Initial channel sync chans := mm.conn.GetChannels() diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index a25a31b..64c53d9 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -124,8 +124,7 @@ func (xm *XMPP) connectLoop(num int) { xm.conn, err = options.NewClient() if err != nil { xm.connected = false - log.Debugf("XMPP failed to connect / disconnected: %s\n", err) - log.Debugf("Retrying in %ds\n", xm.timeout) + xm.handler.SystemMessage(fmt.Sprintf("XMPP failed to connect (%s). Retrying in %ds", err, xm.timeout)) time.Sleep(time.Duration(xm.timeout) * time.Second) xm.timeout *= 2 if xm.timeout > 600 { @@ -139,7 +138,7 @@ func (xm *XMPP) connectLoop(num int) { if joined { _, err := xm.conn.JoinMUCNoHistory(muc, xm.nickname) if err != nil { - log.Warnf("Could not rejoin MUC %s after reconnection: %s", muc, err) + xm.handler.SystemMessage(fmt.Sprintf("Could not rejoin MUC %s after reconnection: %s", muc, err)) xm.handler.Left(RoomID(muc)) delete(xm.joinedMUC, muc) } @@ -149,8 +148,7 @@ func (xm *XMPP) connectLoop(num int) { err = xm.handleXMPP() xm.connected = false - log.Debugf("XMPP disconnected: %s\n", err) - log.Debugf("Reconnecting.\n") + xm.handler.SystemMessage(fmt.Sprintf("XMPP disconnected (%s), reconnecting)", err)) } } } -- cgit v1.2.3