diff --git a/.husky/pre-commit b/.husky/pre-commit
index 8a79c3470..2665d0376 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -4,4 +4,4 @@
echo "\nRunning GIT hooks..."
yarn cleanbuild
yarn nx affected --target=lint
-#yarn nx affected --target=test
\ No newline at end of file
+yarn nx affected --target=test
\ No newline at end of file
diff --git a/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx b/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx
index 93b49170c..3bdb3a6e5 100644
--- a/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx
+++ b/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx
@@ -9,17 +9,17 @@ const ChatViewComponentTest = () => {
'bafyreidesy6f4iu34eqccmqh55g35wu36lvlz42c63ivtmgjjhezlzdqta',
'bafyreig3gs4tpwxumiz5fxypyt4omlxhvrvuj66kfoyioeshawlau6lgem',
];
-
+console.log('in chat view component')
return (
Chat UI Test page
-
{console.log('in close')}} />
+ {/* {console.log('in close')}} /> */}
- {console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY} modalPositionType={MODAL_POSITION_TYPE.RELATIVE}/>
+ {/* {console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY} modalPositionType={MODAL_POSITION_TYPE.RELATIVE}/> */}
console.log("BOIIII RETURNNNSSSSS")}
- chatId='4ac5ab85c9c3d57adbdf2dba79357e56b2f9ef0256befe750d9f93af78d2ca68'
+ chatId='a5dad31b20c9aaf761221b57f6f0ab96b03a456525159378388e896475b1f943'
limit={10}
isConnected={true}
groupInfoModalBackground={MODAL_BACKGROUND_TYPE.OVERLAY}
diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/AddWalletContent.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/AddWalletContent.tsx
index e99062b39..9ccddc723 100644
--- a/packages/uiweb/src/lib/components/chat/ChatProfile/AddWalletContent.tsx
+++ b/packages/uiweb/src/lib/components/chat/ChatProfile/AddWalletContent.tsx
@@ -24,6 +24,7 @@ import CloseIcon from '../../../icons/close.svg';
import { ChatSearchInput, CustomStyleParamsType, ModalHeader } from '../reusables';
import useGetChatProfile from '../../../hooks/useGetChatProfile';
import { BackIcon } from '../../../icons/Back';
+import useChatProfile from '../../../hooks/chat/useChatProfile';
type AddWalletContentProps = {
@@ -50,7 +51,7 @@ export const AddWalletContent = ({
const [filteredUserData, setFilteredUserData] = useState(null);
const { account, env } = useChatData();
const isMobile = useMediaQuery(device.mobileL);
- const {fetchChatProfile} = useGetChatProfile();
+ const {fetchUserChatProfile} = useChatProfile();
const groupInfoToast = useToast();
const customSearchStyle:CustomStyleParamsType = {
background:theme.backgroundColor?.modalInputBackground,
@@ -64,7 +65,7 @@ export const AddWalletContent = ({
//fix ens search
const newChatUser = await getNewChatUser({
searchText: searchedText,
- fetchChatProfile,
+ fetchChatProfile:fetchUserChatProfile,
env,
});
if(newChatUser){
diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx
index e47d24135..26b6643f9 100644
--- a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx
+++ b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx
@@ -68,7 +68,7 @@ export const ChatProfile: React.FC = ({
const fetchProfileData = async () => {
if (isValidETHAddress(chatId)) {
- const ChatProfile = await fetchUserChatProfile({ profileId: chatId });
+ const ChatProfile = await fetchUserChatProfile({ profileId: chatId,env });
const result = await resolveNewEns(chatId, provider);
setEnsName(result);
setChatInfo(ChatProfile);
diff --git a/packages/uiweb/src/lib/components/chat/ChatViewBubble/ChatViewBubble.tsx b/packages/uiweb/src/lib/components/chat/ChatViewBubble/ChatViewBubble.tsx
index e7a672dbb..99ab8e81d 100644
--- a/packages/uiweb/src/lib/components/chat/ChatViewBubble/ChatViewBubble.tsx
+++ b/packages/uiweb/src/lib/components/chat/ChatViewBubble/ChatViewBubble.tsx
@@ -25,13 +25,14 @@ import {
pCAIP10ToWallet,
shortenText,
} from '../../../helpers';
+import { formatTime } from '../../../helpers/timestamp';
const SenderMessageAddress = ({ chat }: { chat: IMessagePayload }) => {
const { account } = useContext(ChatDataContext);
const theme = useContext(ThemeContext);
return (
<>
- {chat.fromCAIP10.split(':')[1] !== account && (
+ {(chat.fromCAIP10).split(':')[1] !== account && (
{
fontWeight={theme.fontWeight?.chatReceivedBubbleAddressText}
color={theme.textColor?.chatReceivedBubbleAddressText}
>
- {chat.fromDID.split(':')[1].slice(0, 6)}...
- {chat.fromDID.split(':')[1].slice(-6)}
+ {chat.fromCAIP10.split(':')[1].slice(0, 6)}...
+ {chat.fromCAIP10.split(':')[1].slice(-6)}
)}
>
@@ -65,7 +66,7 @@ const SenderMessageProfilePicture = ({ chat }: { chat: IMessagePayload }) => {
}, [account, chat.fromCAIP10]);
return (
- {chat.fromCAIP10.split(':')[1] !== account && (
+ {(chat.fromCAIP10).split(':')[1] !== account && (
{pfp && (
{
const theme = useContext(ThemeContext);
- const time = moment(chat.timestamp).format('hh:mm a');
+ const time = formatTime(chat.timestamp)
return (
{
const { account } = useChatData();
const position =
- pCAIP10ToWallet(decryptedMessagePayload.fromDID).toLowerCase() !== account?.toLowerCase()
+ pCAIP10ToWallet(decryptedMessagePayload.fromCAIP10).toLowerCase() !== account?.toLowerCase()
? 0
: 1;
const { tweetId, messageType }: TwitterFeedReturnType = checkTwitterUrl({
@@ -347,7 +348,7 @@ export const ChatViewBubble = ({ decryptedMessagePayload }: { decryptedMessagePa
});
const [isGroup, setIsGroup] = useState(false);
useEffect(() => {
- if (decryptedMessagePayload.toDID.split(':')[0] === 'eip155') {
+ if ((decryptedMessagePayload.toCAIP10).split(':')[0] === 'eip155') {
if (isGroup) {
setIsGroup(false);
}
@@ -356,7 +357,7 @@ export const ChatViewBubble = ({ decryptedMessagePayload }: { decryptedMessagePa
setIsGroup(true);
}
}
- }, [decryptedMessagePayload.toDID, isGroup]);
+ }, [decryptedMessagePayload.toCAIP10, isGroup]);
if (messageType === 'TwitterFeedLink') {
decryptedMessagePayload.messageType = 'TwitterFeedLink';
diff --git a/packages/uiweb/src/lib/components/chat/ChatViewList/ApproveRequestBubble.tsx b/packages/uiweb/src/lib/components/chat/ChatViewList/ApproveRequestBubble.tsx
index 140d7abc5..b8a8510e3 100644
--- a/packages/uiweb/src/lib/components/chat/ChatViewList/ApproveRequestBubble.tsx
+++ b/packages/uiweb/src/lib/components/chat/ChatViewList/ApproveRequestBubble.tsx
@@ -26,7 +26,7 @@ export const ApproveRequestBubble = ({
chatId,
setChatFeed,
}: IApproveRequestBubbleProps) => {
- const { pgpPrivateKey } = useChatData();
+ const { alias } = useChatData();
const ApproveRequestText = {
GROUP: `You were invited to the group ${chatFeed?.groupInformation?.groupName}. Please accept to continue messaging in this group.`,
@@ -39,13 +39,7 @@ export const ApproveRequestBubble = ({
const handleApproveChatRequest = async () => {
try {
- if (!pgpPrivateKey) {
- return;
- }
-
- const response = await approveChatRequest({
- chatId,
- });
+ const response = await alias.chat.accept(chatId);
if (response) {
const updatedChatFeed = { ...(chatFeed as IFeeds) };
updatedChatFeed.intent = response;
diff --git a/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx b/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx
index 451df1678..8232cb137 100644
--- a/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx
+++ b/packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx
@@ -33,6 +33,8 @@ import useGetGroup from '../../../hooks/chat/useGetGroup';
import useGetChatProfile from '../../../hooks/useGetChatProfile';
import useFetchChat from '../../../hooks/chat/useFetchChat';
import { ApproveRequestBubble } from './ApproveRequestBubble';
+import { formatTime } from '../../../helpers/timestamp';
+import useChatProfile from '../../../hooks/chat/useChatProfile';
/**
* @interface IThemeProps
@@ -51,7 +53,7 @@ export const ChatViewList: React.FC = (
options: IChatViewListProps
) => {
const { chatId, limit = chatLimit, chatFilterList = [] } = options || {};
- const { pgpPrivateKey, account, connectedProfile, setConnectedProfile } =
+ const { account, pushUser, } =
useChatData();
const [chatFeed, setChatFeed] = useState({} as IFeeds);
const [chatStatusText, setChatStatusText] = useState('');
@@ -63,7 +65,7 @@ export const ChatViewList: React.FC = (
const listInnerRef = useRef(null);
const [isMember, setIsMember] = useState(false);
const { fetchChat } = useFetchChat();
- const { fetchChatProfile } = useGetChatProfile();
+ const { fetchUserChatProfile } = useChatProfile();
const { getGroup } = useGetGroup();
const { messagesSinceLastConnection, groupInformationSinceLastConnection } =
@@ -76,58 +78,49 @@ export const ChatViewList: React.FC = (
setChatStatusText('');
}, [chatId, account, env]);
- useEffect(() => {
- (async () => {
- if (!connectedProfile && account) {
- const user = await fetchChatProfile({ profileId: account!, env });
- if (user) setConnectedProfile(user);
- }
- })();
- }, [account]);
-
useEffect(() => {
setMessages(undefined);
setConversationHash(undefined);
- }, [chatId, account, pgpPrivateKey, env]);
+ }, [chatId, account, env]);
//need to make a common method for fetching chatFeed to ruse in messageInput
useEffect(() => {
(async () => {
- if (!account && !env) return;
- const chat = await fetchChat({ chatId });
- if (Object.keys(chat || {}).length) {
- setConversationHash(chat?.threadhash as string);
- setChatFeed(chat as IFeeds);
- }
- else {
- let newChatFeed;
- let group;
- const result = await getNewChatUser({
- searchText: chatId,
- fetchChatProfile,
- env,
- });
- if (result) {
- newChatFeed = getDefaultFeedObject({ user: result });
+ if (pushUser) {
+ const chat = await fetchChat();
+ if (chat) {
+ setConversationHash(chat?.threadhash as string);
+ setChatFeed(chat as IFeeds);
} else {
- group = await getGroup({ searchText: chatId });
- if (group) {
- newChatFeed = getDefaultFeedObject({ groupInformation: group });
+ let newChatFeed;
+ let group;
+ const result = await getNewChatUser({
+ searchText: chatId,
+ fetchChatProfile:fetchUserChatProfile,
+ env,
+ });
+ if (result) {
+ newChatFeed = getDefaultFeedObject({ user: result });
+ } else {
+ group = await getGroup({ searchText: chatId });
+ if (group) {
+ newChatFeed = getDefaultFeedObject({ groupInformation: group });
+ }
}
- }
- if (newChatFeed) {
- if (!newChatFeed?.groupInformation) {
- setChatStatusText(ChatStatus.FIRST_CHAT);
+ if (newChatFeed) {
+ if (!newChatFeed?.groupInformation) {
+ setChatStatusText(ChatStatus.FIRST_CHAT);
+ }
+ setConversationHash(newChatFeed.threadhash as string);
+ setChatFeed(newChatFeed);
+ } else {
+ setChatStatusText(ChatStatus.INVALID_CHAT);
}
- setConversationHash(newChatFeed.threadhash as string);
- setChatFeed(newChatFeed);
- } else {
- setChatStatusText(ChatStatus.INVALID_CHAT);
}
+ setLoading(false);
}
- setLoading(false);
})();
- }, [chatId, pgpPrivateKey, account, env]);
+ }, [chatId, account, env, pushUser]);
//moniters socket changes
useEffect(() => {
@@ -138,7 +131,7 @@ export const ChatViewList: React.FC = (
setFilteredMessages([
messagesSinceLastConnection,
] as IMessageIPFSWithCID[]);
-
+
setConversationHash(messagesSinceLastConnection.cid);
} else {
const newChatViewList = appendUniqueMessages(
@@ -168,12 +161,12 @@ export const ChatViewList: React.FC = (
}, [groupInformationSinceLastConnection]);
useEffect(() => {
- if (conversationHash) {
+ // if (conversationHash) {
(async function () {
await getMessagesCall();
})();
- }
- }, [conversationHash, pgpPrivateKey, account, env,chatFeed]);
+ // }
+ }, [conversationHash, account, env, chatFeed, pushUser]);
useEffect(() => {
scrollToBottom();
@@ -191,10 +184,10 @@ export const ChatViewList: React.FC = (
}
}, [messages]);
- useEffect(()=>{
- if(chatFeed && !chatFeed?.groupInformation?.isPublic && account)
- {
+ useEffect(() => {
+
+ if (chatFeed && !chatFeed?.groupInformation?.isPublic && account) {
chatFeed?.groupInformation?.members.forEach((acc) => {
if (
acc.wallet.toLowerCase() === walletToPCAIP10(account!).toLowerCase()
@@ -203,17 +196,17 @@ export const ChatViewList: React.FC = (
}
});
}
- },[account,chatFeed])
+ }, [account, chatFeed])
//methods
const scrollToBottom = () => {
- setTimeout(()=>{
+ setTimeout(() => {
if (listInnerRef.current) {
- listInnerRef.current.scrollTop = listInnerRef.current.scrollHeight +100;
+ listInnerRef.current.scrollTop = listInnerRef.current.scrollHeight + 100;
}
- },0)
-
+ }, 0)
+
};
const onScroll = async () => {
@@ -233,23 +226,17 @@ export const ChatViewList: React.FC = (
};
const getMessagesCall = async () => {
- let threadHash = null;
- if (!messages) {
- threadHash = conversationHash;
- } else {
- threadHash = messages?.lastThreadHash;
- }
-
- if (
- threadHash &&
- ((account && pgpPrivateKey&& chatFeed && !chatFeed?.groupInformation) ||
- (chatFeed && chatFeed?.groupInformation))
- ) {
-
- const chatHistory = await historyMessages({
- limit: limit,
- threadHash,
- });
+ // if (!messages) {
+ // threadHash = conversationHash;
+ // } else {
+ // threadHash = messages?.lastThreadHash;
+ // }
+console.log('in get message call')
+console.log(pushUser)
+ if (pushUser && chatId) {
+ console.log('push user there')
+
+ const chatHistory = await historyMessages({chatId});
if (chatHistory?.length) {
if (Object.keys(messages || {}) && messages?.messages.length) {
const newChatViewList = appendUniqueMessages(
@@ -279,12 +266,12 @@ export const ChatViewList: React.FC = (
}
};
- const ifBlurChat = () =>{
+ const ifBlurChat = () => {
return !!(
chatFeed &&
chatFeed?.groupInformation &&
!chatFeed?.groupInformation?.isPublic &&
- ((!isMember && pgpPrivateKey) || (!pgpPrivateKey))
+ (!isMember)
);
}
@@ -293,7 +280,7 @@ export const ChatViewList: React.FC = (
dateNum: string;
};
const renderDate = ({ chat, dateNum }: RenderDataType) => {
- const timestampDate = dateToFromNowDaily(chat.timestamp as number);
+ const timestampDate = formatTime(chat.timestamp);
dates.add(dateNum);
return (
= (
{!loading && (
<>
{chatFeed &&
- (chatFeed.publicKey ||
- (chatFeed?.groupInformation &&
- !chatFeed?.groupInformation?.isPublic)) ? (
+ (chatFeed.publicKey ||
+ (chatFeed?.groupInformation &&
+ !chatFeed?.groupInformation?.isPublic)) ? (
) : (
= (
{messages?.messages &&
messages?.messages?.map(
(chat: IMessageIPFS, index: number) => {
- const dateNum = moment(chat.timestamp).format('L');
+ const dateNum = formatTime(chat.timestamp);
const position =
pCAIP10ToWallet(chat.fromDID).toLowerCase() !==
- account?.toLowerCase()
+ account?.toLowerCase()
? 0
: 1;
return (
<>
{dates.has(dateNum)
? null
- : renderDate({ chat, dateNum })}
+ : dateNum ? renderDate({ chat, dateNum }) : null}
= (
};
//styles
-const ChatViewListCard = styled(Section)`
+const ChatViewListCard = styled(Section) `
&::-webkit-scrollbar-thumb {
background: ${(props) => props.theme.scrollbarColor};
border-radius: 10px;
@@ -425,4 +412,3 @@ const ChatViewListCard = styled(Section)`
overscroll-behavior: contain;
scroll-behavior: smooth;
`;
-
diff --git a/packages/uiweb/src/lib/components/chat/ConnectButton/ConnectButton.tsx b/packages/uiweb/src/lib/components/chat/ConnectButton/ConnectButton.tsx
index 45aa9c3ba..6a144303f 100644
--- a/packages/uiweb/src/lib/components/chat/ConnectButton/ConnectButton.tsx
+++ b/packages/uiweb/src/lib/components/chat/ConnectButton/ConnectButton.tsx
@@ -1,15 +1,18 @@
import { useContext, useEffect, useState } from 'react';
import styled from 'styled-components';
-import { ethers } from 'ethers';
+import { Signer, ethers } from 'ethers';
import { useAccount, useChatData } from '../../../hooks';
import { ThemeContext } from '../theme/ThemeProvider';
-
+import useGetChatProfile from '../../../hooks/useGetChatProfile';
+import useCreateChatProfile from '../../../hooks/useCreateChatProfile';
+import useDecryptPGPKey from '../../../hooks/useDecryptPGPKey';
import { getAddressFromSigner } from '../../../helpers';
import { IChatTheme } from '../theme';
import { device } from '../../../config';
+import useChatProfile from '../../../hooks/chat/useChatProfile';
/**
* @interface IThemeProps
@@ -18,17 +21,25 @@ import { device } from '../../../config';
interface IThemeProps {
theme?: IChatTheme;
}
-
+interface IConnectButtonProps {
+ autoConnect?: boolean;
+}
export const ConnectButtonSub = ({autoConnect = false}) => {
const {wallet, connecting , connect, disconnect} = useAccount();
const {
signer,
+ account,
+ env,
setAccount,
setSigner,
+ alias,
+ setAlias
} = useChatData();
const theme = useContext(ThemeContext);
+ const {fetchUserChatProfile} = useChatProfile();
+ const {decryptPGPKey} = useDecryptPGPKey();
const setUserData = () => {
@@ -51,6 +62,19 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
setUserData()
}, [wallet])
+ //initialise user hook
+
+ // useEffect(() => {
+ // (async () => {
+ // if (!alias && signer) {
+ // const user = await fetchChatProfile({signer: signer, env});
+ // if (user) {
+ // setAlias(user);
+ // }
+ // }
+ // })();
+ // }, [alias, signer]);
+
return !signer ? (
diff --git a/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx b/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx
index 7a38fed61..4d634e08d 100644
--- a/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx
+++ b/packages/uiweb/src/lib/components/chat/MessageInput/MessageInput.tsx
@@ -28,7 +28,7 @@ import {
setAccessControl,
} from '../../../helpers';
import useFetchChat from '../../../hooks/chat/useFetchChat';
-import useGetChatProfile from '../../../hooks/useGetChatProfile';
+import useChatProfile from '../../../hooks/chat/useChatProfile';
import useGetGroup from '../../../hooks/chat/useGetGroup';
import useApproveChatRequest from '../../../hooks/chat/useApproveChatRequest';
import {
@@ -115,13 +115,11 @@ export const MessageInput: React.FC = ({
const {
account,
env,
- connectedProfile,
- setConnectedProfile,
- pgpPrivateKey,
signer,
+ pushUser,
} = useChatData();
const { fetchChat } = useFetchChat();
- const { fetchChatProfile } = useGetChatProfile();
+ const { fetchUserChatProfile } = useChatProfile();
const { getGroup } = useGetGroup();
const statusToast = useToast();
const textAreaRef = useRef(null);
@@ -143,14 +141,16 @@ export const MessageInput: React.FC = ({
}, [textAreaRef, typedMessage]);
//need to do something about fetching connectedUser in every component
- useEffect(() => {
- (async () => {
- if (!connectedProfile && account) {
- const user = await fetchChatProfile({ profileId: account!, env });
- if (user) setConnectedProfile(user);
- }
- })();
- }, [account]);
+ //initalization not needed here
+
+ // useEffect(() => {
+ // (async () => {
+ // if (!pushUser && signer) {
+ // const user = await fetchUserChatProfile({ profileId: account!,env });
+ // if (user) setpushUser(user);
+ // }
+ // })();
+ // }, [pushUser]);
useEffect(() => {
const storedTimestampJSON = localStorage.getItem(chatId);
@@ -183,6 +183,7 @@ export const MessageInput: React.FC = ({
setChatFeed(updateChatFeed);
}
}
+ console.log(chatFeed)
}, [groupInformationSinceLastConnection]);
useEffect(() => {
@@ -200,15 +201,16 @@ export const MessageInput: React.FC = ({
useEffect(() => {
(async () => {
if (!account && !env) return;
- if (account && env) {
- const chat = await fetchChat({ chatId });
+ if (pushUser) {
+ console.log('in fetch message input')
+ const chat = await fetchChat();
if (Object.keys(chat || {}).length) setChatFeed(chat as IFeeds);
else {
let newChatFeed;
let group;
const result = await getNewChatUser({
searchText: chatId,
- fetchChatProfile,
+ fetchChatProfile:fetchUserChatProfile,
env,
});
if (result) {
@@ -225,19 +227,15 @@ export const MessageInput: React.FC = ({
}
}
})();
- }, [chatId, pgpPrivateKey, account, env]);
+ }, [chatId, account, env, pushUser]);
useEffect(() => {
- console.log('in useEffect')
- console.log(chatFeed)
if (!account && !env && !chatId) return;
if (account && env && chatId && chatFeed && chatFeed?.groupInformation) {
setIsMember(checkIfMember(chatFeed, account));
setIsRules(checkIfAccessVerifiedGroup(chatFeed));
}
- }, [chatId, chatFeed, account, env]);
-console.log(isMember)
-console.log(checkIfMember(chatFeed, account!))
+ }, [chatId, chatFeed, account, env, pushUser]);
const addEmoji = (emojiData: EmojiClickData, event: MouseEvent): void => {
setTypedMessage(typedMessage + emojiData.emoji);
setShowEmojis(false);
@@ -255,9 +253,7 @@ console.log(checkIfMember(chatFeed, account!))
const handleJoinGroup = async () => {
if (chatFeed && chatFeed?.groupInformation?.isPublic) {
- const response = await approveChatRequest({
- chatId,
- });
+ const response = await pushUser.chat.accept(chatId);
if (response) {
await updateChatFeed();
}
@@ -332,11 +328,11 @@ console.log(checkIfMember(chatFeed, account!))
};
const isJoinGroup = () => {
- return !!pgpPrivateKey && !isMember;
+ return !isMember;
};
const isNotVerified = () => {
- return !!pgpPrivateKey && !verified && isMember && isRules;
+ return !verified && isMember && isRules;
};
const sendPushMessage = async (content: string, type: string) => {
@@ -374,7 +370,7 @@ console.log(checkIfMember(chatFeed, account!))
const updateChatFeed = async () => {
- const chat = await fetchChat({ chatId });
+ const chat = await fetchChat();
if (Object.keys(chat || {}).length) {
@@ -382,20 +378,21 @@ console.log(checkIfMember(chatFeed, account!))
}
};
- return !(pgpPrivateKey && account) && isConnected ? (
+ return !(account) && isConnected ? (
- ) : !checkIfIntent({ chat: chatFeed, account: account! }) &&
+ ) :
+ !checkIfIntent({ chat: chatFeed, account: account! }) &&
Object.keys(chatFeed || {}).length ? (
)}
- {!!pgpPrivateKey && !verificationSuccessfull && (
+ {!verificationSuccessfull && (
) : null}
- {!!pgpPrivateKey &&
+ {
(((isRules ? verified : true) && isMember) ||
(chatFeed && !chatFeed?.groupInformation)) && (
<>
diff --git a/packages/uiweb/src/lib/context/chatContext.ts b/packages/uiweb/src/lib/context/chatContext.ts
index 1757a940a..ac635d7ab 100644
--- a/packages/uiweb/src/lib/context/chatContext.ts
+++ b/packages/uiweb/src/lib/context/chatContext.ts
@@ -6,8 +6,6 @@ import { createContext } from "react";
export interface IChatDataContextValues {
account: string | null;
setAccount: React.Dispatch>;
- pgpPrivateKey: string | null;
- setPgpPrivateKey: React.Dispatch>;
signer: SignerType | undefined;
setSigner: React.Dispatch>;
env: Env;
@@ -18,6 +16,8 @@ export interface IChatDataContextValues {
setIsPushChatSocketConnected: React.Dispatch>;
connectedProfile: IUser | undefined;
setConnectedProfile: (connectedProfile: IUser) => void;
+ pushUser: any;
+ setPushUser: React.Dispatch>;
}
export const initialChatDataContextValues: IChatDataContextValues = {
@@ -29,10 +29,6 @@ export const initialChatDataContextValues: IChatDataContextValues = {
setSigner: () => {
/**/
},
- pgpPrivateKey: '',
- setPgpPrivateKey: () => {
- /**/
- },
env: Constants.ENV.PROD,
setEnv: () => {
/**/
@@ -48,7 +44,11 @@ export const initialChatDataContextValues: IChatDataContextValues = {
connectedProfile: undefined,
setConnectedProfile: () => {
/** */
- }
+ },
+ pushUser: null,
+ setPushUser: () => {
+ /** */
+ },
}
diff --git a/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx b/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
index a6f969222..3563701d7 100644
--- a/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
+++ b/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
@@ -5,20 +5,16 @@ import {
IChatDataContextValues,
} from '../context/chatContext';
import { ThemeContext } from '../components/chat/theme/ThemeProvider';
-import useGetChatProfile from '../hooks/useGetChatProfile';
import { IUser, SignerType } from '@pushprotocol/restapi';
import { IChatTheme, lightChatTheme } from '../components/chat/theme';
import { getAddressFromSigner, pCAIP10ToWallet } from '../helpers';
-import useCreateChatProfile from '../hooks/useCreateChatProfile';
-import useDecryptPGPKey from '../hooks/useDecryptPGPKey';
-
+import useInitializePushUser from '../hooks/chat/useInitializePushUser';
export interface IChatUIProviderProps {
children: ReactNode;
theme?: IChatTheme;
account?: string | null;
signer?: SignerType | undefined;
- pgpPrivateKey?: string | null;
env?: ENV;
}
@@ -26,105 +22,61 @@ export const ChatUIProvider = ({
children,
account = null,
theme,
- pgpPrivateKey = null,
signer = undefined,
env = Constants.ENV.PROD,
}: IChatUIProviderProps) => {
- const [accountVal, setAccountVal] = useState(pCAIP10ToWallet(account!));
- const [pushChatSocket, setPushChatSocket] = useState(null);
- const [signerVal, setSignerVal] = useState(signer);
-
- const [pgpPrivateKeyVal, setPgpPrivateKeyVal] =
- useState(pgpPrivateKey);
+ const [accountVal, setAccountVal] = useState(
+ pCAIP10ToWallet(account!)
+ );
+ const [pushChatSocket, setPushChatSocket] = useState(null);
+ const [signerVal, setSignerVal] = useState(signer);
+ const [pushUser, setPushUser] = useState(null);
const [envVal, setEnvVal] = useState(env);
- const {fetchChatProfile} = useGetChatProfile();
- const [connectedProfile,setConnectedProfile]=useState(undefined);
-
+ const [connectedProfile, setConnectedProfile] = useState(
+ undefined
+ );
+ const { initializePushUser } = useInitializePushUser();
const [isPushChatSocketConnected, setIsPushChatSocketConnected] =
- useState(false);
- const {createChatProfile} = useCreateChatProfile();
- const {decryptPGPKey} = useDecryptPGPKey();
+ useState(false);
useEffect(() => {
- (async()=>{
+ (async () => {
resetStates();
setEnvVal(env);
-
+
if (signer) {
if (!account) {
const address = await getAddressFromSigner(signer);
setAccountVal(address);
- }
- else{
+ } else {
setAccountVal(account);
}
- }
+ }
setSignerVal(signer);
- setPgpPrivateKeyVal(pgpPrivateKey);
- })()
-
- }, [env,account,signer,pgpPrivateKey])
-
+ })();
+ }, [env, account, signer]);
useEffect(() => {
(async () => {
- if (accountVal && signerVal) {
- if (!pgpPrivateKeyVal) await handleUserCreation();
+ if (Object.keys(signer || {}).length && account) {
+ const pushUser = await initializePushUser({ signer: signer!, account });
+ setPushUser(pushUser);
}
})();
- }, [accountVal, signerVal]);
-
+ }, [signer, account, env]);
- const handleUserCreation = async () => {
- if (!accountVal && !envVal) return;
- try {
- let user = await fetchChatProfile({ profileId: accountVal! ,env:envVal});
- if (!user) {
- if (!signerVal) return;
- user = await createChatProfile({ signer: signerVal ,env:envVal});
- }
- if (user?.encryptedPrivateKey && !pgpPrivateKey) {
- const decryptedPgpKey = await decryptPGPKey({
- encryptedPrivateKey: user.encryptedPrivateKey,
- account: accountVal!,
- signer: signerVal,
- env: envVal,
- });
- if(decryptedPgpKey)
- setPgpPrivateKeyVal(decryptedPgpKey);
- }
- } catch (e: any) {
- console.log(e);
- }
+ const resetStates = () => {
+ setPushChatSocket(null);
+ setIsPushChatSocketConnected(false);
};
-const resetStates = () => {
- setPushChatSocket(null);
- setIsPushChatSocketConnected(false);
-
-};
-
-
-
-useEffect(() => {
- (async () => {
- let user;
- if (account) {
- user = await fetchChatProfile({ profileId: account,env });
- if (user) setConnectedProfile(user);
- }
- })();
- }, [account,env,pgpPrivateKey]);
-
const value: IChatDataContextValues = {
account: accountVal,
- signer:signerVal,
- setSigner:setSignerVal,
+ signer: signerVal,
+ setSigner: setSignerVal,
setAccount: setAccountVal,
- pgpPrivateKey: pgpPrivateKeyVal,
- setPgpPrivateKey: setPgpPrivateKeyVal,
env: envVal,
setEnv: setEnvVal,
pushChatSocket,
@@ -132,10 +84,11 @@ useEffect(() => {
isPushChatSocketConnected,
setIsPushChatSocketConnected,
connectedProfile,
- setConnectedProfile
+ setConnectedProfile,
+ pushUser,
+ setPushUser,
};
-
const PROVIDER_THEME = Object.assign({}, lightChatTheme, theme);
return (
diff --git a/packages/uiweb/src/lib/helpers/chat/chat.ts b/packages/uiweb/src/lib/helpers/chat/chat.ts
index 81c4ade7d..41520228a 100644
--- a/packages/uiweb/src/lib/helpers/chat/chat.ts
+++ b/packages/uiweb/src/lib/helpers/chat/chat.ts
@@ -1,7 +1,7 @@
import * as PushAPI from '@pushprotocol/restapi';
import type { ENV } from '../../config';
import { Constants } from '../../config';
-import type {
+import type {
AccountEnvOptionsType,
IGroup,
IMessageIPFS,
@@ -218,10 +218,10 @@ export const getChatId = ({
msg: IMessageIPFS;
account: string;
}) => {
- if (pCAIP10ToWallet(msg.fromDID).toLowerCase() === account.toLowerCase()) {
- return msg.toDID;
+ if (pCAIP10ToWallet(msg.fromCAIP10).toLowerCase() === account.toLowerCase()) {
+ return msg.toCAIP10;
}
- return !isPCAIP(msg.toDID) ? msg.toDID : msg.fromDID;
+ return !isPCAIP(msg.toCAIP10) ? msg.toCAIP10 : msg.fromCAIP10;
};
export const appendUniqueMessages = (
@@ -253,10 +253,10 @@ export const checkIfSameChat = (
chatId = walletToPCAIP10(chatId);
if (
Object.keys(msg || {}).length &&
- (((chatId.toLowerCase() === msg.fromCAIP10?.toLowerCase()) &&
+ (((chatId.toLowerCase() === (msg.fromCAIP10?.toLowerCase())) &&
( walletToPCAIP10(account!).toLowerCase() ===
msg.toCAIP10?.toLowerCase())) ||
- ((chatId.toLowerCase() === msg.toCAIP10?.toLowerCase()) &&
+ ((chatId.toLowerCase() === (msg.toCAIP10?.toLowerCase())) &&
(walletToPCAIP10(account!).toLowerCase() ===
msg.fromCAIP10?.toLowerCase())))
) {
@@ -273,4 +273,4 @@ export const checkIfSameChat = (
console.log(chatId);
return false;
-};
+};
\ No newline at end of file
diff --git a/packages/uiweb/src/lib/helpers/chat/search.ts b/packages/uiweb/src/lib/helpers/chat/search.ts
index ce5448dba..7a4b3aa06 100644
--- a/packages/uiweb/src/lib/helpers/chat/search.ts
+++ b/packages/uiweb/src/lib/helpers/chat/search.ts
@@ -74,7 +74,7 @@ export const getNewChatUser = async ({
// address = await getAddress(searchText, env);
// }
if (address) {
- chatProfile = await fetchChatProfile({ profileId: address, env });
+ chatProfile = await fetchChatProfile({ profileId: address,env });
if (!chatProfile)
chatProfile = displayDefaultUser({ caip10: walletToPCAIP10(address) });
return chatProfile;
diff --git a/packages/uiweb/src/lib/helpers/timestamp.ts b/packages/uiweb/src/lib/helpers/timestamp.ts
new file mode 100644
index 000000000..a83c81a13
--- /dev/null
+++ b/packages/uiweb/src/lib/helpers/timestamp.ts
@@ -0,0 +1,15 @@
+export const formatTime = (timestamp: any) => {
+ let date;
+ let timestamp1;
+ if (typeof timestamp === 'string') {
+ timestamp1 = parseInt(timestamp);
+ } else {
+ timestamp1 = timestamp;
+ }
+ const time = new Date(timestamp1!);
+ if (!isNaN(time.getTime())) {
+ const time1 = time.toLocaleTimeString('en-US');
+ date = time1.slice(0, -6) + time1.slice(-2);
+ }
+ return date;
+};
diff --git a/packages/uiweb/src/lib/hooks/chat/index.ts b/packages/uiweb/src/lib/hooks/chat/index.ts
index d497e66d6..16e3f5f39 100644
--- a/packages/uiweb/src/lib/hooks/chat/index.ts
+++ b/packages/uiweb/src/lib/hooks/chat/index.ts
@@ -4,7 +4,6 @@ export * from './useChatData';
export * from './useChatProfile';
export * from './usePushChatSocket';
export * from './useFetchChat';
-export * from './useFetchConversationHash';
export * from './usePushSendMessage';
export * from './useGetGroupByID';
export * from './useAccount';
diff --git a/packages/uiweb/src/lib/hooks/chat/useApproveChatRequest.ts b/packages/uiweb/src/lib/hooks/chat/useApproveChatRequest.ts
index 676705a7f..644d39693 100644
--- a/packages/uiweb/src/lib/hooks/chat/useApproveChatRequest.ts
+++ b/packages/uiweb/src/lib/hooks/chat/useApproveChatRequest.ts
@@ -9,22 +9,14 @@ interface ApproveChatParams {
const useApproveChatRequest = () => {
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
- const { account, env,pgpPrivateKey,signer } =useChatData();
+ const { account, env,signer, pushUser } =useChatData();
const approveChatRequest = useCallback(async (options:ApproveChatParams) => {
const {
-
chatId,
} = options || {};
setLoading(true);
try {
- const response = await PushAPI.chat.approve({
- status: 'Approved',
- account: account,
- senderAddress: chatId,
- signer:signer, // receiver's address or chatId of a group
- pgpPrivateKey:pgpPrivateKey,
- env: env,
- });
+ const response = await pushUser.chat.accept(chatId);
setLoading(false);
return response;
} catch (error: Error | any) {
@@ -35,7 +27,7 @@ const useApproveChatRequest = () => {
}
},
- [account,env,signer,pgpPrivateKey]
+ [account,env,signer,pushUser]
);
diff --git a/packages/uiweb/src/lib/hooks/chat/useChatProfile.ts b/packages/uiweb/src/lib/hooks/chat/useChatProfile.ts
index 8a6d71411..4d384ae31 100644
--- a/packages/uiweb/src/lib/hooks/chat/useChatProfile.ts
+++ b/packages/uiweb/src/lib/hooks/chat/useChatProfile.ts
@@ -4,13 +4,17 @@ import { useChatData } from './useChatData';
export interface ProfileParams {
profileId: string;
+ env:PushAPI.Env
}
+//need to change it to new sdk method
const useChatProfile = () => {
- const { env } = useChatData();
+ // const { env } = useChatData();
+
const fetchUserChatProfile = useCallback(
async ({
- profileId
+ profileId,
+ env
}: ProfileParams): Promise => {
try {
const profile = await PushAPI.user.get({
@@ -23,7 +27,7 @@ const useChatProfile = () => {
return;
}
},
- [env]
+ []
);
return { fetchUserChatProfile };
diff --git a/packages/uiweb/src/lib/hooks/chat/useFetchChat.ts b/packages/uiweb/src/lib/hooks/chat/useFetchChat.ts
index d1bbd06dc..f2b041283 100644
--- a/packages/uiweb/src/lib/hooks/chat/useFetchChat.ts
+++ b/packages/uiweb/src/lib/hooks/chat/useFetchChat.ts
@@ -4,28 +4,21 @@ import { useCallback, useContext, useState } from 'react';
import { useChatData } from './useChatData';
-interface fetchChat {
- chatId: string;
-}
+
const useFetchChat = () => {
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
- const { account, env,pgpPrivateKey } = useChatData();
+ const { account, env, pushUser } = useChatData();
const fetchChat = useCallback(
- async ({ chatId}: fetchChat) => {
+ async () => {
setLoading(true);
try {
- const chat = await PushAPI.chat.chat({
- account: account? account : '0xeeE5A266D7cD954bE3Eb99062172E7071E664023',
- toDecrypt: pgpPrivateKey ? true : false,
- pgpPrivateKey: String(pgpPrivateKey),
- recipient: chatId,
- env: env
- });
- return chat;
+ const chat = await pushUser.chat.list("CHATS")
+ console.log(chat)
+ return chat[0];
} catch (error: Error | any) {
setLoading(false);
setError(error.message);
@@ -36,10 +29,10 @@ const useFetchChat = () => {
setLoading(false);
}
},
- [pgpPrivateKey,env,account]
+ [env,account, pushUser]
);
return { fetchChat, error, loading };
};
-export default useFetchChat;
+export default useFetchChat;
\ No newline at end of file
diff --git a/packages/uiweb/src/lib/hooks/chat/useFetchConversationHash.ts b/packages/uiweb/src/lib/hooks/chat/useFetchConversationHash.ts
deleted file mode 100644
index 5b65d4c61..000000000
--- a/packages/uiweb/src/lib/hooks/chat/useFetchConversationHash.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import * as PushAPI from '@pushprotocol/restapi';
-import { Env } from '@pushprotocol/restapi';
-import { useCallback, useContext, useState } from 'react';
-import { useChatData } from './useChatData';
-
-interface conversationHashParams {
- conversationId: string;
-}
-
-const useFetchConversationHash = () => {
- const [error, setError] = useState();
- const [loading, setLoading] = useState(false);
- const { account, env } = useChatData();
-
- const fetchConversationHash = useCallback(
- async ({ conversationId }: conversationHashParams) => {
- setLoading(true);
- try {
- const response = await PushAPI.chat.conversationHash({
- conversationId,
- account: account ? account : '0xeeE5A266D7cD954bE3Eb99062172E7071E664023',
- env: env,
- });
- setLoading(false);
- return response;
- } catch (error: Error | any) {
- setLoading(false);
- setError(error.message);
- console.log(error);
- return;
- }
- },
- [env, account]
- );
- return { fetchConversationHash, error, loading };
-};
-
-export default useFetchConversationHash;
diff --git a/packages/uiweb/src/lib/hooks/chat/useFetchHistoryMessages.ts b/packages/uiweb/src/lib/hooks/chat/useFetchHistoryMessages.ts
index 0082622f9..dde4850fc 100644
--- a/packages/uiweb/src/lib/hooks/chat/useFetchHistoryMessages.ts
+++ b/packages/uiweb/src/lib/hooks/chat/useFetchHistoryMessages.ts
@@ -1,15 +1,14 @@
-import * as PushAPI from '@pushprotocol/restapi';
-import type { IMessageIPFS } from '@pushprotocol/restapi';
+
import { useCallback, useContext, useState } from 'react';
-import { ChatDataContext } from '../../context';
+
import { useChatData } from './useChatData';
interface HistoryMessagesParams {
- threadHash: string;
+ chatId?: string;
limit?: number;
}
@@ -19,20 +18,13 @@ const useFetchHistoryMessages
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
- const { account, env,pgpPrivateKey } = useChatData();
+ const { account, env, pushUser } = useChatData();
- const historyMessages = useCallback(async ({threadHash,limit = 10,}:HistoryMessagesParams) => {
+ const historyMessages = useCallback(async ({chatId}: HistoryMessagesParams) => {
setLoading(true);
try {
- const chatHistory:IMessageIPFS[] = await PushAPI.chat.history({
- threadhash: threadHash,
- account:account ? account : '0xeeE5A266D7cD954bE3Eb99062172E7071E664023',
- toDecrypt: pgpPrivateKey ? true : false,
- pgpPrivateKey: String(pgpPrivateKey),
- limit: limit,
- env: env
- });
+ const chatHistory = await pushUser.chat.history(chatId)
chatHistory.reverse();
return chatHistory;
} catch (error: Error | any) {
@@ -43,9 +35,9 @@ const useFetchHistoryMessages
} finally {
setLoading(false);
}
- }, [pgpPrivateKey,account,env]);
+ }, [account,env, pushUser]);
return { historyMessages, error, loading };
};
-export default useFetchHistoryMessages;
+export default useFetchHistoryMessages;
\ No newline at end of file
diff --git a/packages/uiweb/src/lib/hooks/chat/useInitializePushUser.ts b/packages/uiweb/src/lib/hooks/chat/useInitializePushUser.ts
new file mode 100644
index 000000000..b445c062d
--- /dev/null
+++ b/packages/uiweb/src/lib/hooks/chat/useInitializePushUser.ts
@@ -0,0 +1,32 @@
+import {PushAPI, SignerType} from '@pushprotocol/restapi';
+import { useCallback, useContext } from 'react';
+import { useChatData } from './useChatData';
+
+export interface ProfileParams {
+ signer: SignerType;
+ account:string;
+}
+
+const useInitializePushUser = () => {
+ const { env } = useChatData();
+
+ const initializePushUser = useCallback(
+ async ({
+ signer,
+ account
+ }: ProfileParams): Promise => {
+ try {
+ const pushUser = await PushAPI.initialize(signer, {env: env,account:account})
+ return pushUser;
+ } catch (error) {
+ console.log(error);
+ return;
+ }
+ },
+ []
+ );
+
+ return { initializePushUser };
+};
+
+export default useInitializePushUser;
diff --git a/packages/uiweb/src/lib/hooks/chat/usePushChatSocket.ts b/packages/uiweb/src/lib/hooks/chat/usePushChatSocket.ts
index 91d8a737c..ee01e7e51 100644
--- a/packages/uiweb/src/lib/hooks/chat/usePushChatSocket.ts
+++ b/packages/uiweb/src/lib/hooks/chat/usePushChatSocket.ts
@@ -1,117 +1,91 @@
-import { createSocketConnection, EVENTS } from '@pushprotocol/socket';
import { useCallback, useEffect, useState } from 'react';
-import { ENV } from '../../config';
-import * as PushAPI from '@pushprotocol/restapi';
-
import { useChatData } from './useChatData';
-import { SOCKET_TYPE } from '../../types';
-import useGetChatProfile from '../useGetChatProfile';
-export type PushChatSocketHookOptions = {
- account?: string | null;
- env?: ENV;
-};
+import { CONSTANTS } from '@pushprotocol/restapi';
+
+
export const usePushChatSocket = () => {
const {
- account,
- pgpPrivateKey,
- pushChatSocket,
- setPushChatSocket,
setIsPushChatSocketConnected,
isPushChatSocketConnected,
- connectedProfile,
- setConnectedProfile,
env,
+ pushUser
} = useChatData();
-const {fetchChatProfile} = useGetChatProfile();
const [messagesSinceLastConnection, setMessagesSinceLastConnection] =
useState({});
- const [acceptedRequestMessage, setAcceptedRequestMessage] =
+ const [acceptedRequestMessage, setAcceptedRequestMessage] =
useState({});
+ const [stream, setStream] = useState();
const [
groupInformationSinceLastConnection,
setGroupInformationSinceLastConnection,
] = useState({});
- // useEffect(() => {
- // // console.log(pgpPrivateKey, "pgppppppppp")
- // // console.log(connectedProfile, "connectedProfileeeeeeeee")
- // }, [pgpPrivateKey, connectedProfile])
-
- const addSocketEvents = useCallback(() => {
+ const addSocketEvents = useCallback(async () => {
console.log('addSocketEvents');
- pushChatSocket?.on(EVENTS.CONNECT, () => {
+ stream.on(CONSTANTS.STREAM.CONNECT, () => {
+
setIsPushChatSocketConnected(true);
- });
+ })
- pushChatSocket?.on(EVENTS.DISCONNECT, (reason: string) => {
+ stream.on(CONSTANTS.STREAM.DISCONNECT, (reason: string) => {
setIsPushChatSocketConnected(false);
});
- pushChatSocket?.on(EVENTS.CHAT_RECEIVED_MESSAGE, async (chat: any) => {
-
-
- if (!connectedProfile || !pgpPrivateKey) {
- return;
- }
+ stream.on(CONSTANTS.STREAM.CHAT, async (chat: any) => {
+ console.log('chat', chat);
if (
- ( chat.messageCategory === 'Request') &&
+ (chat.messageCategory === 'Request') &&
(chat.messageContent === null) &&
(chat.messageType === null)
) {
setAcceptedRequestMessage(chat);
- }
- else
- {
- const response = await PushAPI.chat.decryptConversation({
- messages: [chat],
- connectedUser: connectedProfile,
- pgpPrivateKey: pgpPrivateKey,
- env: env,
+ } else {
+ // Extract 'from' and 'to' from the 'message' property
+ //shfit to a new func
+ const fromCAIP10 = chat.from;
+ const toCAIP10 = chat.to.join(', '); // Use the appropriate separator if needed
+ // Create a new object with modified properties
+ const messageContent = chat.message.content;
+ const modifiedChat = {
+ ...chat,
+ fromCAIP10: fromCAIP10,
+ toCAIP10: toCAIP10,
+ messageContent: messageContent,
+ };
+ delete modifiedChat.from;
+ delete modifiedChat.to;
+
+ setMessagesSinceLastConnection((chats: any) => {
+ return modifiedChat;
});
-
- if (response && response.length) {
- setMessagesSinceLastConnection(response[0]);
- }
}
-
- });
- pushChatSocket?.on(EVENTS.CHAT_GROUPS, (groupInfo: any) => {
- /**
- * We receive a group creation or updated event.
- */
- setGroupInformationSinceLastConnection(groupInfo);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
- pushChatSocket,
- account,
- pgpPrivateKey,
messagesSinceLastConnection,
env,
- connectedProfile,
+ pushUser,
+ stream
]);
const removeSocketEvents = useCallback(() => {
- pushChatSocket?.off(EVENTS.CONNECT);
- pushChatSocket?.off(EVENTS.DISCONNECT);
- pushChatSocket?.off(EVENTS.CHAT_GROUPS);
- pushChatSocket?.off(EVENTS.CHAT_RECEIVED_MESSAGE);
- }, [pushChatSocket]);
+ stream?.disconnect();
+ }, [stream]);
useEffect(() => {
- if (pushChatSocket) {
+ if (stream) {
addSocketEvents();
}
return () => {
- if (pushChatSocket) {
+ if (stream) {
removeSocketEvents();
}
};
- }, [pushChatSocket, pgpPrivateKey, connectedProfile]);
+ }, [stream, pushUser]);
/**
* Whenever the required params to create a connection object change
@@ -119,30 +93,26 @@ const {fetchChatProfile} = useGetChatProfile();
* - create a new connection object
*/
useEffect(() => {
- if (account) {
- if (pushChatSocket && pushChatSocket.connected) {
- // pushChatSocket?.disconnect();
- } else {
- const main = async () => {
- const connectionObject = createSocketConnection({
- user: account,
- env,
- socketType: SOCKET_TYPE.CHAT,
- socketOptions: { autoConnect: true, reconnectionAttempts: 3 },
- });
- console.warn('new connection object: ', connectionObject);
-
- setPushChatSocket(connectionObject);
- };
- main().catch((err) => console.error(err));
- }
+ if (!stream && pushUser) {
+ const main = async () => {
+
+ const stream = await pushUser.initStream(
+ [
+ CONSTANTS.STREAM.CHAT,
+ ],
+ {}
+ );
+ setStream(stream);
+ await stream.connect();
+ console.warn('new connection object: ', stream);
+ };
+ main().catch((err) => console.error(err));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [account, env, pgpPrivateKey]);
+ }, [pushUser, env, stream]);
return {
- pushChatSocket,
isPushChatSocketConnected,
messagesSinceLastConnection,
acceptedRequestMessage,
diff --git a/packages/uiweb/src/lib/hooks/chat/usePushSendMessage.ts b/packages/uiweb/src/lib/hooks/chat/usePushSendMessage.ts
index 4c4ff6173..a51a9f947 100644
--- a/packages/uiweb/src/lib/hooks/chat/usePushSendMessage.ts
+++ b/packages/uiweb/src/lib/hooks/chat/usePushSendMessage.ts
@@ -1,9 +1,6 @@
-import * as PushAPI from '@pushprotocol/restapi';
-import { useCallback, useContext, useState } from 'react';
-import useVerifyAccessControl from './useVerifyAccessControl';
+import { useCallback, useState } from 'react';
import { useChatData } from '..';
-import { ENV } from '../../config';
-import { setAccessControl } from '../../helpers';
+
interface SendMessageParams {
message: string;
@@ -11,42 +8,38 @@ interface SendMessageParams {
messageType?: 'Text' | 'Image' | 'File' | 'GIF' | 'MediaEmbed';
}
-const usePushSendMessage = () => {
+const usePushSendMessage = () => {
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
- const { pgpPrivateKey, env, account } = useChatData();
+ const { env, account, pushUser } = useChatData();
const sendMessage = useCallback(
async (options: SendMessageParams) => {
const { chatId, message, messageType } = options || {};
setLoading(true);
try {
- const response = await PushAPI.chat.send({
- messageContent: message,
- messageType: messageType,
- receiverAddress: chatId,
- account: account ? account : undefined,
- pgpPrivateKey: pgpPrivateKey ? pgpPrivateKey : undefined,
- env: env,
- });
+ const response = await pushUser.chat.send(chatId, {
+ type: messageType,
+ content: message,
+ })
setLoading(false);
if (!response) {
return false;
}
return response;
} catch (error: Error | any) {
-
+
setLoading(false);
setError(error.message);
console.log(error);
return error.message;
}
},
- [pgpPrivateKey, account,env]
+ [ account, env, pushUser]
);
return { sendMessage, error, loading };
};
-export default usePushSendMessage;
+export default usePushSendMessage;
\ No newline at end of file
diff --git a/packages/uiweb/src/lib/hooks/chatAndNotification/chat/index.ts b/packages/uiweb/src/lib/hooks/chatAndNotification/chat/index.ts
index 49cf9937a..1304a70ad 100644
--- a/packages/uiweb/src/lib/hooks/chatAndNotification/chat/index.ts
+++ b/packages/uiweb/src/lib/hooks/chatAndNotification/chat/index.ts
@@ -1,7 +1,6 @@
export * from './useFetchChats';
export * from './useFetchRequests';
export * from './useFetchHistoryMessages';
-export * from './useFetchConversationHash';
export * from './useApproveChatRequest';
export * from './useFetchChat';
export * from './usePushSendMessage';
diff --git a/packages/uiweb/src/lib/hooks/chatAndNotification/chat/usePushSendMessage.ts b/packages/uiweb/src/lib/hooks/chatAndNotification/chat/usePushSendMessage.ts
index 646601d41..d59407c95 100644
--- a/packages/uiweb/src/lib/hooks/chatAndNotification/chat/usePushSendMessage.ts
+++ b/packages/uiweb/src/lib/hooks/chatAndNotification/chat/usePushSendMessage.ts
@@ -4,7 +4,6 @@ import { useCallback, useContext, useState } from 'react';
import { Constants } from '../../../config';
import { ChatMainStateContext, ChatAndNotificationPropsContext } from '../../../context';
import type { ChatMainStateContextType } from '../../../context/chatAndNotification/chat/chatMainStateContext';
-import useFetchChat from './useFetchChat';
interface SendMessageParams {
message: string;
@@ -16,12 +15,11 @@ interface SendMessageParams {
const usePushSendMessage = () => {
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
- const { setChatFeed, setChat, chatsFeed, chats, selectedChatId } =
+ const { setChat,chats, selectedChatId } =
useContext(ChatMainStateContext);
const { account, env, decryptedPgpPvtKey } =
useContext(ChatAndNotificationPropsContext);
- const { fetchChat } = useFetchChat();
const sendMessage = useCallback(
async (options: SendMessageParams) => {
const { receiver, message, messageType } = options || {};
diff --git a/packages/uiweb/src/lib/hooks/useGetChatProfile.ts b/packages/uiweb/src/lib/hooks/useGetChatProfile.ts
index 8937a7026..c49f29848 100644
--- a/packages/uiweb/src/lib/hooks/useGetChatProfile.ts
+++ b/packages/uiweb/src/lib/hooks/useGetChatProfile.ts
@@ -1,6 +1,7 @@
import * as PushAPI from '@pushprotocol/restapi';
import { useCallback, useContext } from 'react';
-import { ChatAndNotificationPropsContext } from '../context';
+import { Constants } from '../config';
+
export interface GetProfileParams {
profileId: string;
@@ -11,7 +12,7 @@ const useGetChatProfile = () => {
const fetchChatProfile = useCallback(
async ({
profileId,
- env
+ env
}: GetProfileParams): Promise => {
try {
const profile = await PushAPI.user.get({
@@ -30,4 +31,4 @@ const useGetChatProfile = () => {
return { fetchChatProfile };
};
-export default useGetChatProfile;
+export default useGetChatProfile;
\ No newline at end of file
diff --git a/packages/uiweb/yarn.lock b/packages/uiweb/yarn.lock
index d714d5fff..4d3ac82a3 100644
--- a/packages/uiweb/yarn.lock
+++ b/packages/uiweb/yarn.lock
@@ -3618,6 +3618,11 @@ node-gyp-build@^4.2.0, node-gyp-build@^4.3.0:
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.1.tgz#24b6d075e5e391b8d5539d98c7fc5c210cac8a3e"
integrity sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==
+normalize-wheel@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/normalize-wheel/-/normalize-wheel-1.0.1.tgz#aec886affdb045070d856447df62ecf86146ec45"
+ integrity sha512-1OnlAPZ3zgrk8B91HyRj+eVv+kS5u+Z0SCsak6Xil/kmgEia50ga7zfkumayonZrImffAxPU/5WcyGhzetHNPA==
+
object-inspect@^1.9.0:
version "1.12.3"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.3.tgz#ba62dffd67ee256c8c086dfae69e016cd1f198b9"
@@ -3816,11 +3821,24 @@ randombytes@^2.1.0:
dependencies:
safe-buffer "^5.1.0"
+react-easy-crop@^4.1.4:
+ version "4.7.5"
+ resolved "https://registry.yarnpkg.com/react-easy-crop/-/react-easy-crop-4.7.5.tgz#1526827fc83e38b079372310f983bc0517ba6442"
+ integrity sha512-qKfI4PuhaH1jOLC3DQfQB0cE0z+3N7bfyPkPejQmylXNb8nstfPMH+oHj3gKgpBHLFUiQp/C1rY7sVCVgtjn3Q==
+ dependencies:
+ normalize-wheel "^1.0.1"
+ tslib "2.0.1"
+
react-icons@^4.10.1:
version "4.10.1"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.10.1.tgz#3f3b5eec1f63c1796f6a26174a1091ca6437a500"
integrity sha512-/ngzDP/77tlCfqthiiGNZeYFACw85fUjZtLbedmJ5DTlNDIwETxhwBzdOJ21zj4iJdvc0J3y7yOsX3PpxAJzrw==
+react-image-file-resizer@^0.4.7:
+ version "0.4.8"
+ resolved "https://registry.yarnpkg.com/react-image-file-resizer/-/react-image-file-resizer-0.4.8.tgz#85f4ae4469fd2867d961568af660ef403d7a79af"
+ integrity sha512-Ue7CfKnSlsfJ//SKzxNMz8avDgDSpWQDOnTKOp/GNRFJv4dO9L5YGHNEnj40peWkXXAK2OK0eRIoXhOYpUzUTQ==
+
react-property@2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/react-property/-/react-property-2.0.0.tgz"
@@ -4214,6 +4232,11 @@ tslib@1.14.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
+tslib@2.0.1:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e"
+ integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==
+
tslib@^2.0.0, tslib@^2.1.0, tslib@^2.3.0:
version "2.5.0"
resolved "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz"