merge protobuf attachment and preview types

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

@ -157,8 +157,10 @@ message ConfigurationMessage {
} }
message Contact { message Contact {
optional bytes publicKey = 1; // @required
optional string name = 2; required bytes publicKey = 1;
// @required
required string name = 2;
optional string profilePicture = 3; optional string profilePicture = 3;
optional bytes profileKey = 4; optional bytes profileKey = 4;
} }
@ -179,7 +181,7 @@ message ReceiptMessage {
} }
// @required // @required
optional Type type = 1; required Type type = 1;
repeated uint64 timestamp = 2; repeated uint64 timestamp = 2;
} }
@ -190,7 +192,7 @@ message AttachmentPointer {
} }
// @required // @required
optional fixed64 id = 1; required fixed64 id = 1;
optional string contentType = 2; optional string contentType = 2;
optional bytes key = 3; optional bytes key = 3;
optional uint32 size = 4; optional uint32 size = 4;

@ -8,7 +8,6 @@ import { LokiProfile } from '../../../../types/Message';
import { MessageParams } from '../Message'; import { MessageParams } from '../Message';
interface AttachmentPointerCommon { interface AttachmentPointerCommon {
id?: number;
contentType?: string; contentType?: string;
key?: Uint8Array; key?: Uint8Array;
size?: number; size?: number;
@ -23,10 +22,12 @@ interface AttachmentPointerCommon {
export interface AttachmentPointer extends AttachmentPointerCommon { export interface AttachmentPointer extends AttachmentPointerCommon {
url?: string; url?: string;
id?: number;
} }
export interface AttachmentPointerWithUrl extends AttachmentPointerCommon { export interface AttachmentPointerWithUrl extends AttachmentPointerCommon {
url: string; url: string;
id: number;
} }
export interface Preview { export interface Preview {
@ -35,39 +36,53 @@ export interface Preview {
image?: AttachmentPointer; image?: AttachmentPointer;
} }
export interface QuotedAttachment { export interface PreviewWithAttachmentUrl {
url: string;
id: number;
title?: string;
image?: AttachmentPointerWithUrl;
}
interface QuotedAttachmentCommon {
contentType?: string; contentType?: string;
fileName?: string; fileName?: string;
}
export interface QuotedAttachment extends QuotedAttachmentCommon {
thumbnail?: AttachmentPointer; thumbnail?: AttachmentPointer;
} }
export interface QuotedAttachmentWithUrl extends QuotedAttachmentCommon {
thumbnail?: AttachmentPointerWithUrl | QuotedAttachment;
}
export interface Quote { export interface Quote {
id: number; id: number;
author: string; author: string;
text?: string; text?: string;
attachments?: Array<QuotedAttachment>; attachments?: Array<QuotedAttachmentWithUrl>;
} }
export interface VisibleMessageParams extends MessageParams { export interface VisibleMessageParams extends MessageParams {
attachments?: Array<AttachmentPointer>; attachments?: Array<AttachmentPointerWithUrl>;
body?: string; body?: string;
quote?: Quote; quote?: Quote;
expireTimer?: number; expireTimer?: number;
lokiProfile?: LokiProfile; lokiProfile?: LokiProfile;
preview?: Array<Preview>; preview?: Array<PreviewWithAttachmentUrl>;
syncTarget?: string; // null means it is not a synced message syncTarget?: string; // null means it is not a synced message
} }
export class VisibleMessage extends DataMessage { export class VisibleMessage extends DataMessage {
public readonly expireTimer?: number; public readonly expireTimer?: number;
private readonly attachments?: Array<AttachmentPointer>; private readonly attachments?: Array<AttachmentPointerWithUrl>;
private readonly body?: string; private readonly body?: string;
private readonly quote?: Quote; private readonly quote?: Quote;
private readonly profileKey?: Uint8Array; private readonly profileKey?: Uint8Array;
private readonly displayName?: string; private readonly displayName?: string;
private readonly avatarPointer?: string; private readonly avatarPointer?: string;
private readonly preview?: Array<Preview>; private readonly preview?: Array<PreviewWithAttachmentUrl>;
/// In the case of a sync message, the public key of the person the message was targeted at. /// In the case of a sync message, the public key of the person the message was targeted at.
/// - Note: `null or undefined` if this isn't a sync message. /// - Note: `null or undefined` if this isn't a sync message.
@ -141,22 +156,20 @@ export class VisibleMessage extends DataMessage {
dataMessage.quote.author = this.quote.author; dataMessage.quote.author = this.quote.author;
dataMessage.quote.text = this.quote.text; dataMessage.quote.text = this.quote.text;
if (this.quote.attachments) { if (this.quote.attachments) {
dataMessage.quote.attachments = this.quote.attachments.map( dataMessage.quote.attachments = this.quote.attachments.map(attachment => {
(attachment: QuotedAttachment) => { const quotedAttachment = new SignalService.DataMessage.Quote.QuotedAttachment();
const quotedAttachment = new SignalService.DataMessage.Quote.QuotedAttachment(); if (attachment.contentType) {
if (attachment.contentType) { quotedAttachment.contentType = attachment.contentType;
quotedAttachment.contentType = attachment.contentType;
}
if (attachment.fileName) {
quotedAttachment.fileName = attachment.fileName;
}
if (attachment.thumbnail) {
quotedAttachment.thumbnail = attachment.thumbnail;
}
return quotedAttachment;
} }
); if (attachment.fileName) {
quotedAttachment.fileName = attachment.fileName;
}
if (attachment.thumbnail && (attachment.thumbnail as any).id) {
quotedAttachment.thumbnail = attachment.thumbnail as any; // be sure to keep the typescript guard on id above
}
return quotedAttachment;
});
} }
} }

@ -5,8 +5,10 @@ import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl, AttachmentPointerWithUrl,
Preview, Preview,
PreviewWithAttachmentUrl,
Quote, Quote,
QuotedAttachment, QuotedAttachment,
QuotedAttachmentWithUrl,
} 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';
@ -101,7 +103,7 @@ export class AttachmentFsV2Utils {
public static async uploadAttachmentsToFsV2( public static async uploadAttachmentsToFsV2(
attachments: Array<Attachment> attachments: Array<Attachment>
): Promise<Array<AttachmentPointer>> { ): Promise<Array<AttachmentPointerWithUrl>> {
const promises = (attachments || []).map(async attachment => const promises = (attachments || []).map(async attachment =>
this.uploadToFsV2({ this.uploadToFsV2({
attachment, attachment,
@ -114,7 +116,7 @@ export class AttachmentFsV2Utils {
public static async uploadLinkPreviewsToFsV2( public static async uploadLinkPreviewsToFsV2(
previews: Array<RawPreview> previews: Array<RawPreview>
): Promise<Array<Preview>> { ): Promise<Array<PreviewWithAttachmentUrl>> {
const promises = (previews || []).map(async preview => { 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 (!preview.image) { if (!preview.image) {
@ -127,8 +129,9 @@ export class AttachmentFsV2Utils {
return { return {
...preview, ...preview,
image, image,
url: preview.url || image.url, url: image.url,
} as Preview; id: image.id,
};
}); });
return _.compact(await Promise.all(promises)); return _.compact(await Promise.all(promises));
} }
@ -145,13 +148,18 @@ export class AttachmentFsV2Utils {
attachment: attachment.thumbnail, attachment: attachment.thumbnail,
}); });
} }
if (!thumbnail) {
return attachment;
}
return { return {
...attachment, ...attachment,
thumbnail, thumbnail,
} as QuotedAttachment; url: thumbnail.url,
id: thumbnail.id,
} as QuotedAttachmentWithUrl;
}); });
const attachments = await Promise.all(promises); const attachments = _.compact(await Promise.all(promises));
return { return {
...quote, ...quote,

@ -5,6 +5,7 @@ import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl, AttachmentPointerWithUrl,
Preview, Preview,
PreviewWithAttachmentUrl,
Quote, Quote,
QuotedAttachment, QuotedAttachment,
} from '../messages/outgoing/visibleMessage/VisibleMessage'; } from '../messages/outgoing/visibleMessage/VisibleMessage';
@ -59,7 +60,7 @@ export async function uploadV2(params: UploadParamsV2): Promise<AttachmentPointe
export async function uploadAttachmentsV2( export async function uploadAttachmentsV2(
attachments: Array<Attachment>, attachments: Array<Attachment>,
openGroup: OpenGroupRequestCommonType openGroup: OpenGroupRequestCommonType
): Promise<Array<AttachmentPointer>> { ): Promise<Array<AttachmentPointerWithUrl>> {
const promises = (attachments || []).map(async attachment => const promises = (attachments || []).map(async attachment =>
exports.uploadV2({ exports.uploadV2({
attachment, attachment,
@ -73,7 +74,7 @@ export async function uploadAttachmentsV2(
export async function uploadLinkPreviewsV2( export async function uploadLinkPreviewsV2(
previews: Array<RawPreview>, previews: Array<RawPreview>,
openGroup: OpenGroupRequestCommonType openGroup: OpenGroupRequestCommonType
): Promise<Array<Preview>> { ): Promise<Array<PreviewWithAttachmentUrl>> {
const promises = (previews || []).map(async preview => { 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 (!preview.image) { if (!preview.image) {
@ -89,6 +90,7 @@ export async function uploadLinkPreviewsV2(
...preview, ...preview,
image, image,
url: preview.url || (image.url as string), url: preview.url || (image.url as string),
id: image.id as number,
}; };
}); });
return _.compact(await Promise.all(promises)); return _.compact(await Promise.all(promises));
@ -103,7 +105,7 @@ export async function uploadQuoteThumbnailsV2(
} }
const promises = (quote.attachments ?? []).map(async attachment => { const promises = (quote.attachments ?? []).map(async attachment => {
let thumbnail: AttachmentPointer | undefined; let thumbnail: PreviewWithAttachmentUrl | undefined;
if (attachment.thumbnail) { if (attachment.thumbnail) {
thumbnail = await exports.uploadV2({ thumbnail = await exports.uploadV2({
attachment: attachment.thumbnail, attachment: attachment.thumbnail,

@ -20,7 +20,9 @@ import { SignalService } from '../../protobuf';
import _ from 'lodash'; import _ from 'lodash';
import { import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl,
Preview, Preview,
PreviewWithAttachmentUrl,
Quote, Quote,
VisibleMessage, VisibleMessage,
} from '../messages/outgoing/visibleMessage/VisibleMessage'; } from '../messages/outgoing/visibleMessage/VisibleMessage';
@ -237,9 +239,9 @@ const buildSyncVisibleMessage = (
key, key,
digest, digest,
}; };
}) as Array<AttachmentPointer>; }) as Array<AttachmentPointerWithUrl>;
const quote = (dataMessage.quote as Quote) || undefined; const quote = (dataMessage.quote as Quote) || undefined;
const preview = (dataMessage.preview as Array<Preview>) || []; const preview = (dataMessage.preview as Array<PreviewWithAttachmentUrl>) || [];
const expireTimer = dataMessage.expireTimer; const expireTimer = dataMessage.expireTimer;
return new VisibleMessage({ return new VisibleMessage({

@ -6,7 +6,9 @@ import { toNumber } from 'lodash';
import { Constants } from '../../../../session'; import { Constants } from '../../../../session';
import { import {
AttachmentPointer, AttachmentPointer,
AttachmentPointerWithUrl,
Preview, Preview,
PreviewWithAttachmentUrl,
Quote, Quote,
VisibleMessage, VisibleMessage,
} from '../../../../session/messages/outgoing/visibleMessage/VisibleMessage'; } from '../../../../session/messages/outgoing/visibleMessage/VisibleMessage';
@ -84,10 +86,10 @@ describe('VisibleMessage', () => {
}); });
it('can create message with a preview', () => { it('can create message with a preview', () => {
let preview: Preview; let preview: PreviewWithAttachmentUrl;
preview = { url: 'url', title: 'title' }; preview = { url: 'url', title: 'title', id: 1234 };
const previews = new Array<Preview>(); const previews = new Array<PreviewWithAttachmentUrl>();
previews.push(preview); previews.push(preview);
const message = new VisibleMessage({ const message = new VisibleMessage({
@ -106,10 +108,10 @@ describe('VisibleMessage', () => {
}); });
it('can create message with an AttachmentPointer', () => { it('can create message with an AttachmentPointer', () => {
let attachment: AttachmentPointer; let attachment: AttachmentPointerWithUrl;
attachment = { url: 'url', contentType: 'contentType', id: 1234 }; attachment = { url: 'url', contentType: 'contentType', id: 1234 };
const attachments = new Array<AttachmentPointer>(); const attachments = new Array<AttachmentPointerWithUrl>();
attachments.push(attachment); attachments.push(attachment);
const message = new VisibleMessage({ const message = new VisibleMessage({

Loading…
Cancel
Save