Use DurationInSeconds for expireTimer
This commit is contained in:
parent
cf57c7aaf0
commit
6be69a7ba8
59 changed files with 411 additions and 216 deletions
|
@ -7,23 +7,27 @@ import protobuf from '../protobuf/wrap';
|
|||
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import { normalizeUuid } from '../util/normalizeUuid';
|
||||
import { DurationInSeconds } from '../util/durations';
|
||||
import * as log from '../logging/log';
|
||||
|
||||
import Avatar = Proto.ContactDetails.IAvatar;
|
||||
|
||||
const { Reader } = protobuf;
|
||||
|
||||
type OptionalAvatar = { avatar?: Avatar | null };
|
||||
type OptionalFields = { avatar?: Avatar | null; expireTimer?: number | null };
|
||||
|
||||
type DecoderBase<Message extends OptionalAvatar> = {
|
||||
type DecoderBase<Message extends OptionalFields> = {
|
||||
decodeDelimited(reader: protobuf.Reader): Message | undefined;
|
||||
};
|
||||
|
||||
export type MessageWithAvatar<Message extends OptionalAvatar> = Omit<
|
||||
type HydratedAvatar = Avatar & { data: Uint8Array };
|
||||
|
||||
type MessageWithAvatar<Message extends OptionalFields> = Omit<
|
||||
Message,
|
||||
'avatar'
|
||||
> & {
|
||||
avatar?: (Avatar & { data: Uint8Array }) | null;
|
||||
avatar?: HydratedAvatar;
|
||||
expireTimer?: DurationInSeconds;
|
||||
};
|
||||
|
||||
export type ModifiedGroupDetails = MessageWithAvatar<Proto.GroupDetails>;
|
||||
|
@ -32,7 +36,7 @@ export type ModifiedContactDetails = MessageWithAvatar<Proto.ContactDetails>;
|
|||
|
||||
/* eslint-disable @typescript-eslint/brace-style -- Prettier conflicts with ESLint */
|
||||
abstract class ParserBase<
|
||||
Message extends OptionalAvatar,
|
||||
Message extends OptionalFields,
|
||||
Decoder extends DecoderBase<Message>,
|
||||
Result
|
||||
> implements Iterable<Result>
|
||||
|
@ -57,28 +61,33 @@ abstract class ParserBase<
|
|||
return undefined;
|
||||
}
|
||||
|
||||
if (!proto.avatar) {
|
||||
return {
|
||||
...proto,
|
||||
avatar: null,
|
||||
let avatar: HydratedAvatar | undefined;
|
||||
if (proto.avatar) {
|
||||
const attachmentLen = proto.avatar.length ?? 0;
|
||||
const avatarData = this.reader.buf.slice(
|
||||
this.reader.pos,
|
||||
this.reader.pos + attachmentLen
|
||||
);
|
||||
this.reader.skip(attachmentLen);
|
||||
|
||||
avatar = {
|
||||
...proto.avatar,
|
||||
|
||||
data: avatarData,
|
||||
};
|
||||
}
|
||||
|
||||
const attachmentLen = proto.avatar.length ?? 0;
|
||||
const avatarData = this.reader.buf.slice(
|
||||
this.reader.pos,
|
||||
this.reader.pos + attachmentLen
|
||||
);
|
||||
this.reader.skip(attachmentLen);
|
||||
let expireTimer: DurationInSeconds | undefined;
|
||||
|
||||
if (proto.expireTimer != null) {
|
||||
expireTimer = DurationInSeconds.fromSeconds(proto.expireTimer);
|
||||
}
|
||||
|
||||
return {
|
||||
...proto,
|
||||
|
||||
avatar: {
|
||||
...proto.avatar,
|
||||
|
||||
data: avatarData,
|
||||
},
|
||||
avatar,
|
||||
expireTimer,
|
||||
};
|
||||
} catch (error) {
|
||||
log.error(
|
||||
|
@ -118,6 +127,7 @@ export class GroupBuffer extends ParserBase<
|
|||
if (!proto.members) {
|
||||
return proto;
|
||||
}
|
||||
|
||||
return {
|
||||
...proto,
|
||||
members: proto.members.map((member, i) => {
|
||||
|
|
|
@ -45,6 +45,7 @@ import { normalizeUuid } from '../util/normalizeUuid';
|
|||
import { parseIntOrThrow } from '../util/parseIntOrThrow';
|
||||
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
||||
import { Zone } from '../util/Zone';
|
||||
import { DurationInSeconds } from '../util/durations';
|
||||
import { deriveMasterKeyFromGroupV1, bytesToUuid } from '../Crypto';
|
||||
import type { DownloadedAttachmentType } from '../types/Attachment';
|
||||
import { Address } from '../types/Address';
|
||||
|
@ -2058,7 +2059,7 @@ export default class MessageReceiver
|
|||
attachments,
|
||||
preview,
|
||||
canReplyToStory: Boolean(msg.allowsReplies),
|
||||
expireTimer: durations.DAY / 1000,
|
||||
expireTimer: DurationInSeconds.DAY,
|
||||
flags: 0,
|
||||
groupV2,
|
||||
isStory: true,
|
||||
|
|
|
@ -65,6 +65,7 @@ import { concat, isEmpty, map } from '../util/iterables';
|
|||
import type { SendTypesType } from '../util/handleMessageSend';
|
||||
import { shouldSaveProto, sendTypesEnum } from '../util/handleMessageSend';
|
||||
import { uuidToBytes } from '../util/uuidToBytes';
|
||||
import type { DurationInSeconds } from '../util/durations';
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import * as log from '../logging/log';
|
||||
import type { Avatar, EmbeddedContactType } from '../types/EmbeddedContact';
|
||||
|
@ -174,7 +175,7 @@ export type MessageOptionsType = {
|
|||
attachments?: ReadonlyArray<AttachmentType> | null;
|
||||
body?: string;
|
||||
contact?: Array<ContactWithHydratedAvatar>;
|
||||
expireTimer?: number;
|
||||
expireTimer?: DurationInSeconds;
|
||||
flags?: number;
|
||||
group?: {
|
||||
id: string;
|
||||
|
@ -198,7 +199,7 @@ export type GroupSendOptionsType = {
|
|||
attachments?: Array<AttachmentType>;
|
||||
contact?: Array<ContactWithHydratedAvatar>;
|
||||
deletedForEveryoneTimestamp?: number;
|
||||
expireTimer?: number;
|
||||
expireTimer?: DurationInSeconds;
|
||||
flags?: number;
|
||||
groupCallUpdate?: GroupCallUpdateType;
|
||||
groupV1?: GroupV1InfoType;
|
||||
|
@ -221,7 +222,7 @@ class Message {
|
|||
|
||||
contact?: Array<ContactWithHydratedAvatar>;
|
||||
|
||||
expireTimer?: number;
|
||||
expireTimer?: DurationInSeconds;
|
||||
|
||||
flags?: number;
|
||||
|
||||
|
@ -1358,7 +1359,7 @@ export default class MessageSender {
|
|||
contact?: Array<ContactWithHydratedAvatar>;
|
||||
contentHint: number;
|
||||
deletedForEveryoneTimestamp: number | undefined;
|
||||
expireTimer: number | undefined;
|
||||
expireTimer: DurationInSeconds | undefined;
|
||||
groupId: string | undefined;
|
||||
identifier: string;
|
||||
messageText: string | undefined;
|
||||
|
|
3
ts/textsecure/Types.d.ts
vendored
3
ts/textsecure/Types.d.ts
vendored
|
@ -7,6 +7,7 @@ import type { UUID, UUIDStringType } from '../types/UUID';
|
|||
import type { TextAttachmentType } from '../types/Attachment';
|
||||
import type { GiftBadgeStates } from '../components/conversation/Message';
|
||||
import type { MIMEType } from '../types/MIME';
|
||||
import type { DurationInSeconds } from '../util/durations';
|
||||
|
||||
export {
|
||||
IdentityKeyType,
|
||||
|
@ -207,7 +208,7 @@ export type ProcessedDataMessage = {
|
|||
group?: ProcessedGroupContext;
|
||||
groupV2?: ProcessedGroupV2Context;
|
||||
flags: number;
|
||||
expireTimer: number;
|
||||
expireTimer: DurationInSeconds;
|
||||
profileKey?: string;
|
||||
timestamp: number;
|
||||
quote?: ProcessedQuote;
|
||||
|
|
|
@ -28,7 +28,7 @@ import type {
|
|||
import { WarnOnlyError } from './Errors';
|
||||
import { GiftBadgeStates } from '../components/conversation/Message';
|
||||
import { APPLICATION_OCTET_STREAM, stringToMIMEType } from '../types/MIME';
|
||||
import { SECOND } from '../util/durations';
|
||||
import { SECOND, DurationInSeconds } from '../util/durations';
|
||||
|
||||
const FLAGS = Proto.DataMessage.Flags;
|
||||
export const ATTACHMENT_MAX = 32;
|
||||
|
@ -299,7 +299,7 @@ export function processDataMessage(
|
|||
group: processGroupContext(message.group),
|
||||
groupV2: processGroupV2Context(message.groupV2),
|
||||
flags: message.flags ?? 0,
|
||||
expireTimer: message.expireTimer ?? 0,
|
||||
expireTimer: DurationInSeconds.fromSeconds(message.expireTimer ?? 0),
|
||||
profileKey:
|
||||
message.profileKey && message.profileKey.length > 0
|
||||
? Bytes.toBase64(message.profileKey)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue