diff --git a/src/components/Chat/GroupForum.tsx b/src/components/Chat/GroupForum.tsx
index bfc1f05..7e01883 100644
--- a/src/components/Chat/GroupForum.tsx
+++ b/src/components/Chat/GroupForum.tsx
@@ -24,7 +24,8 @@ export const GroupForum = ({
myAddress,
hide,
defaultThread,
- setDefaultThread
+ setDefaultThread,
+ isPrivate
}) => {
const { rootHeight } = useContext(MyContext);
const [isMoved, setIsMoved] = useState(false);
@@ -50,7 +51,8 @@ export const GroupForum = ({
left: hide && '-1000px'
}}
>
-
+
);
diff --git a/src/components/Group/Forum/GroupMail.tsx b/src/components/Group/Forum/GroupMail.tsx
index d569b27..38d93e9 100644
--- a/src/components/Group/Forum/GroupMail.tsx
+++ b/src/components/Group/Forum/GroupMail.tsx
@@ -46,7 +46,7 @@ import LazyLoad from "../../../common/LazyLoad";
import { delay } from "../../../utils/helpers";
import { NewThread } from "./NewThread";
import { getBaseApi } from "../../../background";
-import { decryptPublishes, getTempPublish } from "../../Chat/GroupAnnouncements";
+import { decryptPublishes, getTempPublish, handleUnencryptedPublishes } from "../../Chat/GroupAnnouncements";
import CheckSVG from "../../../assets/svgs/Check.svg";
import SortSVG from "../../../assets/svgs/Sort.svg";
import ArrowDownSVG from "../../../assets/svgs/ArrowDown.svg";
@@ -66,7 +66,8 @@ export const GroupMail = ({
secretKey,
defaultThread,
setDefaultThread,
- hide
+ hide,
+ isPrivate
}) => {
const [viewedThreads, setViewedThreads] = React.useState({});
const [filterMode, setFilterMode] = useState("Recently active");
@@ -123,7 +124,7 @@ export const GroupMail = ({
}
- const getEncryptedResource = async ({ name, identifier, resource }) => {
+ const getEncryptedResource = async ({ name, identifier, resource }, isPrivate) => {
let data = dataPublishes.current[`${name}-${identifier}`]
if(!data || (data?.update || data?.created !== (resource?.updated || resource?.created))){
const res = await fetch(
@@ -136,7 +137,7 @@ export const GroupMail = ({
} else {
data = data.data
}
- const response = await decryptPublishes([{ data }], secretKey);
+ const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
const messageData = response[0];
return messageData.decryptedData;
@@ -212,7 +213,7 @@ export const GroupMail = ({
name: message.name,
identifier: message.identifier,
resource: message
- }),
+ }, isPrivate),
delay(5000),
]);
} catch (error) {}
@@ -255,7 +256,7 @@ export const GroupMail = ({
}
}
},
- [allThreads]
+ [allThreads, isPrivate]
);
const getMailMessages = React.useCallback(
async (groupId: string, members: any) => {
@@ -327,7 +328,7 @@ export const GroupMail = ({
name: thread.name,
identifier: message.threadId,
resource: thread
- }),
+ }, isPrivate),
delay(10000),
]);
if (threadRes?.title) {
@@ -356,16 +357,16 @@ export const GroupMail = ({
// dispatch(setIsLoadingCustom(null));
}
},
- [secretKey]
+ [secretKey, isPrivate]
);
const getMessages = React.useCallback(async () => {
// if ( !groupId || members?.length === 0) return;
- if (!groupId) return;
+ if (!groupId || isPrivate === null) return;
await getMailMessages(groupId, members);
- }, [getMailMessages, groupId, members, secretKey]);
+ }, [getMailMessages, groupId, members, secretKey, isPrivate]);
const interval = useRef(null);
@@ -378,7 +379,7 @@ export const GroupMail = ({
firstMount.current = false;
}
// if (groupId && !firstMount.current && members.length > 0) {
- if (groupId && !firstMount.current) {
+ if (groupId && !firstMount.current && isPrivate !== null) {
if (filterMode === "Recently active") {
getMessages();
} else if (filterMode === "Newest") {
@@ -389,7 +390,7 @@ export const GroupMail = ({
setTempData()
firstMount.current = true;
}
- }, [groupId, members, filterMode, hide]);
+ }, [groupId, members, filterMode, hide, isPrivate]);
const closeThread = useCallback(() => {
setCurrentThread(null);
@@ -468,7 +469,7 @@ export const GroupMail = ({
} else if (filterMode === "Oldest") {
getAllThreads(groupId, "Oldest", true);
}
- }, [filterMode])
+ }, [filterMode, isPrivate])
const updateThreadActivityCurrentThread = ()=> {
if(!currentThread) return
@@ -540,6 +541,7 @@ export const GroupMail = ({
secretKey={secretKey}
getSecretKey={getSecretKey}
updateThreadActivityCurrentThread={updateThreadActivityCurrentThread}
+ isPrivate={isPrivate}
/>
);
@@ -620,6 +622,7 @@ export const GroupMail = ({
userInfo={userInfo}
getSecretKey={getSecretKey}
myName={userInfo?.name}
+ isPrivate={isPrivate}
/>
{
const { show } = React.useContext(MyContext);
@@ -245,8 +246,8 @@ export const NewThread = ({
reply,
};
- const secretKey = await getSecretKey(false, true);
- if (!secretKey) {
+ const secretKey = isPrivate === false ? null : await getSecretKey(false, true);
+ if (!secretKey && isPrivate) {
throw new Error("Cannot get group secret key");
}
@@ -254,7 +255,7 @@ export const NewThread = ({
const idThread = uid.rnd();
const idMsg = uid.rnd();
const messageToBase64 = await objectToBase64(mailObject);
- const encryptSingleFirstPost = await encryptSingleFunc(
+ const encryptSingleFirstPost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
messageToBase64,
secretKey
);
@@ -266,7 +267,7 @@ export const NewThread = ({
};
const threadToBase64 = await objectToBase64(threadObject);
- const encryptSingleThread = await encryptSingleFunc(
+ const encryptSingleThread = isPrivate === false ? threadToBase64 : await encryptSingleFunc(
threadToBase64,
secretKey
);
@@ -321,7 +322,7 @@ export const NewThread = ({
if (!currentThread) throw new Error("unable to locate thread Id");
const idThread = currentThread.threadId;
const messageToBase64 = await objectToBase64(mailObject);
- const encryptSinglePost = await encryptSingleFunc(
+ const encryptSinglePost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
messageToBase64,
secretKey
);
diff --git a/src/components/Group/Forum/Thread.tsx b/src/components/Group/Forum/Thread.tsx
index f393d5d..608489e 100644
--- a/src/components/Group/Forum/Thread.tsx
+++ b/src/components/Group/Forum/Thread.tsx
@@ -37,6 +37,7 @@ import { NewThread } from "./NewThread";
import {
decryptPublishes,
getTempPublish,
+ handleUnencryptedPublishes,
} from "../../Chat/GroupAnnouncements";
import { LoadingSnackbar } from "../../Snackbar/LoadingSnackbar";
import { subscribeToEvent, unsubscribeFromEvent } from "../../../utils/events";
@@ -71,7 +72,7 @@ const getEncryptedResource = async ({
resource,
groupId,
dataPublishes,
-}) => {
+},isPrivate) => {
let data = dataPublishes[`${name}-${identifier}`];
if (
!data ||
@@ -99,7 +100,7 @@ const getEncryptedResource = async ({
} else {
data = data.data;
}
- const response = await decryptPublishes([{ data }], secretKey);
+ const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
const messageData = response[0];
return messageData.decryptedData;
@@ -114,6 +115,7 @@ export const Thread = ({
secretKey,
getSecretKey,
updateThreadActivityCurrentThread,
+ isPrivate
}: ThreadProps) => {
const [tempPublishedList, setTempPublishedList] = useState([]);
const [messages, setMessages] = useState([]);
@@ -164,7 +166,7 @@ export const Thread = ({
resource: message,
groupId: groupInfo?.groupId,
dataPublishes: dataPublishes.current,
- });
+ }, isPrivate);
if (responseDataMessage?.error) {
const fullObject = {
@@ -323,9 +325,9 @@ export const Thread = ({
[messages, secretKey]
);
const getMessages = React.useCallback(async () => {
- if (!currentThread || !secretKey || !groupInfo?.groupId) return;
+ if (!currentThread || (!secretKey && isPrivate) || !groupInfo?.groupId || isPrivate === null) return;
await getMailMessages(currentThread, null, null, false, groupInfo?.groupId);
- }, [getMailMessages, currentThread, secretKey, groupInfo?.groupId]);
+ }, [getMailMessages, currentThread, secretKey, groupInfo?.groupId, isPrivate]);
const firstMount = useRef(false);
const saveTimestamp = useCallback((currentThread: any, username?: string) => {
@@ -380,10 +382,11 @@ export const Thread = ({
if (currentThreadRef.current?.threadId !== currentThread?.threadId) {
firstMount.current = false;
}
- if (currentThread && secretKey && !firstMount.current) {
+ if(!secretKey && isPrivate) return
+ if (currentThread && !firstMount.current && isPrivate !== null) {
getMessagesMiddleware();
}
- }, [currentThread, secretKey]);
+ }, [currentThread, secretKey, isPrivate]);
const messageCallback = useCallback((msg: any) => {
// dispatch(addToHashMapMail(msg))
// setMessages((prev) => [msg, ...prev])
@@ -576,6 +579,7 @@ export const Thread = ({
myName={userInfo?.name}
publishCallback={setTempData}
setPostReply={setPostReply}
+ isPrivate={isPrivate}
/>
>