Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download all attachments to messages. #2928

Draft
wants to merge 8 commits into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"typingAlt": "Typing animation for this conversation",
"contactAvatarAlt": "Avatar for contact $name$",
"downloadAttachment": "Download Attachment",
"downloadAllAttachments": "Download All Attachments",
"replyToMessage": "Reply to message",
"replyingToMessage": "Replying to:",
"originalMessageNotFound": "Original message not found",
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"bunyan": "^1.8.15",
"bytebuffer": "^5.0.1",
"classnames": "2.2.5",
"cmake-js": "^7.2.1",
"config": "1.28.1",
"country-code-lookup": "^0.0.19",
"curve25519-js": "https://github.com/oxen-io/curve25519-js",
Expand Down Expand Up @@ -167,6 +168,7 @@
"@types/sinon": "9.0.4",
"@types/styled-components": "^5.1.4",
"@types/uuid": "8.3.4",
"@types/wicg-file-system-access": "^2020.9.6",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"chai": "^4.3.4",
Expand Down Expand Up @@ -202,7 +204,7 @@
"sass-loader": "^13.2.2",
"sinon": "9.0.2",
"ts-loader": "^9.4.2",
"typescript": "^5.1.6",
"typescript": "^5.3.0-dev.20230916",
"webpack": "^5.76.3",
"webpack-cli": "^5.1.4"
},
Expand All @@ -221,10 +223,7 @@
"mac": {
"category": "public.app-category.social-networking",
"icon": "build/icon-mac.icns",
"target": [
"dmg",
"zip"
],
"target": [ "dmg", "zip" ],
"bundleVersion": "1",
"hardenedRuntime": true,
"gatekeeperAssess": false,
Expand All @@ -243,9 +242,7 @@
"publisherName": "Oxen Labs",
"verifyUpdateCodeSignature": false,
"icon": "build/icon.ico",
"target": [
"nsis"
]
"target": [ "nsis" ]
},
"nsis": {
"deleteAppDataOnUninstall": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
useSelectedWeAreAdmin,
useSelectedWeAreModerator,
} from '../../../../state/selectors/selectedConversation';
import { saveAttachmentToDisk } from '../../../../util/attachmentsUtil';
import {
saveAttachmentToDisk,
saveAttachmentToDiskQuietly,
} from '../../../../util/attachmentsUtil';
import { Reactions } from '../../../../util/reactions';
import { SessionContextMenuContainer } from '../../../SessionContextMenuContainer';
import { SessionEmojiPanel, StyledEmojiPanel } from '../../SessionEmojiPanel';
Expand Down Expand Up @@ -278,6 +281,25 @@ export const MessageContextMenu = (props: Props) => {
}
};

const saveAllAttachments = async (e: ItemParams) => {
e.event.stopPropagation();
if (!attachments?.length || !convoId || !sender) {
return;
}
const messageTimestamp = timestamp || serverTimestamp || 0;
const dir = await window.showDirectoryPicker({ id: 1, mode: 'readwrite' });
for (let i = 0; i < attachments?.length; i++) {
void saveAttachmentToDiskQuietly({
attachment: attachments[i],
messageTimestamp,
messageSender: sender,
conversationId: convoId,
index: i,
dir,
});
}
};

