controller_model.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. import {ContactControllerModel} from '../controller_model/contact';
  18. import {DistributionListControllerModel} from '../controller_model/distributionList';
  19. import {GroupControllerModel} from '../controller_model/group';
  20. import {MeControllerModel} from '../controller_model/me';
  21. import {WebClientService} from './webclient';
  22. // Type aliases
  23. import ControllerModelMode = threema.ControllerModelMode;
  24. /**
  25. * Factory to create ControllerModels
  26. */
  27. export class ControllerModelService {
  28. private $log: ng.ILogService;
  29. private $translate: ng.translate.ITranslateService;
  30. private $mdDialog: ng.material.IDialogService;
  31. private webClientService: WebClientService;
  32. public static $inject = ['$log', '$translate', '$mdDialog', 'WebClientService'];
  33. constructor($log: ng.ILogService, $translate: ng.translate.ITranslateService,
  34. $mdDialog: ng.material.IDialogService, webClientService: WebClientService) {
  35. this.$log = $log;
  36. this.$translate = $translate;
  37. this.$mdDialog = $mdDialog;
  38. this.webClientService = webClientService;
  39. }
  40. public me(
  41. receiver: threema.MeReceiver,
  42. mode: ControllerModelMode,
  43. ): threema.ControllerModel<threema.MeReceiver> {
  44. return new MeControllerModel(
  45. this.$log,
  46. this.$translate,
  47. this.$mdDialog,
  48. this.webClientService,
  49. mode,
  50. receiver,
  51. );
  52. }
  53. public contact(
  54. receiver: threema.ContactReceiver,
  55. mode: ControllerModelMode,
  56. ): threema.ControllerModel<threema.ContactReceiver> {
  57. return new ContactControllerModel(
  58. this.$log,
  59. this.$translate,
  60. this.$mdDialog,
  61. this.webClientService,
  62. mode,
  63. receiver,
  64. );
  65. }
  66. public group(
  67. receiver: threema.GroupReceiver,
  68. mode: ControllerModelMode,
  69. ): threema.ControllerModel<threema.GroupReceiver> {
  70. return new GroupControllerModel(
  71. this.$log,
  72. this.$translate,
  73. this.$mdDialog,
  74. this.webClientService,
  75. mode,
  76. receiver,
  77. );
  78. }
  79. public distributionList(
  80. receiver: threema.DistributionListReceiver,
  81. mode: ControllerModelMode,
  82. ): threema.ControllerModel<threema.DistributionListReceiver> {
  83. return new DistributionListControllerModel(
  84. this.$log,
  85. this.$translate,
  86. this.$mdDialog,
  87. this.webClientService,
  88. mode,
  89. receiver,
  90. );
  91. }
  92. }