Browse Source

Notify user of stuff going on in backends (not done for FB Messenger)

master
Alex 9 months ago
parent
commit
aa6c5628e9
5 changed files with 14 additions and 10 deletions
  1. +5
    -1
      account.go
  2. +3
    -0
      connector/connector.go
  3. +2
    -3
      connector/irc/irc.go
  4. +1
    -1
      connector/mattermost/mattermost.go
  5. +3
    -5
      connector/xmpp/xmpp.go

+ 5
- 1
account.go View File

@ -182,7 +182,7 @@ func LoadDbAccounts(mxid string, key *[32]byte) {
func (a *Account) ezbrMessagef(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
msg = fmt.Sprintf("%s: %s", a.Protocol, msg)
msg = fmt.Sprintf("%s %s: %s", a.Protocol, a.AccountName, msg)
ezbrSystemSend(a.MatrixUser, msg)
}
@ -231,6 +231,10 @@ func (a *Account) delAutojoin(roomId RoomID) {
// ---- Begin event handlers ----
func (a *Account) SystemMessage(msg string) {
a.ezbrMessagef("%s", msg)
}
func (a *Account) SaveConfig(config Configuration) {
a.Config = config
if key, ok := userKeys[a.MatrixUser]; ok {

+ 3
- 0
connector/connector.go View File

@ -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)

+ 2
- 3
connector/irc/irc.go View File

@ -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
}

+ 1
- 1
connector/mattermost/mattermost.go View File

@ -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()

+ 3
- 5
connector/xmpp/xmpp.go View File

@ -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))
}
}
}

Loading…
Cancel
Save