/
UserInfoService.lua
77 lines (56 loc) · 1.71 KB
/
UserInfoService.lua
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--[=[
Centralized provider for user info so we can coordinate web requests.
@class UserInfoService
]=]
local require = require(script.Parent.loader).load(script)
local UserInfoAggregator = require("UserInfoAggregator")
local Maid = require("Maid")
local UserInfoService = {}
UserInfoService.ServiceName = "UserInfoService"
function UserInfoService:Init(serviceBag)
assert(not self._serviceBag, "Already initialized")
self._serviceBag = assert(serviceBag, "No serviceBag")
self._maid = Maid.new()
self._aggregator = self._maid:Add(UserInfoAggregator.new())
end
--[=[
Promises the user info for the given user, aggregating all requests to reduce
calls into Roblox.
@param userId number
@return Promise<UserInfo>
]=]
function UserInfoService:PromiseUserInfo(userId)
assert(type(userId) == "number", "Bad userId")
return self._aggregator:PromiseUserInfo(userId)
end
--[=[
Observes the user info for the user
@param userId number
@return Observable<UserInfo>
]=]
function UserInfoService:ObserveUserInfo(userId)
assert(type(userId) == "number", "Bad userId")
return self._aggregator:ObserveDisplayName(userId)
end
--[=[
Promises the user display name for the userId
@param userId number
@return Promise<string>
]=]
function UserInfoService:PromiseDisplayName(userId)
assert(type(userId) == "number", "Bad userId")
return self._aggregator:PromiseDisplayName(userId)
end
--[=[
Observes the user display name for the userId
@param userId number
@return Observable<string>
]=]
function UserInfoService:ObserveDisplayName(userId)
assert(type(userId) == "number", "Bad userId")
return self._aggregator:ObserveDisplayName(userId)
end
function UserInfoService:Destroy()
self._maid:DoCleaning()
end
return UserInfoService