add gs
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
local CoreGui = game:GetService("CoreGui")
|
||||
local Modules = CoreGui.RobloxGui.Modules
|
||||
local LuaApp = Modules.LuaApp
|
||||
|
||||
local MockId = require(LuaApp.MockId)
|
||||
|
||||
local Alert = {}
|
||||
|
||||
Alert.AlertType = {
|
||||
DIALOG = "DIALOG",
|
||||
}
|
||||
|
||||
function Alert.new(titleKey, messageKey, messageArguments, alertType)
|
||||
local self = {}
|
||||
|
||||
self.titleKey = titleKey
|
||||
self.messageKey = messageKey
|
||||
self.messageArguments = messageArguments
|
||||
self.createdAt = tick()
|
||||
self.id = MockId()
|
||||
self.type = alertType
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return Alert
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
local CoreGui = game:GetService("CoreGui")
|
||||
local Modules = CoreGui.RobloxGui.Modules
|
||||
local LuaApp = Modules.LuaApp
|
||||
|
||||
local MockId = require(LuaApp.MockId)
|
||||
|
||||
local AssetInfo = {}
|
||||
|
||||
function AssetInfo.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function AssetInfo.mock(mergeTable)
|
||||
local self = AssetInfo.new(mergeTable)
|
||||
|
||||
self.id = MockId()
|
||||
self.Name = "BarricadeZ"
|
||||
self.AssetId = 1055125381
|
||||
self.AssetTypeId = Enum.AssetType.Place.Value
|
||||
self.Description = "The Best Game Ever"
|
||||
|
||||
if mergeTable ~= nil then
|
||||
for key, value in pairs(mergeTable) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return AssetInfo
|
||||
@@ -0,0 +1,183 @@
|
||||
local CoreGui = game:GetService("CoreGui")
|
||||
local Modules = CoreGui.RobloxGui.Modules
|
||||
local LuaApp = Modules.LuaApp
|
||||
local LuaChat = Modules.LuaChat
|
||||
|
||||
local MockId = require(LuaApp.MockId)
|
||||
local OrderedMap = require(LuaChat.OrderedMap)
|
||||
local Constants = require(LuaChat.Constants)
|
||||
local DateTime = require(LuaChat.DateTime)
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local function getMessageId(message)
|
||||
return message.id
|
||||
end
|
||||
|
||||
local function messageSortPredicate(a, b)
|
||||
local aValue = a.sent:GetUnixTimestamp()
|
||||
local bValue = b.sent:GetUnixTimestamp()
|
||||
|
||||
return aValue < bValue
|
||||
end
|
||||
|
||||
local function sendingMessageSortPredicate(a, b)
|
||||
return a.order < b.order
|
||||
end
|
||||
|
||||
local Conversation = {}
|
||||
|
||||
Conversation.Type = {
|
||||
MULTI_USER_CONVERSATION = "MultiUserConversation",
|
||||
ONE_TO_ONE_CONVERSATION = "OneToOneConversation",
|
||||
}
|
||||
|
||||
function Conversation.IdForFakeOneOnOne(participants)
|
||||
--For any two users, there can only exist a single one-to-one
|
||||
--conversation. We can use this invariant to create a unique id
|
||||
--that persists before and after it's created on the server.
|
||||
local id = Conversation.Type.ONE_TO_ONE_CONVERSATION
|
||||
table.sort(participants)
|
||||
for _, userId in ipairs(participants) do
|
||||
id = id.."-"..tostring(userId)
|
||||
end
|
||||
return id
|
||||
end
|
||||
|
||||
function Conversation.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Conversation.mock(mergeTable)
|
||||
local self = Conversation.new()
|
||||
|
||||
self.messages = OrderedMap.new(getMessageId, messageSortPredicate)
|
||||
self.sendingMessages = OrderedMap.new(getMessageId, sendingMessageSortPredicate)
|
||||
self.id = MockId()
|
||||
--I'm adding a clientId here so that the NewChatGroup view can know that a
|
||||
--conversation was successfully saved. We could also do a callback,
|
||||
--but this seems to fit more cleanly with the flux architecture we're already using
|
||||
--...though we could also create a second store for pending conversations, store.PendingConversations
|
||||
self.clientId = MockId()
|
||||
self.title = ""
|
||||
self.initiator = MockId()
|
||||
self.hasUnreadMessages = false
|
||||
self.conversationType = Conversation.Type.MULTI_USER_CONVERSATION
|
||||
self.participants = {}
|
||||
self.usersTyping = {}
|
||||
self.isUserLeaving = false
|
||||
self.fetchingOlderMessages = false
|
||||
self.fetchedOldestMessage = false
|
||||
self.serverState = Constants.ServerState.NONE
|
||||
self.pinnedGame = {}
|
||||
self.pinnedGame.universeId = MockId()
|
||||
self.pinnedGame.rootPlaceId = MockId()
|
||||
|
||||
self.lastUpdated = DateTime.now()
|
||||
|
||||
self.titleForViewer = "title"
|
||||
self.isDefaultTitle = true
|
||||
|
||||
if mergeTable ~= nil then
|
||||
for key, value in pairs(mergeTable) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Conversation.fromUser(user)
|
||||
|
||||
local self = Conversation.new()
|
||||
|
||||
self.messages = OrderedMap.new(getMessageId, messageSortPredicate)
|
||||
self.sendingMessages = OrderedMap.new(getMessageId, sendingMessageSortPredicate)
|
||||
self.clientId = MockId()
|
||||
self.title = user.name
|
||||
self.initiator = nil
|
||||
self.hasUnreadMessages = false
|
||||
self.conversationType = Conversation.Type.ONE_TO_ONE_CONVERSATION
|
||||
self.participants = { tostring(Players.LocalPlayer.UserId), user.id }
|
||||
self.usersTyping = {}
|
||||
self.isUserLeaving = false
|
||||
self.fetchingOlderMessages = false
|
||||
self.fetchedOldestMessage = false
|
||||
self.serverState = Constants.ServerState.NONE
|
||||
|
||||
self.id = Conversation.IdForFakeOneOnOne(self.participants)
|
||||
|
||||
self.lastUpdated = nil
|
||||
|
||||
self.isDefaultTitle = true
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Conversation.empty(mergeTable)
|
||||
local self = Conversation.new()
|
||||
|
||||
self.id = "-1"
|
||||
self.messages = OrderedMap.new(getMessageId, messageSortPredicate)
|
||||
self.sendingMessages = OrderedMap.new(getMessageId, sendingMessageSortPredicate)
|
||||
self.title = ""
|
||||
self.initiator = "0"
|
||||
self.hasUnreadMessages = false
|
||||
self.conversationType = Conversation.Type.MULTI_USER_CONVERSATION
|
||||
self.participants = {}
|
||||
self.usersTyping = {}
|
||||
self.isUserLeaving = false
|
||||
self.fetchingOlderMessages = false
|
||||
self.serverState = Constants.ServerState.NONE
|
||||
self.pinnedGame = {}
|
||||
|
||||
self.lastUpdated = DateTime.now()
|
||||
|
||||
self.isDefaultTitle = true
|
||||
|
||||
if mergeTable ~= nil then
|
||||
for key, value in pairs(mergeTable) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Conversation.fromWeb(data, clientId)
|
||||
local self = Conversation.new()
|
||||
|
||||
self.messages = OrderedMap.new(getMessageId, messageSortPredicate)
|
||||
self.sendingMessages = OrderedMap.new(getMessageId, sendingMessageSortPredicate)
|
||||
self.id = tostring(data.id)
|
||||
self.clientId = clientId or MockId()
|
||||
self.title = data.title
|
||||
self.initiator = tostring(data.initiator.targetId)
|
||||
self.hasUnreadMessages = data.hasUnreadMessages
|
||||
self.conversationType = data.conversationType
|
||||
self.participants = {}
|
||||
self.usersTyping = {}
|
||||
self.isUserLeaving = false
|
||||
self.fetchingOlderMessages = false
|
||||
self.serverState = Constants.ServerState.CREATED
|
||||
self.pinnedGame = {}
|
||||
if data.conversationUniverse ~= nil then
|
||||
self.pinnedGame.universeId = tostring(data.conversationUniverse.universeId)
|
||||
self.pinnedGame.rootPlaceId = tostring(data.conversationUniverse.rootPlaceId)
|
||||
end
|
||||
|
||||
self.lastUpdated = DateTime.fromIsoDate(data.lastUpdated)
|
||||
|
||||
self.titleForViewer = data.conversationTitle.titleForViewer
|
||||
self.isDefaultTitle = data.conversationTitle.isDefaultTitle
|
||||
|
||||
for _, webParticipant in ipairs(data.participants) do
|
||||
table.insert(self.participants, tostring(webParticipant.targetId))
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return Conversation
|
||||
@@ -0,0 +1,34 @@
|
||||
local GameParams = {}
|
||||
|
||||
function GameParams.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GameParams.fromPlaceId(placeId)
|
||||
local self = GameParams.new()
|
||||
|
||||
self.placeId = placeId
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GameParams.fromUserId(userId)
|
||||
local self = GameParams.new()
|
||||
|
||||
self.userId = userId
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GameParams.fromPlaceInstance(placeId, gameInstanceId)
|
||||
local self = GameParams.new()
|
||||
|
||||
self.placeId = placeId
|
||||
self.gameInstanceId = gameInstanceId
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return GameParams
|
||||
@@ -0,0 +1,122 @@
|
||||
local CoreGui = game:GetService("CoreGui")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local Modules = CoreGui.RobloxGui.Modules
|
||||
local LuaApp = Modules.LuaApp
|
||||
local LuaChat = Modules.LuaChat
|
||||
|
||||
local MockId = require(LuaApp.MockId)
|
||||
local DateTime = require(LuaChat.DateTime)
|
||||
|
||||
local FFlagEnableChatMessageType = settings():GetFFlag("EnableChatMessageType")
|
||||
|
||||
local Message = {}
|
||||
if FFlagEnableChatMessageType then
|
||||
Message = {
|
||||
MessageTypes = {
|
||||
PlainText = 'PlainText'
|
||||
}
|
||||
}
|
||||
Message.__index = Message
|
||||
end
|
||||
|
||||
function Message.new()
|
||||
local self = {}
|
||||
|
||||
if FFlagEnableChatMessageType then
|
||||
setmetatable(self, Message)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
function Message.mock(mergeTable)
|
||||
local self = Message.new()
|
||||
|
||||
self.id = MockId()
|
||||
self.senderTargetId = MockId()
|
||||
self.conversationId = MockId()
|
||||
self.senderType = "MESSAGE SENDERTYPE"
|
||||
self.content = "MESSAGE CONTENT"
|
||||
self.read = false
|
||||
self.sent = DateTime.now()
|
||||
self.previousMessageId = nil
|
||||
self.filteredForReceivers = false
|
||||
|
||||
if mergeTable ~= nil then
|
||||
for key, value in pairs(mergeTable) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Message.fromWeb(data, conversationId, previousMessageId)
|
||||
if FFlagEnableChatMessageType then
|
||||
if not Message.DoRequiredFieldsPresent(data) then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local self = Message.new()
|
||||
self.id = data.id
|
||||
self.senderTargetId = tostring(data.senderTargetId)
|
||||
self.senderType = data.senderType
|
||||
self.read = data.read
|
||||
self.sent = DateTime.fromIsoDate(data.sent)
|
||||
self.conversationId = tostring(conversationId)
|
||||
self.previousMessageId = previousMessageId
|
||||
self.filteredForReceivers = false
|
||||
|
||||
if FFlagEnableChatMessageType then
|
||||
self:parseContent(data)
|
||||
else
|
||||
self.content = data.content
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Message.fromSentWeb(data, conversationId, previousMessageId)
|
||||
if FFlagEnableChatMessageType then
|
||||
if not Message.DoRequiredFieldsPresent(data) then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local self = Message.new()
|
||||
self.id = data.messageId
|
||||
self.senderTargetId = tostring(Players.LocalPlayer.UserId)
|
||||
self.senderType = "User"
|
||||
self.read = true
|
||||
self.sent = DateTime.fromIsoDate(data.sent)
|
||||
self.conversationId = tostring(conversationId)
|
||||
self.previousMessageId = previousMessageId
|
||||
self.filteredForReceivers = data.filteredForReceivers
|
||||
|
||||
if FFlagEnableChatMessageType then
|
||||
self:parseContent(data)
|
||||
else
|
||||
self.content = data.content
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
if FFlagEnableChatMessageType then
|
||||
function Message.DoRequiredFieldsPresent(data)
|
||||
return data and data.id and data.messageType and data.senderTargetId and data.sent
|
||||
end
|
||||
|
||||
function Message:parseContent(data)
|
||||
self.messageType = data.messageType
|
||||
if data.messageType == Message.MessageTypes.PlainText then
|
||||
self.content = data.content
|
||||
else
|
||||
-- UI will decide on which placeholder to use
|
||||
self.content = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Message
|
||||
@@ -0,0 +1,103 @@
|
||||
|
||||
local Message = require(script.Parent.Message)
|
||||
|
||||
local FFlagEnableChatMessageType = settings():GetFFlag("EnableChatMessageType")
|
||||
|
||||
local function createMockResponse(content, contentType)
|
||||
return {
|
||||
messageType = contentType,
|
||||
id = "1-2-3-4",
|
||||
senderTargetId = 987789,
|
||||
senderType = "User",
|
||||
content = content,
|
||||
sent = "2018-09-24T16:22:23.233Z"
|
||||
}
|
||||
end
|
||||
|
||||
return function ()
|
||||
if not FFlagEnableChatMessageType then
|
||||
return
|
||||
end
|
||||
|
||||
describe("WHEN fromWeb factory method is called", function()
|
||||
it("SHOULD not construct from nil response", function()
|
||||
local message = Message.fromWeb(nil, "", "")
|
||||
expect(message).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD not construct from empty response", function()
|
||||
local message = Message.fromWeb({}, "", "")
|
||||
expect(message).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response", function()
|
||||
local mockContent = "mockContent"
|
||||
local message = Message.fromWeb(createMockResponse(mockContent, "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(mockContent)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response with empty content", function()
|
||||
local message = Message.fromWeb(createMockResponse("", "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal("")
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response with nil content", function()
|
||||
local message = Message.fromWeb(createMockResponse(nil, "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from non PlainText message response with placeholder content (TBD, empty for now)", function()
|
||||
local message = Message.fromWeb(createMockResponse(nil, "SomeUnknownContent"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(nil)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("WHEN fromSentWeb factory method is called", function()
|
||||
it("SHOULD not construct from nil response", function()
|
||||
local message = Message.fromSentWeb(nil, "", "")
|
||||
expect(message).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD not construct from empty response", function()
|
||||
local message = Message.fromSentWeb({}, "", "")
|
||||
expect(message).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response", function()
|
||||
local mockContent = "mockContent"
|
||||
local message = Message.fromSentWeb(createMockResponse(mockContent, "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(mockContent)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response with empty content", function()
|
||||
local message = Message.fromSentWeb(createMockResponse("", "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal("")
|
||||
end)
|
||||
|
||||
it("SHOULD construct from PlainText message response with nil content", function()
|
||||
local message = Message.fromSentWeb(createMockResponse(nil, "PlainText"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(nil)
|
||||
end)
|
||||
|
||||
it("SHOULD construct from non PlainText message response with placeholder content (TBD, empty for now)", function()
|
||||
local message = Message.fromSentWeb(createMockResponse(nil, "SomeUnknownContent"), "", "")
|
||||
|
||||
expect(message).to.be.ok()
|
||||
expect(message.content).to.equal(nil)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
-----------------------------------------------------------------------------
|
||||
--- ---
|
||||
--- Under Migration to CorePackages ---
|
||||
--- ---
|
||||
--- Please put your changes in AppTempCommon. ---
|
||||
--- NOTE: You will have to rebuild for changes to kick in ---
|
||||
-----------------------------------------------------------------------------
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
return require(CorePackages.AppTempCommon.LuaChat.Models.PlaceInfoModel)
|
||||
@@ -0,0 +1,9 @@
|
||||
return function(title, pageView, configs)
|
||||
return {
|
||||
title = title,
|
||||
content = {
|
||||
component = pageView,
|
||||
options = configs
|
||||
},
|
||||
}
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
local ThumbnailModel = {}
|
||||
|
||||
function ThumbnailModel.new()
|
||||
local self = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function ThumbnailModel.mock()
|
||||
local self = ThumbnailModel.new()
|
||||
|
||||
self.image = "imageToken"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function ThumbnailModel.fromWeb(data)
|
||||
local self = {}
|
||||
self.image = data or ""
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return ThumbnailModel
|
||||
@@ -0,0 +1,14 @@
|
||||
local ToastModel = {}
|
||||
|
||||
function ToastModel.new(id, messageKey, messageArguments)
|
||||
local self = {}
|
||||
|
||||
self.messageKey = messageKey
|
||||
self.messageArguments = messageArguments
|
||||
self.id = id
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return ToastModel
|
||||
|
||||
Reference in New Issue
Block a user