add gs
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
local RetrievalStatus = require(CorePackages.AppTempCommon.LuaApp.Enum.RetrievalStatus)
|
||||
|
||||
local FetchUserFriendsStarted = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsStarted)
|
||||
local FetchUserFriendsFailed = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsFailed)
|
||||
local FetchUserFriendsCompleted = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsCompleted)
|
||||
|
||||
local function setFieldPerUser(state, fieldName, userId, value)
|
||||
local field = state[fieldName] or {}
|
||||
return Immutable.JoinDictionaries(state, {
|
||||
[fieldName] = Immutable.JoinDictionaries(field, {
|
||||
[userId] = value
|
||||
})
|
||||
})
|
||||
end
|
||||
|
||||
local function setRetrievalStatus(state, userId, status)
|
||||
return setFieldPerUser(state, "retrievalStatus", userId, status)
|
||||
end
|
||||
|
||||
local function setRetrievalFailureResponse(state, userId, response)
|
||||
return setFieldPerUser(state, "retrievalFailureResponse", userId, response)
|
||||
end
|
||||
|
||||
return function(state, action)
|
||||
state = state or {
|
||||
retrievalStatus = {},
|
||||
retrievalFailureResponse = {},
|
||||
}
|
||||
|
||||
if action.type == FetchUserFriendsStarted.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Fetching)
|
||||
elseif action.type == FetchUserFriendsFailed.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Failed)
|
||||
state = setRetrievalFailureResponse(state, action.userId, action.response)
|
||||
elseif action.type == FetchUserFriendsCompleted.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Done)
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
local ReceivedPlacesInfos = require(CorePackages.AppTempCommon.LuaApp.Actions.ReceivedPlacesInfos)
|
||||
|
||||
return function(state, action)
|
||||
state = state or {}
|
||||
|
||||
if action.type == ReceivedPlacesInfos.name then
|
||||
for _, placeInfo in pairs(action.placesInfos) do
|
||||
state = Immutable.Set(state, tostring(placeInfo.universeId), placeInfo)
|
||||
end
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
@@ -0,0 +1,117 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
|
||||
local AddUser = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUser)
|
||||
local AddUsers = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUsers)
|
||||
local ReceivedUserPresence = require(CorePackages.AppTempCommon.LuaChat.Actions.ReceivedUserPresence)
|
||||
local RemoveUser = require(CorePackages.AppTempCommon.LuaApp.Actions.RemoveUser)
|
||||
local SetUserIsFriend = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserIsFriend)
|
||||
local SetUserMembershipType = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserMembershipType)
|
||||
local SetUserPresence = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserPresence)
|
||||
local SetUserThumbnail = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserThumbnail)
|
||||
|
||||
local FFlagFixUsersReducerDataLoss = settings():GetFFlag("FixUsersReducerDataLoss")
|
||||
|
||||
return function(state, action)
|
||||
state = state or {}
|
||||
|
||||
if action.type == AddUser.name then
|
||||
local user = action.user
|
||||
state = Immutable.Set(state, user.id, user)
|
||||
elseif action.type == AddUsers.name then
|
||||
if FFlagFixUsersReducerDataLoss then
|
||||
local addedUsers = action.users
|
||||
local usersUpdate = {}
|
||||
for userId, addedUser in pairs(addedUsers) do
|
||||
local existingUser = state[userId]
|
||||
if existingUser then
|
||||
usersUpdate[userId] = Immutable.JoinDictionaries(existingUser, addedUser)
|
||||
else
|
||||
usersUpdate[userId] = addedUser
|
||||
end
|
||||
end
|
||||
|
||||
state = Immutable.JoinDictionaries(state, usersUpdate)
|
||||
else
|
||||
local users = action.users
|
||||
state = Immutable.JoinDictionaries(state, users)
|
||||
end
|
||||
|
||||
elseif action.type == SetUserIsFriend.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
local newUser = Immutable.Set(user, "isFriend", action.isFriend)
|
||||
state = Immutable.Set(state, user.id, newUser)
|
||||
else
|
||||
warn("Setting isFriend on user", action.userId, "who doesn't exist yet")
|
||||
end
|
||||
elseif action.type == SetUserPresence.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
local newUser = Immutable.JoinDictionaries(user, {
|
||||
presence = action.presence,
|
||||
lastLocation = action.lastLocation,
|
||||
})
|
||||
state = Immutable.Set(state, user.id, newUser)
|
||||
else
|
||||
warn("Setting presence on user", action.userId, "who doesn't exist yet")
|
||||
end
|
||||
elseif action.type == ReceivedUserPresence.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
presence = action.presence,
|
||||
lastLocation = action.lastLocation,
|
||||
placeId = action.placeId,
|
||||
rootPlaceId = action.rootPlaceId,
|
||||
gameInstanceId = action.gameInstanceId,
|
||||
lastOnline = action.lastOnline,
|
||||
universeId = action.universeId,
|
||||
}),
|
||||
})
|
||||
end
|
||||
elseif action.type == SetUserThumbnail.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
if FFlagFixUsersReducerDataLoss then
|
||||
local thumbnails = user.thumbnails or {}
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
thumbnails = Immutable.JoinDictionaries(thumbnails, {
|
||||
[action.thumbnailType] = Immutable.JoinDictionaries(thumbnails[action.thumbnailType] or {}, {
|
||||
[action.thumbnailSize] = action.image,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
else
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
thumbnails = Immutable.JoinDictionaries(user.thumbnails, {
|
||||
[action.thumbnailType] = Immutable.JoinDictionaries(user.thumbnails[action.thumbnailType] or {}, {
|
||||
[action.thumbnailSize] = action.image,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
end
|
||||
end
|
||||
elseif action.type == SetUserMembershipType.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
membership = action.membershipType,
|
||||
}),
|
||||
})
|
||||
end
|
||||
elseif action.type == RemoveUser.name then
|
||||
if state[action.userId] then
|
||||
state = Immutable.RemoveFromDictionary(state, action.userId)
|
||||
end
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
@@ -0,0 +1,106 @@
|
||||
return function()
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local MockId = require(CorePackages.AppTempCommon.LuaApp.MockId)
|
||||
local User = require(CorePackages.AppTempCommon.LuaApp.Models.User)
|
||||
local Users = require(CorePackages.AppTempCommon.LuaApp.Reducers.Users)
|
||||
|
||||
local AddUser = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUser)
|
||||
local ReceivedUserPresence = require(CorePackages.AppTempCommon.LuaChat.Actions.ReceivedUserPresence)
|
||||
local SetUserIsFriend = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserIsFriend)
|
||||
local SetUserMembershipType = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserMembershipType)
|
||||
local SetUserPresence = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserPresence)
|
||||
|
||||
describe("initial state", function()
|
||||
it("should return an initial table when passed nil", function()
|
||||
local state = Users(nil, {})
|
||||
expect(state).to.be.a("table")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("AddUser", function()
|
||||
it("should add a user to the store", function()
|
||||
local user = User.mock()
|
||||
local state = {}
|
||||
|
||||
state = Users(state, AddUser(user))
|
||||
|
||||
expect(state[user.id]).to.equal(user)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserIsFriend", function()
|
||||
it("should set isFriend on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
expect(state[user.id].isFriend).to.equal(false)
|
||||
|
||||
state = Users(state, SetUserIsFriend(user.id, true))
|
||||
expect(state[user.id].isFriend).to.equal(true)
|
||||
|
||||
state = Users(state, SetUserIsFriend(user.id, false))
|
||||
expect(state[user.id].isFriend).to.equal(false)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserPresence", function()
|
||||
it("should set presence on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.OFFLINE)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.ONLINE))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.ONLINE)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.IN_GAME))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.IN_GAME)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.IN_STUDIO))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.IN_STUDIO)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ReceivedUserPresence", function()
|
||||
it("should set presence on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
local existingPresence = user.presence
|
||||
local newPresence = 'ONLINE'
|
||||
local lastLocation = MockId()
|
||||
local newPlaceId = MockId()
|
||||
|
||||
state = Users(state, ReceivedUserPresence(user.id, newPresence, lastLocation, newPlaceId))
|
||||
|
||||
expect(user.presence).to.equal(existingPresence)
|
||||
expect(state[user.id].presence).to.equal(newPresence)
|
||||
expect(state[user.id].lastLocation).to.equal(lastLocation)
|
||||
expect(state[user.id].placeId).to.equal(newPlaceId)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserMembershipType", function()
|
||||
it("should set membership on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
local existingMembership = user.membership
|
||||
local newMembership = Enum.MembershipType.BuildersClub
|
||||
|
||||
state = Users(state, SetUserMembershipType(user.id, newMembership))
|
||||
|
||||
expect(user.membership).to.equal(existingMembership)
|
||||
expect(state[user.id].membership).to.equal(newMembership)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
Reference in New Issue
Block a user