Drop group messages that don't change group
This commit is contained in:
parent
4289c28a38
commit
ba6cb653bf
7 changed files with 158 additions and 117 deletions
22
ts/textsecure.d.ts
vendored
22
ts/textsecure.d.ts
vendored
|
@ -62,6 +62,11 @@ export type TextSecureType = {
|
|||
remove: (key: string | Array<string>) => Promise<void>;
|
||||
protocol: StorageProtocolType;
|
||||
};
|
||||
messageReceiver: {
|
||||
downloadAttachment: (
|
||||
attachment: AttachmentPointerClass
|
||||
) => Promise<DownloadAttachmentType>;
|
||||
};
|
||||
messaging: {
|
||||
sendStickerPackSync: (
|
||||
operations: Array<{
|
||||
|
@ -172,6 +177,23 @@ export declare class AttachmentPointerClass {
|
|||
cdnNumber?: number;
|
||||
}
|
||||
|
||||
export type DownloadAttachmentType = {
|
||||
data: ArrayBuffer;
|
||||
cdnId?: ProtoBigNumberType;
|
||||
cdnKey?: string;
|
||||
contentType?: string;
|
||||
size?: number;
|
||||
thumbnail?: ProtoBinaryType;
|
||||
fileName?: string;
|
||||
flags?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
caption?: string;
|
||||
blurHash?: string;
|
||||
uploadTimestamp?: ProtoBigNumberType;
|
||||
cdnNumber?: number;
|
||||
};
|
||||
|
||||
export declare class ContactDetailsClass {
|
||||
static decode: (
|
||||
data: ArrayBuffer | ByteBufferClass,
|
||||
|
|
|
@ -20,8 +20,8 @@ import { IncomingIdentityKeyError } from './Errors';
|
|||
import {
|
||||
AttachmentPointerClass,
|
||||
DataMessageClass,
|
||||
DownloadAttachmentType,
|
||||
EnvelopeClass,
|
||||
ProtoBigNumberType,
|
||||
ReceiptMessageClass,
|
||||
SyncMessageClass,
|
||||
TypingMessageClass,
|
||||
|
@ -62,22 +62,6 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
type AttachmentType = {
|
||||
cdnId?: string;
|
||||
cdnKey?: string;
|
||||
data: ArrayBuffer;
|
||||
contentType?: string;
|
||||
size?: number;
|
||||
fileName?: string;
|
||||
flags?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
caption?: string;
|
||||
blurHash?: string;
|
||||
uploadTimestamp?: ProtoBigNumberType;
|
||||
cdnNumber?: number;
|
||||
};
|
||||
|
||||
type CacheAddItemType = {
|
||||
envelope: EnvelopeClass;
|
||||
data: UnprocessedType;
|
||||
|
@ -1591,7 +1575,9 @@ class MessageReceiverInner extends EventTarget {
|
|||
digest: attachment.digest ? attachment.digest.toString('base64') : null,
|
||||
};
|
||||
}
|
||||
async downloadAttachment(attachment: AttachmentPointerClass) {
|
||||
async downloadAttachment(
|
||||
attachment: AttachmentPointerClass
|
||||
): Promise<DownloadAttachmentType> {
|
||||
const encrypted = await this.server.getAttachment(
|
||||
attachment.cdnId || attachment.cdnKey,
|
||||
attachment.cdnNumber || 0
|
||||
|
@ -1623,7 +1609,7 @@ class MessageReceiverInner extends EventTarget {
|
|||
}
|
||||
async handleAttachment(
|
||||
attachment: AttachmentPointerClass
|
||||
): Promise<AttachmentType> {
|
||||
): Promise<DownloadAttachmentType> {
|
||||
const cleaned = this.cleanAttachment(attachment);
|
||||
return this.downloadAttachment(cleaned);
|
||||
}
|
||||
|
@ -1866,7 +1852,7 @@ export default class MessageReceiver {
|
|||
close: () => Promise<void>;
|
||||
downloadAttachment: (
|
||||
attachment: AttachmentPointerClass
|
||||
) => Promise<AttachmentType>;
|
||||
) => Promise<DownloadAttachmentType>;
|
||||
stopProcessing: () => Promise<void>;
|
||||
unregisterBatchers: () => void;
|
||||
|
||||
|
|
32
ts/util/downloadAttachment.ts
Normal file
32
ts/util/downloadAttachment.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import {
|
||||
AttachmentPointerClass,
|
||||
DownloadAttachmentType,
|
||||
} from '../textsecure.d';
|
||||
|
||||
type AttachmentData = AttachmentPointerClass & {
|
||||
id?: string;
|
||||
};
|
||||
|
||||
export async function downloadAttachment(
|
||||
attachmentData: AttachmentData
|
||||
): Promise<DownloadAttachmentType | null> {
|
||||
let downloaded;
|
||||
try {
|
||||
if (attachmentData.id) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
attachmentData.cdnId = attachmentData.id;
|
||||
}
|
||||
downloaded = await window.textsecure.messageReceiver.downloadAttachment(
|
||||
attachmentData
|
||||
);
|
||||
} catch (error) {
|
||||
// Attachments on the server expire after 30 days, then start returning 404
|
||||
if (error && error.code === 404) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
return downloaded;
|
||||
}
|
|
@ -4,6 +4,7 @@ import { arrayBufferToObjectURL } from './arrayBufferToObjectURL';
|
|||
import { combineNames } from './combineNames';
|
||||
import { createBatcher } from './batcher';
|
||||
import { createWaitBatcher } from './waitBatcher';
|
||||
import { downloadAttachment } from './downloadAttachment';
|
||||
import { hasExpired } from './hasExpired';
|
||||
import { isFileDangerous } from './isFileDangerous';
|
||||
import { makeLookup } from './makeLookup';
|
||||
|
@ -16,6 +17,7 @@ export {
|
|||
combineNames,
|
||||
createBatcher,
|
||||
createWaitBatcher,
|
||||
downloadAttachment,
|
||||
GoogleChrome,
|
||||
hasExpired,
|
||||
isFileDangerous,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue