-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.rb
More file actions
32 lines (25 loc) · 681 Bytes
/
user.rb
File metadata and controls
32 lines (25 loc) · 681 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
require 'sequel'
AWAY_MINS = Rational(ENV.fetch("USER_AWAY_THRESHOLD", 5),24*60)
class User < Sequel::Model
def self.new_from_params(name, zulip_id, email, mac)
# TODO: handle dupes
User.create({name: name, zulip_id: zulip_id, email: email, mac: mac})
end
def self.seen_recently
return User.all if ENV["RACK_ENV"] == "development"
# find users seen within the last 10 minutes
User.where { |u| u.last_seen > ( DateTime.now - AWAY_MINS) }.all
end
def self.seen_recently_printable
seen_recently.map { |u| u.name }
end
def seen!
set(last_seen: DateTime.now)
save
end
end
class NoUser
def name
"No registered users"
end
end