Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

CLIAVATAR-167: Stop player thumbnails from being NA #863

Merged
merged 6 commits into from May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions CoreScriptsRoot/CoreScripts/BlockPlayerPrompt.lua
Expand Up @@ -18,30 +18,52 @@ end

local CoreGuiModules = RobloxGui:WaitForChild("Modules")
local PromptCreator = require(CoreGuiModules:WaitForChild("PromptCreator"))
local SocialUtil = require(CoreGuiModules:WaitForChild("SocialUtil"))
local PlayerDropDownModule = require(CoreGuiModules:WaitForChild("PlayerDropDown"))
local BlockingUtility = PlayerDropDownModule:CreateBlockingUtility()

local THUMBNAIL_URL = "https://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&format=png&userId="
local BUST_THUMBNAIL_URL = "https://www.roblox.com/bust-thumbnail/image?width=420&height=420&format=png&userId="

local REGULAR_THUMBNAIL_IMAGE_SIZE = Enum.ThumbnailSize.Size420x420
local CONSOLE_THUMBNAIL_IMAGE_SIZE = Enum.ThumbnailSize.Size180x180

local REGULAR_THUMBNAIL_IMAGE_TYPE = Enum.ThumnailType.AvatarBust
local CONSOLE_THUMBNAIL_IMAGE_TYPE = Enum.ThumbnailType.AvatarThumbnail

function createFetchImageFunction(...)
return function(imageLabel)
spawn(function()
local imageUrl = SocialUtil.GetPlayerImage(...)
if imageLabel and imageLabel.Parent then
frame.Icon.Image = imageUrl
end
end)
end
end

function DoPromptBlockPlayer(playerToBlock)
if BlockingUtility:IsPlayerBlockedByUserId(playerToBlock.UserId) then
return
end

local function promptCompletedCallback(clickedConfirm)
if clickedConfirm then
local successfullyBlocked = BlockingUtility:BlockPlayerAsync(playerToBlock)
if not successfullyBlocked then
while PromptCreator:IsCurrentlyPrompting() do
wait()
end

