threema.d.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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. type LogType = 'debug' | 'trace' | 'info' | 'warn' | 'error';
  20. type LogLevel = 'none' | 'debug' | 'info' | 'warn' | 'error';
  21. type LogRecord = [number, LogType, any?, ...any[]];
  22. /**
  23. * An object can be marked as confidential in which case it needs to
  24. * implement the censor method. This mixin is being used for sanitising log
  25. * records when using the report tool.
  26. */
  27. interface Confidential<U, C> {
  28. uncensored: U;
  29. censored(): C;
  30. }
  31. interface Avatar {
  32. // Low resolution avatar URI
  33. low?: ArrayBuffer;
  34. // High resolution avatar URI
  35. high?: ArrayBuffer;
  36. }
  37. interface WireMessageAcknowledgement {
  38. id: string;
  39. success: boolean;
  40. error?: string;
  41. }
  42. /**
  43. * Messages that are sent through the secure data channel as encrypted msgpack bytes.
  44. */
  45. interface WireMessage {
  46. type: string;
  47. subType: string;
  48. id?: string;
  49. ack?: WireMessageAcknowledgement;
  50. args?: any;
  51. data?: any;
  52. }
  53. type MessageType = 'text' | 'image' | 'video' | 'audio' | 'location' | 'contact' |
  54. 'status' | 'ballot' | 'file' | 'voipStatus' | 'unknown';
  55. type MessageState = 'pending' | 'sending' | 'send-failed' | 'sent' | 'delivered' |
  56. 'read' | 'user-ack' | 'user-dec';
  57. const enum InitializationStep {
  58. ClientInfo = 'client info',
  59. Conversations = 'conversations',
  60. Receivers = 'receivers',
  61. Profile = 'profile',
  62. }
  63. interface InitializationStepRoutine {
  64. requiredSteps: InitializationStep[];
  65. callback: any;
  66. }
  67. interface Thumbnail {
  68. img?: ArrayBuffer; // Note: Does not exist in ARP
  69. preview: ArrayBuffer;
  70. previewDataUrl?: string, // Note: Does not exist in ARP
  71. width: number;
  72. height: number;
  73. }
  74. const enum EventType {
  75. Created = 'created',
  76. Sent = 'sent',
  77. Delivered = 'delivered',
  78. Read = 'read',
  79. Acked = 'acked',
  80. Modified = 'modified',
  81. }
  82. /**
  83. * A message event, e.g. when it was delivered, read or modified.
  84. */
  85. interface MessageEvent {
  86. // The event type
  87. type: EventType;
  88. // Unix timestamp in seconds
  89. date: number;
  90. }
  91. /**
  92. * A Threema chat message.
  93. */
  94. interface Message {
  95. type: MessageType;
  96. id: string;
  97. body?: string;
  98. thumbnail?: Thumbnail;
  99. date?: number;
  100. events?: MessageEvent[];
  101. sortKey: number;
  102. partnerId: string;
  103. isOutbox: boolean;
  104. isStatus: boolean;
  105. caption?: string;
  106. statusType?: 'text' | 'firstUnreadMessage';
  107. unread?: boolean;
  108. state?: MessageState;
  109. quote?: Quote;
  110. file?: FileInfo;
  111. video?: VideoInfo;
  112. audio?: AudioInfo;
  113. voip?: VoipStatusInfo;
  114. location?: LocationInfo;
  115. // only for temporary Messages
  116. temporaryId?: string;
  117. errorMessage?: string;
  118. }
  119. interface FileInfo {
  120. name: string;
  121. size: number;
  122. type: string;
  123. inApp: boolean; // See: https://github.com/threema-ch/app-remote-protocol/issues/4
  124. }
  125. interface VideoInfo {
  126. duration: number;
  127. size?: number;
  128. }
  129. interface AudioInfo {
  130. duration: number;
  131. }
  132. const enum VoipStatus {
  133. Missed = 1,
  134. Finished = 2,
  135. Rejected = 3,
  136. Aborted = 4,
  137. }
  138. const enum VoipRejectReason {
  139. Unknown = 0,
  140. Busy = 1,
  141. Timeout = 2,
  142. Rejected = 3,
  143. Disabled = 4,
  144. }
  145. interface VoipStatusInfo {
  146. status: VoipStatus;
  147. duration?: number;
  148. reason?: VoipRejectReason;
  149. }
  150. interface LocationInfo {
  151. lat: number;
  152. lon: number;
  153. accuracy: number;
  154. description: string;
  155. address?: string;
  156. }
  157. interface BlobInfo {
  158. buffer: ArrayBuffer;
  159. mimetype: string;
  160. filename: string;
  161. }
  162. /**
  163. * All possible receiver types.
  164. */
  165. type ReceiverType = 'me' | 'contact' | 'group' | 'distributionList';
  166. /**
  167. * Access Object for receivers
  168. */
  169. interface ReceiverAccess {
  170. canDelete?: boolean;
  171. }
  172. interface ContactReceiverAccess extends ReceiverAccess {
  173. canChangeAvatar: boolean;
  174. canChangeFirstName: boolean;
  175. canChangeLastName: boolean;
  176. }
  177. interface GroupReceiverAccess extends ReceiverAccess {
  178. canChangeAvatar: boolean;
  179. canChangeName: boolean;
  180. canChangeMembers?: boolean;
  181. canLeave?: boolean;
  182. canSync?: boolean;
  183. }
  184. interface DistributionListReceiverAccess extends ReceiverAccess {
  185. canChangeMembers?: boolean;
  186. }
  187. const enum IdentityType {
  188. Regular = 0,
  189. Work = 1,
  190. }
  191. /**
  192. * The base class for a receiver. Only type and id.
  193. */
  194. interface BaseReceiver {
  195. id: string;
  196. type: ReceiverType;
  197. }
  198. /**
  199. * A generic receiver.
  200. *
  201. * Note that the id is not unique for all receivers, only for all receivers
  202. * of a certain type. The primary key for a receiver is the tuple (type, id).
  203. */
  204. interface Receiver extends BaseReceiver {
  205. // The display name
  206. displayName: string;
  207. // The color used for the avatar
  208. color: string;
  209. // The avatar, may be set if already fetched
  210. avatar?: Avatar;
  211. // Permissions towards this receiver
  212. access: ReceiverAccess;
  213. // Whether the chat with this receiver is locked. Used for private chats.
  214. locked: boolean;
  215. // Whether the chat with this receiver is visible. Used for private chats.
  216. visible: boolean;
  217. }
  218. /**
  219. * A contact.
  220. */
  221. interface ContactReceiver extends Receiver {
  222. // Flag indicating whether this is the own profile or another contact
  223. type: 'contact' | 'me';
  224. // Public nickname, if set
  225. publicNickname?: string;
  226. // First name, if set
  227. firstName?: string;
  228. // Last name, if set
  229. lastName?: string;
  230. // Verification level integer (1-3)
  231. verificationLevel?: number;
  232. // Feature mask
  233. featureMask: number;
  234. // The identity state
  235. state: 'ACTIVE' | 'INACTIVE';
  236. // Contact hidden?
  237. hidden: boolean;
  238. // The Threema public key
  239. publicKey: ArrayBuffer;
  240. // System confact information
  241. systemContact?: SystemContact;
  242. // Permissions towards this contact
  243. access: ContactReceiverAccess;
  244. // Whether this is a contact from the same Threema Work package.
  245. // Only relevant for Threema Work users.
  246. isWork?: boolean;
  247. // Whether this contact is blocked
  248. isBlocked?: boolean;
  249. // The identity type.
  250. // 0 - Regular Threema user.
  251. // 1 - Threema Work user.
  252. identityType?: IdentityType;
  253. }
  254. /**
  255. * Own contact.
  256. */
  257. interface MeReceiver extends ContactReceiver {
  258. type: 'me';
  259. }
  260. /**
  261. * A group.
  262. */
  263. interface GroupReceiver extends Receiver {
  264. type: 'group';
  265. disabled: boolean;
  266. members: string[];
  267. administrator: string;
  268. access: GroupReceiverAccess;
  269. createdAt: number;
  270. }
  271. /**
  272. * A distribution list.
  273. */
  274. interface DistributionListReceiver extends Receiver {
  275. type: 'distributionList';
  276. members: string[];
  277. access: DistributionListReceiverAccess;
  278. }
  279. interface SystemContact {
  280. emails?: SystemContactEmail[];
  281. phoneNumbers?: SystemContactPhone[];
  282. }
  283. interface SystemContactEmail {
  284. label: string;
  285. address: string;
  286. }
  287. interface SystemContactPhone {
  288. label: string;
  289. number: string;
  290. }
  291. /**
  292. * A conversation.
  293. */
  294. interface Conversation {
  295. type: ReceiverType;
  296. id: string;
  297. position?: number;
  298. messageCount: number;
  299. unreadCount: number;
  300. latestMessage?: Message;
  301. receiver?: Receiver;
  302. avatar?: ArrayBuffer;
  303. notifications?: NotificationSettings;
  304. isStarred?: boolean;
  305. }
  306. /**
  307. * A conversation with a position field, used for updating a conversation.
  308. */
  309. interface ConversationWithPosition extends Conversation {
  310. position: number;
  311. }
  312. interface NotificationSettings {
  313. sound: NotificationSound;
  314. dnd: NotificationDnd;
  315. }
  316. interface NotificationSound {
  317. mode: NotificationSoundMode;
  318. }
  319. const enum NotificationSoundMode {
  320. Default = 'default',
  321. Muted = 'muted',
  322. }
  323. interface NotificationDnd {
  324. mode: NotificationDndMode;
  325. mentionOnly?: boolean;
  326. until?: number;
  327. }
  328. const enum NotificationDndMode {
  329. Off = 'off',
  330. On = 'on',
  331. Until = 'until',
  332. }
  333. /**
  334. * A form of the notification settings where things like the "until" mode
  335. * have been processed already.
  336. */
  337. interface SimplifiedNotificationSettings {
  338. sound: {
  339. muted: boolean,
  340. };
  341. dnd: {
  342. enabled: boolean,
  343. mentionOnly: boolean,
  344. };
  345. }
  346. /**
  347. * Connection state in the welcome dialog.
  348. *
  349. * States:
  350. *
  351. * - new: Initial state
  352. * - connecting: Connecting to signaling server
  353. * - push: When trying to reconnect, waiting for push notification to arrive
  354. * - manual_start: When trying to reconnect, waiting for manual session start
  355. * - already_connected: When the user is already connected in another tab or window
  356. * - waiting: Waiting for new-responder message from signaling server
  357. * - peer_handshake: Doing SaltyRTC handshake with the peer
  358. * - loading: Loading initial data
  359. * - done: Initial loading is finished
  360. * - closed: Connection is closed
  361. * - reconnect_failed: Reconnecting failed after several attempts
  362. *
  363. */
  364. type ConnectionBuildupState = 'new' | 'connecting' | 'push' | 'manual_start' | 'already_connected'
  365. | 'waiting' | 'peer_handshake' | 'loading' | 'done' | 'closed' | 'reconnect_failed';
  366. interface ConnectionBuildupStateChange {
  367. state: ConnectionBuildupState;
  368. prevState: ConnectionBuildupState;
  369. }
  370. /**
  371. * Connection state of the task peer connection.
  372. */
  373. const enum TaskConnectionState {
  374. New = 'new',
  375. Connecting = 'connecting',
  376. Connected = 'connected',
  377. Reconnecting = 'reconnecting',
  378. Disconnected = 'disconnected',
  379. }
  380. /**
  381. * Connection state of the WebRTC peer connection.
  382. */
  383. const enum GlobalConnectionState {
  384. Ok = 'ok',
  385. Warning = 'warning',
  386. Error = 'error',
  387. }
  388. interface GlobalConnectionStateChange {
  389. state: GlobalConnectionState;
  390. prevState: GlobalConnectionState;
  391. }
  392. /**
  393. * Type of message to be sent to a receiver.
  394. */
  395. type MessageContentType = 'text' | 'file';
  396. interface MessageData {
  397. // optional quote object
  398. quote?: Quote;
  399. }
  400. /**
  401. * Payload for a file message.
  402. */
  403. interface FileMessageData extends MessageData {
  404. // File name
  405. name: string;
  406. // File MIME type
  407. fileType: string;
  408. // Size in bytes
  409. size: number;
  410. // File bytes
  411. data: ArrayBuffer;
  412. // Caption string
  413. caption?: string;
  414. // Send as file message
  415. sendAsFile?: boolean;
  416. }
  417. /**
  418. * Payload for a text message.
  419. */
  420. interface TextMessageData extends MessageData {
  421. // Text to be sent
  422. text: string;
  423. }
  424. interface Quote {
  425. identity: string;
  426. text: string;
  427. }
  428. interface PushSessionConfig {
  429. retryTimeoutInitMs: number;
  430. retryTimeoutMaxMs: number;
  431. triesMax: number;
  432. timeToLiveRange: number[];
  433. }
  434. const enum PushTokenType {
  435. Gcm = 'gcm',
  436. Apns = 'apns',
  437. }
  438. const enum PushTokenPrefix {
  439. Gcm = 'g',
  440. Apns = 'a',
  441. }
  442. interface TrustedKeyStoreData {
  443. ownPublicKey: Uint8Array;
  444. ownSecretKey: Uint8Array;
  445. peerPublicKey: Uint8Array;
  446. pushToken: string | null;
  447. pushTokenType: PushTokenType | null;
  448. }
  449. const enum BrowserName {
  450. Chrome = 'chrome',
  451. ChromeIos = 'chromeIos',
  452. Firefox = 'firefox',
  453. FirefoxIos = 'firefoxIos',
  454. InternetExplorer = 'ie',
  455. Edge = 'edge',
  456. Opera = 'opera',
  457. Safari = 'safari',
  458. }
  459. interface PromiseRequestResult<T> {
  460. success: boolean;
  461. error?: string;
  462. data?: T;
  463. }
  464. type OnRemovedCallback = (identity: string) => void;
  465. const enum ControllerModelMode {
  466. NEW = 'new',
  467. VIEW = 'view',
  468. EDIT = 'edit',
  469. CHAT = 'chat',
  470. }
  471. const enum ContactReceiverFeature {
  472. NONE = 0x00,
  473. AUDIO = 0x01,
  474. GROUP_CHAT = 0x02,
  475. BALLOT = 0x04,
  476. FILE = 0x08,
  477. VOIP = 0x10,
  478. }
  479. interface ControllerModel<T extends BaseReceiver> {
  480. /**
  481. * The receiver type that is handled by this controller model.
  482. */
  483. receiverType: threema.ReceiverType;
  484. /**
  485. * The title shown in the header.
  486. */
  487. subject: string;
  488. /**
  489. * Loading state.
  490. */
  491. isLoading: boolean;
  492. /**
  493. * Save the changes, return a promise with the receiver.
  494. */
  495. save(): Promise<T>;
  496. /**
  497. * Delete all messages in this conversation.
  498. */
  499. clean(ev: any): any;
  500. /**
  501. * Validate this receiver.
  502. */
  503. isValid(): boolean;
  504. /*
  505. * Return whether this receiver can be chatted with.
  506. */
  507. canChat(): boolean;
  508. /**
  509. * Can this receiver be edited?
  510. */
  511. canEdit(): boolean;
  512. /**
  513. * Can this receiver be cleaned?
  514. */
  515. canClean(): boolean;
  516. /*
  517. * Return whether this receiver can show a QR code of the public key.
  518. */
  519. canShowQr(): boolean;
  520. /**
  521. * The editing mode, e.g. view or edit this receiver.
  522. */
  523. getMode(): ControllerModelMode;
  524. /**
  525. * Set the on removed callback.
  526. */
  527. setOnRemoved(callback: OnRemovedCallback): void;
  528. }
  529. interface ControllerModelWithMembers {
  530. /**
  531. * A required feature flag that all members must have.
  532. */
  533. requiredMemberFeatureMask: threema.ContactReceiverFeature;
  534. /**
  535. * Callback called when the members change.
  536. */
  537. onChangeMembers(identities: string[]): void;
  538. /**
  539. * Return the members of this receiver.
  540. */
  541. getMembers(): string[];
  542. }
  543. interface Alert {
  544. source: string;
  545. type: string;
  546. message: string;
  547. }
  548. interface ReceiverListener {
  549. onConversationRemoved(receiver: Receiver);
  550. }
  551. interface Config {
  552. // Version
  553. VERSION: string;
  554. // General
  555. SELF_HOSTED: boolean;
  556. VERSION_MOUNTAIN: string;
  557. VERSION_MOUNTAIN_URL: string;
  558. VERSION_MOUNTAIN_IMAGE_URL: string;
  559. VERSION_MOUNTAIN_IMAGE_COPYRIGHT: string;
  560. VERSION_MOUNTAIN_HEIGHT: number;
  561. PREV_PROTOCOL_LAST_VERSION: string | null;
  562. GIT_BRANCH: string;
  563. // SaltyRTC
  564. SALTYRTC_HOST: string | null;
  565. SALTYRTC_HOST_PREFIX: string | null;
  566. SALTYRTC_HOST_SUFFIX: string | null;
  567. SALTYRTC_PORT: number;
  568. SALTYRTC_SERVER_KEY: string | null;
  569. // ICE
  570. ICE_SERVERS: RTCIceServer[];
  571. // Push
  572. PUSH_URL: string;
  573. // Logging/debugging
  574. LOG_TAG_PADDING: number,
  575. CONSOLE_LOG_LEVEL: LogLevel;
  576. REPORT_LOG_LEVEL: LogLevel;
  577. REPORT_LOG_LIMIT: number;
  578. COMPOSE_AREA_LOG_LEVEL: LogLevel;
  579. SALTYRTC_LOG_LEVEL: saltyrtc.LogLevel;
  580. TIMER_LOG_LEVEL: LogLevel;
  581. ARP_LOG_LEVEL: LogLevel;
  582. ARP_LOG_TRACE: boolean;
  583. MSGPACK_LOG_TRACE: boolean;
  584. }
  585. interface InitialConversationData {
  586. draft: string;
  587. initialText: string;
  588. }
  589. interface BrowserMinVersions {
  590. FF: number;
  591. CHROME: number;
  592. OPERA: number;
  593. SAFARI: number;
  594. }
  595. interface BatteryStatus {
  596. percent: number | null;
  597. isCharging: boolean;
  598. }
  599. const enum OperatingSystem {
  600. Android = 'android',
  601. Ios = 'ios',
  602. }
  603. interface ClientInfo {
  604. // The device name
  605. device: string;
  606. // The operating system
  607. os: OperatingSystem;
  608. // The operating system version (e.g. "5.1")
  609. osVersion: string;
  610. // Whether the app is the *work* variant of Threema
  611. isWork: boolean;
  612. // The GCM / APNS push token
  613. pushToken?: string;
  614. // The device configuration
  615. configuration: AppConfig;
  616. // The device capabilities
  617. capabilities: AppCapabilities;
  618. }
  619. interface AppConfig {
  620. voipEnabled: boolean;
  621. voipForceTurn: boolean;
  622. largeSingleEmoji: boolean;
  623. showInactiveIDs: boolean;
  624. }
  625. interface AppCapabilities {
  626. maxGroupSize: number;
  627. maxFileSize: number;
  628. distributionLists: boolean;
  629. imageFormat: ImageFormat;
  630. mdm?: MdmRestrictions;
  631. }
  632. /**
  633. * MIME types for the images exchanged between app and browser.
  634. */
  635. interface ImageFormat {
  636. avatar: string;
  637. thumbnail: string;
  638. }
  639. interface MdmRestrictions {
  640. disableAddContact?: boolean;
  641. disableCreateGroup?: boolean;
  642. disableSaveToGallery?: boolean;
  643. disableExport?: boolean;
  644. disableMessagePreview?: boolean;
  645. disableCalls?: boolean;
  646. readonlyProfile?: boolean;
  647. }
  648. interface ProfileUpdate {
  649. publicNickname?: string;
  650. avatar?: ArrayBuffer;
  651. }
  652. interface Profile extends ProfileUpdate {
  653. identity: string;
  654. publicKey: ArrayBuffer;
  655. }
  656. interface Mention {
  657. identity: string;
  658. query: string;
  659. isAll: boolean;
  660. }
  661. interface WebClientServiceStopArguments {
  662. reason: DisconnectReason;
  663. send: boolean;
  664. close: boolean | string;
  665. connectionBuildupState?: ConnectionBuildupState;
  666. }
  667. const enum ChosenTask {
  668. None = 'none',
  669. WebRTC = 'webrtc',
  670. RelayedData = 'relayed-data',
  671. }
  672. const enum DisconnectReason {
  673. SessionStopped = 'stop',
  674. SessionDeleted = 'delete',
  675. WebclientDisabled = 'disable',
  676. SessionReplaced = 'replace',
  677. SessionError = 'error',
  678. }
  679. interface EmojiInfo {
  680. // The plain emoji string
  681. emojiString: string;
  682. // The image path, e.g. emoji/png32/1f9df-200d-2640-fe0f.png
  683. imgPath: string;
  684. // The codepoint string, e.g. 1f9df-200d-2640-fe0f
  685. codepoint: string;
  686. }
  687. namespace Container {
  688. interface ReceiverData {
  689. contacts: ContactReceiver[];
  690. groups: GroupReceiver[];
  691. distributionLists: DistributionListReceiver[];
  692. }
  693. interface Converter {
  694. addReceiverToConversation(receivers: Receivers);
  695. }
  696. interface Filters {
  697. hasData(receivers);
  698. hasContact(contacts);
  699. isValidMessage(contacts);
  700. }
  701. interface Receivers {
  702. me: MeReceiver;
  703. contacts: Map<string, ContactReceiver>;
  704. groups: Map<string, GroupReceiver>;
  705. distributionLists: Map<string, DistributionListReceiver>;
  706. get(receiverType: ReceiverType): Receiver | Map<string, Receiver>;
  707. getData(receiver: BaseReceiver): Receiver | null;
  708. set(data: ReceiverData): void;
  709. setMe(data: MeReceiver): void;
  710. setContacts(data: ContactReceiver[]): void;
  711. setGroups(data: GroupReceiver[]): void;
  712. setDistributionLists(data: DistributionListReceiver[]): void;
  713. extend(receiverType: ReceiverType, data: Receiver): Receiver;
  714. extendDistributionList(data: DistributionListReceiver): DistributionListReceiver;
  715. extendGroup(data: GroupReceiver): GroupReceiver;
  716. extendMe(data: MeReceiver): MeReceiver;
  717. extendContact(data: ContactReceiver): ContactReceiver;
  718. }
  719. interface Conversations {
  720. get(): Conversation[];
  721. set(data: Conversation[]): void;
  722. find(pattern: Conversation | Receiver): Conversation | null;
  723. add(conversation: Conversation): void;
  724. updateOrAdd(conversation: Conversation, returnOld?: boolean): Conversation | null;
  725. remove(conversation: Conversation): void;
  726. setFilter(filter: (data: Conversation[]) => Conversation[]): void;
  727. setConverter(converter: (data: Conversation) => Conversation): void;
  728. }
  729. interface Messages {
  730. converter: (data: Message) => Message;
  731. getList(receiver: BaseReceiver): Message[];
  732. clear($scope: ng.IScope): void;
  733. clearReceiverMessages(receiver: BaseReceiver): number;
  734. contains(receiver: BaseReceiver): boolean;
  735. hasMore(receiver: BaseReceiver): boolean;
  736. setMore(receiver: BaseReceiver, more: boolean): void;
  737. getReferenceMsgId(receiver: BaseReceiver): string;
  738. isRequested(receiver: BaseReceiver): boolean;
  739. setRequested(receiver: BaseReceiver): void;
  740. clearRequested(receiver: BaseReceiver): void;
  741. addNewer(receiver: BaseReceiver, messages: Message[]): void;
  742. addOlder(receiver: BaseReceiver, messages: Message[]): void;
  743. addStatusMessage(receiver: BaseReceiver, text: string): void;
  744. update(receiver: BaseReceiver, message: Message): boolean;
  745. setThumbnail(receiver: BaseReceiver, messageId: string, thumbnailImage: ArrayBuffer): boolean;
  746. remove(receiver: BaseReceiver, messageId: string): boolean;
  747. removeTemporary(receiver: BaseReceiver, temporaryMessageId: string): boolean;
  748. bindTemporaryToMessageId(receiver: BaseReceiver, temporaryId: string, messageId: string): Message | null;
  749. notify(receiver: BaseReceiver, $scope: ng.IScope): void;
  750. register(receiver: BaseReceiver, $scope: ng.IScope, callback: any): Message[];
  751. updateFirstUnreadMessage(receiver: BaseReceiver);
  752. }
  753. interface Typing {
  754. setTyping(receiver: BaseReceiver): void;
  755. unsetTyping(receiver: BaseReceiver): void;
  756. clearAll(): void;
  757. isTyping(receiver: BaseReceiver): boolean;
  758. }
  759. interface Drafts {
  760. setQuote(receiver: Receiver, quote: Quote): void;
  761. removeQuote(receiver: Receiver): void;
  762. getQuote(receiver: Receiver): Quote;
  763. setText(receiver: Receiver, draftMessage: string): void;
  764. removeText(receiver: Receiver): void;
  765. getText(receiver: Receiver): string;
  766. }
  767. interface Factory {
  768. Converter: Container.Converter;
  769. Filters: Container.Filters;
  770. createReceivers: () => Receivers;
  771. createConversations: () => Conversations;
  772. createMessages: () => Messages;
  773. createTyping: () => Typing;
  774. createDrafts: () => Drafts;
  775. }
  776. }
  777. }