import React from 'react'; import { useUserList } from '@sendbird/uikit-chat-hooks'; import { useActionMenu } from '@sendbird/uikit-react-native-foundation'; import { useGroupChannelHandler } from '@sendbird/uikit-tools'; import { NOOP, isDifferentChannel, useFreshCallback } from '@sendbird/uikit-utils'; import StatusComposition from '../components/StatusComposition'; import UserActionBar from '../components/UserActionBar'; import { createGroupChannelMutedMembersModule } from '../domain/groupChannelMutedMembers'; import type { GroupChannelMutedMembersFragment, GroupChannelMutedMembersModule, } from '../domain/groupChannelMutedMembers/types'; import { useLocalization, useSendbirdChat } from '../hooks/useContext'; const createGroupChannelMutedMembersFragment = ( initModule?: Partial, ): GroupChannelMutedMembersFragment => { const GroupChannelMutedMembersModule = createGroupChannelMutedMembersModule(initModule); return ({ onPressHeaderLeft = NOOP, channel, renderUser, queryCreator = () => channel.createMutedUserListQuery({ limit: 20 }), }) => { const { STRINGS } = useLocalization(); const { sdk, currentUser } = useSendbirdChat(); const { openMenu } = useActionMenu(); const { users, deleteUser, upsertUser, loading, refresh, error, next } = useUserList(sdk, { queryCreator }); useGroupChannelHandler(sdk, { onUserMuted(eventChannel, user) { if (isDifferentChannel(eventChannel, channel)) return; upsertUser(user); }, onUserUnmuted(eventChannel, user) { if (isDifferentChannel(eventChannel, channel)) return; deleteUser(user.userId); }, onUserLeft(eventChannel, user) { if (isDifferentChannel(eventChannel, channel)) return; deleteUser(user.userId); }, onUserBanned(eventChannel, user) { if (isDifferentChannel(eventChannel, channel)) return; deleteUser(user.userId); }, }); const _renderUser: NonNullable = useFreshCallback((props) => { if (renderUser) return renderUser(props); const { user } = props; return ( { openMenu({ title: user.nickname || STRINGS.LABELS.USER_NO_NAME, menuItems: [ { title: STRINGS.LABELS.UNMUTE, onPress: () => channel.unmuteUser(user).then(() => deleteUser(user.userId)), }, ], }); }} /> ); }); return ( } error={Boolean(error)} ErrorComponent={} > } /> ); }; }; export default createGroupChannelMutedMembersFragment;