Skip to content

Commit

Permalink
Fix DotYouClient with bad loggedInIdentity fallback; (#553)
Browse files Browse the repository at this point in the history
* Fix DotYouClient with bac loggedInIdentity fallback;

* Fix following the type change;
  • Loading branch information
stef-coenen authored Jan 24, 2025
1 parent e91cd6c commit 8007a4b
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ChatInfo = ({
const target = usePortal('modal-container');

const loggedOnIdentity = useDotYouClientContext().getLoggedInIdentity();
if (!loggedOnIdentity) return null;
const conversationContent = conversation.fileMetadata.appData.content;
const recipients = conversationContent.recipients.filter(
(recipient) => recipient !== loggedOnIdentity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ActionGroup,
AuthorImage,
AuthorName,
CHAT_ROOT_PATH,
ConnectionImage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const useCommunityAccessVerifier = (
}
});

if (!circleHasAccess) {
if (!circleHasAccess && loggedOnIdentity) {
const extendUrl = getExtendCirclePermissionUrl(
loggedOnIdentity,
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const useCommunityMessage = (props?: {
...updatedChatMessage,
};
const identity = dotYouClient.getLoggedInIdentity();
if (identity !== updatedChatMessage.fileMetadata.originalAuthor) {
if (identity && identity !== updatedChatMessage.fileMetadata.originalAuthor) {
transformedMessage.fileMetadata.appData.content.collaborators = Array.from(
new Set([
...(updatedChatMessage.fileMetadata.appData.content.collaborators || []),
Expand Down Expand Up @@ -294,7 +294,7 @@ export const useCommunityMessage = (props?: {
onMutate: async ({ updatedChatMessage, community }) => {
const transformedMessage = { ...updatedChatMessage };
const identity = dotYouClient.getLoggedInIdentity();
if (identity !== updatedChatMessage.fileMetadata.originalAuthor) {
if (identity && identity !== updatedChatMessage.fileMetadata.originalAuthor) {
transformedMessage.fileMetadata.appData.content.collaborators = Array.from(
new Set([
...(updatedChatMessage.fileMetadata.appData.content.collaborators || []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const useMyStatus = (props: {
const queryClient = useQueryClient();

const fetchMyStatus = async (community: HomebaseFile<CommunityDefinition>) => {
return await getStatus(dotYouClient, community, odinId || dotYouClient.getLoggedInIdentity());
return await getStatus(
dotYouClient,
community,
odinId || dotYouClient.getLoggedInIdentity() || ''
);
};

const setMyStatus = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export const useCommunityThreads = ({
);

return (
allThreadMeta.filter((meta) => meta && meta.participants.includes(identity)) as ThreadMeta[]
allThreadMeta.filter(
(meta) => meta && identity && meta.participants.includes(identity)
) as ThreadMeta[]
).sort((a, b) => b.lastMessageCreated - a.lastMessageCreated);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export const useCommunityMemberUpdater = (
useEffect(() => {
if (!membersFetched || !community || !isAdmin || !communityCircleId) return;

const circleMembers = [...(members?.map((member) => member.domain) || []), loggedOnIdentity];
const circleMembers = [
...(members?.map((member) => member.domain) || []),
loggedOnIdentity,
].filter(Boolean) as string[];
const communityMembers = community.fileMetadata.appData.content.members || [];

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const setStatus = async (
const currentStatus = await internalGetStatus(
dotYouClient,
community,
dotYouClient.getLoggedInIdentity()
dotYouClient.getLoggedInIdentity() || ''
);

const newStatus: NewHomebaseFile<CommunityStatus> = {
Expand Down Expand Up @@ -67,7 +67,7 @@ const internalSaveStatusFile = async (
const targetDrive = getTargetDriveFromCommunityId(
community.fileMetadata.appData.uniqueId as string
);
const uniqueId = toGuidId(dotYouClient.getLoggedInIdentity());
const uniqueId = toGuidId(dotYouClient.getLoggedInIdentity() || '');
const metedata: UploadFileMetadata = {
versionTag: status?.fileMetadata.versionTag,
allowDistribution: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const MailComposer = ({
message: [],
originId: originId || getNewId(),
threadId: threadId || getNewId(),
sender: loggedOnIdentity,
sender: loggedOnIdentity || '',
forwardedMailThread,
deliveryStatus: MailDeliveryStatus.NotSent,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ const ConnectLink = ({ className }: { className: string }) => {
const isAuthenticated = dotYouClient.isAuthenticated();
const isOwner = dotYouClient.isOwner();

const host = new DotYouClient({
hostIdentity: dotYouClient.getLoggedInIdentity(),
api: ApiType.Guest,
}).getRoot();
const loggedOnIdentity = dotYouClient.getLoggedInIdentity();
const host = loggedOnIdentity
? new DotYouClient({
hostIdentity: loggedOnIdentity,
api: ApiType.Guest,
}).getRoot()
: undefined;

const { data: securityContext } = useSecurityContext(undefined, isAuthenticated).fetch;
const isConnected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const CirclePermissionView = ({
stringGuidsEqual(circleDef.id, AUTO_CONNECTIONS_CIRCLE_ID);

if (!circleDef) return null;
if (!loggedInIdentity) return null;

const LinkWrapper = ({ children, className }: { children: ReactNode; className: string }) =>
onClick ? (
Expand Down
13 changes: 8 additions & 5 deletions packages/common/common-app/src/socialFeed/Blocks/Meta/Meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const ExternalActions = ({
getReportContentUrl,
} = useManageSocialFeed({ odinId });

if (!loggedOnIdentity) return null;
const host = new DotYouClient({ api: ApiType.Guest, hostIdentity: loggedOnIdentity }).getRoot();
const options: ActionGroupOptionProps[] = [
{
Expand Down Expand Up @@ -286,10 +287,12 @@ const GroupChannelActions = ({
const hostIdentity = useDotYouClientContext().getHostIdentity();

const isAuthor = postFile.fileMetadata.originalAuthor === loggedOnIdentity;
const host = new DotYouClient({
api: ApiType.Guest,
hostIdentity: loggedOnIdentity,
}).getRoot();
const host = loggedOnIdentity
? new DotYouClient({
api: ApiType.Guest,
hostIdentity: loggedOnIdentity,
}).getRoot()
: undefined;

const {
removeFromFeed: { mutateAsync: removeFromMyFeed },
Expand All @@ -316,7 +319,7 @@ const GroupChannelActions = ({
},
});

if (isAuthor) {
if (isAuthor && host) {
options.push({
icon: Pencil,
label: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const OwnerActions = ({
const { mutateAsync: editPost } = useManagePost().update;

const navigate = useNavigate();
if (!loggedOnIdentity) return null;
const host = new DotYouClient({ api: ApiType.Guest, hostIdentity: loggedOnIdentity }).getRoot();

return (
Expand Down
8 changes: 6 additions & 2 deletions packages/libs/js-lib/src/core/DotYouClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export class BaseDotYouClient {
);
}

getLoggedInIdentity(): string {
return this._options?.loggedInIdentity || this.getHostIdentity();
getLoggedInIdentity(): string | undefined {
return this._options?.loggedInIdentity ||
this.getType() === ApiType.Owner ||
this.getType() === ApiType.App
? this.getHostIdentity()
: undefined;
}

isOwner(): boolean {
Expand Down

0 comments on commit 8007a4b

Please sign in to comment.