Browse Source

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

pull/3135/head
Gabe Kangas 3 years ago
parent
commit
00a5fb8dc8
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
  1. 24
      web/components/ui/Content/Content.tsx

24
web/components/ui/Content/Content.tsx

@ -123,6 +123,7 @@ export const Content: FC = () => { @@ -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 = () => { @@ -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 = () => { @@ -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

Loading…
Cancel
Save