mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-04-28 05:47:52 +00:00
public group threads unencrypted
This commit is contained in:
parent
f88a44294d
commit
6002ec5c79
@ -24,7 +24,8 @@ export const GroupForum = ({
|
|||||||
myAddress,
|
myAddress,
|
||||||
hide,
|
hide,
|
||||||
defaultThread,
|
defaultThread,
|
||||||
setDefaultThread
|
setDefaultThread,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const { rootHeight } = useContext(MyContext);
|
const { rootHeight } = useContext(MyContext);
|
||||||
const [isMoved, setIsMoved] = useState(false);
|
const [isMoved, setIsMoved] = useState(false);
|
||||||
@ -50,7 +51,8 @@ export const GroupForum = ({
|
|||||||
left: hide && '-1000px'
|
left: hide && '-1000px'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<GroupMail hide={hide} getSecretKey={getSecretKey} selectedGroup={selectedGroup} userInfo={userInfo} secretKey={secretKey} defaultThread={defaultThread} setDefaultThread={setDefaultThread} />
|
<GroupMail isPrivate={isPrivate}
|
||||||
|
hide={hide} getSecretKey={getSecretKey} selectedGroup={selectedGroup} userInfo={userInfo} secretKey={secretKey} defaultThread={defaultThread} setDefaultThread={setDefaultThread} />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -46,7 +46,7 @@ import LazyLoad from "../../../common/LazyLoad";
|
|||||||
import { delay } from "../../../utils/helpers";
|
import { delay } from "../../../utils/helpers";
|
||||||
import { NewThread } from "./NewThread";
|
import { NewThread } from "./NewThread";
|
||||||
import { getBaseApi } from "../../../background";
|
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 CheckSVG from "../../../assets/svgs/Check.svg";
|
||||||
import SortSVG from "../../../assets/svgs/Sort.svg";
|
import SortSVG from "../../../assets/svgs/Sort.svg";
|
||||||
import ArrowDownSVG from "../../../assets/svgs/ArrowDown.svg";
|
import ArrowDownSVG from "../../../assets/svgs/ArrowDown.svg";
|
||||||
@ -66,7 +66,8 @@ export const GroupMail = ({
|
|||||||
secretKey,
|
secretKey,
|
||||||
defaultThread,
|
defaultThread,
|
||||||
setDefaultThread,
|
setDefaultThread,
|
||||||
hide
|
hide,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const [viewedThreads, setViewedThreads] = React.useState<any>({});
|
const [viewedThreads, setViewedThreads] = React.useState<any>({});
|
||||||
const [filterMode, setFilterMode] = useState<string>("Recently active");
|
const [filterMode, setFilterMode] = useState<string>("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}`]
|
let data = dataPublishes.current[`${name}-${identifier}`]
|
||||||
if(!data || (data?.update || data?.created !== (resource?.updated || resource?.created))){
|
if(!data || (data?.update || data?.created !== (resource?.updated || resource?.created))){
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
@ -136,7 +137,7 @@ export const GroupMail = ({
|
|||||||
} else {
|
} else {
|
||||||
data = data.data
|
data = data.data
|
||||||
}
|
}
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
return messageData.decryptedData;
|
return messageData.decryptedData;
|
||||||
@ -212,7 +213,7 @@ export const GroupMail = ({
|
|||||||
name: message.name,
|
name: message.name,
|
||||||
identifier: message.identifier,
|
identifier: message.identifier,
|
||||||
resource: message
|
resource: message
|
||||||
}),
|
}, isPrivate),
|
||||||
delay(5000),
|
delay(5000),
|
||||||
]);
|
]);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
@ -255,7 +256,7 @@ export const GroupMail = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[allThreads]
|
[allThreads, isPrivate]
|
||||||
);
|
);
|
||||||
const getMailMessages = React.useCallback(
|
const getMailMessages = React.useCallback(
|
||||||
async (groupId: string, members: any) => {
|
async (groupId: string, members: any) => {
|
||||||
@ -327,7 +328,7 @@ export const GroupMail = ({
|
|||||||
name: thread.name,
|
name: thread.name,
|
||||||
identifier: message.threadId,
|
identifier: message.threadId,
|
||||||
resource: thread
|
resource: thread
|
||||||
}),
|
}, isPrivate),
|
||||||
delay(10000),
|
delay(10000),
|
||||||
]);
|
]);
|
||||||
if (threadRes?.title) {
|
if (threadRes?.title) {
|
||||||
@ -356,16 +357,16 @@ export const GroupMail = ({
|
|||||||
// dispatch(setIsLoadingCustom(null));
|
// dispatch(setIsLoadingCustom(null));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[secretKey]
|
[secretKey, isPrivate]
|
||||||
);
|
);
|
||||||
|
|
||||||
const getMessages = React.useCallback(async () => {
|
const getMessages = React.useCallback(async () => {
|
||||||
|
|
||||||
// if ( !groupId || members?.length === 0) return;
|
// if ( !groupId || members?.length === 0) return;
|
||||||
if (!groupId) return;
|
if (!groupId || isPrivate === null) return;
|
||||||
|
|
||||||
await getMailMessages(groupId, members);
|
await getMailMessages(groupId, members);
|
||||||
}, [getMailMessages, groupId, members, secretKey]);
|
}, [getMailMessages, groupId, members, secretKey, isPrivate]);
|
||||||
|
|
||||||
const interval = useRef<any>(null);
|
const interval = useRef<any>(null);
|
||||||
|
|
||||||
@ -378,7 +379,7 @@ export const GroupMail = ({
|
|||||||
firstMount.current = false;
|
firstMount.current = false;
|
||||||
}
|
}
|
||||||
// if (groupId && !firstMount.current && members.length > 0) {
|
// if (groupId && !firstMount.current && members.length > 0) {
|
||||||
if (groupId && !firstMount.current) {
|
if (groupId && !firstMount.current && isPrivate !== null) {
|
||||||
if (filterMode === "Recently active") {
|
if (filterMode === "Recently active") {
|
||||||
getMessages();
|
getMessages();
|
||||||
} else if (filterMode === "Newest") {
|
} else if (filterMode === "Newest") {
|
||||||
@ -389,7 +390,7 @@ export const GroupMail = ({
|
|||||||
setTempData()
|
setTempData()
|
||||||
firstMount.current = true;
|
firstMount.current = true;
|
||||||
}
|
}
|
||||||
}, [groupId, members, filterMode, hide]);
|
}, [groupId, members, filterMode, hide, isPrivate]);
|
||||||
|
|
||||||
const closeThread = useCallback(() => {
|
const closeThread = useCallback(() => {
|
||||||
setCurrentThread(null);
|
setCurrentThread(null);
|
||||||
@ -468,7 +469,7 @@ export const GroupMail = ({
|
|||||||
} else if (filterMode === "Oldest") {
|
} else if (filterMode === "Oldest") {
|
||||||
getAllThreads(groupId, "Oldest", true);
|
getAllThreads(groupId, "Oldest", true);
|
||||||
}
|
}
|
||||||
}, [filterMode])
|
}, [filterMode, isPrivate])
|
||||||
|
|
||||||
const updateThreadActivityCurrentThread = ()=> {
|
const updateThreadActivityCurrentThread = ()=> {
|
||||||
if(!currentThread) return
|
if(!currentThread) return
|
||||||
@ -540,6 +541,7 @@ export const GroupMail = ({
|
|||||||
secretKey={secretKey}
|
secretKey={secretKey}
|
||||||
getSecretKey={getSecretKey}
|
getSecretKey={getSecretKey}
|
||||||
updateThreadActivityCurrentThread={updateThreadActivityCurrentThread}
|
updateThreadActivityCurrentThread={updateThreadActivityCurrentThread}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -620,6 +622,7 @@ export const GroupMail = ({
|
|||||||
userInfo={userInfo}
|
userInfo={userInfo}
|
||||||
getSecretKey={getSecretKey}
|
getSecretKey={getSecretKey}
|
||||||
myName={userInfo?.name}
|
myName={userInfo?.name}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
<ComposeContainerBlank
|
<ComposeContainerBlank
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -144,7 +144,8 @@ export const NewThread = ({
|
|||||||
closeCallback,
|
closeCallback,
|
||||||
postReply,
|
postReply,
|
||||||
myName,
|
myName,
|
||||||
setPostReply
|
setPostReply,
|
||||||
|
isPrivate
|
||||||
}: NewMessageProps) => {
|
}: NewMessageProps) => {
|
||||||
const { show } = React.useContext(MyContext);
|
const { show } = React.useContext(MyContext);
|
||||||
|
|
||||||
@ -245,8 +246,8 @@ export const NewThread = ({
|
|||||||
reply,
|
reply,
|
||||||
};
|
};
|
||||||
|
|
||||||
const secretKey = await getSecretKey(false, true);
|
const secretKey = isPrivate === false ? null : await getSecretKey(false, true);
|
||||||
if (!secretKey) {
|
if (!secretKey && isPrivate) {
|
||||||
throw new Error("Cannot get group secret key");
|
throw new Error("Cannot get group secret key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +255,7 @@ export const NewThread = ({
|
|||||||
const idThread = uid.rnd();
|
const idThread = uid.rnd();
|
||||||
const idMsg = uid.rnd();
|
const idMsg = uid.rnd();
|
||||||
const messageToBase64 = await objectToBase64(mailObject);
|
const messageToBase64 = await objectToBase64(mailObject);
|
||||||
const encryptSingleFirstPost = await encryptSingleFunc(
|
const encryptSingleFirstPost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
|
||||||
messageToBase64,
|
messageToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
@ -266,7 +267,7 @@ export const NewThread = ({
|
|||||||
};
|
};
|
||||||
const threadToBase64 = await objectToBase64(threadObject);
|
const threadToBase64 = await objectToBase64(threadObject);
|
||||||
|
|
||||||
const encryptSingleThread = await encryptSingleFunc(
|
const encryptSingleThread = isPrivate === false ? threadToBase64 : await encryptSingleFunc(
|
||||||
threadToBase64,
|
threadToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
@ -321,7 +322,7 @@ export const NewThread = ({
|
|||||||
if (!currentThread) throw new Error("unable to locate thread Id");
|
if (!currentThread) throw new Error("unable to locate thread Id");
|
||||||
const idThread = currentThread.threadId;
|
const idThread = currentThread.threadId;
|
||||||
const messageToBase64 = await objectToBase64(mailObject);
|
const messageToBase64 = await objectToBase64(mailObject);
|
||||||
const encryptSinglePost = await encryptSingleFunc(
|
const encryptSinglePost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
|
||||||
messageToBase64,
|
messageToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
|
@ -37,6 +37,7 @@ import { NewThread } from "./NewThread";
|
|||||||
import {
|
import {
|
||||||
decryptPublishes,
|
decryptPublishes,
|
||||||
getTempPublish,
|
getTempPublish,
|
||||||
|
handleUnencryptedPublishes,
|
||||||
} from "../../Chat/GroupAnnouncements";
|
} from "../../Chat/GroupAnnouncements";
|
||||||
import { LoadingSnackbar } from "../../Snackbar/LoadingSnackbar";
|
import { LoadingSnackbar } from "../../Snackbar/LoadingSnackbar";
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from "../../../utils/events";
|
import { subscribeToEvent, unsubscribeFromEvent } from "../../../utils/events";
|
||||||
@ -71,7 +72,7 @@ const getEncryptedResource = async ({
|
|||||||
resource,
|
resource,
|
||||||
groupId,
|
groupId,
|
||||||
dataPublishes,
|
dataPublishes,
|
||||||
}) => {
|
},isPrivate) => {
|
||||||
let data = dataPublishes[`${name}-${identifier}`];
|
let data = dataPublishes[`${name}-${identifier}`];
|
||||||
if (
|
if (
|
||||||
!data ||
|
!data ||
|
||||||
@ -99,7 +100,7 @@ const getEncryptedResource = async ({
|
|||||||
} else {
|
} else {
|
||||||
data = data.data;
|
data = data.data;
|
||||||
}
|
}
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
return messageData.decryptedData;
|
return messageData.decryptedData;
|
||||||
@ -114,6 +115,7 @@ export const Thread = ({
|
|||||||
secretKey,
|
secretKey,
|
||||||
getSecretKey,
|
getSecretKey,
|
||||||
updateThreadActivityCurrentThread,
|
updateThreadActivityCurrentThread,
|
||||||
|
isPrivate
|
||||||
}: ThreadProps) => {
|
}: ThreadProps) => {
|
||||||
const [tempPublishedList, setTempPublishedList] = useState([]);
|
const [tempPublishedList, setTempPublishedList] = useState([]);
|
||||||
const [messages, setMessages] = useState<any[]>([]);
|
const [messages, setMessages] = useState<any[]>([]);
|
||||||
@ -164,7 +166,7 @@ export const Thread = ({
|
|||||||
resource: message,
|
resource: message,
|
||||||
groupId: groupInfo?.groupId,
|
groupId: groupInfo?.groupId,
|
||||||
dataPublishes: dataPublishes.current,
|
dataPublishes: dataPublishes.current,
|
||||||
});
|
}, isPrivate);
|
||||||
|
|
||||||
if (responseDataMessage?.error) {
|
if (responseDataMessage?.error) {
|
||||||
const fullObject = {
|
const fullObject = {
|
||||||
@ -323,9 +325,9 @@ export const Thread = ({
|
|||||||
[messages, secretKey]
|
[messages, secretKey]
|
||||||
);
|
);
|
||||||
const getMessages = React.useCallback(async () => {
|
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);
|
await getMailMessages(currentThread, null, null, false, groupInfo?.groupId);
|
||||||
}, [getMailMessages, currentThread, secretKey, groupInfo?.groupId]);
|
}, [getMailMessages, currentThread, secretKey, groupInfo?.groupId, isPrivate]);
|
||||||
const firstMount = useRef(false);
|
const firstMount = useRef(false);
|
||||||
|
|
||||||
const saveTimestamp = useCallback((currentThread: any, username?: string) => {
|
const saveTimestamp = useCallback((currentThread: any, username?: string) => {
|
||||||
@ -380,10 +382,11 @@ export const Thread = ({
|
|||||||
if (currentThreadRef.current?.threadId !== currentThread?.threadId) {
|
if (currentThreadRef.current?.threadId !== currentThread?.threadId) {
|
||||||
firstMount.current = false;
|
firstMount.current = false;
|
||||||
}
|
}
|
||||||
if (currentThread && secretKey && !firstMount.current) {
|
if(!secretKey && isPrivate) return
|
||||||
|
if (currentThread && !firstMount.current && isPrivate !== null) {
|
||||||
getMessagesMiddleware();
|
getMessagesMiddleware();
|
||||||
}
|
}
|
||||||
}, [currentThread, secretKey]);
|
}, [currentThread, secretKey, isPrivate]);
|
||||||
const messageCallback = useCallback((msg: any) => {
|
const messageCallback = useCallback((msg: any) => {
|
||||||
// dispatch(addToHashMapMail(msg))
|
// dispatch(addToHashMapMail(msg))
|
||||||
// setMessages((prev) => [msg, ...prev])
|
// setMessages((prev) => [msg, ...prev])
|
||||||
@ -576,6 +579,7 @@ export const Thread = ({
|
|||||||
myName={userInfo?.name}
|
myName={userInfo?.name}
|
||||||
publishCallback={setTempData}
|
publishCallback={setTempData}
|
||||||
setPostReply={setPostReply}
|
setPostReply={setPostReply}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -2521,6 +2521,7 @@ export const Group = ({
|
|||||||
hide={groupSection !== "forum"}
|
hide={groupSection !== "forum"}
|
||||||
defaultThread={defaultThread}
|
defaultThread={defaultThread}
|
||||||
setDefaultThread={setDefaultThread}
|
setDefaultThread={setDefaultThread}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
<AdminSpace adminsWithNames={adminsWithNames} selectedGroup={selectedGroup?.groupId} myAddress={myAddress} userInfo={userInfo} hide={groupSection !== "adminSpace"} isAdmin={admins.includes(myAddress)} />
|
<AdminSpace adminsWithNames={adminsWithNames} selectedGroup={selectedGroup?.groupId} myAddress={myAddress} userInfo={userInfo} hide={groupSection !== "adminSpace"} isAdmin={admins.includes(myAddress)} />
|
||||||
</>
|
</>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user