Skip to content

Commit 5d1ca96

Browse files
committed
duplicate user
1 parent f96c0fb commit 5d1ca96

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/components/chat/usersList.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const UsersList = () => {
1616
const { chatRoomId, oneToOneRoomId } = useChat();
1717
const dispatch = useChatDispatch();
1818
const [userList, setUserList] = useState<User[] | []>([]);
19+
const [userCount, setUserCount] = useState<number>(0);
1920

2021
useEffect(() => {
2122
setLoading(true);
@@ -24,7 +25,13 @@ const UsersList = () => {
2425
const data = snapshot.val();
2526
if (data) {
2627
const users = Object.values(data) as User[];
27-
setUserList(users.filter((user) => user.uid !== authUser?.uid));
28+
setUserCount(users.length || 0);
29+
// Remove duplicate users and the current user
30+
const uniqueUsers = users.filter(
31+
(user, index, self) =>
32+
user.uid && user.uid !== authUser?.uid && index === self.findIndex((u) => u.uid === user.uid)
33+
);
34+
setUserList(uniqueUsers);
2835
dispatch({
2936
type: ChatActionType.SET_USER_LIST,
3037
payload: data,
@@ -87,7 +94,7 @@ const UsersList = () => {
8794
src={authUser?.profile_picture}
8895
colorPalette={"orange"}
8996
/>
90-
<Avatar colorPalette={'orange'} fallback={`+${numberFormatter.format(userList?.length)}`} />
97+
<Avatar colorPalette={'orange'} fallback={`+${numberFormatter.format(userCount)}`} />
9198
</AvatarGroup>
9299
<Text fontWeight="medium" textStyle={"sm"} lineClamp={1}>
93100
Common Group

0 commit comments

Comments
 (0)