threema.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. declare const angular: ng.IAngularStatic;
  18. declare namespace threema {
  19. interface Avatar {
  20. // Low resolution avatar path
  21. low?: string;
  22. // High resolution avatar path
  23. high?: string;
  24. }
  25. interface AvatarRegistry {
  26. contact: Avatar;
  27. group: Avatar;
  28. distributionList: Avatar;
  29. }
  30. /**
  31. * Messages that are sent through the secure data channel as encrypted msgpack bytes.
  32. */
  33. interface WireMessage {
  34. type: string;
  35. subType: string;
  36. args?: any;
  37. data?: any;
  38. }
  39. type MessageType = 'text' | 'image' | 'video' | 'audio' | 'location' | 'contact' |
  40. 'status' | 'ballot' | 'file' | 'voipStatus' | 'unknown';
  41. type MessageState = 'delivered' | 'read' | 'send-failed' | 'sent' | 'user-ack' |
  42. 'user-dec' | 'pending' | 'sending';
  43. type InitializationStep = 'client info' | 'conversations' | 'receivers';
  44. interface InitializationStepRoutine {
  45. requiredSteps: InitializationStep[];
  46. callback: any;
  47. }
  48. interface Thumbnail {
  49. img?: string;
  50. preview: string;
  51. width: number;
  52. height: number;
  53. }
  54. /**
  55. * A Threema chat message.
  56. */
  57. interface Message {
  58. type: MessageType;
  59. id: number;
  60. body: string;
  61. thumbnail?: Thumbnail;
  62. date: string;
  63. partnerId: string;
  64. isOutbox: boolean;
  65. isStatus: boolean;
  66. caption?: string;
  67. statusType?: 'text' | 'firstUnreadMessage';
  68. unread?: boolean;
  69. state?: MessageState;
  70. quote?: Quote;
  71. file?: FileInfo;
  72. video?: VideoInfo;
  73. audio?: AudioInfo;
  74. voip?: VoipStatusInfo;
  75. location?: LocationInfo;
  76. // only for temporary Messages
  77. temporaryId?: string;
  78. errorMessage?: string;
  79. }
  80. interface FileInfo {
  81. description: string;
  82. name: string;
  83. size: number;
  84. type: string;
  85. inApp: boolean;
  86. }
  87. interface VideoInfo {
  88. duration: number;
  89. size: number;
  90. }
  91. interface AudioInfo {
  92. duration: number;
  93. }
  94. interface VoipStatusInfo {
  95. status: number;
  96. }
  97. interface LocationInfo {
  98. lat: number;
  99. lon: number;
  100. accuracy: number;
  101. address: string;
  102. poi: string;
  103. }
  104. /**
  105. * All possible receiver types.
  106. */
  107. type ReceiverType = 'me' | 'contact' | 'group' | 'distributionList';
  108. /**
  109. * Access Object for receivers
  110. */
  111. interface ReceiverAccess {
  112. canDelete?: boolean;
  113. }
  114. interface ContactReceiverAccess extends ReceiverAccess {
  115. canChangeAvatar: boolean;
  116. canChangeFirstName: boolean;
  117. canChangeLastName: boolean;
  118. }
  119. interface GroupReceiverAccess extends ReceiverAccess {
  120. canChangeAvatar: boolean;
  121. canChangeName: boolean;
  122. canChangeMembers?: boolean;
  123. canLeave?: boolean;
  124. canSync?: boolean;
  125. }
  126. interface DistributionListReceiverAccess extends ReceiverAccess {
  127. canChangeMembers?: boolean;
  128. }
  129. const enum IdentityType {
  130. Regular = 0,
  131. Work
  132. }
  133. /**
  134. * The base class for a receiver. Only type and id.
  135. */
  136. interface BaseReceiver {
  137. id: string;
  138. type: ReceiverType;
  139. }
  140. /**
  141. * A generic receiver.
  142. *
  143. * Note that the id is not unique for all receivers, only for all receivers
  144. * of a certain type. The primary key for a receiver is the tuple (type, id).
  145. */
  146. interface Receiver extends BaseReceiver {
  147. // The display name
  148. displayName: string;
  149. // The color used for the avatar
  150. color: string;
  151. // The avatar, may be set if already fetched
  152. avatar?: Avatar;
  153. // Permissions towards this receiver
  154. access: ReceiverAccess;
  155. // Whether the chat with this receiver is locked.
  156. locked?: boolean;
  157. // Whether the chat with this receiver is visible.
  158. visible?: boolean;
  159. }
  160. /**
  161. * A contact.
  162. */
  163. interface ContactReceiver extends Receiver {
  164. // Flag indicating whether this is the own profile or another contact
  165. type: 'contact' | 'me';
  166. // Public nickname, if set
  167. publicNickname?: string;
  168. // First name, if set
  169. firstName?: string;
  170. // Last name, if set
  171. lastName?: string;
  172. // Verification level integer (1-3)
  173. verificationLevel?: number;
  174. // Feature level (0-3)
  175. featureLevel: number | null;
  176. // The identity state
  177. state: 'ACTIVE' | 'INACTIVE';
  178. // The Threema public key
  179. publicKey: ArrayBuffer;
  180. // System confact information
  181. systemContact?: SystemContact;
  182. // Permissions towards this contact
  183. access: ContactReceiverAccess;
  184. // Whether this is a contact from the same Threema Work package.
  185. // Only relevant for Threema Work users.
  186. isWork?: boolean;
  187. // Whether this contact is blocked
  188. isBlocked?: boolean;
  189. // The identity type.
  190. // 0 - Regular Threema user.
  191. // 1 - Threema Work user.
  192. identityType?: IdentityType;
  193. }
  194. /**
  195. * Own contact.
  196. */
  197. interface MeReceiver extends ContactReceiver {
  198. type: 'me';
  199. }
  200. /**
  201. * A group.
  202. */
  203. interface GroupReceiver extends Receiver {
  204. type: 'group';
  205. disabled: boolean;
  206. members: string[];
  207. administrator: string;
  208. access: GroupReceiverAccess;
  209. createdAt?: string;
  210. }
  211. /**
  212. * A distribution list.
  213. */
  214. interface DistributionListReceiver extends Receiver {
  215. type: 'distributionList';
  216. members: string[];
  217. access: DistributionListReceiverAccess;
  218. }
  219. interface SystemContact {
  220. emails?: SystemContactEmail[];
  221. phoneNumbers?: SystemContactPhone[];
  222. }
  223. interface SystemContactEmail {
  224. label: string;
  225. address: string;
  226. }
  227. interface SystemContactPhone {
  228. label: string;
  229. number: string;
  230. }
  231. /**
  232. * A conversation.
  233. */
  234. interface Conversation {
  235. type: ReceiverType;
  236. id: string;
  237. position: number;
  238. messageCount: number;
  239. unreadCount: number;
  240. latestMessage: Message;
  241. receiver?: Receiver;
  242. avatar?: ArrayBuffer;
  243. isMuted?: boolean;
  244. isStarred?: boolean;
  245. }
  246. /**
  247. * Connection state in the welcome dialog.
  248. *
  249. * States:
  250. *
  251. * - new: Initial state
  252. * - connecting: Connecting to signaling server
  253. * - push: When trying to reconnect, waiting for push notification to arrive
  254. * - manual_start: When trying to reconnect, waiting for manual session start
  255. * - already_connected: When the user is already connected in another tab or window
  256. * - waiting: Waiting for new-responder message from signaling server
  257. * - peer_handshake: Doing SaltyRTC handshake with the peer
  258. * - loading: Loading initial data
  259. * - done: Initial loading is finished
  260. * - closed: Connection is closed
  261. *
  262. */
  263. type ConnectionBuildupState = 'new' | 'connecting' | 'push' | 'manual_start' | 'already_connected'
  264. | 'waiting' | 'peer_handshake' | 'loading' | 'done' | 'closed';
  265. interface ConnectionBuildupStateChange {
  266. state: ConnectionBuildupState;
  267. prevState: ConnectionBuildupState;
  268. }
  269. /**
  270. * Connection state of the WebRTC peer connection.
  271. */
  272. type RTCConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected';
  273. /**
  274. * Connection state of the WebRTC peer connection.
  275. */
  276. type GlobalConnectionState = 'ok' | 'warning' | 'error';
  277. /**
  278. * Type of message to be sent to a receiver.
  279. */
  280. type MessageContentType = 'text' | 'file';
  281. interface MessageData {
  282. // optional quote object
  283. quote?: Quote;
  284. }
  285. /**
  286. * Payload for a file message.
  287. */
  288. interface FileMessageData extends MessageData {
  289. // File name
  290. name: string;
  291. // File MIME type
  292. fileType: string;
  293. // Size in bytes
  294. size: number;
  295. // File bytes
  296. data: ArrayBuffer;
  297. // Caption string
  298. caption?: String;
  299. // Send as file message
  300. sendAsFile?: boolean;
  301. }
  302. /**
  303. * Payload for a text message.
  304. */
  305. interface TextMessageData extends MessageData {
  306. // Text to be sent
  307. text: string;
  308. }
  309. /**
  310. * The $stateParams format used for the welcome controller.
  311. */
  312. interface WelcomeStateParams extends ng.ui.IStateParamsService {
  313. initParams: null | {keyStore: saltyrtc.KeyStore, peerTrustedKey: Uint8Array};
  314. }
  315. interface CreateReceiverStateParams extends ng.ui.IStateParamsService {
  316. type: ReceiverType;
  317. initParams: null | {identity: string | null};
  318. }
  319. interface ConversationStateParams extends ng.ui.IStateParamsService {
  320. type: ReceiverType;
  321. id: string;
  322. initParams: null | {text: string | null};
  323. }
  324. interface Quote {
  325. identity: string;
  326. text: string;
  327. }
  328. interface Identity {
  329. identity: string;
  330. publicNickname: String;
  331. publicKey: ArrayBuffer;
  332. fingerprint: string;
  333. }
  334. interface TrustedKeyStoreData {
  335. ownPublicKey: Uint8Array;
  336. ownSecretKey: Uint8Array;
  337. peerPublicKey: Uint8Array;
  338. pushToken: string | null;
  339. }
  340. interface BrowserInfo {
  341. chrome: boolean;
  342. firefox: boolean;
  343. msie: boolean;
  344. opera: boolean;
  345. safari: boolean;
  346. version: string;
  347. textInfo: string;
  348. }
  349. interface PromiseCallbacks {
  350. resolve: (arg: any) => void;
  351. reject: (arg: any) => void;
  352. }
  353. interface PromiseRequestResult<T> {
  354. success: boolean;
  355. message?: string;
  356. data?: T;
  357. }
  358. interface ControllerModel {
  359. subject: string;
  360. isLoading: boolean;
  361. save(): any;
  362. clean(ev: any): any;
  363. isValid(): boolean;
  364. canView(): boolean;
  365. canEdit(): boolean;
  366. canClean(): boolean;
  367. getMode(): number;
  368. setOnRemoved(callback: any): void;
  369. onChangeMembers(identities: string[]): void;
  370. getMembers(): string[];
  371. }
  372. interface Alert {
  373. source: string;
  374. type: string;
  375. message: string;
  376. }
  377. interface ReceiverListener {
  378. onRemoved(receiver: Receiver);
  379. }
  380. interface Config {
  381. SELF_HOSTED: boolean;
  382. PREV_PROTOCOL_LAST_VERSION: string | null;
  383. SALTYRTC_PORT: number;
  384. SALTYRTC_SERVER_KEY: string | null;
  385. SALTYRTC_HOST: string | null;
  386. SALTYRTC_HOST_PREFIX: string | null;
  387. SALTYRTC_HOST_SUFFIX: string | null;
  388. ICE_SERVERS: RTCIceServer[];
  389. PUSH_URL: string;
  390. MSG_DEBUGGING: boolean;
  391. ICE_DEBUGGING: boolean;
  392. }
  393. interface InitialConversationData {
  394. draft: string;
  395. initialText: string;
  396. }
  397. interface BrowserMinVersions {
  398. FF: number;
  399. CHROME: number;
  400. OPERA: number;
  401. }
  402. interface BatteryStatus {
  403. percent: number;
  404. isCharging: boolean;
  405. }
  406. interface MyAccount {
  407. identity: string;
  408. publicKey: ArrayBuffer;
  409. publicNickname: string;
  410. fingerprint?: string;
  411. }
  412. interface ClientInfo {
  413. device: string;
  414. isWork: boolean;
  415. myPushToken?: string;
  416. maxGroupSize?: number;
  417. myAccount: MyAccount;
  418. }
  419. interface Mention {
  420. identity: string;
  421. query: string;
  422. isAll: boolean;
  423. }
  424. namespace Container {
  425. interface ReceiverData {
  426. me: MeReceiver;
  427. contacts: ContactReceiver[];
  428. groups: GroupReceiver[];
  429. distributionLists: DistributionListReceiver[];
  430. }
  431. interface Converter {
  432. unicodeToEmoji(message);
  433. addReceiverToConversation(receivers: Receivers);
  434. }
  435. interface Filters {
  436. hasData(receivers);
  437. hasContact(contacts);
  438. isValidMessage(contacts);
  439. }
  440. interface Receivers {
  441. me: MeReceiver;
  442. contacts: Map<string, ContactReceiver>;
  443. groups: Map<string, GroupReceiver>;
  444. distributionLists: Map<string, DistributionListReceiver>;
  445. get(receiverType: ReceiverType): Receiver | Map<string, Receiver>;
  446. getData(receiver: BaseReceiver): Receiver | null;
  447. set(data: ReceiverData): void;
  448. setMe(data: MeReceiver): void;
  449. setContacts(data: ContactReceiver[]): void;
  450. setGroups(data: GroupReceiver[]): void;
  451. setDistributionLists(data: DistributionListReceiver[]): void;
  452. extend(receiverType: ReceiverType, data: Receiver): Receiver;
  453. extendDistributionList(data: DistributionListReceiver): DistributionListReceiver;
  454. extendGroup(data: GroupReceiver): GroupReceiver;
  455. extendMe(data: MeReceiver): MeReceiver;
  456. extendContact(data: ContactReceiver): ContactReceiver;
  457. }
  458. interface Conversations {
  459. get(): Conversation[];
  460. set(data: Conversation[]): void;
  461. find(pattern: Conversation | Receiver): Conversation | null;
  462. add(conversation: Conversation): void;
  463. updateOrAdd(conversation: Conversation): void;
  464. remove(conversation: Conversation): void;
  465. setFilter(filter: (data: Conversation[]) => Conversation[]): void;
  466. setConverter(converter: (data: Conversation) => Conversation): void;
  467. }
  468. interface Messages {
  469. converter: (data: Message) => Message;
  470. getList(receiver: Receiver): Message[];
  471. clear($scope: ng.IScope): void;
  472. clearReceiverMessages(receiver: Receiver): Number;
  473. contains(receiver: Receiver): boolean;
  474. hasMore(receiver: Receiver): boolean;
  475. setMore(receiver: Receiver, more: boolean): void;
  476. getReferenceMsgId(receiver: Receiver): number;
  477. isRequested(receiver: Receiver): boolean;
  478. setRequested(receiver: Receiver): void;
  479. clearRequested(receiver): void;
  480. addNewer(receiver: Receiver, messages: Message[]): void;
  481. addOlder(receiver: Receiver, messages: Message[]): void;
  482. update(receiver: Receiver, message: Message): boolean;
  483. setThumbnail(receiver: Receiver, messageId: number, thumbnailImage: string): boolean;
  484. remove(receiver: Receiver, messageId: number): boolean;
  485. removeTemporary(receiver: Receiver, temporaryMessageId: string): boolean;
  486. bindTemporaryToMessageId(receiver: Receiver, temporaryId: string, messageId: number): boolean;
  487. notify(receiver: Receiver, $scope: ng.IScope): void;
  488. register(receiver: Receiver, $scope: ng.IScope, callback: any): Message[];
  489. updateFirstUnreadMessage(receiver: Receiver);
  490. }
  491. interface Typing {
  492. setTyping(receiver: ContactReceiver): void;
  493. unsetTyping(receiver: ContactReceiver): void;
  494. isTyping(receiver: ContactReceiver): boolean;
  495. }
  496. interface Drafts {
  497. setQuote(receiver: Receiver, quote: Quote): void;
  498. removeQuote(receiver: Receiver): void;
  499. getQuote(receiver: Receiver): Quote;
  500. setText(receiver: Receiver, draftMessage: string): void;
  501. removeText(receiver: Receiver): void;
  502. getText(receiver: Receiver): string;
  503. }
  504. interface Factory {
  505. Converter: Container.Converter;
  506. Filters: Container.Filters;
  507. createReceivers: () => Receivers;
  508. createConversations: () => Conversations;
  509. createMessages: () => Messages;
  510. createTyping: () => Typing;
  511. createDrafts: () => Drafts;
  512. }
  513. }
  514. }