Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
review
Browse files Browse the repository at this point in the history
Signed-off-by: Timo K <toger5@hotmail.de>
  • Loading branch information
toger5 committed Mar 5, 2024
1 parent d4e1d86 commit ce38dff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/components/views/dialogs/ShareDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,29 @@ const socials = [
url: (url: string) => `mailto:?body=${url}`,
},
];

// add doc strings to BaseProps
interface BaseProps {
/**
* A function that is called when the dialog is dismissed
*/
onFinished(): void;
/**
* An optional string to use as the dialog title.
* If not provided, an appropriate title for the target type will be used.
*/
customTitle?: string;
/**
* An optional string to use as the dialog subtitle
*/
subtitle?: string;
}

interface Props extends BaseProps {
/**
* The target to link to.
* This can be a Room, User, RoomMember, or MatrixEvent or an already computed URL.
* A <u>matrix.to</u> link will be generated out of it if its no already a computed url.
*/
target: Room | User | RoomMember | URL;
permalinkCreator?: RoomPermalinkCreator;
}
Expand Down
12 changes: 7 additions & 5 deletions src/components/views/rooms/RoomHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function RoomHeader({
toggleCallMaximized: toggleCall,
isViewingCall,
generateCallLink,
canGenerateCallLink,
isConnectedToCall,
hasActiveCallSession,
callOptions,
Expand Down Expand Up @@ -124,15 +125,16 @@ export default function RoomHeader({
const videoClick = useCallback((ev) => videoCallClick(ev, callOptions[0]), [callOptions, videoCallClick]);

const shareClick = useCallback(() => {
const target = generateCallLink ? generateCallLink() : undefined;
if (target) {
try {
// generateCallLink throws if the permissions are not met
const target = generateCallLink();
Modal.createDialog(ShareDialog, {
target,
customTitle: _t("share|share_call"),
subtitle: _t("share|share_call_subtitle"),
});
} else {
logger.error("Could not generate call link.");
} catch (e) {
logger.error("Could not generate call link.", e);
}
}, [generateCallLink]);

Expand Down Expand Up @@ -333,7 +335,7 @@ export default function RoomHeader({
</Tooltip>
);
})}
{isViewingCall && generateCallLink && createExternalLinkButton}
{isViewingCall && canGenerateCallLink && createExternalLinkButton}
{((isConnectedToCall && isViewingCall) || isVideoRoom(room)) && <VideoRoomChatButton room={room} />}

{hasActiveCallSession && !isConnectedToCall && !isViewingCall ? (
Expand Down
11 changes: 7 additions & 4 deletions src/hooks/room/useRoomCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export const useRoomCall = (
videoCallClick(evt: React.MouseEvent | undefined, selectedType: PlatformCallType): void;
toggleCallMaximized: () => void;
isViewingCall: boolean;
generateCallLink: (() => URL) | undefined;
generateCallLink: () => URL;
canGenerateCallLink: boolean;
isConnectedToCall: boolean;
hasActiveCallSession: boolean;
callOptions: PlatformCallType[];
Expand Down Expand Up @@ -271,7 +272,8 @@ export const useRoomCall = (
}, [isViewingCall, room.roomId]);

const generateCallLink = useCallback(() => {
// Should never happen, because the hook only passes generateCallLink if externalSpaUrl is set.
if (!canJoinWithoutInvite)
throw new Error("Cannot create link for room that users can not join without invite.");
if (!guestSpaUrl) throw new Error("No guest SPA url for external links provided.");
const url = new URL(guestSpaUrl);
url.pathname = "/room/";
Expand All @@ -288,7 +290,7 @@ export const useRoomCall = (

logger.info("Generated element call external url:", url);
return url;
}, [guestSpaUrl, room]);
}, [canJoinWithoutInvite, guestSpaUrl, room]);
/**
* We've gone through all the steps
*/
Expand All @@ -299,7 +301,8 @@ export const useRoomCall = (
videoCallClick,
toggleCallMaximized: toggleCallMaximized,
isViewingCall: isViewingCall,
generateCallLink: guestSpaUrl && canJoinWithoutInvite ? generateCallLink : undefined,
generateCallLink,
canGenerateCallLink: guestSpaUrl !== undefined && canJoinWithoutInvite,
isConnectedToCall: isConnectedToCall,
hasActiveCallSession: hasActiveCallSession,
callOptions,
Expand Down

0 comments on commit ce38dff

Please sign in to comment.