feat: add member to group via UserSearch — pass addToGroupId param from GroupSettings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
8aab9d078f
当前提交
b31a91f924
@ -14,7 +14,7 @@ export type RootStackParams = {
|
|||||||
Main: undefined
|
Main: undefined
|
||||||
SingleChat: { targetId: string; targetName: string; targetAvatar?: string }
|
SingleChat: { targetId: string; targetName: string; targetAvatar?: string }
|
||||||
GroupChat: { groupId: string; groupName: string }
|
GroupChat: { groupId: string; groupName: string }
|
||||||
UserSearch: undefined
|
UserSearch: { addToGroupId?: string } | undefined
|
||||||
GroupList: undefined
|
GroupList: undefined
|
||||||
CreateGroup: undefined
|
CreateGroup: undefined
|
||||||
GroupMembers: { groupId: string; groupName: string }
|
GroupMembers: { groupId: string; groupName: string }
|
||||||
|
|||||||
@ -3,17 +3,20 @@ import {
|
|||||||
View, Text, TextInput, FlatList, StyleSheet, TouchableOpacity,
|
View, Text, TextInput, FlatList, StyleSheet, TouchableOpacity,
|
||||||
SafeAreaView, ActivityIndicator, Alert, Image,
|
SafeAreaView, ActivityIndicator, Alert, Image,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation, useRoute } from '@react-navigation/native'
|
||||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
import type { NativeStackNavigationProp, NativeStackScreenProps } from '@react-navigation/native-stack'
|
||||||
import { ImSDK } from '@xuqm/rn-sdk'
|
import { ImSDK } from '@xuqm/rn-sdk'
|
||||||
import { demoApi, type UserProfile } from '../../api/demo'
|
import { demoApi, type UserProfile } from '../../api/demo'
|
||||||
import { load, save, K } from '../../utils/storage'
|
import { load, save, K } from '../../utils/storage'
|
||||||
import type { RootStackParams } from '../../navigation/types'
|
import type { RootStackParams } from '../../navigation/types'
|
||||||
|
|
||||||
type Nav = NativeStackNavigationProp<RootStackParams>
|
type Nav = NativeStackNavigationProp<RootStackParams>
|
||||||
|
type Props = NativeStackScreenProps<RootStackParams, 'UserSearch'>
|
||||||
|
|
||||||
export default function UserSearchScreen() {
|
export default function UserSearchScreen() {
|
||||||
const navigation = useNavigation<Nav>()
|
const navigation = useNavigation<Nav>()
|
||||||
|
const route = useRoute<Props['route']>()
|
||||||
|
const addToGroupId = (route.params as any)?.addToGroupId as string | undefined
|
||||||
const [keyword, setKeyword] = useState('')
|
const [keyword, setKeyword] = useState('')
|
||||||
const [results, setResults] = useState<UserProfile[]>([])
|
const [results, setResults] = useState<UserProfile[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@ -37,15 +40,24 @@ export default function UserSearchScreen() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const addContact = async (user: UserProfile) => {
|
const addContact = async (user: UserProfile) => {
|
||||||
try {
|
if (addToGroupId) {
|
||||||
await ImSDK.addFriend(user.userId)
|
try {
|
||||||
const current = (await load<UserProfile[]>(K.CONTACTS)) ?? []
|
await ImSDK.addGroupMember(addToGroupId, user.userId)
|
||||||
if (!current.find(c => c.userId === user.userId)) {
|
Alert.alert('已添加到群聊', undefined, [{ text: '确定', onPress: () => navigation.goBack() }])
|
||||||
await save(K.CONTACTS, [...current, user])
|
} catch (e: any) {
|
||||||
|
Alert.alert('添加失败', e?.message ?? '请重试')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
await ImSDK.addFriend(user.userId)
|
||||||
|
const current = (await load<UserProfile[]>(K.CONTACTS)) ?? []
|
||||||
|
if (!current.find(c => c.userId === user.userId)) {
|
||||||
|
await save(K.CONTACTS, [...current, user])
|
||||||
|
}
|
||||||
|
Alert.alert('已添加为好友')
|
||||||
|
} catch {
|
||||||
|
Alert.alert('添加失败')
|
||||||
}
|
}
|
||||||
Alert.alert('已添加为好友')
|
|
||||||
} catch {
|
|
||||||
Alert.alert('添加失败')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +99,7 @@ export default function UserSearchScreen() {
|
|||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity style={styles.addBtn} onPress={() => addContact(item)}>
|
<TouchableOpacity style={styles.addBtn} onPress={() => addContact(item)}>
|
||||||
<Text style={styles.addBtnText}>+ 添加</Text>
|
<Text style={styles.addBtnText}>{addToGroupId ? '加入群聊' : '+ 添加'}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -57,7 +57,7 @@ export default function GroupSettingsScreen({ route }: Props) {
|
|||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<>
|
<>
|
||||||
<View style={styles.sep} />
|
<View style={styles.sep} />
|
||||||
<Row label="添加成员" onPress={() => (nav as any).navigate('UserSearch')} />
|
<Row label="添加成员" onPress={() => (nav as any).navigate('UserSearch', { addToGroupId: groupId })} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户