Skip to content

Commit

Permalink
fix: removed unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMikhaelson committed Nov 16, 2023
1 parent 5db0221 commit 1d49e23
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ApproveRequestBubble = ({
chatId,
setChatFeed,
}: IApproveRequestBubbleProps) => {
const { pgpPrivateKey, alias } = useChatData();
const { alias } = useChatData();

const ApproveRequestText = {
GROUP: `You were invited to the group ${chatFeed?.groupInformation?.groupName}. Please accept to continue messaging in this group.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
options: IChatViewListProps
) => {
const { chatId, limit = chatLimit, chatFilterList = [] } = options || {};
const { pgpPrivateKey, account, connectedProfile, setConnectedProfile, signer, alias, setAlias } =
const { account, connectedProfile, setConnectedProfile, signer, alias, setAlias } =
useChatData();
const [chatFeed, setChatFeed] = useState<IFeeds>({} as IFeeds);
const [chatStatusText, setChatStatusText] = useState<string>('');
Expand Down Expand Up @@ -80,7 +80,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
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(() => {
Expand Down Expand Up @@ -123,7 +123,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
setLoading(false);
}
})();
}, [chatId, pgpPrivateKey, account, env, alias]);
}, [chatId, account, env, alias]);

//moniters socket changes
useEffect(() => {
Expand Down Expand Up @@ -171,7 +171,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
await getMessagesCall();
})();
// }
}, [conversationHash, pgpPrivateKey, account, env, chatFeed, alias]);
}, [conversationHash, account, env, chatFeed, alias]);

useEffect(() => {
scrollToBottom();
Expand Down Expand Up @@ -277,7 +277,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
chatFeed &&
chatFeed?.groupInformation &&
!chatFeed?.groupInformation?.isPublic &&
((!isMember && pgpPrivateKey) || (!pgpPrivateKey))
(!isMember)
);
}

Expand Down Expand Up @@ -383,7 +383,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (
{chatFeed &&
account &&
checkIfIntent({
chat: chatFeed as any,
chat: chatFeed,
account: account!,
}) && (
<ApproveRequestBubble
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export const ConnectButtonSub = ({autoConnect = false}) => {

const {
signer,
pgpPrivateKey,
account,
env,
setPgpPrivateKey,
setAccount,
setSigner,
alias,
Expand All @@ -55,7 +53,6 @@ export const ConnectButtonSub = ({autoConnect = false}) => {
} else if (!wallet) {
setAccount('')
setSigner(undefined)
setPgpPrivateKey(null)
}
}
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ export const MessageInput: React.FC<MessageInputProps> = ({
const {
account,
env,
connectedProfile,
setConnectedProfile,
pgpPrivateKey,
signer,
alias,
setAlias
Expand Down Expand Up @@ -229,21 +226,15 @@ export const MessageInput: React.FC<MessageInputProps> = ({
}
}
})();
}, [chatId, pgpPrivateKey, account, env, alias]);
}, [chatId, account, env, alias]);

useEffect(() => {
console.log('in useEffect')
console.log(((isRules ? verified : true) && isMember) ||
(chatFeed && !chatFeed?.groupInformation), "letsseee")
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, alias]);
console.log(isMember)
console.log(checkIfMember(chatFeed, account!))
const addEmoji = (emojiData: EmojiClickData, event: MouseEvent): void => {
setTypedMessage(typedMessage + emojiData.emoji);
setShowEmojis(false);
Expand Down Expand Up @@ -392,23 +383,23 @@ console.log(checkIfMember(chatFeed, account!))
overflow="hidden"
borderRadius="13px"
position="static"
padding={` ${pgpPrivateKey ? '13px 16px' : ''}`}
padding={'13px 16px'}
background={`${theme.backgroundColor?.messageInputBackground}`}
alignItems="center"
justifyContent="space-between"
>
<ConnectButtonSection autoConnect={autoConnect} />
</TypebarSection>
) :
// !checkIfIntent({ chat: chatFeed, account: account! }) &&
!checkIfIntent({ chat: chatFeed, account: account! }) &&
Object.keys(chatFeed || {}).length ? (
<TypebarSection
width="100%"
overflow="hidden"
borderRadius={theme.borderRadius?.messageInput}
position="static"
border={theme.border?.messageInput}
padding={` ${pgpPrivateKey ? '13px 16px' : ''}`}
padding={`13px 16px`}
background={`${theme.backgroundColor?.messageInputBackground}`}
alignItems="center"
justifyContent="space-between"
Expand Down Expand Up @@ -518,7 +509,7 @@ console.log(checkIfMember(chatFeed, account!))
(((isRules ? verified : true) && isMember) ||
(chatFeed && !chatFeed?.groupInformation)) && (
<>
<Section padding='8px' gap="8px" flex="1" position="static">
<Section gap="8px" flex="1" position="static">
{emoji && (
<Div
width="25px"
Expand Down
6 changes: 0 additions & 6 deletions packages/uiweb/src/lib/context/chatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { createContext } from "react";
export interface IChatDataContextValues {
account: string | null;
setAccount: React.Dispatch<React.SetStateAction<string| null>>;
pgpPrivateKey: string | null;
setPgpPrivateKey: React.Dispatch<React.SetStateAction<string | null>>;
signer: SignerType | undefined;
setSigner: React.Dispatch<React.SetStateAction<SignerType | undefined>>;
env: Env;
Expand All @@ -31,10 +29,6 @@ export const initialChatDataContextValues: IChatDataContextValues = {
setSigner: () => {
/**/
},
pgpPrivateKey: '',
setPgpPrivateKey: () => {
/**/
},
env: Constants.ENV.PROD,
setEnv: () => {
/**/
Expand Down
7 changes: 0 additions & 7 deletions packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ export const ChatUIProvider = ({
children,
account = null,
theme,
pgpPrivateKey = null,
signer = undefined,
env = Constants.ENV.PROD,
}: IChatUIProviderProps) => {
const [accountVal, setAccountVal] = useState<string | null>(pCAIP10ToWallet(account!));
const [pushChatSocket, setPushChatSocket] = useState<any>(null);
const [signerVal, setSignerVal] = useState<SignerType| undefined>(signer);
const [alias, setAlias] = useState<any>(null);

const [pgpPrivateKeyVal, setPgpPrivateKeyVal] =
useState<string | null>(pgpPrivateKey);
const [envVal, setEnvVal] = useState<ENV>(env);
const {fetchChatProfile} = useGetChatProfile();
const [connectedProfile,setConnectedProfile]=useState<IUser | undefined>(undefined);
Expand All @@ -57,7 +53,6 @@ export const ChatUIProvider = ({
}
}
setSignerVal(signer);
setPgpPrivateKeyVal(pgpPrivateKey);
})()

}, [env,account, alias,signer])
Expand Down Expand Up @@ -91,8 +86,6 @@ useEffect(() => {
signer:signerVal,
setSigner:setSignerVal,
setAccount: setAccountVal,
pgpPrivateKey: pgpPrivateKeyVal,
setPgpPrivateKey: setPgpPrivateKeyVal,
env: envVal,
setEnv: setEnvVal,
pushChatSocket,
Expand Down
12 changes: 6 additions & 6 deletions packages/uiweb/src/lib/helpers/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,24 @@ export const getDefaultFeedObject = ({
};

type CheckIfIntentType = {
chat: IFeeds;
chat: any;
account: string;
};
export const checkIfIntent = ({
chat,
account,
}: CheckIfIntentType): boolean => {
console.log(chat, account, 'checkIfIntent');
const ChatObject = chat[0];
if (account) {
if (
Object.keys(chat || {}).length &&
chat.combinedDID
Object.keys(ChatObject || {}).length &&
ChatObject.combinedDID
.toLowerCase()
.includes(walletToPCAIP10(account).toLowerCase())
) {
if (
chat.intent &&
chat.intent
ChatObject.intent &&
ChatObject.intent
.toLowerCase()
.includes(walletToPCAIP10(account).toLowerCase())
)
Expand Down
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/hooks/chat/useFetchChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface fetchChat {
const useFetchChat = () => {
const [error, setError] = useState<string>();
const [loading, setLoading] = useState<boolean>(false);
const { account, env,pgpPrivateKey, alias } = useChatData();
const { account, env, alias } = useChatData();


const fetchChat = useCallback(
Expand All @@ -32,7 +32,7 @@ const useFetchChat = () => {
setLoading(false);
}
},
[pgpPrivateKey,env,account, alias]
[env,account, alias]
);

return { fetchChat, error, loading };
Expand Down
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/hooks/chat/useFetchHistoryMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const useFetchHistoryMessages
const [error, setError] = useState<string>();
const [loading, setLoading] = useState<boolean>(false);

const { account, env,pgpPrivateKey, alias } = useChatData();
const { account, env, alias } = useChatData();

const historyMessages = useCallback(async ({chatId}: HistoryMessagesParams) => {

Expand All @@ -46,7 +46,7 @@ const useFetchHistoryMessages
} finally {
setLoading(false);
}
}, [pgpPrivateKey,account,env, alias]);
}, [account,env, alias]);

return { historyMessages, error, loading };
};
Expand Down
1 change: 0 additions & 1 deletion packages/uiweb/src/lib/hooks/chat/usePushChatSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type PushChatSocketHookOptions = {
export const usePushChatSocket = () => {
const {
account,
pgpPrivateKey,
pushChatSocket,
setPushChatSocket,
setIsPushChatSocketConnected,
Expand Down
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/hooks/chat/usePushSendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const usePushSendMessage = () => {
const [error, setError] = useState<string>();
const [loading, setLoading] = useState<boolean>(false);

const { pgpPrivateKey, env, account, alias } = useChatData();
const { env, account, alias } = useChatData();

const sendMessage = useCallback(
async (options: SendMessageParams) => {
Expand All @@ -39,7 +39,7 @@ const usePushSendMessage = () => {
return error.message;
}
},
[pgpPrivateKey, account, env, alias]
[ account, env, alias]
);

return { sendMessage, error, loading };
Expand Down

0 comments on commit 1d49e23

Please sign in to comment.