signal-desktop/ts/model-types.d.ts

394 lines
11 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import * as Backbone from 'backbone';
2020-09-09 02:25:05 +00:00
import { GroupV2ChangeType } from './groups';
2020-11-03 01:19:52 +00:00
import { LocalizerType, BodyRangeType, BodyRangesType } from './types/Util';
import { CallHistoryDetailsFromDiskType } from './types/Calling';
2021-05-28 16:15:17 +00:00
import { CustomColorType } from './types/Colors';
2021-05-25 22:40:04 +00:00
import { DeviceType } from './textsecure/Types';
import { SendOptionsType } from './textsecure/SendMessage';
import { SendMessageChallengeData } from './textsecure/Errors';
import { UserMessage } from './types/Message';
import { MessageModel } from './models/messages';
import { ConversationModel } from './models/conversations';
import { ProfileNameChangeType } from './util/getStringForProfileChange';
2020-11-20 17:30:45 +00:00
import { CapabilitiesType } from './textsecure/WebAPI';
import { ReadStatus } from './messages/MessageReadStatus';
import {
SendState,
SendStateByConversationId,
} from './messages/MessageSendState';
2021-06-01 23:30:25 +00:00
import { GroupNameCollisionsWithIdsByTitle } from './util/groupMemberNameCollisions';
import { ConversationColorType } from './types/Colors';
2021-09-24 20:02:30 +00:00
import { AttachmentType, ThumbnailType } from './types/Attachment';
import { EmbeddedContactType } from './types/EmbeddedContact';
2021-07-13 18:54:53 +00:00
import { SignalService as Proto } from './protobuf';
2021-08-06 00:17:05 +00:00
import { AvatarDataType } from './types/Avatar';
2021-10-26 22:59:08 +00:00
import { UUIDStringType } from './types/UUID';
import { ReactionSource } from './reactions/ReactionSource';
2021-07-13 18:54:53 +00:00
import AccessRequiredEnum = Proto.AccessControl.AccessRequired;
import MemberRoleEnum = Proto.Member.Role;
export type WhatIsThis = any;
export type LastMessageStatus =
| 'paused'
| 'error'
| 'partial-sent'
| 'sending'
| 'sent'
| 'delivered'
| 'read'
| 'viewed';
type TaskResultType = any;
export type CustomError = Error & {
identifier?: string;
number?: string;
data?: object;
retryAfter?: number;
};
export type GroupMigrationType = {
areWeInvited: boolean;
droppedMemberIds: Array<string>;
invitedMembers: Array<GroupV2PendingMemberType>;
};
2021-04-14 22:15:57 +00:00
export type QuotedMessageType = {
attachments: Array<typeof window.WhatIsThis>;
// `author` is an old attribute that holds the author's E164. We shouldn't use it for
// new messages, but old messages might have this attribute.
author?: string;
2021-06-25 16:08:16 +00:00
authorUuid?: string;
bodyRanges?: BodyRangesType;
2021-07-09 19:36:10 +00:00
id: number;
2021-04-14 22:15:57 +00:00
referencedMessageNotFound: boolean;
isViewOnce: boolean;
2021-06-25 16:08:16 +00:00
text?: string;
messageId: string;
2021-04-14 22:15:57 +00:00
};
export type RetryOptions = Readonly<{
type: 'session-reset';
uuid: string;
e164: string;
now: number;
}>;
2021-06-23 16:14:11 +00:00
export type GroupV1Update = {
avatarUpdated?: boolean;
joined?: Array<string>;
left?: string | 'You';
name?: string;
};
export type MessageReactionType = {
emoji: undefined | string;
fromId: string;
targetAuthorUuid: string;
targetTimestamp: number;
timestamp: number;
isSentByConversationId?: Record<string, boolean>;
};
2020-09-11 19:37:01 +00:00
export type MessageAttributesType = {
bodyPending?: boolean;
bodyRanges?: BodyRangesType;
callHistoryDetails?: CallHistoryDetailsFromDiskType;
changedId?: string;
2021-09-24 00:49:05 +00:00
dataMessage?: Uint8Array | null;
decrypted_at?: number;
deletedForEveryone?: boolean;
deletedForEveryoneTimestamp?: number;
errors?: Array<CustomError>;
expirationStartTimestamp?: number | null;
expireTimer?: number;
groupMigration?: GroupMigrationType;
2021-06-23 16:14:11 +00:00
group_update?: GroupV1Update;
hasAttachments?: boolean;
hasFileAttachments?: boolean;
hasVisualMediaAttachments?: boolean;
isErased?: boolean;
isTapToViewInvalid?: boolean;
isViewOnce?: boolean;
key_changed?: string;
local?: boolean;
logger?: unknown;
message?: unknown;
messageTimer?: unknown;
profileChange?: ProfileNameChangeType;
2021-04-14 22:15:57 +00:00
quote?: QuotedMessageType;
reactions?: Array<MessageReactionType>;
requiredProtocolVersion?: number;
retryOptions?: RetryOptions;
sourceDevice?: number;
supportedVersionAtReceive?: unknown;
synced?: boolean;
unidentifiedDeliveryReceived?: boolean;
verified?: boolean;
verifiedChanged?: string;
id: string;
type:
| 'call-history'
| 'chat-session-refreshed'
2021-05-28 19:11:19 +00:00
| 'delivery-issue'
| 'group'
| 'group-v1-migration'
| 'group-v2-change'
2021-05-28 19:11:19 +00:00
| 'incoming'
| 'keychange'
| 'message-history-unsynced'
| 'outgoing'
| 'profile-change'
2021-05-28 19:11:19 +00:00
| 'timer-notification'
2021-06-01 20:45:43 +00:00
| 'universal-timer-notification'
2021-08-05 23:34:49 +00:00
| 'change-number-notification'
2021-05-28 19:11:19 +00:00
| 'verified-change';
body?: string;
attachments?: Array<AttachmentType>;
preview?: Array<WhatIsThis>;
sticker?: {
packId: string;
stickerId: number;
packKey: string;
data?: AttachmentType;
};
2021-05-03 16:38:20 +00:00
sent_at: number;
unidentifiedDeliveries?: Array<string>;
contact?: Array<EmbeddedContactType>;
conversationId: string;
reaction?: WhatIsThis;
2020-09-09 02:25:05 +00:00
expirationTimerUpdate?: {
expireTimer: number;
fromSync?: unknown;
2020-09-09 02:25:05 +00:00
source?: string;
sourceUuid?: string;
};
// Legacy fields for timer update notification only
flags?: number;
groupV2Change?: GroupV2ChangeType;
// Required. Used to sort messages in the database for the conversation timeline.
received_at: number;
2021-03-04 21:44:57 +00:00
received_at_ms?: number;
2020-09-09 02:25:05 +00:00
// More of a legacy feature, needed as we were updating the schema of messages in the
// background, when we were still in IndexedDB, before attachments had gone to disk
// We set this so that the idle message upgrade process doesn't pick this message up
schemaVersion?: number;
// This should always be set for new messages, but older messages may not have them. We
// may not have these for outbound messages, either, as we have not needed them.
serverGuid?: string;
2020-09-09 02:25:05 +00:00
serverTimestamp?: number;
source?: string;
2021-10-26 22:59:08 +00:00
sourceUuid?: UUIDStringType;
timestamp: number;
// Backwards-compatibility with prerelease data schema
invitedGV2Members?: Array<GroupV2PendingMemberType>;
droppedGV2MemberIds?: Array<string>;
2021-07-09 19:36:10 +00:00
sendHQImages?: boolean;
// Should only be present for incoming messages
readStatus?: ReadStatus;
// Should only be present for outgoing messages
sendStateByConversationId?: SendStateByConversationId;
};
export type ConversationAttributesTypeType = 'private' | 'group';
2020-09-11 19:37:01 +00:00
export type ConversationAttributesType = {
accessKey?: string | null;
2020-10-06 17:06:34 +00:00
addedBy?: string;
2021-11-02 23:01:13 +00:00
badges?: Array<
| { id: string }
| {
id: string;
expiresAt: number;
isVisible: boolean;
}
>;
2020-11-20 17:30:45 +00:00
capabilities?: CapabilitiesType;
color?: string;
conversationColor?: ConversationColorType;
2021-05-28 16:15:17 +00:00
customColor?: CustomColorType;
customColorId?: string;
discoveredUnregisteredAt?: number;
2021-08-30 21:32:56 +00:00
draftChanged?: boolean;
2021-09-24 20:02:30 +00:00
draftAttachments?: Array<AttachmentType>;
draftBodyRanges?: Array<BodyRangeType>;
draftTimestamp?: number | null;
inbox_position: number;
isPinned: boolean;
lastMessageDeletedForEveryone: boolean;
lastMessageStatus?: LastMessageStatus | null;
markedUnread: boolean;
messageCount: number;
messageCountBeforeMessageRequests?: number | null;
messageRequestResponseType?: number;
muteExpiresAt?: number;
2021-08-05 12:35:33 +00:00
dontNotifyForMentionsIfMuted?: boolean;
profileAvatar?: null | {
hash: string;
path: string;
};
profileKeyCredential?: string | null;
profileKeyVersion?: string | null;
quotedMessageId?: string | null;
sealedSender?: unknown;
sentMessageCount: number;
sharedGroupNames?: Array<string>;
id: string;
type: ConversationAttributesTypeType;
timestamp?: number | null;
2020-09-09 02:25:05 +00:00
// Shared fields
active_at?: number | null;
draft?: string | null;
isArchived?: boolean;
lastMessage?: string | null;
2020-09-09 02:25:05 +00:00
name?: string;
2020-09-09 00:56:23 +00:00
needsStorageServiceSync?: boolean;
needsVerification?: boolean;
profileSharing: boolean;
storageID?: string;
storageUnknownFields?: string;
unreadCount?: number;
version: number;
2020-09-09 02:25:05 +00:00
// Private core info
2021-10-26 22:59:08 +00:00
uuid?: UUIDStringType;
2020-09-09 02:25:05 +00:00
e164?: string;
// Private other fields
2021-01-26 01:01:19 +00:00
about?: string;
aboutEmoji?: string;
profileFamilyName?: string;
profileKey?: string;
profileName?: string;
2020-09-09 02:25:05 +00:00
verified?: number;
profileLastFetchedAt?: number;
2021-06-01 20:45:43 +00:00
pendingUniversalTimer?: string;
username?: string;
2020-09-09 02:25:05 +00:00
// Group-only
groupId?: string;
// A shorthand, representing whether the user is part of the group. Not strictly for
// when the user manually left the group. But historically, that was the only way
// to leave a group.
left?: boolean;
2020-09-09 02:25:05 +00:00
groupVersion?: number;
// GroupV1 only
members?: Array<string>;
2020-11-20 17:30:45 +00:00
derivedGroupV2Id?: string;
2020-09-09 02:25:05 +00:00
// GroupV2 core info
masterKey?: string;
secretParams?: string;
publicParams?: string;
revision?: number;
2021-05-25 22:40:04 +00:00
senderKeyInfo?: {
createdAtDate: number;
distributionId: string;
memberDevices: Array<DeviceType>;
};
2020-09-09 02:25:05 +00:00
// GroupV2 other fields
accessControl?: {
attributes: AccessRequiredEnum;
members: AccessRequiredEnum;
addFromInviteLink: AccessRequiredEnum;
2020-09-09 02:25:05 +00:00
};
2021-07-20 20:18:35 +00:00
announcementsOnly?: boolean;
2020-09-09 02:25:05 +00:00
avatar?: {
url: string;
path: string;
hash?: string;
} | null;
2021-08-06 00:17:05 +00:00
avatars?: Array<AvatarDataType>;
2021-06-02 00:24:28 +00:00
description?: string;
2020-09-09 02:25:05 +00:00
expireTimer?: number;
membersV2?: Array<GroupV2MemberType>;
pendingMembersV2?: Array<GroupV2PendingMemberType>;
pendingAdminApprovalV2?: Array<GroupV2PendingAdminApprovalType>;
groupInviteLinkPassword?: string;
2020-11-20 17:30:45 +00:00
previousGroupV1Id?: string;
previousGroupV1Members?: Array<string>;
2021-06-01 23:30:25 +00:00
acknowledgedGroupNameCollisions?: GroupNameCollisionsWithIdsByTitle;
// Used only when user is waiting for approval to join via link
isTemporary?: boolean;
temporaryMemberCount?: number;
// Avatars are blurred for some unapproved conversations, but users can manually unblur
// them. If the avatar was unblurred and then changed, we don't update this value so
// the new avatar gets blurred.
//
// This value is useless once the message request has been approved. We don't clean it
// up but could. We don't persist it but could (though we'd probably want to clean it
// up in that case).
unblurredAvatarPath?: string;
2020-09-09 02:25:05 +00:00
};
export type GroupV2MemberType = {
2021-10-26 22:59:08 +00:00
uuid: UUIDStringType;
role: MemberRoleEnum;
2020-09-09 02:25:05 +00:00
joinedAtVersion: number;
// Note that these are temporary flags, generated by applyGroupChange, but eliminated
// by applyGroupState. They are used to make our diff-generation more intelligent but
// not after that.
joinedFromLink?: boolean;
approvedByAdmin?: boolean;
2020-09-09 02:25:05 +00:00
};
2020-09-09 02:25:05 +00:00
export type GroupV2PendingMemberType = {
2021-10-26 22:59:08 +00:00
addedByUserId?: UUIDStringType;
uuid: UUIDStringType;
2020-09-09 02:25:05 +00:00
timestamp: number;
role: MemberRoleEnum;
};
export type GroupV2PendingAdminApprovalType = {
2021-10-26 22:59:08 +00:00
uuid: UUIDStringType;
timestamp: number;
};
export type VerificationOptions = {
2021-09-24 00:49:05 +00:00
key?: null | Uint8Array;
2020-09-09 00:56:23 +00:00
viaContactSync?: boolean;
viaStorageServiceSync?: boolean;
viaSyncMessage?: boolean;
};
export type ShallowChallengeError = CustomError & {
readonly retryAfter: number;
readonly data: SendMessageChallengeData;
};
2021-04-26 16:38:50 +00:00
export declare class ConversationModelCollectionType extends Backbone.Collection<ConversationModel> {
resetLookups(): void;
}
2021-04-26 16:38:50 +00:00
export declare class MessageModelCollectionType extends Backbone.Collection<MessageModel> {}
2021-05-13 19:10:20 +00:00
export type ReactionAttributesType = {
emoji: string;
remove?: boolean;
targetAuthorUuid: string;
targetTimestamp: number;
2021-10-13 16:29:15 +00:00
fromId: string;
2021-05-13 19:10:20 +00:00
timestamp: number;
source: ReactionSource;
2021-05-13 19:10:20 +00:00
};