1
0
Fork 0
forked from External/ergo

add auto-away

This commit is contained in:
Shivaram Lingamneni 2020-05-19 14:12:20 -04:00
parent b94e7ea985
commit a0f4e90b7e
10 changed files with 97 additions and 26 deletions

View file

@ -48,6 +48,7 @@ type Client struct {
accountRegDate time.Time
accountSettings AccountSettings
away bool
autoAway bool
awayMessage string
brbTimer BrbTimer
channels ChannelSet
@ -393,7 +394,7 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string,
client.resizeHistory(config)
_, err := server.clients.SetNick(client, nil, account.Name)
_, err, _ := server.clients.SetNick(client, nil, account.Name)
if err != nil {
server.logger.Error("internal", "could not establish always-on client", account.Name, err.Error())
return
@ -409,6 +410,12 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string,
// this is *probably* ok as long as the persisted memberships are accurate
server.channels.Join(client, chname, "", true, nil)
}
if persistenceEnabled(config.Accounts.Multiclient.AutoAway, client.accountSettings.AutoAway) {
client.autoAway = true
client.away = true
client.awayMessage = client.t("User is currently disconnected")
}
}
func (client *Client) resizeHistory(config *Config) {
@ -1187,6 +1194,7 @@ func (client *Client) Quit(message string, session *Session) {
// otherwise, destroys one specific session, only destroying the client if it
// has no more sessions.
func (client *Client) destroy(session *Session) {
config := client.server.Config()
var sessionsToDestroy []*Session
client.stateMutex.Lock()
@ -1225,6 +1233,17 @@ func (client *Client) destroy(session *Session) {
client.dirtyBits |= IncludeLastSeen
}
exitedSnomaskSent := client.exitedSnomaskSent
autoAway := false
var awayMessage string
if alwaysOn && remainingSessions == 0 && persistenceEnabled(config.Accounts.Multiclient.AutoAway, client.accountSettings.AutoAway) {
autoAway = true
client.autoAway = true
client.away = true
awayMessage = config.languageManager.Translate(client.languages, `Disconnected from the server`)
client.awayMessage = awayMessage
}
client.stateMutex.Unlock()
// XXX there is no particular reason to persist this state here rather than
@ -1272,6 +1291,10 @@ func (client *Client) destroy(session *Session) {
client.server.stats.Remove(registered, invisible, operator)
}
if autoAway {
dispatchAwayNotify(client, true, awayMessage)
}
if !shouldDestroy {
return
}