|
@@ -107,6 +107,7 @@ func (client *Client) AllSessionData(currentSession *Session, hasPrivs bool) (da
|
107
|
107
|
}
|
108
|
108
|
|
109
|
109
|
func (client *Client) AddSession(session *Session) (success bool, numSessions int, lastSeen time.Time, back bool) {
|
|
110
|
+ config := client.server.Config()
|
110
|
111
|
client.stateMutex.Lock()
|
111
|
112
|
defer client.stateMutex.Unlock()
|
112
|
113
|
|
|
@@ -126,11 +127,12 @@ func (client *Client) AddSession(session *Session) (success bool, numSessions in
|
126
|
127
|
client.setLastSeen(time.Now().UTC(), session.deviceID)
|
127
|
128
|
}
|
128
|
129
|
client.sessions = newSessions
|
129
|
|
- if client.autoAway {
|
130
|
|
- back = true
|
131
|
|
- client.autoAway = false
|
132
|
|
- client.away = false
|
|
130
|
+ // TODO(#1551) there should be a cap to opt out of this behavior on a session
|
|
131
|
+ if persistenceEnabled(config.Accounts.Multiclient.AutoAway, client.accountSettings.AutoAway) {
|
133
|
132
|
client.awayMessage = ""
|
|
133
|
+ if len(client.sessions) == 1 {
|
|
134
|
+ back = true
|
|
135
|
+ }
|
134
|
136
|
}
|
135
|
137
|
return true, len(client.sessions), lastSeen, back
|
136
|
138
|
}
|
|
@@ -196,20 +198,54 @@ func (client *Client) Hostname() string {
|
196
|
198
|
|
197
|
199
|
func (client *Client) Away() (result bool, message string) {
|
198
|
200
|
client.stateMutex.Lock()
|
199
|
|
- result, message = client.away, client.awayMessage
|
|
201
|
+ message = client.awayMessage
|
200
|
202
|
client.stateMutex.Unlock()
|
|
203
|
+ result = client.awayMessage != ""
|
201
|
204
|
return
|
202
|
205
|
}
|
203
|
206
|
|
204
|
|
-func (client *Client) SetAway(away bool, awayMessage string) (changed bool) {
|
|
207
|
+func (session *Session) SetAway(awayMessage string) {
|
|
208
|
+ client := session.client
|
|
209
|
+ config := client.server.Config()
|
|
210
|
+
|
205
|
211
|
client.stateMutex.Lock()
|
206
|
|
- changed = away != client.away
|
207
|
|
- client.away = away
|
208
|
|
- client.awayMessage = awayMessage
|
209
|
|
- client.stateMutex.Unlock()
|
|
212
|
+ defer client.stateMutex.Unlock()
|
|
213
|
+
|
|
214
|
+ session.awayMessage = awayMessage
|
|
215
|
+ session.awayAt = time.Now().UTC()
|
|
216
|
+
|
|
217
|
+ autoAway := client.registered && client.alwaysOn && persistenceEnabled(config.Accounts.Multiclient.AutoAway, client.accountSettings.AutoAway)
|
|
218
|
+ if autoAway {
|
|
219
|
+ client.setAutoAwayNoMutex(config)
|
|
220
|
+ } else {
|
|
221
|
+ client.awayMessage = awayMessage
|
|
222
|
+ }
|
210
|
223
|
return
|
211
|
224
|
}
|
212
|
225
|
|
|
226
|
+func (client *Client) setAutoAwayNoMutex(config *Config) {
|
|
227
|
+ // aggregate the away statuses of the individual sessions:
|
|
228
|
+ var globalAwayState string
|
|
229
|
+ var awaySetAt time.Time
|
|
230
|
+ for _, cSession := range client.sessions {
|
|
231
|
+ if cSession.awayMessage == "" {
|
|
232
|
+ // a session is active, we are not auto-away
|
|
233
|
+ client.awayMessage = ""
|
|
234
|
+ return
|
|
235
|
+ } else if cSession.awayAt.After(awaySetAt) {
|
|
236
|
+ // choose the latest available away message from any session
|
|
237
|
+ globalAwayState = cSession.awayMessage
|
|
238
|
+ awaySetAt = cSession.awayAt
|
|
239
|
+ }
|
|
240
|
+ }
|
|
241
|
+ if awaySetAt.IsZero() {
|
|
242
|
+ // no sessions, enable auto-away
|
|
243
|
+ client.awayMessage = config.languageManager.Translate(client.languages, `User is currently disconnected`)
|
|
244
|
+ } else {
|
|
245
|
+ client.awayMessage = globalAwayState
|
|
246
|
+ }
|
|
247
|
+}
|
|
248
|
+
|
213
|
249
|
func (client *Client) AlwaysOn() (alwaysOn bool) {
|
214
|
250
|
client.stateMutex.RLock()
|
215
|
251
|
alwaysOn = client.registered && client.alwaysOn
|
|
@@ -269,12 +305,6 @@ func (client *Client) AwayMessage() (result string) {
|
269
|
305
|
return
|
270
|
306
|
}
|
271
|
307
|
|
272
|
|
-func (client *Client) SetAwayMessage(message string) {
|
273
|
|
- client.stateMutex.Lock()
|
274
|
|
- client.awayMessage = message
|
275
|
|
- client.stateMutex.Unlock()
|
276
|
|
-}
|
277
|
|
-
|
278
|
308
|
func (client *Client) Account() string {
|
279
|
309
|
client.stateMutex.RLock()
|
280
|
310
|
defer client.stateMutex.RUnlock()
|