1
0
Fork 0
mirror of https://github.com/owncast/owncast.git synced 2024-10-28 10:09:39 +01:00

fix: pass username and instance url to external actions. Fixes #3130

This commit is contained in:
Gabe Kangas 2023-07-04 12:14:21 -07:00
parent 5876c7cfbb
commit 00a5fb8dc8
No known key found for this signature in database
GPG key ID: 4345B2060657F330

View file

@ -123,6 +123,7 @@ export const Content: FC = () => {
const { enabled: browserNotificationsEnabled } = browserNotifications;
const { online: isStreamLive } = serverStatus;
const [externalActionToDisplay, setExternalActionToDisplay] = useState<ExternalAction>(null);
const [currentBrowserWindowUrl, setCurrentBrowserWindowUrl] = useState('');
const [supportsBrowserNotifications, setSupportsBrowserNotifications] = useState(false);
const supportFediverseFeatures = fediverseEnabled;
@ -131,11 +132,24 @@ export const Content: FC = () => {
const externalActionSelected = (action: ExternalAction) => {
const { openExternally, url } = action;
const { displayName } = currentUser;
const updatedUrl = new URL(url);
// Append url and username to params so the link knows where we came from and who we are.
updatedUrl.searchParams.append('username', displayName);
updatedUrl.searchParams.append('instance', currentBrowserWindowUrl);
const fullUrl = updatedUrl.toString();
// Overwrite URL with the updated one that includes the params.
const updatedAction = {
...action,
url: fullUrl,
};
// apply openExternally only if we don't have an HTML embed
if (openExternally && url) {
window.open(url, '_blank');
if (openExternally && updatedAction) {
window.open(fullUrl, '_blank');
} else {
setExternalActionToDisplay(action);
setExternalActionToDisplay(updatedAction);
}
};
@ -185,6 +199,10 @@ export const Content: FC = () => {
);
}, [browserNotificationsEnabled]);
useEffect(() => {
setCurrentBrowserWindowUrl(window.location.href);
}, []);
const showChat = isChatAvailable && !chatDisabled && chatState === ChatState.VISIBLE;
// accounts for sidebar width when online in desktop