PromptCreator:CreatePrompt({
WindowTitle = "Error Blocking Player",
MainText = string.format("An error occurred while blocking %s. Please try again later.", playerToBlock.Name),
ConfirmationText = "Okay",
CancelActive = false,
Image = BUST_THUMBNAIL_URL ..playerToBlock.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToBlock.UserId,
FetchImageFunction = createFetchImageFunction(playerToBlock.UserId, REGULAR_THUMBNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToBlock.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
end
Expand All @@ -55,6 +77,8 @@ function DoPromptBlockPlayer(playerToBlock)
CancelActive = true,
Image = BUST_THUMBNAIL_URL ..playerToBlock.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToBlock.UserId,
FetchImageFunction = createFetchImageFunction(playerToBlock.UserId, REGULAR_THUMBNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToBlock.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
PromptCompletedCallback = promptCompletedCallback,
})
end
Expand All @@ -80,6 +104,7 @@ function DoPromptUnblockPlayer(playerToUnblock)
if not BlockingUtility:IsPlayerBlockedByUserId(playerToUnblock.UserId) and false then
return
end

local function promptCompletedCallback(clickedConfirm)
if clickedConfirm then
local successfullyUnblocked = BlockingUtility:UnblockPlayerAsync(playerToUnblock)
Expand All @@ -93,11 +118,14 @@ function DoPromptUnblockPlayer(playerToUnblock)
ConfirmationText = "Okay",
Image = BUST_THUMBNAIL_URL ..playerToUnblock.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToUnblock.UserId,
FetchImageFunction = createFetchImageFunction(playerToUnblock.UserId, REGULAR_THUMBNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToUnblock.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
end
end
end

PromptCreator:CreatePrompt({
WindowTitle = "Confirm Unblock",
MainText = string.format("Would you like to unblock %s?", playerToUnblock.Name),
Expand All @@ -106,6 +134,8 @@ function DoPromptUnblockPlayer(playerToUnblock)
CancelActive = true,
Image = BUST_THUMBNAIL_URL ..playerToUnblock.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToUnblock.UserId,
FetchImageFunction = createFetchImageFunction(playerToUnblock.UserId, REGULAR_THUMBNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToUnblock.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
PromptCompletedCallback = promptCompletedCallback,
})
end
Expand Down
29 changes: 29 additions & 0 deletions CoreScriptsRoot/CoreScripts/FriendPlayerPrompt.lua
Expand Up @@ -23,6 +23,23 @@ local PlayerDropDownModule = require(CoreGuiModules:WaitForChild("PlayerDropDown
local THUMBNAIL_URL = "https://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&format=png&userId="
local BUST_THUMBNAIL_URL = "https://www.roblox.com/bust-thumbnail/image?width=420&height=420&format=png&userId="

local REGULAR_THUMBNAIL_IMAGE_SIZE = Enum.ThumbnailSize.Size420x420
local CONSOLE_THUMBNAIL_IMAGE_SIZE = Enum.ThumbnailSize.Size180x180

local REGULAR_THUMBNAIL_IMAGE_TYPE = Enum.ThumnailType.AvatarBust
local CONSOLE_THUMBNAIL_IMAGE_TYPE = Enum.ThumbnailType.AvatarThumbnail

function createFetchImageFunction(...)
return function(imageLabel)
spawn(function()
local imageUrl = SocialUtil.GetPlayerImage(...)
if imageLabel and imageLabel.Parent then
frame.Icon.Image = imageUrl
end
end)
end
end

function SendFriendRequest(playerToFriend)
local success = pcall(function()
LocalPlayer:RequestFriendship(playerToFriend)
Expand Down Expand Up @@ -58,6 +75,8 @@ function DoPromptRequestFriendPlayer(playerToFriend)
CancelActive = false,
Image = BUST_THUMBNAIL_URL ..playerToFriend.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToFriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToFriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToFriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
else
Expand All @@ -69,6 +88,8 @@ function DoPromptRequestFriendPlayer(playerToFriend)
CancelActive = false,
Image = BUST_THUMBNAIL_URL ..playerToFriend.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToFriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToFriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToFriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
else
Expand All @@ -84,6 +105,8 @@ function DoPromptRequestFriendPlayer(playerToFriend)
CancelActive = false,
Image = BUST_THUMBNAIL_URL ..playerToFriend.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToFriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToFriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToFriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
end
Expand All @@ -99,6 +122,8 @@ function DoPromptRequestFriendPlayer(playerToFriend)
CancelActive = true,
Image = BUST_THUMBNAIL_URL ..playerToFriend.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToFriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToFriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToFriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
PromptCompletedCallback = promptCompletedCallback,
})
end
Expand Down Expand Up @@ -145,6 +170,8 @@ function DoPromptUnfriendPlayer(playerToUnfriend)
CancelActive = false,
Image = BUST_THUMBNAIL_URL ..playerToUnfriend.UserId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These images could be updated to get the fallback image from SocialUtil

ImageConsoleVR = THUMBNAIL_URL ..playerToUnfriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToUnfriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToUnfriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
StripeColor = Color3.fromRGB(183, 34, 54),
})
end
Expand All @@ -158,6 +185,8 @@ function DoPromptUnfriendPlayer(playerToUnfriend)
CancelActive = true,
Image = BUST_THUMBNAIL_URL ..playerToUnfriend.UserId,
ImageConsoleVR = THUMBNAIL_URL ..playerToUnfriend.UserId,
FetchImageFunction = createFetchImageFunction(playerToUnfriend.UserId, REGULAR_THUMNAIL_IMAGE_SIZE, REGULAR_THUMBNAIL_IMAGE_TYPE),
FetchImageFunctionConsoleVR = createFetchImageFunction(playerToUnfriend.UserId, CONSOLE_THUMBNAIL_IMAGE_SIZE, CONSOLE_THUMBNAIL_IMAGE_TYPE),
PromptCompletedCallback = promptCompletedCallback,
})
end
Expand Down
18 changes: 15 additions & 3 deletions CoreScriptsRoot/CoreScripts/NotificationScript2.lua
Expand Up @@ -37,6 +37,9 @@ local tenFootBadgeNotifications = getTenFootBadgeNotifications and tenFootBadgeN
local getDisableScreenshotPopup, disableScreenshotPopupValue = pcall(function() return settings():GetFFlag("DisableScreenshotPopup") end)
local disableScreenshotPopup = getDisableScreenshotPopup and disableScreenshotPopupValue

local useNewThumbnailApiSuccess, useNewThumbnailApiValue = pcall(function() return settings():GetFFlag("CoreScriptsUseNewUserThumbnailAPI") end)
local useNewUserThumbnailAPI = useNewThumbnailApiSuccess and useNewThumbnailApiValue

--[[ Script Variables ]]--
local LocalPlayer = nil
while not Players.LocalPlayer do
Expand All @@ -62,6 +65,9 @@ local isTenFootInterface = require(RobloxGui.Modules.TenFootInterface):IsEnabled
local pointsNotificationsActive = true
local badgesNotificationsActive = true

--[[ Modules ]]--
local SocialUtil = require(RobloxGui.Modules:WaitForChild("SocialUtil"))

--[[ Constants ]]--
local BG_TRANSPARENCY = 0.7
local MAX_NOTIFICATIONS = 3
Expand All @@ -80,6 +86,7 @@ local EASE_DIR = Enum.EasingDirection.InOut
local EASE_STYLE = Enum.EasingStyle.Sine
local TWEEN_TIME = 0.35
local DEFAULT_NOTIFICATION_DURATION = 5
local MAX_GET_FRIEND_IMAGE_YIELD_TIME = 5
local FRIEND_REQUEST_NOTIFICATION_THROTTLE = 5

local friendRequestNotificationFIntSuccess, friendRequestNotificationFIntValue = pcall(function() return tonumber(settings():GetFVariable("FriendRequestNotificationThrottle")) end)
Expand Down Expand Up @@ -202,9 +209,14 @@ PopupText.Parent = PopupFrame
local insertNotification = nil
local removeNotification = nil

local function getFriendImage(playerId, size)
size = size or 48
return ("http://www.roblox.com/thumbs/avatar.ashx?userId=%d&x=%d&y=%d"):format(playerId, size, size)
local function getFriendImage(playerId)
if useNewUserThumbnailAPI then
-- SocialUtil.GetPlayerImage can yield for up to MAX_GET_FRIEND_IMAGE_YIELD_TIME seconds while waiting for thumbnail to be final.
-- It will just return an invalid thumbnail if a valid one can not be generated in time.
return SocialUtil.GetPlayerImage(playerId, Enum.ThumbnailSize.Size48x48, Enum.ThumbnailType.AvatarThumbnail, --[[timeOut = ]] MAX_GET_FRIEND_IMAGE_YIELD_TIME)
else
return ("http://www.roblox.com/thumbs/avatar.ashx?userId=%d&x=%d&y=%d"):format(playerId, 48, 48)
end
end

--
Expand Down
15 changes: 11 additions & 4 deletions CoreScriptsRoot/Modules/PromptCreator.lua
Expand Up @@ -48,6 +48,9 @@ local WasCoreGuiNavigationEnabled = false
local WasGuiNavigationEnabled = false
local WasAutoSelectGuiEnabled = false

local useNewThumbnailApiSuccess, useNewThumbnailApiValue = pcall(function() return settings():GetFFlag("CoreScriptsUseNewUserThumbnailAPI") end)
local useNewUserThumbnailAPI = useNewThumbnailApiSuccess and useNewThumbnailApiValue

-- Inital prompt options. These are passed to CreatePrompt.
local DefaultPromptOptions = {
WindowTitle = "Confirm",
Expand Down Expand Up @@ -195,14 +198,18 @@ local function createScrollingTextLabel(name, size, position, font, textSize, te
end


local function createImageLabel(name, size, position, image)
local function createImageLabel(name, size, position, image, fetchImageFunction)
local imageLabel = Instance.new('ImageLabel')
imageLabel.Name = name
imageLabel.Size = size
imageLabel.BackgroundTransparency = 1
imageLabel.Position = position
imageLabel.Image = image

if useNewUserThumbnailAPI and fetchImageFunction then
fetchImageFunction(imageLabel)
end

return imageLabel
end

Expand Down Expand Up @@ -268,7 +275,7 @@ function CreatePromptVRorConsole(promptOptions)
local xOffset = 90

if promptOptions.ImageConsoleVR then
local image = createImageLabel("Image", UDim2.new(0, 600, 0, 600), UDim2.new(0, 100, 0, 45), promptOptions.ImageConsoleVR)
local image = createImageLabel("Image", UDim2.new(0, 600, 0, 600), UDim2.new(0, 100, 0, 45), promptOptions.ImageConsoleVR, promptOptions.FetchImageFunctionConsoleVR)
image.ZIndex = 9
image.Parent = ContainerFrame

Expand Down Expand Up @@ -335,7 +342,7 @@ function CreatePromptPCorTablet(promptOptions)
local image = nil

if promptOptions.Image then
image = createImageLabel("Image", UDim2.new(0, 150, 0, 150), UDim2.new(0, 15, 0, TITLE_HEIGHT + 17), promptOptions.Image)
image = createImageLabel("Image", UDim2.new(0, 150, 0, 150), UDim2.new(0, 15, 0, TITLE_HEIGHT + 17), promptOptions.Image, promptOptions.FetchImageFunction)
image.ZIndex = 9
image.Parent = ContainerFrame

Expand Down Expand Up @@ -428,7 +435,7 @@ function CreatePromptPhone(promptOptions)
local image = nil

if promptOptions.Image then
image = createImageLabel("Image", UDim2.new(0, 120, 0, 120), UDim2.new(0, 15, 0, TITLE_HEIGHT + 17), promptOptions.Image)
image = createImageLabel("Image", UDim2.new(0, 120, 0, 120), UDim2.new(0, 15, 0, TITLE_HEIGHT + 17), promptOptions.Image, promptOptions.FetchImageFunction)
image.ZIndex = 9
image.Parent = ContainerFrame

Expand Down
18 changes: 17 additions & 1 deletion CoreScriptsRoot/Modules/Settings/Pages/Players.lua
Expand Up @@ -15,6 +15,7 @@ local UserInputService = game:GetService("UserInputService")
RobloxGui:WaitForChild("Modules"):WaitForChild("TenFootInterface")
local utility = require(RobloxGui.Modules.Settings.Utility)
local reportAbuseMenu = require(RobloxGui.Modules.Settings.Pages.ReportAbuseMenu)
local SocialUtil = require(RobloxGui.Modules:WaitForChild("SocialUtil"))
local isTenFootInterface = require(RobloxGui.Modules.TenFootInterface):IsEnabled()

local enablePortraitModeSuccess, enablePortraitModeValue = pcall(function() return settings():GetFFlag("EnablePortraitMode") end)
Expand All @@ -24,6 +25,9 @@ local reportPlayerInMenuSuccess, reportPlayerInMenuValue = pcall(function() retu
-- The player report flag relies on portrait mode being enabled.
local enableReportPlayer = enablePortraitMode and reportPlayerInMenuSuccess and reportPlayerInMenuValue

local useNewThumbnailApiSuccess, useNewThumbnailApiValue = pcall(function() return settings():GetFFlag("CoreScriptsUseNewUserThumbnailAPI") end)
local useNewUserThumbnailAPI = useNewThumbnailApiSuccess and useNewThumbnailApiValue

------------ Constants -------------------
local FRAME_DEFAULT_TRANSPARENCY = .85
local FRAME_SELECTED_TRANSPARENCY = .65
Expand Down Expand Up @@ -513,7 +517,19 @@ local function Initialize()
table.insert(existingPlayerLabels, index, frame)
end
frame.Name = "PlayerLabel" ..player.Name
frame.Icon.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId="..math.max(1, player.UserId)
if useNewUserThumbnailAPI then
-- Immediately assign the image to an image that isn't guaranteed to be generated
frame.Icon.Image = SocialUtil.GetFallbackPlayerImageUrl(math.max(1, player.UserId), Enum.ThumbnailSize.Size180x180, Enum.ThumbnailType.AvatarThumbnail)
-- Spawn a function to get the generated image
spawn(function()
local imageUrl = SocialUtil.GetPlayerImage(math.max(1, player.UserId), Enum.ThumbnailSize.Size180x180, Enum.ThumbnailType.AvatarThumbnail)
if frame and frame.Parent and frame.Parent == this.Page then
frame.Icon.Image = imageUrl
end
end)
else
frame.Icon.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId="..math.max(1, player.UserId)
end
frame.NameLabel.Text = player.Name
frame.ImageTransparency = FRAME_DEFAULT_TRANSPARENCY

Expand Down