add gs
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
local ThumbnailRequest = {}
|
||||
|
||||
function ThumbnailRequest.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function ThumbnailRequest.fromData(thumbnailType, thumbnailSize)
|
||||
local self = ThumbnailRequest.new()
|
||||
|
||||
self.thumbnailType = thumbnailType
|
||||
self.thumbnailSize = thumbnailSize
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return ThumbnailRequest
|
||||
@@ -0,0 +1,117 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local MockId = require(CorePackages.AppTempCommon.LuaApp.MockId)
|
||||
|
||||
local FFlagFixUsersReducerDataLoss = settings():GetFFlag("FixUsersReducerDataLoss")
|
||||
|
||||
local User = {}
|
||||
|
||||
User.PresenceType = {
|
||||
OFFLINE = "OFFLINE",
|
||||
ONLINE = "ONLINE",
|
||||
IN_GAME = "IN_GAME",
|
||||
IN_STUDIO = "IN_STUDIO",
|
||||
}
|
||||
|
||||
function User.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function User.mock()
|
||||
local self = User.new()
|
||||
|
||||
self.id = MockId()
|
||||
|
||||
self.isFetching = false
|
||||
self.isFriend = false
|
||||
self.lastLocation = nil
|
||||
self.name = "USER NAME"
|
||||
self.universeId = nil
|
||||
self.placeId = nil
|
||||
self.rootPlaceId = nil
|
||||
self.gameInstanceId = nil
|
||||
self.lastOnline = 0
|
||||
self.presence = User.PresenceType.OFFLINE
|
||||
self.membership = nil
|
||||
if not FFlagFixUsersReducerDataLoss then
|
||||
self.thumbnails = {}
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function User.fromData(id, name, isFriend)
|
||||
local self = User.new()
|
||||
|
||||
self.id = tostring(id)
|
||||
|
||||
self.isFetching = false
|
||||
self.isFriend = isFriend
|
||||
self.lastLocation = nil
|
||||
self.name = name
|
||||
self.universeId = nil
|
||||
self.placeId = nil
|
||||
self.rootPlaceId = nil
|
||||
self.gameInstanceId = nil
|
||||
self.lastOnline = 0
|
||||
if FFlagFixUsersReducerDataLoss then
|
||||
self.presence = (self.id == tostring(Players.LocalPlayer.UserId)) and User.PresenceType.ONLINE or nil
|
||||
else
|
||||
self.presence = (self.id == tostring(Players.LocalPlayer.UserId)) and User.PresenceType.ONLINE or
|
||||
User.PresenceType.OFFLINE
|
||||
self.thumbnails = {}
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function User.compare(user1, user2)
|
||||
assert(not(user1 == nil and user2 == nil))
|
||||
assert(user1 == nil or typeof(user1) == "table")
|
||||
assert(user2 == nil or typeof(user2) == "table")
|
||||
|
||||
-- Return false if any of the provided input is nil(empty).
|
||||
if not user1 or not user2 then
|
||||
return false
|
||||
end
|
||||
|
||||
for field, valueInUser2 in pairs(user2) do
|
||||
if user1[field] ~= valueInUser2 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
for field, valueInUser1 in pairs(user1) do
|
||||
if user2[field] ~= valueInUser1 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function User.userPresenceToText(localization, user)
|
||||
local presence = user.presence
|
||||
local lastLocation = user.lastLocation
|
||||
|
||||
if not presence then
|
||||
return ''
|
||||
end
|
||||
|
||||
if presence == User.PresenceType.OFFLINE then
|
||||
return localization:Format("Common.Presence.Label.Offline")
|
||||
elseif presence == User.PresenceType.ONLINE then
|
||||
return localization:Format("Common.Presence.Label.Online")
|
||||
elseif (presence == User.PresenceType.IN_GAME) or (presence == User.PresenceType.IN_STUDIO) then
|
||||
if lastLocation ~= nil then
|
||||
return lastLocation
|
||||
else
|
||||
return localization:Format("Common.Presence.Label.Online")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return User
|
||||
@@ -0,0 +1,68 @@
|
||||
return function()
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
local User = require(CorePackages.AppTempCommon.LuaApp.Models.User)
|
||||
|
||||
it("should detect if provided users are identical", function()
|
||||
local clone1 = User.fromData(1, "Andy", true)
|
||||
local clone2 = Immutable.Set(clone1, "isFriend", true)
|
||||
|
||||
local result = User.compare(clone1, clone2)
|
||||
expect(result).to.equal(true)
|
||||
|
||||
result = User.compare(clone2, clone1)
|
||||
expect(result).to.equal(true)
|
||||
end)
|
||||
|
||||
it("should detect when there is one or more fields with different values", function()
|
||||
local andy = User.fromData(1, "Andy", true)
|
||||
local ollie = Immutable.Set(andy, "name", "Ollie")
|
||||
|
||||
local result = User.compare(andy, ollie)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
result = User.compare(ollie, andy)
|
||||
expect(result).to.equal(false)
|
||||
end)
|
||||
|
||||
it("should detect descrepancy when one user model contains more fields than the other", function()
|
||||
local andy = User.fromData(1, "Andy", true)
|
||||
local secretlyNotAndy = Immutable.Set(andy, "someDifferentField", "I'm Ollie!")
|
||||
|
||||
local result = User.compare(andy, secretlyNotAndy)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
result = User.compare(secretlyNotAndy, andy)
|
||||
expect(result).to.equal(false)
|
||||
end)
|
||||
|
||||
it("should throw if invalid input is provided", function()
|
||||
local aString = "I'm not a table."
|
||||
local teddy = User.fromData(1, "Teddy", true)
|
||||
|
||||
expect(function() User.compare(nil, nil) end).to.throw()
|
||||
expect(function() User.compare(aString, nil) end).to.throw()
|
||||
expect(function() User.compare(nil, aString) end).to.throw()
|
||||
expect(function() User.compare(aString, aString) end).to.throw()
|
||||
expect(function() User.compare(teddy, aString) end).to.throw()
|
||||
expect(function() User.compare(aString, teddy) end).to.throw()
|
||||
end)
|
||||
|
||||
it("should return false if any one of the input is empty or nil)", function()
|
||||
local emptyTable = {}
|
||||
local teddy = User.fromData(1, "Teddy", true)
|
||||
|
||||
local result = User.compare(teddy, nil)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
result = User.compare(nil, teddy)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
result = User.compare(teddy, emptyTable)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
result = User.compare(emptyTable, teddy)
|
||||
expect(result).to.equal(false)
|
||||
end)
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user