Gate group chat invites on allowGroupInvites (#10546)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ import {type ListMethods} from '#/view/com/util/List'
|
|||||||
import {android, atoms as a, native, useTheme, web} from '#/alf'
|
import {android, atoms as a, native, useTheme, web} from '#/alf'
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {canBeMessaged, type ConvoWithDetails} from '#/components/dms/util'
|
import {canBeAddedToGroup, type ConvoWithDetails} from '#/components/dms/util'
|
||||||
import * as Toggle from '#/components/forms/Toggle'
|
import * as Toggle from '#/components/forms/Toggle'
|
||||||
import {ArrowLeft_Stroke2_Corner0_Rounded as ArrowLeftIcon} from '#/components/icons/Arrow'
|
import {ArrowLeft_Stroke2_Corner0_Rounded as ArrowLeftIcon} from '#/components/icons/Arrow'
|
||||||
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
|
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
|
||||||
@@ -190,7 +190,9 @@ export function AddMembersFlow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_items.sort(item => {
|
_items.sort(item => {
|
||||||
return item.type === 'profile' && canBeMessaged(item.profile) ? -1 : 1
|
return item.type === 'profile' && canBeAddedToGroup(item.profile)
|
||||||
|
? -1
|
||||||
|
: 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -206,7 +208,9 @@ export function AddMembersFlow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_items.sort(item => {
|
_items.sort(item => {
|
||||||
return item.type === 'profile' && canBeMessaged(item.profile) ? -1 : 1
|
return item.type === 'profile' && canBeAddedToGroup(item.profile)
|
||||||
|
? -1
|
||||||
|
: 1
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {type ListMethods} from '#/view/com/util/List'
|
|||||||
import {android, atoms as a, native, useTheme, web} from '#/alf'
|
import {android, atoms as a, native, useTheme, web} from '#/alf'
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {canBeMessaged} from '#/components/dms/util'
|
import {canBeAddedToGroup, canBeMessaged} from '#/components/dms/util'
|
||||||
import * as TextField from '#/components/forms/TextField'
|
import * as TextField from '#/components/forms/TextField'
|
||||||
import * as Toggle from '#/components/forms/Toggle'
|
import * as Toggle from '#/components/forms/Toggle'
|
||||||
import {
|
import {
|
||||||
@@ -246,6 +246,8 @@ export function InitiateChatFlow({
|
|||||||
|
|
||||||
const items = useMemo(() => {
|
const items = useMemo(() => {
|
||||||
let _items: Item[] = []
|
let _items: Item[] = []
|
||||||
|
const checker =
|
||||||
|
chatState === ChatState.NEW_GROUP_CHAT ? canBeAddedToGroup : canBeMessaged
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
_items.push({
|
_items.push({
|
||||||
@@ -276,7 +278,7 @@ export function InitiateChatFlow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_items = _items.sort(item => {
|
_items = _items.sort(item => {
|
||||||
return item.type === 'profile' && canBeMessaged(item.profile) ? -1 : 1
|
return item.type === 'profile' && checker(item.profile) ? -1 : 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -299,7 +301,7 @@ export function InitiateChatFlow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_items = _items.sort(item => {
|
_items = _items.sort(item => {
|
||||||
return item.type === 'profile' && canBeMessaged(item.profile) ? -1 : 1
|
return item.type === 'profile' && checker(item.profile) ? -1 : 1
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_items.push(...placeholders)
|
_items.push(...placeholders)
|
||||||
@@ -825,7 +827,7 @@ function GroupChatMemberProfileCard({
|
|||||||
moderationOpts: ModerationOpts
|
moderationOpts: ModerationOpts
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const enabled = canBeMessaged(profile)
|
const enabled = canBeAddedToGroup(profile)
|
||||||
const handle = sanitizeHandle(profile.handle, '@')
|
const handle = sanitizeHandle(profile.handle, '@')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -845,7 +847,7 @@ function GroupChatMemberProfileCard({
|
|||||||
<Text
|
<Text
|
||||||
style={[a.leading_snug, t.atoms.text_contrast_high]}
|
style={[a.leading_snug, t.atoms.text_contrast_high]}
|
||||||
numberOfLines={2}>
|
numberOfLines={2}>
|
||||||
<Trans>{handle} can’t be messaged</Trans>
|
<Trans>{handle} can’t be added</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {Trans} from '@lingui/react/macro'
|
|||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {canBeMessaged} from '#/components/dms/util'
|
import {canBeAddedToGroup} from '#/components/dms/util'
|
||||||
import * as Toggle from '#/components/forms/Toggle'
|
import * as Toggle from '#/components/forms/Toggle'
|
||||||
import * as ProfileCard from '#/components/ProfileCard'
|
import * as ProfileCard from '#/components/ProfileCard'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
@@ -19,7 +19,7 @@ export function GroupChatProfileCard({
|
|||||||
moderationOpts: ModerationOpts
|
moderationOpts: ModerationOpts
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const enabled = canBeMessaged(profile)
|
const enabled = canBeAddedToGroup(profile)
|
||||||
const moderation = moderateProfile(profile, moderationOpts)
|
const moderation = moderateProfile(profile, moderationOpts)
|
||||||
const handle = sanitizeHandle(profile.handle, '@')
|
const handle = sanitizeHandle(profile.handle, '@')
|
||||||
const displayName = sanitizeDisplayName(
|
const displayName = sanitizeDisplayName(
|
||||||
@@ -53,7 +53,7 @@ export function GroupChatProfileCard({
|
|||||||
<Text
|
<Text
|
||||||
style={[a.leading_snug, t.atoms.text_contrast_high]}
|
style={[a.leading_snug, t.atoms.text_contrast_high]}
|
||||||
numberOfLines={2}>
|
numberOfLines={2}>
|
||||||
<Trans>{handle} can’t be messaged</Trans>
|
<Trans>{handle} can’t be added</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -24,6 +24,20 @@ export function canBeMessaged(profile: bsky.profile.AnyProfileView) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canBeAddedToGroup(profile: bsky.profile.AnyProfileView) {
|
||||||
|
switch (profile.associated?.chat?.allowGroupInvites) {
|
||||||
|
case 'none':
|
||||||
|
return false
|
||||||
|
case 'all':
|
||||||
|
return true
|
||||||
|
case 'following':
|
||||||
|
case undefined:
|
||||||
|
return Boolean(profile.viewer?.followedBy)
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function localDateString(date: Date) {
|
export function localDateString(date: Date) {
|
||||||
// can't use toISOString because it should be in local time
|
// can't use toISOString because it should be in local time
|
||||||
const mm = date.getMonth()
|
const mm = date.getMonth()
|
||||||
|
|||||||
Reference in New Issue
Block a user