-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusers.go
More file actions
executable file
·36 lines (31 loc) · 936 Bytes
/
users.go
File metadata and controls
executable file
·36 lines (31 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package bus
import (
"time"
"github.com/hexya-erp/hexya/src/models"
"github.com/hexya-erp/hexya/src/models/fields"
"github.com/hexya-erp/pool/h"
"github.com/hexya-erp/pool/m"
"github.com/hexya-erp/pool/q"
)
var fields_User = map[string]models.FieldDefinition{
"IMStatus": fields.Char{
Compute: h.User().Methods().ComputeIMStatus()},
}
// Compute the im_status of the users
func user_ComputeIMStatus(rs m.UserSet) m.UserData {
presence := h.BusPresence().Search(rs.Env(), q.BusPresence().User().Equals(rs)).Limit(1)
res := h.User().NewData().SetIMStatus("offline")
switch {
case time.Since(presence.LastPoll().Time) > disconnectionTimer:
res.SetIMStatus("offline")
case time.Since(presence.LastPresence().Time) > awayTimer:
res.SetIMStatus("away")
default:
res.SetIMStatus("online")
}
return res
}
func init() {
h.User().AddFields(fields_User)
h.User().NewMethod("ComputeIMStatus", user_ComputeIMStatus)
}