made some timestamp required in the protobuf

pull/1692/head
Audric Ackermann 4 years ago
parent 173b49723b
commit c1225b3a74
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,8 +1,5 @@
// Source: https://github.com/signalapp/libsignal-service-java/blob/4684a49b2ed8f32be619e0d0eea423626b6cb2cb/protobuf/SignalService.proto
package signalservice; package signalservice;
option java_package = "org.whispersystems.signalservice.internal.push";
option java_outer_classname = "SignalServiceProtos";
message Envelope { message Envelope {
@ -15,7 +12,7 @@ message Envelope {
required Type type = 1; required Type type = 1;
optional string source = 2; optional string source = 2;
// @required // @required
optional uint64 timestamp = 5; required uint64 timestamp = 5;
optional bytes content = 8; optional bytes content = 8;
} }
@ -25,9 +22,9 @@ message TypingMessage {
STOPPED = 1; STOPPED = 1;
} }
// @required // @required
optional uint64 timestamp = 1; required uint64 timestamp = 1;
// @required // @required
optional Action action = 2; required Action action = 2;
} }
@ -75,16 +72,16 @@ message DataMessage {
} }
// @required // @required
optional uint64 id = 1; required uint64 id = 1;
// @required // @required
optional string author = 2; required string author = 2;
optional string text = 3; optional string text = 3;
repeated QuotedAttachment attachments = 4; repeated QuotedAttachment attachments = 4;
} }
message Preview { message Preview {
// @required // @required
optional string url = 1; required string url = 1;
optional string title = 2; optional string title = 2;
optional AttachmentPointer image = 3; optional AttachmentPointer image = 3;
} }

