Skip to content

Commit

Permalink
fix group embed decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Philreact committed Dec 1, 2024
1 parent 417db3a commit e22072d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/atoms/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ export const blobKeySelector = selectorFamily({
return blobs[key] || null; // Return the value for the key or null if not found
},
});


export const selectedGroupIdAtom = atom({
key: 'selectedGroupIdAtom',
default: null,
});
5 changes: 3 additions & 2 deletions src/components/Embeds/AttachmentEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const AttachmentCard = ({
errorMsg,
encryptionType,
setInfoSnack,
setOpenSnack
setOpenSnack,
selectedGroupId
}) => {

const [isOpen, setIsOpen] = useState(true);
Expand Down Expand Up @@ -100,7 +101,7 @@ export const AttachmentCard = ({

{
data64: data,
groupId: 683,
groupId: selectedGroupId,
}

);
Expand Down
11 changes: 7 additions & 4 deletions src/components/Embeds/Embed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { extractComponents } from "../Chat/MessageDisplay";
import { executeEvent } from "../../utils/events";

import { base64ToBlobUrl } from "../../utils/fileReading";
import { useRecoilValue, useSetRecoilState } from "recoil";
import { blobControllerAtom, blobKeySelector, resourceKeySelector } from "../../atoms/global";
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
import { blobControllerAtom, blobKeySelector, resourceKeySelector, selectedGroupIdAtom } from "../../atoms/global";
import { parseQortalLink } from "./embed-utils";
import { PollCard } from "./PollEmbed";
import { ImageCard } from "./ImageEmbed";
Expand Down Expand Up @@ -59,6 +59,7 @@ export const Embed = ({ embedLink }) => {
const [imageUrl, setImageUrl] = useState("");
const [parsedData, setParsedData] = useState(null);
const setBlobs = useSetRecoilState(blobControllerAtom);
const [selectedGroupId] = useRecoilState(selectedGroupIdAtom)

const resourceData = useMemo(()=> {
const parsedDataOnTheFly = parseQortalLink(embedLink);
Expand Down Expand Up @@ -153,7 +154,7 @@ export const Embed = ({ embedLink }) => {

{
data64: data,
groupId: 683,
groupId: selectedGroupId,
}

);
Expand All @@ -163,7 +164,7 @@ export const Embed = ({ embedLink }) => {
}

if (!decryptedData || decryptedData?.error) throw new Error("Could not decrypt data");
imageFinalUrl = base64ToBlobUrl(decryptedData)
imageFinalUrl = base64ToBlobUrl(decryptedData, parsedData?.mimeType ? decodeURIComponent(parsedData?.mimeType) : undefined)
setBlobs((prev=> {
return {
...prev,
Expand Down Expand Up @@ -357,6 +358,8 @@ export const Embed = ({ embedLink }) => {
isLoadingParent={isLoading}
errorMsg={errorMsg}
encryptionType={encryptionType}
selectedGroupId={selectedGroupId}

/>
)}
<CustomizedSnackbars
Expand Down
5 changes: 5 additions & 0 deletions src/components/Group/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ import { AppsDesktop } from "../Apps/AppsDesktop";
import { formatEmailDate } from "./QMailMessages";
import { useHandleMobileNativeBack } from "../../hooks/useHandleMobileNativeBack";
import { AdminSpace } from "../Chat/AdminSpace";
import { useSetRecoilState } from "recoil";
import { selectedGroupIdAtom } from "../../atoms/global";

// let touchStartY = 0;
// let disablePullToRefresh = false;
Expand Down Expand Up @@ -473,6 +475,7 @@ export const Group = ({
const [appsMode, setAppsMode] = useState('home')
const [isOpenSideViewDirects, setIsOpenSideViewDirects] = useState(false)
const [isOpenSideViewGroups, setIsOpenSideViewGroups] = useState(false)
const setSelectedGroupId = useSetRecoilState(selectedGroupIdAtom)
const toggleSideViewDirects = ()=> {
if(isOpenSideViewGroups){
setIsOpenSideViewGroups(false)
Expand All @@ -498,6 +501,8 @@ export const Group = ({

useEffect(() => {
selectedGroupRef.current = selectedGroup;
setSelectedGroupId(selectedGroup?.groupId)

}, [selectedGroup]);

useEffect(() => {
Expand Down

0 comments on commit e22072d

Please sign in to comment.