Download in context menu
Open PDF on download
This commit is contained in:
parent
1e63191100
commit
8666907cbc
@ -10,7 +10,7 @@ import type { AppStickersManager } from "../../lib/appManagers/appStickersManage
|
||||
import type { AppUsersManager } from "../../lib/appManagers/appUsersManager";
|
||||
import type { AppInlineBotsManager } from "../../lib/appManagers/appInlineBotsManager";
|
||||
import type { AppPhotosManager } from "../../lib/appManagers/appPhotosManager";
|
||||
import type { AppDocsManager } from "../../lib/appManagers/appDocsManager";
|
||||
import type { AppDocsManager, MyDocument } from "../../lib/appManagers/appDocsManager";
|
||||
import type { AppPeersManager } from "../../lib/appManagers/appPeersManager";
|
||||
import type sessionStorage from '../../lib/sessionStorage';
|
||||
import type Chat from "./chat";
|
||||
@ -2427,7 +2427,7 @@ export default class ChatBubbles {
|
||||
lastContainer && lastContainer.append(timeSpan.cloneNode(true));
|
||||
|
||||
bubble.classList.remove('is-message-empty');
|
||||
messageDiv.classList.add((doc.type !== 'photo' ? doc.type || 'document' : 'document') + '-message');
|
||||
messageDiv.classList.add((!(['photo', 'pdf'] as MyDocument['type'][]).includes(doc.type) ? doc.type || 'document' : 'document') + '-message');
|
||||
processingWebPage = true;
|
||||
|
||||
break;
|
||||
|
@ -24,6 +24,7 @@ import { cancelEvent } from "../../helpers/dom/cancelEvent";
|
||||
import cancelSelection from "../../helpers/dom/cancelSelection";
|
||||
import { attachClickEvent } from "../../helpers/dom/clickEvent";
|
||||
import isSelectionEmpty from "../../helpers/dom/isSelectionEmpty";
|
||||
import appDocsManager, { MyDocument } from "../../lib/appManagers/appDocsManager";
|
||||
|
||||
export default class ChatContextMenu {
|
||||
private buttons: (ButtonMenuItemOptions & {verify: () => boolean, notDirect?: () => boolean, withSelection?: true})[];
|
||||
@ -241,6 +242,16 @@ export default class ChatContextMenu {
|
||||
text: 'Message.Context.Unpin',
|
||||
onClick: this.onUnpinClick,
|
||||
verify: () => this.message.pFlags.pinned && this.appPeersManager.canPinMessage(this.peerId),
|
||||
}, {
|
||||
icon: 'download',
|
||||
text: 'MediaViewer.Context.Download',
|
||||
onClick: () => {
|
||||
appDocsManager.saveDocFile(this.message.media.document);
|
||||
},
|
||||
verify: () => {
|
||||
const doc: MyDocument = this.message.media?.document;
|
||||
return doc && doc.type && !(['gif', 'photo', 'video', 'sticker'] as MyDocument['type'][]).includes(doc.type);
|
||||
}
|
||||
}, {
|
||||
icon: 'checkretract',
|
||||
text: 'Chat.Poll.Unvote',
|
||||
|
@ -37,7 +37,7 @@ import { animateSingle } from '../helpers/animation';
|
||||
import renderImageFromUrl from '../helpers/dom/renderImageFromUrl';
|
||||
import sequentialDom from '../helpers/sequentialDom';
|
||||
import { fastRaf } from '../helpers/schedulers';
|
||||
import appDownloadManager from '../lib/appManagers/appDownloadManager';
|
||||
import appDownloadManager, { DownloadBlob } from '../lib/appManagers/appDownloadManager';
|
||||
import appStickersManager from '../lib/appManagers/appStickersManager';
|
||||
import { cancelEvent } from '../helpers/dom/cancelEvent';
|
||||
import { attachClickEvent } from '../helpers/dom/clickEvent';
|
||||
@ -546,7 +546,16 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS
|
||||
|
||||
const load = () => {
|
||||
const doc = appDocsManager.getDoc(docDiv.dataset.docId);
|
||||
const download = appDocsManager.saveDocFile(doc, appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : 0);
|
||||
let download: DownloadBlob;
|
||||
if(doc.type === 'pdf') {
|
||||
download = appDocsManager.downloadDoc(doc, appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : 0);
|
||||
download.then(() => {
|
||||
const cacheContext = appDownloadManager.getCacheContext(doc);
|
||||
window.open(cacheContext.url);
|
||||
});
|
||||
} else {
|
||||
download = appDocsManager.saveDocFile(doc, appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : 0);
|
||||
}
|
||||
|
||||
if(downloadDiv) {
|
||||
download.then(onLoad);
|
||||
|
@ -12,7 +12,7 @@
|
||||
const App = {
|
||||
id: 1025907,
|
||||
hash: '452b0359b988148995f22ff0f4229750',
|
||||
version: '0.5.2',
|
||||
version: '0.5.3',
|
||||
langPackVersion: '0.1.6',
|
||||
langPack: 'macos',
|
||||
langPackCode: 'en',
|
||||
|
@ -36,6 +36,7 @@ export function blobConstruct(blobParts: any, mimeType: string = ''): Blob {
|
||||
return blob;
|
||||
}
|
||||
|
||||
// https://www.iana.org/assignments/media-types/media-types.xhtml
|
||||
export function blobSafeMimeType(mimeType: string) {
|
||||
if([
|
||||
'image/jpeg',
|
||||
@ -49,7 +50,8 @@ export function blobSafeMimeType(mimeType: string) {
|
||||
'audio/ogg',
|
||||
'audio/mpeg',
|
||||
'audio/mp4',
|
||||
'application/json'
|
||||
'application/json',
|
||||
'application/pdf'
|
||||
].indexOf(mimeType) === -1) {
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
2
src/layer.d.ts
vendored
2
src/layer.d.ts
vendored
@ -3101,7 +3101,7 @@ export namespace Document {
|
||||
video_thumbs?: Array<VideoSize>,
|
||||
dc_id: number,
|
||||
attributes: Array<DocumentAttribute>,
|
||||
type?: 'gif' | 'sticker' | 'audio' | 'voice' | 'video' | 'round' | 'photo',
|
||||
type?: 'gif' | 'sticker' | 'audio' | 'voice' | 'video' | 'round' | 'photo' | 'pdf',
|
||||
h?: number,
|
||||
w?: number,
|
||||
file_name?: string,
|
||||
|
@ -21,6 +21,7 @@ import appPhotosManager from './appPhotosManager';
|
||||
import blur from '../../helpers/blur';
|
||||
import apiManager from '../mtproto/mtprotoworker';
|
||||
import { MOUNT_CLASS_TO } from '../../config/debug';
|
||||
import { getFullDate } from '../../helpers/date';
|
||||
|
||||
export type MyDocument = Document.document;
|
||||
|
||||
@ -96,8 +97,7 @@ export class AppDocsManager {
|
||||
doc.duration = attribute.duration;
|
||||
doc.audioTitle = attribute.title;
|
||||
doc.audioPerformer = attribute.performer;
|
||||
doc.type = attribute.pFlags.voice && doc.mime_type === "audio/ogg" ? 'voice' : 'audio';
|
||||
|
||||
doc.type = attribute.pFlags.voice && doc.mime_type === 'audio/ogg' ? 'voice' : 'audio';
|
||||
/* if(apiDoc.type === 'audio') {
|
||||
apiDoc.supportsStreaming = true;
|
||||
} */
|
||||
@ -174,6 +174,15 @@ export class AppDocsManager {
|
||||
}
|
||||
}
|
||||
|
||||
if(doc.mime_type === 'application/pdf') {
|
||||
doc.type = 'pdf';
|
||||
}
|
||||
|
||||
if(doc.type === 'voice' || doc.type === 'round') {
|
||||
// browser will identify extension
|
||||
doc.file_name = doc.type + '_' + getFullDate(new Date(doc.date * 1000), {monthAsNumber: true, leadingZero: true}).replace(/[:\.]/g, '-').replace(', ', '_');
|
||||
}
|
||||
|
||||
if(apiManager.isServiceWorkerOnline()) {
|
||||
if((doc.type === 'gif' && doc.size > 8e6) || doc.type === 'audio' || doc.type === 'video') {
|
||||
doc.supportsStreaming = true;
|
||||
@ -247,7 +256,7 @@ export class AppDocsManager {
|
||||
dcId: doc.dc_id,
|
||||
location: inputFileLocation,
|
||||
size: thumb ? thumb.size : doc.size,
|
||||
mimeType: mimeType,
|
||||
mimeType,
|
||||
fileName: doc.file_name,
|
||||
queueId,
|
||||
onlyCache
|
||||
|
@ -2,7 +2,7 @@
|
||||
"predicate": "document",
|
||||
"params": [
|
||||
{"name": "thumbs", "type": "Array<PhotoSize.photoSize | PhotoSize.photoCachedSize | PhotoSize.photoStrippedSize | PhotoSize.photoPathSize>"},
|
||||
{"name": "type", "type": "'gif' | 'sticker' | 'audio' | 'voice' | 'video' | 'round' | 'photo'"},
|
||||
{"name": "type", "type": "'gif' | 'sticker' | 'audio' | 'voice' | 'video' | 'round' | 'photo' | 'pdf'"},
|
||||
{"name": "h", "type": "number"},
|
||||
{"name": "w", "type": "number"},
|
||||
{"name": "file_name", "type": "string"},
|
||||
|
Loading…
Reference in New Issue
Block a user