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

This commit is contained in:
Alex 2020-05-04 18:36:55 +02:00
parent 1d54a50c31
commit aa6c5628e9
5 changed files with 14 additions and 10 deletions

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 {

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)

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
}

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

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