const saveAttachment = (e: ItemParams) => {
// this is quite dirty but considering that we want the context menu of the message to show on click on the attachment
// and the context menu save attachment item to save the right attachment I did not find a better way for now.
Expand Down Expand Up @@ -358,6 +380,9 @@ export const MessageContextMenu = (props: Props) => {
{attachments?.length ? (
<Item onClick={saveAttachment}>{window.i18n('downloadAttachment')}</Item>
) : null}
{attachments?.length ? (
<Item onClick={saveAllAttachments}>{window.i18n('downloadAllAttachments')}</Item>
) : null}
<Item onClick={copyText}>{window.i18n('copyMessage')}</Item>
{(isSent || !isOutgoing) && (
<Item onClick={onReply}>{window.i18n('replyToMessage')}</Item>
Expand Down
1 change: 1 addition & 0 deletions ts/mains/main_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const appUserModelId = 'com.loki-project.messenger-desktop';
console.log('Set Windows Application User Model ID (AUMID)', {
appUserModelId,
});
app.commandLine.appendSwitch('enable-experimental-web-platform-features');
app.setAppUserModelId(appUserModelId);

// Keep a global reference of the window object, if you don't, the window will
Expand Down
28 changes: 28 additions & 0 deletions ts/types/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,34 @@ export const isVoiceMessage = (attachment: Attachment): boolean => {
return false;
};

export const saveQuietly = async ({
attachment,
index,
timestamp,
dir,
}: {
attachment: AttachmentType;
index?: number;
getAbsolutePath: (relativePath: string) => string;
timestamp?: number;
dir: FileSystemDirectoryHandle;
}): Promise<void> => {
const isObjectURLRequired = isUndefined(attachment.fileName);
const filename = getSuggestedFilename({ attachment, timestamp, index });
const response = await fetch(attachment.url);
if (response.status !== 200) {
return;
}
const blob = await response.blob();
const file = await dir.getFileHandle(filename, { create: true });
const writable = await file.createWritable();
await writable.write(blob);
await writable.close();
if (isObjectURLRequired) {
URL.revokeObjectURL(attachment.url);
}
};

export const save = ({
attachment,
document,
Expand Down
1 change: 1 addition & 0 deletions ts/types/LocalizerKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export type LocalizerKeys =
| 'documentsEmptyState'
| 'done'
| 'downloadAttachment'
| 'downloadAllAttachments'
| 'editGroup'
| 'editGroupName'
| 'editMenuCopy'
Expand Down
28 changes: 27 additions & 1 deletion ts/util/attachmentsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StagedAttachmentType } from '../components/conversation/composition/Com
import { SignalService } from '../protobuf';
import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
import { sendDataExtractionNotification } from '../session/messages/outgoing/controlMessage/DataExtractionNotificationMessage';
import { AttachmentType, save } from '../types/Attachment';
import { AttachmentType, save, saveQuietly } from '../types/Attachment';
import { IMAGE_GIF, IMAGE_JPEG, IMAGE_PNG, IMAGE_TIFF, IMAGE_UNKNOWN } from '../types/MIME';
import { getAbsoluteAttachmentPath, processNewAttachment } from '../types/MessageAttachment';
import { THUMBNAIL_SIDE } from '../types/attachments/VisualAttachment';
Expand Down Expand Up @@ -382,6 +382,32 @@ export async function readAvatarAttachment(attachment: {
return { attachment, data: dataReadFromBlob, size: dataReadFromBlob.byteLength };
}

export const saveAttachmentToDiskQuietly = async ({
attachment,
messageTimestamp,
messageSender,
conversationId,
index,
dir,
}: {
attachment: AttachmentType;
messageTimestamp: number;
messageSender: string;
conversationId: string;
index: number;
dir: FileSystemDirectoryHandle;
}) => {
const decryptedUrl = await getDecryptedMediaUrl(attachment.url, attachment.contentType, false);
await saveQuietly({
attachment: { ...attachment, url: decryptedUrl },
getAbsolutePath: getAbsoluteAttachmentPath,
timestamp: messageTimestamp,
index,
dir,
});
await sendDataExtractionNotification(conversationId, messageSender, messageTimestamp);
};

export const saveAttachmentToDisk = async ({
attachment,
messageTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// "paths": {}, // A series of entries which re-map imports to lookup locations relative to the 'baseUrl'.
// "rootDirs": [], // List of root folders whose combined content represents the structure of the project at runtime.
// "typeRoots": [], // List of folders to include type definitions from.
// "types": [], // Type declaration files to be included in compilation.
// "types": ["@types/wicg-file-system-access"], // Type declaration files to be included in compilation.
// "allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
"useUnknownInCatchVariables": false,
"esModuleInterop": true, // Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'.
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,11 @@
resolved "https://registry.yarnpkg.com/@types/verror/-/verror-1.10.6.tgz#3e600c62d210c5826460858f84bcbb65805460bb"
integrity sha512-NNm+gdePAX1VGvPcGZCDKQZKYSiAWigKhKaz5KF94hG6f2s8de9Ow5+7AbXoeKxL8gavZfk4UquSAygOF2duEQ==

"@types/wicg-file-system-access@^2020.9.6":
version "2020.9.6"
resolved "https://registry.yarnpkg.com/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.6.tgz#da34476b1e29451c8b7aa1a6db86b185647cd970"
integrity sha512-6hogE75Hl2Ov/jgp8ZhDaGmIF/q3J07GtXf8nCJCwKTHq7971po5+DId7grft09zG7plBwpF6ZU0yx9Du4/e1A==

"@types/yargs-parser@*":
version "21.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b"
Expand Down Expand Up @@ -7385,10 +7390,10 @@ typedarray-to-buffer@^3.1.5:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==

typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==
typescript@^5.3.0-dev.20230916:
version "5.3.0-dev.20230916"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.0-dev.20230916.tgz#b5ba3e64a12b558485527593959ae6d671165aa0"
integrity sha512-X8rf5tDJ3BV2qv7AMPWAKI3+DIt1qzDLI5Ahw27IT1iii/IGNeSBTWYDc4pjD0OgSF30q2wFjNeOJyfeOo0IJQ==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
Expand Down
Loading