Skip to content

Commit

Permalink
message actions: Use authless URLs to access uploaded files.
Browse files Browse the repository at this point in the history
Using the new helper tryGetFileDownloadURL, we now try to generate
and use temporary authless URLs for realm uploaded files.

We open files using the temporary URL in the browser, as opposed
to downloading them directly, because 1. The browser can usually
open several file types instantly and 2. If the browser can not handle
displaying the file, a system dialog shows up, both on Android and iOS,
showing platform specific ways to handle the file, such as opening in
Google Drive, Saving to iCloud and other options based on installed
apps, which is convenient for the user.

Fixes: zulip#3033.
  • Loading branch information
agrawal-d committed Jun 3, 2020
1 parent 72db4f0 commit d153cc3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/message/messagesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import type { Narrow, Dispatch, GetState } from '../types';
import { getAuth, getUsersById, isNarrowValid, getIsHydrated } from '../selectors';
import { DO_NARROW } from '../actionConstants';
import { getFullUrl } from '../utils/url';
import { getMessageIdFromLink, getNarrowFromLink } from '../utils/internalLinks';
import openLink from '../utils/openLink';
import { fetchMessagesInNarrow } from './fetchActions';
import { navigateToChat } from '../nav/navActions';
import { FIRST_UNREAD_ANCHOR } from '../anchor';
import { getStreamsById } from '../subscriptions/subscriptionSelectors';

import tryGetFileDownloadUrl from '../api/tryGetFileDownloadUrl';
import { isUrlOnRealm, getFullUrl } from '../utils/url';
/**
* Navigate to the given narrow, while fetching any data needed.
*
Expand All @@ -36,7 +36,10 @@ export const doNarrow = (narrow: Narrow, anchor: number = FIRST_UNREAD_ANCHOR) =
dispatch(navigateToChat(narrow));
};

export const messageLinkPress = (href: string) => (dispatch: Dispatch, getState: GetState) => {
export const messageLinkPress = (href: string) => async (
dispatch: Dispatch,
getState: GetState,
) => {
const state = getState();
const auth = getAuth(state);
const usersById = getUsersById(state);
Expand All @@ -45,7 +48,10 @@ export const messageLinkPress = (href: string) => (dispatch: Dispatch, getState:
if (narrow) {
const anchor = getMessageIdFromLink(href, auth.realm);
dispatch(doNarrow(narrow, anchor));
return;
} else if (!isUrlOnRealm(href, auth.realm)) {
openLink(href);
} else {
const url = (await tryGetFileDownloadUrl(href, auth)) ?? getFullUrl(href, auth.realm);
openLink(url);
}
openLink(getFullUrl(href, auth.realm));
};

0 comments on commit d153cc3

Please sign in to comment.