Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / sections / DrivePublic / utils / usePublicLinkOwnerInfo.ts
blobec14d3effd22f780b135dcee11c89958f923a04c
1 import { type DecryptedLink, usePublicSessionUser } from '../../../../store';
3 export const usePublicLinkOwnerInfo = (linksInput: DecryptedLink | DecryptedLink[]) => {
4     const { userAddressEmail } = usePublicSessionUser();
6     const links = Array.isArray(linksInput) ? linksInput : [linksInput];
8     if (!userAddressEmail || !links.length) {
9         return {
10             isCreator: false,
11             isLastEditor: false,
12         };
13     }
15     const isLastEditor = links.every((link) => {
16         const signatureAddress = link.isFile ? link.activeRevision?.signatureAddress : link.signatureAddress;
17         return signatureAddress === userAddressEmail;
18     });
20     const isCreator = links.every((link) => {
21         return link.signatureAddress === userAddressEmail;
22     });
24     return {
25         isCreator,
26         isLastEditor,
27     };