@ -56,7 +56,7 @@ export const parseMessages = async (
const opengroupv2Message = OpenGroupMessageV2.fromJson(r); const opengroupv2Message = OpenGroupMessageV2.fromJson(r);
if ( if (
!opengroupv2Message?.serverId || !opengroupv2Message?.serverId ||
!opengroupv2Message.sentTimestamp || !opengroupv2Message.sentTimestamp || // this is our serverTimestamp
!opengroupv2Message.base64EncodedData || !opengroupv2Message.base64EncodedData ||
!opengroupv2Message.base64EncodedSignature !opengroupv2Message.base64EncodedSignature
) { ) {

@ -5,10 +5,9 @@ import { DataMessage } from '..';
import { Constants } from '../../..'; import { Constants } from '../../..';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
import { LokiProfile } from '../../../../types/Message'; import { LokiProfile } from '../../../../types/Message';
import { ExpirationTimerUpdateMessage } from '../controlMessage/ExpirationTimerUpdateMessage';
import { MessageParams } from '../Message'; import { MessageParams } from '../Message';
export interface AttachmentPointer { interface AttachmentPointerCommon {
id?: number; id?: number;
contentType?: string; contentType?: string;
key?: Uint8Array; key?: Uint8Array;
@ -20,11 +19,18 @@ export interface AttachmentPointer {
width?: number; width?: number;
height?: number; height?: number;
caption?: string; caption?: string;
}
export interface AttachmentPointer extends AttachmentPointerCommon {
url?: string; url?: string;
} }
export interface AttachmentPointerWithUrl extends AttachmentPointerCommon {
url: string;
}
export interface Preview { export interface Preview {
url?: string; url: string;
title?: string; title?: string;
image?: AttachmentPointer; image?: AttachmentPointer;
} }
@ -36,8 +42,8 @@ export interface QuotedAttachment {
} }
export interface Quote { export interface Quote {
id?: number; id: number;
author?: string; author: string;
text?: string; text?: string;
attachments?: Array<QuotedAttachment>; attachments?: Array<QuotedAttachment>;
} }

@ -3,12 +3,14 @@ import { Attachment } from '../../types/Attachment';
import { import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl,
Preview, Preview,
Quote, Quote,
QuotedAttachment, QuotedAttachment,
} from '../messages/outgoing/visibleMessage/VisibleMessage'; } from '../messages/outgoing/visibleMessage/VisibleMessage';
import { FSv2 } from '../../fileserver'; import { FSv2 } from '../../fileserver';
import { addAttachmentPadding } from '../crypto/BufferPadding'; import { addAttachmentPadding } from '../crypto/BufferPadding';
import _ from 'lodash';
interface UploadParams { interface UploadParams {
attachment: Attachment; attachment: Attachment;
@ -17,21 +19,21 @@ interface UploadParams {
shouldPad?: boolean; shouldPad?: boolean;
} }
interface RawPreview { export interface RawPreview {
url?: string; url?: string;
title?: string; title?: string;
image: Attachment; image: Attachment;
} }
interface RawQuoteAttachment { export interface RawQuoteAttachment {
contentType?: string; contentType?: string;
fileName?: string; fileName?: string;
thumbnail?: Attachment; thumbnail?: Attachment;
} }
interface RawQuote { export interface RawQuote {
id?: number; id: number;
author?: string; author: string;
text?: string; text?: string;
attachments?: Array<RawQuoteAttachment>; attachments?: Array<RawQuoteAttachment>;
} }
@ -40,7 +42,7 @@ interface RawQuote {
export class AttachmentFsV2Utils { export class AttachmentFsV2Utils {
private constructor() {} private constructor() {}
public static async uploadToFsV2(params: UploadParams): Promise<AttachmentPointer> { public static async uploadToFsV2(params: UploadParams): Promise<AttachmentPointerWithUrl> {
const { attachment, isRaw = false, shouldPad = false } = params; const { attachment, isRaw = false, shouldPad = false } = params;
if (typeof attachment !== 'object' || attachment == null) { if (typeof attachment !== 'object' || attachment == null) {
throw new Error('Invalid attachment passed.'); throw new Error('Invalid attachment passed.');
@ -84,15 +86,17 @@ export class AttachmentFsV2Utils {
if (FSv2.useFileServerAPIV2Sending) { if (FSv2.useFileServerAPIV2Sending) {
const uploadToV2Result = await FSv2.uploadFileToFsV2(attachmentData); const uploadToV2Result = await FSv2.uploadFileToFsV2(attachmentData);
if (uploadToV2Result) { if (uploadToV2Result) {
pointer.id = uploadToV2Result.fileId; const pointerWithUrl: AttachmentPointerWithUrl = {
pointer.url = uploadToV2Result.fileUrl; ...pointer,
} else { id: uploadToV2Result.fileId,
window?.log?.warn('upload to file server v2 failed'); url: uploadToV2Result.fileUrl,
};
return pointerWithUrl;
} }
return pointer; window?.log?.warn('upload to file server v2 failed');
} else { throw new Error(`upload to file server v2 of ${attachment.fileName} failed`);
throw new Error('Only v2 fileserver upload is supported');
} }
throw new Error('Only v2 fileserver upload is supported');
} }
public static async uploadAttachmentsToFsV2( public static async uploadAttachmentsToFsV2(
@ -111,19 +115,22 @@ export class AttachmentFsV2Utils {
public static async uploadLinkPreviewsToFsV2( public static async uploadLinkPreviewsToFsV2(
previews: Array<RawPreview> previews: Array<RawPreview>
): Promise<Array<Preview>> { ): Promise<Array<Preview>> {
const promises = (previews || []).map(async item => { const promises = (previews || []).map(async preview => {
// some links does not have an image associated, and it makes the whole message fail to send // some links does not have an image associated, and it makes the whole message fail to send
if (!item.image) { if (!preview.image) {
return item; window.log.warn('tried to upload file to fsv2 without image.. skipping');
return undefined;
} }
const image = await this.uploadToFsV2({
attachment: preview.image,
});
return { return {
...item, ...preview,
image: await this.uploadToFsV2({ image,
attachment: item.image, url: preview.url || image.url,
}), } as Preview;
};
}); });
return Promise.all(promises); return _.compact(await Promise.all(promises));
} }
public static async uploadQuoteThumbnailsToFsV2(quote?: RawQuote): Promise<Quote | undefined> { public static async uploadQuoteThumbnailsToFsV2(quote?: RawQuote): Promise<Quote | undefined> {

@ -1,41 +1,24 @@
import * as crypto from 'crypto';
import { Attachment } from '../../types/Attachment'; import { Attachment } from '../../types/Attachment';
import { OpenGroupRequestCommonType } from '../../opengroup/opengroupV2/ApiUtil'; import { OpenGroupRequestCommonType } from '../../opengroup/opengroupV2/ApiUtil';
import { import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl,
Preview, Preview,
Quote, Quote,
QuotedAttachment, QuotedAttachment,
} from '../messages/outgoing/visibleMessage/VisibleMessage'; } from '../messages/outgoing/visibleMessage/VisibleMessage';
import { uploadFileOpenGroupV2 } from '../../opengroup/opengroupV2/OpenGroupAPIV2'; import { uploadFileOpenGroupV2 } from '../../opengroup/opengroupV2/OpenGroupAPIV2';
import { addAttachmentPadding } from '../crypto/BufferPadding'; import { addAttachmentPadding } from '../crypto/BufferPadding';
import { RawPreview, RawQuote } from './Attachments';
import _ from 'lodash';
interface UploadParamsV2 { interface UploadParamsV2 {
attachment: Attachment; attachment: Attachment;
openGroup: OpenGroupRequestCommonType; openGroup: OpenGroupRequestCommonType;
} }
interface RawPreview { export async function uploadV2(params: UploadParamsV2): Promise<AttachmentPointerWithUrl> {
url?: string;
title?: string;
image: Attachment;
}
interface RawQuoteAttachment {
contentType?: string;
fileName?: string;
thumbnail?: Attachment;
}
interface RawQuote {
id?: number;
author?: string;
text?: string;
attachments?: Array<RawQuoteAttachment>;
}
export async function uploadV2(params: UploadParamsV2): Promise<AttachmentPointer> {
const { attachment, openGroup } = params; const { attachment, openGroup } = params;
if (typeof attachment !== 'object' || attachment == null) { if (typeof attachment !== 'object' || attachment == null) {
throw new Error('Invalid attachment passed.'); throw new Error('Invalid attachment passed.');
@ -62,10 +45,15 @@ export async function uploadV2(params: UploadParamsV2): Promise<AttachmentPointe
const fileDetails = await uploadFileOpenGroupV2(new Uint8Array(paddedAttachment), openGroup); const fileDetails = await uploadFileOpenGroupV2(new Uint8Array(paddedAttachment), openGroup);
pointer.id = fileDetails?.fileId || undefined; if (!fileDetails) {
pointer.url = fileDetails?.fileUrl || undefined; throw new Error(`upload to fileopengroupv2 of ${attachment.fileName} failed`);
}
return pointer; return {
...pointer,
id: fileDetails.fileId,
url: fileDetails.fileUrl,
};
} }
export async function uploadAttachmentsV2( export async function uploadAttachmentsV2(
@ -86,20 +74,24 @@ export async function uploadLinkPreviewsV2(
previews: Array<RawPreview>, previews: Array<RawPreview>,
openGroup: OpenGroupRequestCommonType openGroup: OpenGroupRequestCommonType
): Promise<Array<Preview>> { ): Promise<Array<Preview>> {
const promises = (previews || []).map(async item => { const promises = (previews || []).map(async preview => {
// some links does not have an image associated, and it makes the whole message fail to send // some links does not have an image associated, and it makes the whole message fail to send
if (!item.image) { if (!preview.image) {
return item; window.log.warn('tried to upload file to opengroupv2 without image.. skipping');
return undefined;
} }
const image = await exports.uploadV2({
attachment: preview.image,
openGroup,
});
return { return {
...item, ...preview,
image: await exports.uploadV2({ image,
attachment: item.image, url: preview.url || (image.url as string),
openGroup,
}),
}; };
}); });
return Promise.all(promises); return _.compact(await Promise.all(promises));
} }
export async function uploadQuoteThumbnailsV2( export async function uploadQuoteThumbnailsV2(
@ -121,7 +113,7 @@ export async function uploadQuoteThumbnailsV2(
return { return {
...attachment, ...attachment,
thumbnail, thumbnail,
} as QuotedAttachment; };
}); });
const attachments = await Promise.all(promises); const attachments = await Promise.all(promises);

Loading…
Cancel
Save