Hack-modify avi path to use smaller thumbs behind gate (#4816)

* Hack-modify avi path to use smaller thumbs behind gate

* Only use small thumbs on smaller rendering
zio/stable
Paul Frazee 2024-07-23 16:57:51 -07:00 committed by GitHub
parent 67ce18a113
commit 4af6bcb11a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View File

@ -14,3 +14,4 @@ export type Gate =
| 'suggested_follows_interstitial'
| 'ungroup_follow_backs'
| 'videos'
| 'small_avi_thumb'

View File

@ -8,6 +8,7 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'
import {useGate} from '#/lib/statsig/statsig'
import {logger} from '#/logger'
import {usePalette} from 'lib/hooks/usePalette'
import {
@ -179,6 +180,7 @@ let UserAvatar = ({
const pal = usePalette('default')
const backgroundColor = pal.colors.backgroundLight
const finalShape = overrideShape ?? (type === 'user' ? 'circle' : 'square')
const gate = useGate()
const aviStyle = useMemo(() => {
if (finalShape === 'square') {
@ -221,7 +223,12 @@ let UserAvatar = ({
testID="userAvatarImage"
style={aviStyle}
resizeMode="cover"
source={{uri: avatar}}
source={{
uri: hackModifyThumbnailPath(
avatar,
size < 90 && gate('small_avi_thumb'),
),
}}
blurRadius={moderation?.blur ? BLUR_AMOUNT : 0}
/>
) : (
@ -229,7 +236,12 @@ let UserAvatar = ({
testID="userAvatarImage"
style={aviStyle}
contentFit="cover"
source={{uri: avatar}}
source={{
uri: hackModifyThumbnailPath(
avatar,
size < 90 && gate('small_avi_thumb'),
),
}}
blurRadius={moderation?.blur ? BLUR_AMOUNT : 0}
/>
)}
@ -433,6 +445,16 @@ let PreviewableUserAvatar = ({
PreviewableUserAvatar = memo(PreviewableUserAvatar)
export {PreviewableUserAvatar}
// HACK
// We have started serving smaller avis but haven't updated lexicons to give the data properly
// manually string-replace to use the smaller ones
// -prf
function hackModifyThumbnailPath(uri: string, isEnabled: boolean): string {
return isEnabled
? uri.replace('/img/avatar/plain/', '/img/avatar_thumbnail/plain/')
: uri
}
const styles = StyleSheet.create({
editButtonContainer: {
position: 'absolute',