Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group message in the inbox #2380 #2386

Merged
merged 27 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b5cbb55
support group message: init
roienatan Dec 8, 2023
1f6ebb8
init 2
roienatan Dec 8, 2023
bb6da2e
init 3
roienatan Dec 9, 2023
5ce3f9f
clean
roienatan Dec 9, 2023
15843f5
init 4
roienatan Dec 10, 2023
ec27daa
.
roienatan Dec 10, 2023
4500a0f
updates #1 + clean
roienatan Dec 10, 2023
6880c8a
custom MultiValue component to show short label of multi value
roienatan Dec 11, 2023
c02d5f6
support finding group chats with getDMUserChatChannel
roienatan Dec 11, 2023
526f4b4
updates 2
roienatan Dec 12, 2023
54b6c9a
new hook useUsersByIds to fetch multiple Users by uids
roienatan Dec 13, 2023
3beeb11
show group creator name in the last message text when a group is crea…
roienatan Dec 13, 2023
71464e6
.
roienatan Dec 13, 2023
a78d9b0
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 13, 2023
31224db
disable mention dropdown for a group chat
roienatan Dec 13, 2023
b90fc80
backgroundColor for the select option when not hoverd
roienatan Dec 13, 2023
0a28e6b
show only first name in title of group chat ; add title prop when hov…
roienatan Dec 14, 2023
6deed38
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 14, 2023
d879d35
merge dev
roienatan Dec 14, 2023
f3fbcb8
fix crash: adding conditinal chaining dmUsers?.[0]?.photoURL
roienatan Dec 15, 2023
6d20588
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 17, 2023
21f12cb
hover title with full usernames ; title for group chat with first nam…
roienatan Dec 17, 2023
f495b11
.
roienatan Dec 18, 2023
2069944
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 18, 2023
3c2611d
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 19, 2023
c217334
code review updates
roienatan Dec 19, 2023
dac849b
Merge branch 'dev' into cw-2380-support-group-message
roienatan Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export default function ChatComponent({
users={users}
shouldReinitializeEditor={shouldReinitializeEditor}
onClearFinished={onClearFinished}
groupChat={chatChannel && chatChannel?.participants.length > 2}
/>
<button
className={styles.sendIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const useDiscussionChatAdapter = (options: Options): Return => {
const userId = user?.uid;
const { data: commonMembers, fetchCommonMembers } = useCommonMembers();

const allUsers = useMemo(() => commonMembers.map(({ user }) => user), [commonMembers]);
const allUsers = useMemo(
() => commonMembers.map(({ user }) => user),
[commonMembers],
);

const discussionUsers = useMemo(
() => allUsers.filter((user) => user.uid !== userId),
Expand Down
5 changes: 4 additions & 1 deletion src/pages/common/components/FeedItem/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export interface FeedItemBaseContentProps {
hasImages?: boolean;
isLoading?: boolean;
shouldHideBottomContent?: boolean;
dmUserId?: string;
dmUserIds?: string[];
hasUnseenMention?: boolean;
notion?: CommonNotion;
isGroupMessage?: boolean;
createdBy?: string;
hoverTitle?: string;
}

export interface GetLastMessageOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ProfileContent: FC<ProfileContentProps> = (props) => {
if (onDMClick) {
onDMClick();
} else {
fetchDMUserChatChannel(userId);
fetchDMUserChatChannel([userId]);
}
};

Expand Down
73 changes: 46 additions & 27 deletions src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { FC, useCallback, useEffect } from "react";
import React, { FC, useCallback, useEffect, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { selectUser } from "@/pages/Auth/store/selectors";
import { useChatContext } from "@/pages/common/components/ChatComponent";
import { UserAvatar } from "@/shared/components";
import { LastSeenEntity } from "@/shared/constants";
import { ChatChannelToDiscussionConverter } from "@/shared/converters";
import { useChatChannelUserStatus, useUserById } from "@/shared/hooks/useCases";
import {
useChatChannelUserStatus,
useUsersByIds,
} from "@/shared/hooks/useCases";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { GroupChatIcon } from "@/shared/icons";
import { ChatChannelFeedLayoutItemProps } from "@/shared/interfaces";
import { ChatChannel } from "@/shared/models";
import { getUserName } from "@/shared/utils";
import { getUserName, joinWithLast } from "@/shared/utils";
import { inboxActions } from "@/store/states";
import { FeedItemBaseContent } from "../FeedItemBaseContent";
import { useChatChannelSubscription, useMenuItems } from "./hooks";
Expand All @@ -19,7 +23,7 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
const { chatChannel, isActive, onActiveItemDataChange } = props;
const dispatch = useDispatch();
const isTabletView = useIsTabletView();
const { fetchUser: fetchDMUser, data: dmUser } = useUserById();
const { fetchUsers: fetchDMUsers, data: dmUsers } = useUsersByIds();
const {
data: chatChannelUserStatus,
fetched: isChatChannelUserStatusFetched,
Expand All @@ -30,14 +34,23 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
useChatContext();
const user = useSelector(selectUser());
const userId = user?.uid;
const dmUserId =
chatChannel.participants.length === 1
? chatChannel.participants[0]
: chatChannel.participants.filter(
(participant) => participant !== userId,
)[0];
const dmUserName = getUserName(dmUser);
const finalTitle = dmUserName;

const isGroupMessage = chatChannel.participants.length > 2;
const dmUserIds = useMemo(
() =>
chatChannel.participants.filter((participant) => participant !== userId),
[],
);

const dmUsersNames = dmUsers?.map((user) => getUserName(user));
const dmFirstNames = dmUsers?.map((user) => user.firstName);
const finalTitle = joinWithLast(isGroupMessage ? dmFirstNames : dmUsersNames);
const hoverTitle = isGroupMessage ? joinWithLast(dmUsersNames) : finalTitle;
const groupChatCreatorName = getUserName(
chatChannel.createdBy === user?.uid
? user
: dmUsers?.find((user) => user.uid === chatChannel.createdBy),
);

const handleOpenChat = useCallback(() => {
setChatItem({
Expand Down Expand Up @@ -70,20 +83,23 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
[dispatch],
);

const renderImage = (className?: string) => (
<UserAvatar
className={className}
photoURL={dmUser?.photoURL}
nameForRandomAvatar={dmUserName}
userName={dmUserName}
/>
);
const renderImage = (className?: string) =>
isGroupMessage ? (
<GroupChatIcon className={className} />
) : (
<UserAvatar
className={className}
photoURL={dmUsers?.[0]?.photoURL}
nameForRandomAvatar={dmUsersNames?.[0]}
userName={dmUsersNames?.[0]}
/>
);

useChatChannelSubscription(chatChannel.id, userId, handleChatChannelUpdate);

useEffect(() => {
fetchDMUser(dmUserId);
}, [dmUserId]);
fetchDMUsers(dmUserIds); // dm users not including the current user.
}, [dmUserIds]);

useEffect(() => {
fetchChatChannelUserStatus({
Expand All @@ -104,14 +120,14 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
}, [isChatChannelUserStatusFetched, shouldAllowChatAutoOpen]);

useEffect(() => {
if (isActive && finalTitle) {
if (isActive && finalTitle && dmUsersNames) {
onActiveItemDataChange?.({
itemId: chatChannel.id,
title: finalTitle,
image: dmUser?.photoURL,
title: dmUsersNames?.[0],
image: dmUsers?.[0]?.photoURL,
});
}
}, [isActive, finalTitle, dmUser?.photoURL]);
}, [isActive, finalTitle, dmUsers?.[0]?.photoURL, dmUsersNames?.[0]]);

return (
<FeedItemBaseContent
Expand All @@ -129,7 +145,10 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
ownerId={userId}
renderImage={renderImage}
isImageRounded
dmUserId={dmUserId}
dmUserIds={dmUserIds}
isGroupMessage={isGroupMessage}
createdBy={groupChatCreatorName}
hoverTitle={hoverTitle}
/>
);
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
max-height: 29.25rem;
border-radius: 0;
box-shadow: 0 0.25rem 0.9375rem var(--drop-shadow);
height: 37rem;

:global(.modal__header-wrapper--with-modal-padding) {
.modalHeader {
Expand All @@ -19,10 +20,6 @@
padding: 0 1.5rem;
}

.modalContent {
padding: 0;
}

.modalCloseWrapper {
top: 0.5rem;
margin: 0;
Expand All @@ -31,6 +28,7 @@
@include tablet {
max-width: unset;
max-height: unset;
height: 100%;
}
}

Expand Down Expand Up @@ -82,3 +80,22 @@
.userItem {
padding: 0.375rem 1.75rem;
}

.optionWrapper {
display: flex;
align-items: center;
}

.userAvatar {
margin-right: 0.75rem;
}

.searchIcon {
margin-right: 0.5rem;
}

.createGroupChatButton {
margin-left: auto;
margin-top: 1rem;
width: 10rem;
}
Loading
Loading