123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- /**
- * This file is part of Threema Web.
- *
- * Threema Web is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
- */
- // Types used for the Threema Webclient.
- declare const angular: ng.IAngularStatic;
- declare namespace threema {
- interface Avatar {
- // Low resolution avatar path
- low?: string;
- // High resolution avatar path
- high?: string;
- }
- interface AvatarRegistry {
- contact: Avatar;
- group: Avatar;
- distributionList: Avatar;
- }
- /**
- * Messages that are sent through the secure data channel as encrypted msgpack bytes.
- */
- interface WireMessage {
- type: string;
- subType: string;
- args?: any;
- data?: any;
- }
- type WireMessageCallback = (message: WireMessage, result: any) => boolean;
- type MessageType = 'text' | 'image' | 'video' | 'audio' | 'location' | 'status' | 'ballot' | 'file';
- type MessageState = 'delivered' | 'read' | 'send-failed' | 'sent' | 'user-ack' | 'user-dec' | 'pending' | 'sending';
- interface Thumbnail {
- img?: string;
- preview: string;
- width: number;
- height: number;
- }
- /**
- * A Threema chat message.
- */
- interface Message {
- type: MessageType;
- id: number;
- body: string;
- thumbnail?: Thumbnail;
- date: string;
- partnerId: string;
- isOutbox: boolean;
- isStatus: boolean;
- caption?: string;
- statusType?: 'text' | 'firstUnreadMessage';
- unread?: boolean;
- state?: MessageState;
- quote?: Quote;
- file?: FileInfo;
- video?: VideoInfo;
- audio?: AudioInfo;
- location?: LocationInfo;
- // only for temporary Messages
- temporaryId?: string;
- errorMessage?: string;
- }
- interface FileInfo {
- description: string;
- name: string;
- size: number;
- type: string;
- inApp: boolean;
- }
- interface VideoInfo {
- duration: number;
- size: number;
- }
- interface AudioInfo {
- duration: number;
- }
- interface LocationInfo {
- lat: number;
- lon: number;
- accuracy: number;
- address: string;
- poi: string;
- }
- /**
- * All possible receiver types.
- */
- type ReceiverType = 'me' | 'contact' | 'group' | 'distributionList';
- /**
- * Access Object for receivers
- */
- interface ReceiverAccess {
- canDelete?: boolean;
- }
- interface ContactReceiverAccess extends ReceiverAccess {
- canChangeAvatar: boolean;
- canChangeFirstName: boolean;
- canChangeLastName: boolean;
- }
- interface GroupReceiverAccess extends ReceiverAccess {
- canChangeAvatar: boolean;
- canChangeName: boolean;
- canChangeMembers?: boolean;
- canLeave?: boolean;
- canSync?: boolean;
- }
- interface DistributionListReceiverAccess extends ReceiverAccess {
- canChangeMembers?: boolean;
- }
- /**
- * A generic receiver.
- *
- * Note that the id is not unique for all receivers, only for all receivers
- * of a certain type. The primary key for a receiver is the tuple (type, id).
- */
- interface Receiver {
- type?: ReceiverType;
- id: string;
- displayName: string;
- color: string;
- avatar?: Avatar; // May be set if already fetched
- access: ReceiverAccess;
- locked?: boolean;
- visible?: boolean;
- }
- /**
- * A contact.
- */
- interface ContactReceiver extends Receiver {
- type?: 'contact' | 'me';
- publicNickname?: string;
- firstName?: string;
- lastName?: string;
- verificationLevel?: number;
- state: string;
- featureLevel: number | null;
- publicKey: ArrayBuffer;
- systemContact?: SystemContact;
- access: ContactReceiverAccess;
- }
- /**
- * Own contact.
- */
- interface MeReceiver extends ContactReceiver {
- type?: 'me';
- }
- /**
- * A group.
- */
- interface GroupReceiver extends Receiver {
- type?: 'group';
- disabled: boolean;
- members: string[];
- administrator: string;
- access: GroupReceiverAccess;
- }
- /**
- * A distribution list.
- */
- interface DistributionListReceiver extends Receiver {
- type?: 'distributionList';
- members: string[];
- access: DistributionListReceiverAccess;
- }
- interface SystemContact {
- emails?: SystemContactEmail[];
- phoneNumbers?: SystemContactPhone[];
- }
- interface SystemContactEmail {
- label: string;
- address: string;
- }
- interface SystemContactPhone {
- label: string;
- number: string;
- }
- /**
- * A conversation.
- */
- interface Conversation {
- type: ReceiverType;
- id: string;
- position: number;
- messageCount: number;
- unreadCount: number;
- latestMessage: Message;
- receiver?: Receiver;
- avatar?: ArrayBuffer;
- }
- /**
- * Connection state in the welcome dialog.
- */
- type ConnectionBuildupState = 'new' | 'push' | 'manual_start' | 'connecting' | 'waiting'
- | 'peer_handshake' | 'loading' | 'done' | 'closed';
- /**
- * Connection state of the WebRTC peer connection.
- */
- type RTCConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected';
- /**
- * Connection state of the WebRTC peer connection.
- */
- type GlobalConnectionState = 'ok' | 'warning' | 'error';
- /**
- * Type of message to be sent to a receiver.
- */
- type MessageContentType = 'text' | 'file';
- /**
- * Possible message types sent to the receiver.
- */
- type MessageDataType = 'text' | 'file';
- interface MessageData {
- // optional quote object
- quote?: Quote;
- }
- /**
- * Payload for a file message.
- */
- interface FileMessageData extends MessageData {
- // File name
- name: string;
- // File MIME type
- fileType: string;
- // Size in bytes
- size: number;
- // File bytes
- data: ArrayBuffer;
- // Caption string
- caption?: String;
- // Send as file message
- sendAsFile?: boolean;
- }
- /**
- * Payload for a text message.
- */
- interface TextMessageData extends MessageData {
- // Text to be sent
- text: string;
- }
- /**
- * The $stateParams format used for the welcome controller.
- */
- interface WelcomeStateParams extends ng.ui.IStateParamsService {
- initParams: null | {keyStore: saltyrtc.KeyStore, peerTrustedKey: Uint8Array};
- }
- interface CreateReceiverStateParams extends ng.ui.IStateParamsService {
- type: string;
- initParams: null | {identity: null};
- }
- /**
- * State service.
- */
- interface StateService {
- // WebRTC states
- signalingConnectionState: saltyrtc.SignalingState;
- rtcConnectionState: RTCConnectionState;
- // Global connection state
- state: 'ok' | 'warning' | 'error';
- stage: 'signaling' | 'rtc';
- wasConnected: boolean;
- // Connection buildup
- connectionBuildupState: ConnectionBuildupState;
- progress: number;
- slowConnect: boolean;
- // Update states
- updateSignalingConnectionState(state: saltyrtc.SignalingState): void;
- updateRtcConnectionState(state: RTCConnectionState): void;
- updateConnectionBuildupState(state: ConnectionBuildupState): void;
- reset(): void;
- }
- /**
- * Notification service.
- */
- interface NotificationService {
- requestNotificationPermission(): void;
- showNotification(id: string, title: string, body: string,
- avatar: string | null, clickCallback: any | null): boolean;
- clearCache(tag: string): void;
- }
- interface MessageService {
- getAccess(message: Message, receiver: Receiver): MessageAccess;
- createTemporary(receiver: Receiver, type: string, messageData: MessageData): Message;
- showStatusIcon(message: Message, receiver: Receiver): boolean;
- getFileName(message: Message): string;
- }
- interface MessageAccess {
- quote: boolean;
- ack: boolean;
- dec: boolean;
- delete: boolean;
- download: boolean;
- copy: boolean;
- }
- interface Quote {
- identity: string;
- text: string;
- }
- interface Identity {
- identity: string;
- publicNickname: String;
- publicKey: ArrayBuffer;
- fingerprint: string;
- }
- interface TrustedKeyStoreData {
- ownPublicKey: Uint8Array;
- ownSecretKey: Uint8Array;
- peerPublicKey: Uint8Array;
- pushToken: string | null;
- }
- interface TrustedKeyStoreService {
- blocked: boolean;
- storeTrustedKey(ownPublicKey: Uint8Array, ownSecretKey: Uint8Array, peerPublicKey: Uint8Array,
- pushToken: string | null, password: string): void;
- hasTrustedKey(): boolean;
- retrieveTrustedKey(password: string): TrustedKeyStoreData;
- clearTrustedKey(): void;
- }
- interface PushService {
- init(pushToken: string): void;
- reset(): void;
- isAvailable(): boolean;
- sendPush(session: Uint8Array): Promise<boolean>;
- }
- interface BrowserInfo {
- chrome: boolean;
- firefox: boolean;
- msie: boolean;
- opera: boolean;
- safari: boolean;
- version: string;
- textInfo: string;
- }
- interface BrowserService {
- getBrowser(): BrowserInfo;
- isVisible(): boolean;
- }
- interface TitleService {
- updateUnreadCount(count: number): void;
- }
- interface FingerPrintService {
- generate(publicKey: ArrayBuffer): string;
- }
- interface ContactService {
- requiredDetails(contactReceiver: ContactReceiver): Promise<ContactReceiver>;
- }
- interface ControllerModelService {
- contact(receiver: ContactReceiver, mode: any): ControllerModel;
- group(receiver: GroupReceiver, mode: any): ControllerModel;
- distributionList(receiver: DistributionListReceiver, mode: any): ControllerModel;
- }
- interface QrCodeService {
- buildQrCodePayload(initiatorKey: Uint8Array, authToken: Uint8Array, serverKey: Uint8Array | null,
- host: string, port: number,
- persistent: boolean): string;
- }
- interface PromiseCallbacks {
- resolve: (arg: any) => void;
- reject: (arg: any) => void;
- }
- interface PromiseRequestResult<T> {
- success: boolean;
- message?: string;
- data?: T;
- }
- interface ControllerModel {
- subject: string;
- isLoading: boolean;
- save(): any;
- isValid(): boolean;
- canEdit(): boolean;
- getMode(): number;
- setOnRemoved(callback: any): void;
- }
- interface AvatarControllerModel {
- onChangeAvatar: (image: ArrayBuffer) => void;
- getAvatar(): ArrayBuffer | null;
- }
- interface Alert {
- source: string;
- type: string;
- message: string;
- }
- interface ReceiverListener {
- onRemoved(receiver: Receiver);
- }
- interface Config {
- SELF_HOSTED: boolean;
- SALTYRTC_PORT: number;
- SALTYRTC_SERVER_KEY: string | null;
- SALTYRTC_HOST: string | null;
- SALTYRTC_HOST_PREFIX: string | null;
- SALTYRTC_HOST_SUFFIX: string | null;
- SALTYRTC_STUN: RTCIceServer;
- SALTYRTC_TURN: RTCIceServer;
- PUSH_URL: string;
- }
- interface BrowserMinVersions {
- FF: number;
- CHROME: number;
- OPERA: number;
- }
- interface MimeService {
- isImage(mimeType: string): boolean;
- isAudio(mimeType: string): boolean;
- isVideo(mimeType: string): boolean;
- getLabel(mimeType: string): string;
- getIconUrl(mimeType: string): string;
- }
- interface ReceiverService {
- setActive(activeReceiver: Receiver): void;
- getActive(): Receiver;
- isConversationActive(conversation: Conversation): boolean;
- compare(a: Conversation | Receiver, b: Conversation| Receiver): boolean;
- isContact(receiver: Receiver): boolean;
- isGroup(receiver: Receiver): boolean;
- isDistributionList(receiver: Receiver): boolean;
- isBusinessContact(receiver: Receiver): boolean;
- }
- interface WebClientDefault {
- getAvatar(type: string, highResolution: boolean): string;
- }
- interface WebClientService {
- salty: saltyrtc.SaltyRTC;
- messages: Container.Messages;
- conversations: Container.Conversations;
- receivers: Container.Receivers;
- alerts: Alert[];
- defaults: WebClientDefault;
- receiverListener: ReceiverListener[];
- me: MeReceiver;
- contacts: Map<string, ContactReceiver>;
- groups: Map<string, GroupReceiver>;
- distributionLists: Map<string, DistributionListReceiver>;
- typing: Container.Typing;
- buildQrCodePayload(persistent: boolean): string;
- init(keyStore?: saltyrtc.KeyStore, peerTrustedKey?: Uint8Array, resetField?: boolean): void;
- start(): ng.IPromise<any>;
- stop(requestedByUs: boolean, deleteStoredData?: boolean, resetPush?: boolean, redirect?: boolean): void;
- registerInitializationStep(name: string): void;
- setReceiverListener(listener: ReceiverListener): void;
- requestClientInfo(): void;
- requestReceivers(): void;
- requestConversations(): void;
- requestMessages(receiver: Receiver, reloadExisting?: boolean): number;
- requestAvatar(receiver: Receiver, highResolution: boolean): Promise<any>;
- requestThumbnail(receiver: Receiver, message: Message): Promise<any>;
- requestBlob(msgId: number, receiver: Receiver): Promise<ArrayBuffer>;
- requestRead(receiver, newestMessageId: number): void;
- requestContactDetail(contactReceiver: ContactReceiver): Promise<any>;
- sendMessage(receiver, type: MessageContentType, message: MessageData): Promise<Promise<any>>;
- ackMessage(receiver, message: Message, acknowledged?: boolean): void;
- deleteMessage(receiver, message: Message): void;
- sendMeIsTyping(receiver, isTyping: boolean): void;
- sendKeyPersisted(): void;
- addContact(threemaId: String): Promise<ContactReceiver>;
- modifyContact(threemaId: String, firstName: String, lastName: String, avatar?: ArrayBuffer):
- Promise<ContactReceiver>;
- createGroup(members: String[], name: String, avatar?: ArrayBuffer): Promise<GroupReceiver>;
- modifyGroup(id: string, members: String[], name: String, avatar?: ArrayBuffer): Promise<GroupReceiver>;
- leaveGroup(group: GroupReceiver): Promise<any>;
- deleteGroup(group: GroupReceiver): Promise<any>;
- syncGroup(group: GroupReceiver): Promise<any>;
- createDistributionList(members: String[], name: String): Promise<DistributionListReceiver>;
- modifyDistributionList(id: string, members: String[], name: String): Promise<DistributionListReceiver>;
- deleteDistributionList(distributionList: DistributionListReceiver): Promise<any>;
- isTyping(receiver: ContactReceiver): boolean;
- getMyIdentity(): Identity;
- getQuote(receiver: Receiver): Quote;
- setQuote(receiver: Receiver, message?: Message): void;
- setDraft(receiver: Receiver, message: string): void;
- getDraft(receiver: Receiver): string;
- setPassword(password: string): void;
- clearCache(): void;
- getMaxTextLength(): number;
- }
- interface ControllerService {
- setControllerName(name: string): void;
- getControllerName(): string;
- }
- interface StringService {
- /**
- * create chunks of a string by counting the used bytes
- * @param str
- * @param byteLength
- * @param offset
- */
- byteChunk(str: string, byteLength: number, offset: number): string[];
- }
- namespace Container {
- interface ReceiverData {
- me: MeReceiver;
- contacts: ContactReceiver[];
- groups: GroupReceiver[];
- distributionLists: DistributionListReceiver[];
- }
- interface Converter {
- unicodeToEmoji(message);
- addReceiverToConversation(receivers: Receivers);
- }
- interface Filters {
- hasData(receivers);
- hasContact(contacts);
- isValidMessage(contacts);
- }
- interface Receivers {
- me: MeReceiver;
- contacts: Map<string, ContactReceiver>;
- groups: Map<string, GroupReceiver>;
- distributionLists: Map<string, DistributionListReceiver>;
- get(receiverType: ReceiverType): Receiver | Map<string, Receiver>;
- getData(receiver: Receiver): Receiver | null;
- set(data: ReceiverData): void;
- setMe(data: MeReceiver): void;
- setContacts(data: ContactReceiver[]): void;
- setGroups(data: GroupReceiver[]): void;
- setDistributionLists(data: DistributionListReceiver[]): void;
- extend(receiverType: ReceiverType, data: Receiver): Receiver;
- extendDistributionList(data: DistributionListReceiver): DistributionListReceiver;
- extendGroup(data: GroupReceiver): GroupReceiver;
- extendMe(data: MeReceiver): MeReceiver;
- extendContact(data: ContactReceiver): ContactReceiver;
- }
- interface Conversations {
- get(): Conversation[];
- set(data: Conversation[]): void;
- add(conversation: Conversation): void;
- updateOrAdd(conversation: Conversation): void;
- remove(conversation: Conversation): void;
- setFilter(filter: (data: Conversation[]) => Conversation[]): void;
- setConverter(converter: (data: Conversation) => Conversation): void;
- }
- interface Messages {
- converter: (data: Message) => Message;
- getList(receiver: Receiver): Message[];
- clear($scope: ng.IScope): void;
- clearReceiverMessages(receiver: Receiver): Number;
- contains(receiver: Receiver): boolean;
- hasMore(receiver: Receiver): boolean;
- setMore(receiver: Receiver, more: boolean): void;
- getReferenceMsgId(receiver: Receiver): number;
- isRequested(receiver: Receiver): boolean;
- setRequested(receiver: Receiver): void;
- clearRequested(receiver): void;
- addNewer(receiver: Receiver, messages: Message[]): void;
- addOlder(receiver: Receiver, messages: Message[]): void;
- update(receiver: Receiver, message: Message): boolean;
- setThumbnail(receiver: Receiver, messageId: number, thumbnailImage: string): boolean;
- remove(receiver: Receiver, messageId: number): boolean;
- removeTemporary(receiver: Receiver, temporaryMessageId: string): boolean;
- bindTemporaryToMessageId(receiver: Receiver, temporaryId: string, messageId: number): boolean;
- notify(receiver: Receiver, $scope: ng.IScope): void;
- register(receiver: Receiver, $scope: ng.IScope, callback: any): Message[];
- updateFirstUnreadMessage(receiver: Receiver);
- }
- interface Typing {
- setTyping(receiver: ContactReceiver): void;
- unsetTyping(receiver: ContactReceiver): void;
- isTyping(receiver: ContactReceiver): boolean;
- }
- interface Drafts {
- setQuote(receiver: Receiver, quote: Quote): void;
- removeQuote(receiver: Receiver): void;
- getQuote(receiver: Receiver): Quote;
- setText(receiver: Receiver, draftMessage: string): void;
- removeText(receiver: Receiver): void;
- getText(receiver: Receiver): string;
- }
- interface Factory {
- Converter: Container.Converter;
- Filters: Container.Filters;
- createReceivers: () => Receivers;
- createConversations: () => Conversations;
- createMessages: () => Messages;
- createTyping: () => Typing;
- createDrafts: () => Drafts;
- }
- }
- }
|