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

partial fix for chat info #1274

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions packages/restapi/src/lib/chat/getChatInfo.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { convertToValidDID, getAPIBaseUrls } from '../helpers';
import Constants, { ENV } from '../constants';
import { axiosGet } from '../utils/axiosUtil';
import { handleError } from '../errors/validationError';
import { convertToValidDID, getAPIBaseUrls } from '../helpers';
import { axiosGet } from '../utils/axiosUtil';

/**
* Represents the response type for the chat status.
*/
export interface ChatInfoResponse {
meta: {
group: boolean;
encryption: boolean;
groupInfo: {
public: boolean;
};
};
list: string;
participants: string[];
2,031 changes: 1,687 additions & 344 deletions packages/uiweb/dist/packages/restapi/packages/restapi/CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -2,6 +2,15 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [0.5.3](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.5.2...socket-0.5.3) (2023-11-15)


### Bug Fixes

* shift testnet env to sepolia ([#473](https://github.com/ethereum-push-notification-service/push-sdk/issues/473)) ([12f1392](https://github.com/ethereum-push-notification-service/push-sdk/commit/12f1392a4f4e800f720a0c2c34822bf502f15dac))



## [0.5.2](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.5.1...socket-0.5.2) (2023-08-03)


2 changes: 2 additions & 0 deletions packages/uiweb/package.json
Original file line number Diff line number Diff line change
@@ -25,10 +25,12 @@
"html-react-parser": "^1.4.13",
"livekit-client": "^1.13.3",
"moment": "^2.29.4",
"protobufjs": "^7.2.6",
"raf": "^3.4.0",
"react-easy-crop": "^4.1.4",
"react-icons": "^4.10.1",
"react-image-file-resizer": "^0.4.7",
"react-player": "^2.16.0",
"react-toastify": "^9.1.3",
"react-twitter-embed": "^4.0.4",
"uuid": "^9.0.1"
111 changes: 39 additions & 72 deletions packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx
Original file line number Diff line number Diff line change
@@ -13,9 +13,6 @@ import { appendUniqueMessages, dateToFromNowDaily, pCAIP10ToWallet, walletToPCAI
import { useChatData, usePushChatStream } from '../../../hooks';
import useFetchChat from '../../../hooks/chat/useFetchChat';
import useFetchMessageUtilities from '../../../hooks/chat/useFetchMessageUtilities';
import useGetGroupByIDnew from '../../../hooks/chat/useGetGroupByIDnew';
import useGroupMemberUtilities from '../../../hooks/chat/useGroupMemberUtilities';
import usePushUser from '../../../hooks/usePushUser';
import { Section, Span, Spinner } from '../../reusables';
import { ChatViewBubble } from '../ChatViewBubble';
import { checkIfNewRequest, transformStreamToIMessageIPFSWithCID } from '../helpers';
@@ -44,8 +41,6 @@ interface IThemeProps {
interface IChatViewListInitialized {
loading: boolean;
chatInfo: ChatInfoResponse | null;
groupInfo: Group | null;
isParticipant: boolean;
isHidden: boolean;
invalidChat: boolean;
}
@@ -64,24 +59,19 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
const [initialized, setInitialized] = useState<IChatViewListInitialized>({
loading: true,
chatInfo: null,
groupInfo: null,
isParticipant: false,
isHidden: false,
invalidChat: false,
});

const { chatId, limit = chatLimit, chatFilterList = [] } = options || {};
const { user, toast } = useChatData();
const [groupInfo, setGroupInfo] = useState<Group | null>(null);

// const [chatStatusText, setChatStatusText] = useState<string>('');
const [messages, setMessages] = useState<IMessageIPFSWithCID[]>([]);
const { historyMessages, historyLoading: messageLoading } = useFetchMessageUtilities();
const listInnerRef = useRef<HTMLDivElement>(null);
const [stopPagination, setStopPagination] = useState<boolean>(false);
const { fetchChat } = useFetchChat();
const { getGroupByIDnew } = useGetGroupByIDnew();
const { fetchMemberStatus } = useGroupMemberUtilities();

// for stream
const {
@@ -91,52 +81,51 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
participantJoinStream,
participantLeaveStream,
participantRemoveStream,
groupUpdateStream,
} = useChatData();

const theme = useContext(ThemeContext);
const dates = new Set();

// Primary Hook that fetches and sets ChatInfo which then fetches and sets UserInfo or GroupInfo
// Primary Hook that fetches and sets ChatInfo which then fetches and sets UserInfo
// Which then calls await getMessagesCall(); to fetch messages
useEffect(() => {
(async () => {
if (!user) return;
if (chatId) {
const info = await fetchChat({ chatId: chatId });

// get group info
let groupMeta;
if (info && info?.meta?.group) {
groupMeta = await getGroupByIDnew({ groupId: chatId });
}

// get member status
const status = await fetchMemberStatus({
chatId: chatId,
accountId: user?.account || '',
});

// also find out if chat is encrypted
// if readmode, then only public true is considered
// TODO: Hack for interface not declared properly (info?.meta as any)?.encryption
// TODO: Hack for interface not declared properly (info?.meta as any)?.groupInfo?.public
let hidden = false;
if (
user &&
!user.readmode() &&
((info?.meta?.group && status?.participant) ||
(!info?.meta?.group && (info?.list === 'CHATS' || info?.list === 'REQUESTS')) ||
(info?.meta?.group && groupMeta?.isPublic))
) {
if (user && user.readmode()) {
//check if encryption is false, only true for public groups
hidden = !(info?.meta as any)?.groupInfo?.public ?? true;
} else if (user && info?.meta) {
// Only executes when user is not readmode
// if encryption is false, return as is
// covers public group
// TODO: Hack for interface not declared properly (info?.meta as any)?.encryption
if ((info?.meta as any)?.encryption === false) {
hidden = false;
} else if (info?.meta?.group) {
// if encryption is true and group is in user list then hidden is false else true
// if group is encrypted, check if user list is CHATS, encryptioon false takes care of public groups
hidden = info.list === 'CHATS' ? false : true;
} else {
// if it's not a group, then check if list is CHATS or REQUESTS
hidden = info.list === 'CHATS' || info.list === 'REQUESTS' ? false : true;
}
hidden = false;
} else {
// for everything else, set hidden to true
hidden = true;
}

// Finally initialize the component
setInitialized({
loading: false,
chatInfo: Object.keys(info || {}).length ? (info as ChatInfoResponse) : null,
groupInfo: groupMeta ? groupMeta : null,
isParticipant: status?.participant ?? false,
isHidden: hidden,
invalidChat: info === undefined ? true : false,
});
@@ -148,8 +137,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
setInitialized({
loading: true,
chatInfo: null,
groupInfo: null,
isParticipant: false,
isHidden: false,
invalidChat: false,
});
@@ -170,7 +157,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
if (Object.keys(chatAcceptStream || {}).length > 0 && chatAcceptStream.constructor === Object) {
const updatedChatInfo = { ...(initialized.chatInfo as ChatInfoResponse) };
if (updatedChatInfo) updatedChatInfo.list = 'CHATS';
setInitialized({ ...initialized, chatInfo: updatedChatInfo });
setInitialized({ ...initialized, chatInfo: updatedChatInfo, isHidden: false });
}
}, [chatAcceptStream]);

@@ -190,11 +177,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
}
}, [chatRequestStream]);

useEffect(() => {
if (Object.keys(groupUpdateStream || {}).length > 0 && groupUpdateStream.constructor === Object)
transformGroupDetails(groupUpdateStream);
}, [groupUpdateStream]);

const transformSteamMessage = (item: any) => {
if (!user) {
return;
@@ -210,20 +192,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
}
}
};
const transformGroupDetails = (item: any): void => {
if (groupInfo?.chatId === item?.chatId) {
const updatedGroupInfo = groupInfo;
if (updatedGroupInfo) {
updatedGroupInfo.groupName = item?.meta?.name;
updatedGroupInfo.groupDescription = item?.meta?.description;
updatedGroupInfo.groupImage = item?.meta?.image;
updatedGroupInfo.groupCreator = item?.meta?.owner;
updatedGroupInfo.isPublic = !item?.meta?.private;
updatedGroupInfo.rules = item?.meta?.rules;
setGroupInfo(updatedGroupInfo);
}
}
};

useEffect(() => {
if (messages && messages?.length && messages?.length <= limit) {
@@ -343,13 +311,16 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
/>
)}

{/* TODO: Hack for interface not declared properly (initialized.chatInfo?.meta as any)?.encryption */}
{!initialized.loading &&
((user && user.pgpPublicKey) || (initialized.groupInfo && !initialized.groupInfo?.isPublic) ? (
((initialized.chatInfo?.meta as any)?.encryption ? (
<EncryptionMessage id={ENCRYPTION_KEYS.ENCRYPTED} />
) : user && user.readmode() ? (
<EncryptionMessage id={ENCRYPTION_KEYS.PREVIEW} />
) : (
<EncryptionMessage id={groupInfo ? ENCRYPTION_KEYS.NO_ENCRYPTED_GROUP : ENCRYPTION_KEYS.NO_ENCRYPTED} />
<EncryptionMessage
id={initialized.chatInfo?.meta?.group ? ENCRYPTION_KEYS.NO_ENCRYPTED_GROUP : ENCRYPTION_KEYS.NO_ENCRYPTED}
/>
))}
</Section>

@@ -361,19 +332,15 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
margin="10px 0 0 0"
flexDirection="column"
>
<Span
fontSize="13px"
color={theme.textColor?.encryptionMessageText}
fontWeight="400"
>
{messages &&
messages.length === 0 &&
!messageLoading &&
!groupInfo &&
!initialized.invalidChat &&
CHAT_STATUS.FIRST_CHAT}
{initialized.invalidChat && CHAT_STATUS.INVALID_CHAT}
</Span>
{initialized.invalidChat && (
<Span
fontSize="13px"
color={theme.textColor?.encryptionMessageText}
fontWeight="400"
>
{CHAT_STATUS.INVALID_CHAT}
</Span>
)}

{messageLoading ? <Spinner color={theme.spinnerColor} /> : ''}
</Section>
@@ -383,7 +350,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
flexDirection="column"
justifyContent="start"
width="100%"
blur={false}
blur={initialized.isHidden}
>
{messages &&
messages?.map((chat: IMessageIPFS, index: number) => {
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ export const EncryptionMessage = ({ id, className }: { id: EncryptionKeys; class
const EncryptionMessageContent = {
ENCRYPTED: {
IconComponent: <EncryptionIcon size="15" />,
text: 'Messages are end-to-end encrypted. Only users in this chat can view or listen to them. Click to learn more.',
text: 'Messages are end-to-end encrypted. Only users in this chat can view or listen to them.',
},
NO_ENCRYPTED: {
IconComponent: <NoEncryptionIcon size="15" />,
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ import { ChangeEvent, useContext, useEffect, useRef, useState } from 'react';

import EmojiPicker, { EmojiClickData } from 'emoji-picker-react';
import GifPicker from 'gif-picker-react';
import { createPortal } from 'react-dom';
import { MdCheckCircle, MdError } from 'react-icons/md';
import styled from 'styled-components';
import { createPortal } from 'react-dom';

import { deriveChatId, pCAIP10ToWallet, setAccessControl, walletToPCAIP10 } from '../../../helpers';
import { useChatData, useClickAway, useDeviceWidthCheck, usePushChatStream } from '../../../hooks';
@@ -236,7 +236,7 @@ export const MessageInput: React.FC<MessageInputProps> = ({
chatId: prevInfo.chatId, // Directly use the existing chatId, ensuring it's not undefined
meta: {
group: prevInfo.meta?.group ?? false, // Provide default value if undefined
encrypted: prevInfo.meta?.encrypted ?? false,
encryption: prevInfo.meta?.encryption ?? false,
},
};
});
5 changes: 4 additions & 1 deletion packages/uiweb/src/lib/components/chat/types/index.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,10 @@ export interface ChatInfoResponse {
chatId: string;
meta: {
group: boolean;
encrypted: boolean;
encryption: boolean;
groupInfo?: {
public: boolean;
};
};
participants?: Array<string>;
recipient?: string;
Loading
Loading