mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
Merge pull request #1218 from slingamn/saset_alwayson.1
clean up always-on state machine
This commit is contained in:
commit
d9cab88780
@ -903,23 +903,6 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
|
||||
am.server.RandomlyRename(currentClient)
|
||||
}
|
||||
}
|
||||
// #1216: we may have created an always-on client
|
||||
if client == nil {
|
||||
config := am.server.Config()
|
||||
if persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, PersistentUnspecified) {
|
||||
accountData, err := am.LoadAccount(account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
am.server.AddAlwaysOnClient(
|
||||
accountData,
|
||||
nil,
|
||||
nil,
|
||||
config.Accounts.defaultUserModes,
|
||||
"",
|
||||
)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1242,7 +1242,9 @@ func (client *Client) destroy(session *Session) {
|
||||
wasReattach := session != nil && session.client != client
|
||||
sessionRemoved := false
|
||||
registered := client.registered
|
||||
alwaysOn := client.alwaysOn
|
||||
// XXX a temporary (reattaching) client can be marked alwaysOn when it logs in,
|
||||
// but then the session attaches to another client and we need to clean it up here
|
||||
alwaysOn := registered && client.alwaysOn
|
||||
|
||||
var remainingSessions int
|
||||
if session == nil {
|
||||
|
@ -203,7 +203,7 @@ func (client *Client) SetAway(away bool, awayMessage string) (changed bool) {
|
||||
|
||||
func (client *Client) AlwaysOn() (alwaysOn bool) {
|
||||
client.stateMutex.Lock()
|
||||
alwaysOn = client.alwaysOn
|
||||
alwaysOn = client.registered && client.alwaysOn
|
||||
client.stateMutex.Unlock()
|
||||
return
|
||||
}
|
||||
@ -290,11 +290,8 @@ func (client *Client) Login(account ClientAccount) {
|
||||
client.account = account.NameCasefolded
|
||||
client.accountName = account.Name
|
||||
client.accountSettings = account.Settings
|
||||
// check `registered` to avoid incorrectly marking a temporary (pre-reattach),
|
||||
// SASL'ing client as always-on
|
||||
if client.registered {
|
||||
// mark always-on here: it will not be respected until the client is registered
|
||||
client.alwaysOn = alwaysOn
|
||||
}
|
||||
client.accountRegDate = account.RegisteredAt
|
||||
return
|
||||
}
|
||||
@ -375,7 +372,7 @@ func (client *Client) SetMode(mode modes.Mode, on bool) bool {
|
||||
func (client *Client) SetRealname(realname string) {
|
||||
client.stateMutex.Lock()
|
||||
client.realname = realname
|
||||
alwaysOn := client.alwaysOn
|
||||
alwaysOn := client.registered && client.alwaysOn
|
||||
client.stateMutex.Unlock()
|
||||
if alwaysOn {
|
||||
client.markDirty(IncludeRealname)
|
||||
|
Loading…
Reference in New Issue
Block a user