@wireapp/core 17.29.0 → 17.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/package.json +8 -8
  3. package/src/main/conversation/ConversationMapper.js +2 -0
  4. package/src/main/conversation/ConversationService.d.ts +5 -2
  5. package/src/main/conversation/ConversationService.js +0 -2
  6. package/src/main/conversation/message/PayloadBundle.d.ts +3 -0
  7. package/src/main/cryptography/GenericMessageMapper.d.ts +0 -1
  8. package/src/main/cryptography/GenericMessageMapper.js +23 -158
  9. package/src/main/Account.js.map +0 -1
  10. package/src/main/Account.test.browser.js +0 -114
  11. package/src/main/Account.test.node.d.ts +0 -1
  12. package/src/main/Account.test.node.js +0 -214
  13. package/src/main/Account.test.node.js.map +0 -1
  14. package/src/main/Account.test.node.ts +0 -236
  15. package/src/main/Account.ts +0 -401
  16. package/src/main/CoreError.js.map +0 -1
  17. package/src/main/CoreError.ts +0 -30
  18. package/src/main/auth/LoginSanitizer.js.map +0 -1
  19. package/src/main/auth/LoginSanitizer.test.node.d.ts +0 -1
  20. package/src/main/auth/LoginSanitizer.test.node.js +0 -56
  21. package/src/main/auth/LoginSanitizer.test.node.js.map +0 -1
  22. package/src/main/auth/LoginSanitizer.test.node.ts +0 -68
  23. package/src/main/auth/LoginSanitizer.ts +0 -44
  24. package/src/main/auth/index.js.map +0 -1
  25. package/src/main/auth/index.ts +0 -20
  26. package/src/main/broadcast/AvailabilityType.js.map +0 -1
  27. package/src/main/broadcast/AvailabilityType.ts +0 -22
  28. package/src/main/broadcast/BroadcastService.js.map +0 -1
  29. package/src/main/broadcast/BroadcastService.ts +0 -66
  30. package/src/main/broadcast/index.js.map +0 -1
  31. package/src/main/broadcast/index.ts +0 -21
  32. package/src/main/client/ClientBackendRepository.js.map +0 -1
  33. package/src/main/client/ClientBackendRepository.ts +0 -33
  34. package/src/main/client/ClientDatabaseRepository.js.map +0 -1
  35. package/src/main/client/ClientDatabaseRepository.ts +0 -130
  36. package/src/main/client/ClientInfo.js.map +0 -1
  37. package/src/main/client/ClientInfo.ts +0 -28
  38. package/src/main/client/ClientService.js.map +0 -1
  39. package/src/main/client/ClientService.ts +0 -116
  40. package/src/main/client/index.js.map +0 -1
  41. package/src/main/client/index.ts +0 -23
  42. package/src/main/connection/ConnectionService.js.map +0 -1
  43. package/src/main/connection/ConnectionService.ts +0 -49
  44. package/src/main/connection/index.js.map +0 -1
  45. package/src/main/connection/index.ts +0 -20
  46. package/src/main/conversation/AbortReason.js.map +0 -1
  47. package/src/main/conversation/AbortReason.ts +0 -22
  48. package/src/main/conversation/AssetService.js.map +0 -1
  49. package/src/main/conversation/AssetService.test.node.d.ts +0 -1
  50. package/src/main/conversation/AssetService.test.node.js +0 -61
  51. package/src/main/conversation/AssetService.test.node.js.map +0 -1
  52. package/src/main/conversation/AssetService.test.node.ts +0 -65
  53. package/src/main/conversation/AssetService.ts +0 -60
  54. package/src/main/conversation/AssetTransferState.js.map +0 -1
  55. package/src/main/conversation/AssetTransferState.ts +0 -23
  56. package/src/main/conversation/ClientActionType.js.map +0 -1
  57. package/src/main/conversation/ClientActionType.ts +0 -20
  58. package/src/main/conversation/ConversationMapper.js.map +0 -1
  59. package/src/main/conversation/ConversationMapper.test.node.d.ts +0 -1
  60. package/src/main/conversation/ConversationMapper.test.node.js +0 -111
  61. package/src/main/conversation/ConversationMapper.test.node.js.map +0 -1
  62. package/src/main/conversation/ConversationMapper.test.node.ts +0 -154
  63. package/src/main/conversation/ConversationMapper.ts +0 -54
  64. package/src/main/conversation/ConversationService.js.map +0 -1
  65. package/src/main/conversation/ConversationService.test.node.d.ts +0 -1
  66. package/src/main/conversation/ConversationService.test.node.js +0 -344
  67. package/src/main/conversation/ConversationService.test.node.js.map +0 -1
  68. package/src/main/conversation/ConversationService.test.node.ts +0 -416
  69. package/src/main/conversation/ConversationService.ts +0 -1020
  70. package/src/main/conversation/GenericMessageType.js.map +0 -1
  71. package/src/main/conversation/GenericMessageType.ts +0 -44
  72. package/src/main/conversation/MessageTimer.js.map +0 -1
  73. package/src/main/conversation/MessageTimer.test.node.d.ts +0 -1
  74. package/src/main/conversation/MessageTimer.test.node.js +0 -88
  75. package/src/main/conversation/MessageTimer.test.node.js.map +0 -1
  76. package/src/main/conversation/MessageTimer.test.node.ts +0 -103
  77. package/src/main/conversation/MessageTimer.ts +0 -56
  78. package/src/main/conversation/ReactionType.js.map +0 -1
  79. package/src/main/conversation/ReactionType.ts +0 -23
  80. package/src/main/conversation/content/AssetContent.js.map +0 -1
  81. package/src/main/conversation/content/AssetContent.ts +0 -71
  82. package/src/main/conversation/content/ButtonActionConfirmationContent.js.map +0 -1
  83. package/src/main/conversation/content/ButtonActionConfirmationContent.ts +0 -21
  84. package/src/main/conversation/content/ButtonActionContent.js.map +0 -1
  85. package/src/main/conversation/content/ButtonActionContent.ts +0 -21
  86. package/src/main/conversation/content/CallingContent.js.map +0 -1
  87. package/src/main/conversation/content/CallingContent.ts +0 -20
  88. package/src/main/conversation/content/ClearedContent.js.map +0 -1
  89. package/src/main/conversation/content/ClearedContent.ts +0 -21
  90. package/src/main/conversation/content/ClientActionContent.js.map +0 -1
  91. package/src/main/conversation/content/ClientActionContent.ts +0 -22
  92. package/src/main/conversation/content/ClientAddContent.js.map +0 -1
  93. package/src/main/conversation/content/ClientAddContent.ts +0 -24
  94. package/src/main/conversation/content/ClientRemoveContent.js.map +0 -1
  95. package/src/main/conversation/content/ClientRemoveContent.ts +0 -25
  96. package/src/main/conversation/content/CompositeContent.js.map +0 -1
  97. package/src/main/conversation/content/CompositeContent.ts +0 -21
  98. package/src/main/conversation/content/ConfirmationContent.js.map +0 -1
  99. package/src/main/conversation/content/ConfirmationContent.ts +0 -21
  100. package/src/main/conversation/content/ContentType.js.map +0 -1
  101. package/src/main/conversation/content/ContentType.ts +0 -112
  102. package/src/main/conversation/content/ConversationContent.js.map +0 -1
  103. package/src/main/conversation/content/ConversationContent.ts +0 -71
  104. package/src/main/conversation/content/DeletedContent.js.map +0 -1
  105. package/src/main/conversation/content/DeletedContent.ts +0 -21
  106. package/src/main/conversation/content/EditedTextContent.js.map +0 -1
  107. package/src/main/conversation/content/EditedTextContent.ts +0 -31
  108. package/src/main/conversation/content/FileContent.js.map +0 -1
  109. package/src/main/conversation/content/FileContent.ts +0 -32
  110. package/src/main/conversation/content/HiddenContent.js.map +0 -1
  111. package/src/main/conversation/content/HiddenContent.ts +0 -21
  112. package/src/main/conversation/content/ImageContent.js.map +0 -1
  113. package/src/main/conversation/content/ImageContent.ts +0 -25
  114. package/src/main/conversation/content/KnockContent.js.map +0 -1
  115. package/src/main/conversation/content/KnockContent.ts +0 -21
  116. package/src/main/conversation/content/LinkPreviewContent.js.map +0 -1
  117. package/src/main/conversation/content/LinkPreviewContent.ts +0 -32
  118. package/src/main/conversation/content/LocationContent.js.map +0 -1
  119. package/src/main/conversation/content/LocationContent.ts +0 -29
  120. package/src/main/conversation/content/MentionContent.js.map +0 -1
  121. package/src/main/conversation/content/MentionContent.ts +0 -21
  122. package/src/main/conversation/content/QuoteContent.js.map +0 -1
  123. package/src/main/conversation/content/QuoteContent.ts +0 -29
  124. package/src/main/conversation/content/ReactionContent.js.map +0 -1
  125. package/src/main/conversation/content/ReactionContent.ts +0 -27
  126. package/src/main/conversation/content/TextContent.js.map +0 -1
  127. package/src/main/conversation/content/TextContent.ts +0 -29
  128. package/src/main/conversation/content/TweetContent.js.map +0 -1
  129. package/src/main/conversation/content/TweetContent.ts +0 -21
  130. package/src/main/conversation/content/index.js.map +0 -1
  131. package/src/main/conversation/content/index.ts +0 -49
  132. package/src/main/conversation/index.js.map +0 -1
  133. package/src/main/conversation/index.ts +0 -28
  134. package/src/main/conversation/message/CompositeContentBuilder.js.map +0 -1
  135. package/src/main/conversation/message/CompositeContentBuilder.ts +0 -60
  136. package/src/main/conversation/message/Message.js.map +0 -1
  137. package/src/main/conversation/message/Message.ts +0 -24
  138. package/src/main/conversation/message/MessageBuilder.js.map +0 -1
  139. package/src/main/conversation/message/MessageBuilder.test.browser.js +0 -27
  140. package/src/main/conversation/message/MessageBuilder.ts +0 -488
  141. package/src/main/conversation/message/MessageService.js.map +0 -1
  142. package/src/main/conversation/message/MessageService.test.node.d.ts +0 -1
  143. package/src/main/conversation/message/MessageService.test.node.js +0 -308
  144. package/src/main/conversation/message/MessageService.test.node.js.map +0 -1
  145. package/src/main/conversation/message/MessageService.test.node.ts +0 -398
  146. package/src/main/conversation/message/MessageService.ts +0 -383
  147. package/src/main/conversation/message/MessageToProtoMapper.js.map +0 -1
  148. package/src/main/conversation/message/MessageToProtoMapper.ts +0 -114
  149. package/src/main/conversation/message/OtrMessage.js.map +0 -1
  150. package/src/main/conversation/message/OtrMessage.ts +0 -160
  151. package/src/main/conversation/message/PayloadBundle.js.map +0 -1
  152. package/src/main/conversation/message/PayloadBundle.ts +0 -98
  153. package/src/main/conversation/message/TeamMessage.js.map +0 -1
  154. package/src/main/conversation/message/TeamMessage.ts +0 -72
  155. package/src/main/conversation/message/TextContentBuilder.js.map +0 -1
  156. package/src/main/conversation/message/TextContentBuilder.ts +0 -88
  157. package/src/main/conversation/message/UserClientsUtil.js.map +0 -1
  158. package/src/main/conversation/message/UserClientsUtil.ts +0 -44
  159. package/src/main/conversation/message/UserClientsUtils.test.node.d.ts +0 -1
  160. package/src/main/conversation/message/UserClientsUtils.test.node.js +0 -42
  161. package/src/main/conversation/message/UserClientsUtils.test.node.js.map +0 -1
  162. package/src/main/conversation/message/UserClientsUtils.test.node.ts +0 -44
  163. package/src/main/conversation/message/UserMessage.js.map +0 -1
  164. package/src/main/conversation/message/UserMessage.ts +0 -95
  165. package/src/main/cryptography/AssetCryptography.browser.js.map +0 -1
  166. package/src/main/cryptography/AssetCryptography.browser.ts +0 -76
  167. package/src/main/cryptography/AssetCryptography.node.js.map +0 -1
  168. package/src/main/cryptography/AssetCryptography.node.ts +0 -85
  169. package/src/main/cryptography/CryptographyDatabaseRepository.js.map +0 -1
  170. package/src/main/cryptography/CryptographyDatabaseRepository.ts +0 -44
  171. package/src/main/cryptography/CryptographyService.js.map +0 -1
  172. package/src/main/cryptography/CryptographyService.test.browser.js +0 -195
  173. package/src/main/cryptography/CryptographyService.test.node.d.ts +0 -1
  174. package/src/main/cryptography/CryptographyService.test.node.js +0 -228
  175. package/src/main/cryptography/CryptographyService.test.node.js.map +0 -1
  176. package/src/main/cryptography/CryptographyService.test.node.ts +0 -246
  177. package/src/main/cryptography/CryptographyService.ts +0 -246
  178. package/src/main/cryptography/EncryptedAsset.js.map +0 -1
  179. package/src/main/cryptography/EncryptedAsset.ts +0 -30
  180. package/src/main/cryptography/GenericMessageMapper.js.map +0 -1
  181. package/src/main/cryptography/GenericMessageMapper.ts +0 -364
  182. package/src/main/cryptography/MessageHashService.js.map +0 -1
  183. package/src/main/cryptography/MessageHashService.test.browser.js +0 -176
  184. package/src/main/cryptography/MessageHashService.test.node.d.ts +0 -1
  185. package/src/main/cryptography/MessageHashService.test.node.js +0 -138
  186. package/src/main/cryptography/MessageHashService.test.node.js.map +0 -1
  187. package/src/main/cryptography/MessageHashService.test.node.ts +0 -176
  188. package/src/main/cryptography/MessageHashService.ts +0 -109
  189. package/src/main/cryptography/SessionPayloadBundle.js.map +0 -1
  190. package/src/main/cryptography/SessionPayloadBundle.ts +0 -23
  191. package/src/main/cryptography/index.js.map +0 -1
  192. package/src/main/cryptography/index.ts +0 -23
  193. package/src/main/giphy/GiphyService.js.map +0 -1
  194. package/src/main/giphy/GiphyService.ts +0 -37
  195. package/src/main/giphy/index.js.map +0 -1
  196. package/src/main/giphy/index.ts +0 -20
  197. package/src/main/index.js.map +0 -1
  198. package/src/main/index.test.browser.js +0 -22
  199. package/src/main/index.ts +0 -34
  200. package/src/main/notification/NotificationBackendRepository.js.map +0 -1
  201. package/src/main/notification/NotificationBackendRepository.ts +0 -33
  202. package/src/main/notification/NotificationDatabaseRepository.js.map +0 -1
  203. package/src/main/notification/NotificationDatabaseRepository.ts +0 -74
  204. package/src/main/notification/NotificationService.js.map +0 -1
  205. package/src/main/notification/NotificationService.test.browser.js +0 -179
  206. package/src/main/notification/NotificationService.test.node.d.ts +0 -1
  207. package/src/main/notification/NotificationService.test.node.js +0 -99
  208. package/src/main/notification/NotificationService.test.node.js.map +0 -1
  209. package/src/main/notification/NotificationService.test.node.ts +0 -124
  210. package/src/main/notification/NotificationService.ts +0 -260
  211. package/src/main/notification/index.js.map +0 -1
  212. package/src/main/notification/index.ts +0 -20
  213. package/src/main/self/SelfService.js.map +0 -1
  214. package/src/main/self/SelfService.ts +0 -59
  215. package/src/main/self/index.js.map +0 -1
  216. package/src/main/self/index.ts +0 -20
  217. package/src/main/team/TeamService.js.map +0 -1
  218. package/src/main/team/TeamService.ts +0 -68
  219. package/src/main/team/index.js.map +0 -1
  220. package/src/main/team/index.ts +0 -20
  221. package/src/main/test/CryptographyHelper.js.map +0 -1
  222. package/src/main/test/CryptographyHelper.ts +0 -57
  223. package/src/main/test/PayloadHelper.js.map +0 -1
  224. package/src/main/test/PayloadHelper.ts +0 -60
  225. package/src/main/user/UserMapper.js.map +0 -1
  226. package/src/main/user/UserMapper.test.node.d.ts +0 -1
  227. package/src/main/user/UserMapper.test.node.js +0 -55
  228. package/src/main/user/UserMapper.test.node.js.map +0 -1
  229. package/src/main/user/UserMapper.test.node.ts +0 -63
  230. package/src/main/user/UserMapper.ts +0 -92
  231. package/src/main/user/UserService.js.map +0 -1
  232. package/src/main/user/UserService.test.node.js +0 -141
  233. package/src/main/user/UserService.ts +0 -98
  234. package/src/main/user/index.js.map +0 -1
  235. package/src/main/user/index.ts +0 -20
  236. package/src/main/util/TypePredicateUtil.js.map +0 -1
  237. package/src/main/util/TypePredicateUtil.test.node.d.ts +0 -1
  238. package/src/main/util/TypePredicateUtil.test.node.js +0 -42
  239. package/src/main/util/TypePredicateUtil.test.node.js.map +0 -1
  240. package/src/main/util/TypePredicateUtil.test.node.ts +0 -44
  241. package/src/main/util/TypePredicateUtil.ts +0 -52
  242. package/src/main/util/index.js.map +0 -1
  243. package/src/main/util/index.ts +0 -20
@@ -1,179 +0,0 @@
1
- /*
2
- * Wire
3
- * Copyright (C) 2018 Wire Swiss GmbH
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see http://www.gnu.org/licenses/.
17
- *
18
- */
19
-
20
- import {APIClient} from '@wireapp/api-client';
21
- import {NotificationService} from '@wireapp/core/src/main/notification/';
22
- import {IndexedDBEngine} from '@wireapp/store-engine-dexie';
23
- import Dexie from 'dexie';
24
- import UUID from 'uuidjs';
25
-
26
- describe('NotificationService', () => {
27
- let storeName = undefined;
28
- describe('Database "setLastEventDate"', () => {
29
- afterEach(done => {
30
- if (storeName) {
31
- const deleteRequest = window.indexedDB.deleteDatabase(storeName);
32
- deleteRequest.onerror = done.fail;
33
- deleteRequest.onsuccess = done;
34
- } else {
35
- done();
36
- }
37
- });
38
-
39
- it('initializes last event date if database entry is not present', async () => {
40
- storeName = UUID.genV4().toString();
41
- const db = new Dexie(storeName);
42
- db.version(1).stores({
43
- amplify: '',
44
- });
45
- const engine = new IndexedDBEngine();
46
- await engine.initWithDb(db);
47
-
48
- const apiClient = new APIClient({
49
- urls: APIClient.BACKEND.STAGING,
50
- });
51
-
52
- const notificationService = new NotificationService(apiClient, {}, engine);
53
- spyOn(notificationService.database, 'getLastEventDate').and.callThrough();
54
- spyOn(engine, 'read').and.callThrough();
55
- spyOn(engine, 'update').and.callThrough();
56
- spyOn(engine, 'create').and.callThrough();
57
-
58
- const returnValue = await notificationService.setLastEventDate(new Date(0));
59
- expect(returnValue).toEqual(new Date(0));
60
-
61
- expect(notificationService.database.getLastEventDate).toHaveBeenCalledTimes(1);
62
- expect(engine.read).toHaveBeenCalledTimes(1);
63
- expect(engine.update).toHaveBeenCalledTimes(0);
64
- expect(engine.create).toHaveBeenCalledTimes(1);
65
- });
66
-
67
- it('updates last event date if an older database record exists', async () => {
68
- storeName = storeName = UUID.genV4().toString();
69
- const db = new Dexie(storeName);
70
- db.version(1).stores({
71
- amplify: '',
72
- });
73
- const engine = new IndexedDBEngine();
74
- await engine.initWithDb(db);
75
-
76
- const apiClient = new APIClient({
77
- urls: APIClient.BACKEND.STAGING,
78
- });
79
-
80
- const notificationService = new NotificationService(apiClient, {}, engine);
81
- await notificationService.setLastEventDate(new Date(0));
82
-
83
- spyOn(notificationService.database, 'getLastEventDate').and.callThrough();
84
- spyOn(engine, 'read').and.callThrough();
85
- spyOn(engine, 'update').and.callThrough();
86
- spyOn(engine, 'create').and.callThrough();
87
-
88
- const newDate = await notificationService.setLastEventDate(new Date(1));
89
- expect(newDate).toEqual(new Date(1));
90
-
91
- expect(notificationService.database.getLastEventDate).toHaveBeenCalledTimes(1);
92
- expect(engine.read).toHaveBeenCalledTimes(1);
93
- expect(engine.update).toHaveBeenCalledTimes(1);
94
- expect(engine.create).toHaveBeenCalledTimes(0);
95
- });
96
- });
97
-
98
- it('ignores last event date update if newer database entry exists', async () => {
99
- storeName = UUID.genV4().toString();
100
- const db = new Dexie(storeName);
101
- db.version(1).stores({
102
- amplify: '',
103
- });
104
- const engine = new IndexedDBEngine();
105
- await engine.initWithDb(db);
106
-
107
- const apiClient = new APIClient({
108
- urls: APIClient.BACKEND.STAGING,
109
- });
110
-
111
- const notificationService = new NotificationService(apiClient, {}, engine);
112
- const greaterDate = new Date(1);
113
- const lesserDate = new Date(0);
114
-
115
- await notificationService.setLastEventDate(greaterDate);
116
-
117
- spyOn(notificationService.database, 'getLastEventDate').and.callThrough();
118
- spyOn(engine, 'read').and.callThrough();
119
- spyOn(engine, 'update').and.callThrough();
120
- spyOn(engine, 'create').and.callThrough();
121
-
122
- const returnValue = await notificationService.setLastEventDate(lesserDate);
123
- expect(returnValue).toEqual(greaterDate);
124
-
125
- expect(notificationService.database.getLastEventDate).toHaveBeenCalledTimes(1);
126
- expect(engine.read).toHaveBeenCalledTimes(1);
127
- expect(engine.update).toHaveBeenCalledTimes(0);
128
- expect(engine.create).toHaveBeenCalledTimes(0);
129
- expect(await notificationService.database.getLastEventDate()).toEqual(greaterDate);
130
- });
131
-
132
- it('initializes last notification ID if database entry is not present', async () => {
133
- storeName = UUID.genV4().toString();
134
- const db = new Dexie(storeName);
135
- db.version(1).stores({
136
- amplify: '',
137
- });
138
- const engine = new IndexedDBEngine();
139
- await engine.initWithDb(db);
140
-
141
- const apiClient = new APIClient({
142
- urls: APIClient.BACKEND.STAGING,
143
- });
144
-
145
- const notificationService = new NotificationService(apiClient, {}, engine);
146
- spyOn(notificationService.database, 'getLastNotificationId').and.callThrough();
147
- spyOn(engine, 'read').and.callThrough();
148
- spyOn(engine, 'update').and.callThrough();
149
- spyOn(engine, 'create').and.callThrough();
150
-
151
- const lastNotificationId = await notificationService.setLastNotificationId({id: '12'});
152
- expect(lastNotificationId).toEqual('12');
153
- });
154
-
155
- it('updates last notification ID if database entry exists', async () => {
156
- storeName = UUID.genV4().toString();
157
- const db = new Dexie(storeName);
158
- db.version(1).stores({
159
- amplify: '',
160
- });
161
- const engine = new IndexedDBEngine();
162
- await engine.initWithDb(db);
163
-
164
- const apiClient = new APIClient({
165
- urls: APIClient.BACKEND.STAGING,
166
- });
167
-
168
- const notificationService = new NotificationService(apiClient, {}, engine);
169
- await notificationService.setLastNotificationId({id: '12'});
170
-
171
- spyOn(notificationService.database, 'getLastNotificationId').and.callThrough();
172
- spyOn(engine, 'read').and.callThrough();
173
- spyOn(engine, 'update').and.callThrough();
174
- spyOn(engine, 'create').and.callThrough();
175
-
176
- const returnValue = await notificationService.setLastNotificationId({id: '13'});
177
- expect(returnValue).toEqual('13');
178
- });
179
- });
@@ -1,99 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2018 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- const api_client_1 = require("@wireapp/api-client");
22
- const store_engine_1 = require("@wireapp/store-engine");
23
- const conversation_1 = require("../conversation");
24
- const NotificationService_1 = require("./NotificationService");
25
- const BASE_URL = 'mock-backend.wire.com';
26
- const MOCK_BACKEND = {
27
- name: 'mock',
28
- rest: `https://${BASE_URL}`,
29
- ws: `wss://${BASE_URL}`,
30
- };
31
- describe('NotificationService', () => {
32
- describe('handleEvent', () => {
33
- it('propagates errors to the outer calling function', async (done) => {
34
- const storeEngine = new store_engine_1.MemoryEngine();
35
- await storeEngine.init('NotificationService.test');
36
- const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
37
- const cryptographyService = {};
38
- const notificationService = new NotificationService_1.NotificationService(apiClient, cryptographyService, storeEngine);
39
- spyOn(notificationService, 'handleEvent').and.throwError('Test error');
40
- notificationService.on(NotificationService_1.NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError => {
41
- expect(notificationError.error.message).toBe('Test error');
42
- done();
43
- });
44
- const notification = {
45
- payload: [{}],
46
- };
47
- await notificationService.handleNotification(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM);
48
- });
49
- });
50
- describe('handleNotification', () => {
51
- it('updates last notification ID when notification is NOT transient', async () => {
52
- const storeEngine = new store_engine_1.MemoryEngine();
53
- await storeEngine.init('NotificationService.test');
54
- const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
55
- const notificationService = new NotificationService_1.NotificationService(apiClient, {}, storeEngine);
56
- spyOn(notificationService, 'handleEvent').and.returnValue({});
57
- const spySetLastNotificationId = spyOn(notificationService, 'setLastNotificationId').and.returnValue({});
58
- const notification = {
59
- payload: [{}],
60
- transient: false,
61
- };
62
- await notificationService.handleNotification(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM);
63
- expect(spySetLastNotificationId.calls.count()).toBe(1);
64
- });
65
- it('does NOT update last notification ID when notification is transient', async () => {
66
- const storeEngine = new store_engine_1.MemoryEngine();
67
- await storeEngine.init('NotificationService.test');
68
- const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
69
- const notificationService = new NotificationService_1.NotificationService(apiClient, {}, storeEngine);
70
- spyOn(notificationService, 'handleEvent').and.returnValue({});
71
- const spySetLastNotificationId = spyOn(notificationService, 'setLastNotificationId').and.returnValue({});
72
- const notification = {
73
- payload: [{}],
74
- transient: true,
75
- };
76
- await notificationService.handleNotification(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM);
77
- expect(spySetLastNotificationId.calls.count()).toBe(0);
78
- });
79
- it('does NOT update last notification ID when event processing fails', async (done) => {
80
- const storeEngine = new store_engine_1.MemoryEngine();
81
- await storeEngine.init('NotificationService.test');
82
- const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
83
- const notificationService = new NotificationService_1.NotificationService(apiClient, {}, storeEngine);
84
- notificationService.on(NotificationService_1.NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError => {
85
- expect(notificationError.error.message).toBe('Test error');
86
- expect(spySetLastNotificationId.calls.count()).toBe(0);
87
- done();
88
- });
89
- spyOn(notificationService, 'handleEvent').and.throwError('Test error');
90
- const spySetLastNotificationId = spyOn(notificationService, 'setLastNotificationId').and.returnValue({});
91
- const notification = {
92
- payload: [{}],
93
- transient: true,
94
- };
95
- await notificationService.handleNotification(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM);
96
- });
97
- });
98
- });
99
- //# sourceMappingURL=NotificationService.test.node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotificationService.test.node.js","sourceRoot":"","sources":["NotificationService.test.node.ts"],"names":[],"mappings":"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"}
@@ -1,124 +0,0 @@
1
- /*
2
- * Wire
3
- * Copyright (C) 2018 Wire Swiss GmbH
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see http://www.gnu.org/licenses/.
17
- *
18
- */
19
-
20
- import {APIClient} from '@wireapp/api-client';
21
- import {Notification} from '@wireapp/api-client/src/notification';
22
- import {MemoryEngine} from '@wireapp/store-engine';
23
- import {PayloadBundleSource} from '../conversation';
24
- import {CryptographyService} from '../cryptography';
25
- import {NotificationService} from './NotificationService';
26
-
27
- const BASE_URL = 'mock-backend.wire.com';
28
- const MOCK_BACKEND = {
29
- name: 'mock',
30
- rest: `https://${BASE_URL}`,
31
- ws: `wss://${BASE_URL}`,
32
- };
33
-
34
- describe('NotificationService', () => {
35
- describe('handleEvent', () => {
36
- it('propagates errors to the outer calling function', async done => {
37
- const storeEngine = new MemoryEngine();
38
- await storeEngine.init('NotificationService.test');
39
-
40
- const apiClient = new APIClient({urls: MOCK_BACKEND});
41
-
42
- const cryptographyService = {} as unknown as CryptographyService;
43
- const notificationService = new NotificationService(apiClient, cryptographyService, storeEngine);
44
-
45
- spyOn<any>(notificationService, 'handleEvent').and.throwError('Test error');
46
-
47
- notificationService.on(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError => {
48
- expect(notificationError.error.message).toBe('Test error');
49
- done();
50
- });
51
-
52
- const notification = {
53
- payload: [{}],
54
- } as unknown as Notification;
55
-
56
- await notificationService.handleNotification(notification, PayloadBundleSource.NOTIFICATION_STREAM);
57
- });
58
- });
59
-
60
- describe('handleNotification', () => {
61
- it('updates last notification ID when notification is NOT transient', async () => {
62
- const storeEngine = new MemoryEngine();
63
- await storeEngine.init('NotificationService.test');
64
-
65
- const apiClient = new APIClient({urls: MOCK_BACKEND});
66
- const notificationService = new NotificationService(apiClient, {} as unknown as CryptographyService, storeEngine);
67
-
68
- spyOn<any>(notificationService, 'handleEvent').and.returnValue({});
69
- const spySetLastNotificationId = spyOn<any>(notificationService, 'setLastNotificationId').and.returnValue({});
70
-
71
- const notification = {
72
- payload: [{}],
73
- transient: false,
74
- } as unknown as Notification;
75
-
76
- await notificationService.handleNotification(notification, PayloadBundleSource.NOTIFICATION_STREAM);
77
-
78
- expect(spySetLastNotificationId.calls.count()).toBe(1);
79
- });
80
-
81
- it('does NOT update last notification ID when notification is transient', async () => {
82
- const storeEngine = new MemoryEngine();
83
- await storeEngine.init('NotificationService.test');
84
-
85
- const apiClient = new APIClient({urls: MOCK_BACKEND});
86
- const notificationService = new NotificationService(apiClient, {} as unknown as CryptographyService, storeEngine);
87
-
88
- spyOn<any>(notificationService, 'handleEvent').and.returnValue({});
89
- const spySetLastNotificationId = spyOn<any>(notificationService, 'setLastNotificationId').and.returnValue({});
90
-
91
- const notification = {
92
- payload: [{}],
93
- transient: true,
94
- } as unknown as Notification;
95
-
96
- await notificationService.handleNotification(notification, PayloadBundleSource.NOTIFICATION_STREAM);
97
-
98
- expect(spySetLastNotificationId.calls.count()).toBe(0);
99
- });
100
-
101
- it('does NOT update last notification ID when event processing fails', async done => {
102
- const storeEngine = new MemoryEngine();
103
- await storeEngine.init('NotificationService.test');
104
-
105
- const apiClient = new APIClient({urls: MOCK_BACKEND});
106
- const notificationService = new NotificationService(apiClient, {} as unknown as CryptographyService, storeEngine);
107
- notificationService.on(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError => {
108
- expect(notificationError.error.message).toBe('Test error');
109
- expect(spySetLastNotificationId.calls.count()).toBe(0);
110
- done();
111
- });
112
-
113
- spyOn<any>(notificationService, 'handleEvent').and.throwError('Test error');
114
- const spySetLastNotificationId = spyOn<any>(notificationService, 'setLastNotificationId').and.returnValue({});
115
-
116
- const notification = {
117
- payload: [{}],
118
- transient: true,
119
- } as unknown as Notification;
120
-
121
- await notificationService.handleNotification(notification, PayloadBundleSource.NOTIFICATION_STREAM);
122
- });
123
- });
124
- });
@@ -1,260 +0,0 @@
1
- /*
2
- * Wire
3
- * Copyright (C) 2018 Wire Swiss GmbH
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see http://www.gnu.org/licenses/.
17
- *
18
- */
19
-
20
- import type {APIClient} from '@wireapp/api-client';
21
- import * as Events from '@wireapp/api-client/src/event';
22
- import type {Notification} from '@wireapp/api-client/src/notification/';
23
- import {CRUDEngine, error as StoreEngineError} from '@wireapp/store-engine';
24
- import {EventEmitter} from 'events';
25
- import logdown from 'logdown';
26
- import {PayloadBundle, PayloadBundleSource, PayloadBundleType} from '../conversation';
27
- import type {AssetContent} from '../conversation/content';
28
- import {ConversationMapper} from '../conversation/ConversationMapper';
29
- import * as OtrMessage from '../conversation/message/OtrMessage';
30
- import * as UserMessage from '../conversation/message/UserMessage';
31
- import {CoreError, NotificationError} from '../CoreError';
32
- import type {CryptographyService} from '../cryptography';
33
- import {UserMapper} from '../user/UserMapper';
34
- import {NotificationBackendRepository} from './NotificationBackendRepository';
35
- import {NotificationDatabaseRepository} from './NotificationDatabaseRepository';
36
-
37
- enum TOPIC {
38
- NOTIFICATION_ERROR = 'NotificationService.TOPIC.NOTIFICATION_ERROR',
39
- }
40
-
41
- export type NotificationHandler = (notification: Notification, source: PayloadBundleSource) => Promise<void>;
42
-
43
- export interface NotificationService {
44
- on(event: PayloadBundleType.ASSET, listener: (payload: OtrMessage.FileAssetMessage) => void): this;
45
- on(event: PayloadBundleType.BUTTON_ACTION, listener: (payload: OtrMessage.ButtonActionMessage) => void): this;
46
- on(event: PayloadBundleType.ASSET_ABORT, listener: (payload: OtrMessage.FileAssetAbortMessage) => void): this;
47
- on(event: PayloadBundleType.ASSET_IMAGE, listener: (payload: OtrMessage.ImageAssetMessage) => void): this;
48
- on(event: PayloadBundleType.ASSET_META, listener: (payload: OtrMessage.FileAssetMetaDataMessage) => void): this;
49
- on(event: PayloadBundleType.CALL, listener: (payload: OtrMessage.CallMessage) => void): this;
50
- on(event: PayloadBundleType.CLIENT_ACTION, listener: (payload: OtrMessage.ResetSessionMessage) => void): this;
51
- on(event: PayloadBundleType.CLIENT_ADD, listener: (payload: UserMessage.UserClientAddMessage) => void): this;
52
- on(event: PayloadBundleType.CLIENT_REMOVE, listener: (payload: UserMessage.UserClientRemoveMessage) => void): this;
53
- on(event: PayloadBundleType.CONFIRMATION, listener: (payload: OtrMessage.ConfirmationMessage) => void): this;
54
- on(event: PayloadBundleType.CONNECTION_REQUEST, listener: (payload: UserMessage.UserConnectionMessage) => void): this;
55
- on(event: PayloadBundleType.USER_UPDATE, listener: (payload: UserMessage.UserUpdateMessage) => void): this;
56
- on(
57
- event: PayloadBundleType.CONVERSATION_CLEAR,
58
- listener: (payload: OtrMessage.ClearConversationMessage) => void,
59
- ): this;
60
- on(event: PayloadBundleType.CONVERSATION_RENAME, listener: (payload: Events.ConversationRenameEvent) => void): this;
61
- on(event: PayloadBundleType.LOCATION, listener: (payload: OtrMessage.LocationMessage) => void): this;
62
- on(event: PayloadBundleType.MEMBER_JOIN, listener: (payload: Events.TeamMemberJoinEvent) => void): this;
63
- on(event: PayloadBundleType.MESSAGE_DELETE, listener: (payload: OtrMessage.DeleteMessage) => void): this;
64
- on(event: PayloadBundleType.MESSAGE_EDIT, listener: (payload: OtrMessage.EditedTextMessage) => void): this;
65
- on(event: PayloadBundleType.MESSAGE_HIDE, listener: (payload: OtrMessage.HideMessage) => void): this;
66
- on(event: PayloadBundleType.PING, listener: (payload: OtrMessage.PingMessage) => void): this;
67
- on(event: PayloadBundleType.REACTION, listener: (payload: OtrMessage.ReactionMessage) => void): this;
68
- on(event: PayloadBundleType.TEXT, listener: (payload: OtrMessage.TextMessage) => void): this;
69
- on(
70
- event: PayloadBundleType.TIMER_UPDATE,
71
- listener: (payload: Events.ConversationMessageTimerUpdateEvent) => void,
72
- ): this;
73
- on(event: PayloadBundleType.TYPING, listener: (payload: Events.ConversationTypingEvent) => void): this;
74
- on(event: PayloadBundleType.UNKNOWN, listener: (payload: any) => void): this;
75
- on(event: TOPIC.NOTIFICATION_ERROR, listener: (payload: NotificationError) => void): this;
76
- }
77
-
78
- export class NotificationService extends EventEmitter {
79
- private readonly apiClient: APIClient;
80
- private readonly backend: NotificationBackendRepository;
81
- private readonly cryptographyService: CryptographyService;
82
- private readonly database: NotificationDatabaseRepository;
83
- private readonly logger = logdown('@wireapp/core/notification/NotificationService', {
84
- logger: console,
85
- markdown: false,
86
- });
87
- public static readonly TOPIC = TOPIC;
88
-
89
- constructor(apiClient: APIClient, cryptographyService: CryptographyService, storeEngine: CRUDEngine) {
90
- super();
91
- this.apiClient = apiClient;
92
- this.cryptographyService = cryptographyService;
93
- this.backend = new NotificationBackendRepository(this.apiClient);
94
- this.database = new NotificationDatabaseRepository(storeEngine);
95
- }
96
-
97
- public async getAllNotifications(): Promise<Notification[]> {
98
- const clientId = this.apiClient.clientId;
99
- const lastNotificationId = await this.database.getLastNotificationId();
100
- return this.backend.getAllNotifications(clientId, lastNotificationId);
101
- }
102
-
103
- /** Should only be called with a completely new client. */
104
- public async initializeNotificationStream(): Promise<string> {
105
- const clientId = this.apiClient.clientId;
106
- await this.setLastEventDate(new Date(0));
107
- const latestNotification = await this.backend.getLastNotification(clientId);
108
- return this.setLastNotificationId(latestNotification);
109
- }
110
-
111
- public async hasHistory(): Promise<boolean> {
112
- const notificationEvents = await this.getNotificationEventList();
113
- return !!notificationEvents.length;
114
- }
115
-
116
- public getNotificationEventList(): Promise<Events.BackendEvent[]> {
117
- return this.database.getNotificationEventList();
118
- }
119
-
120
- public async setLastEventDate(eventDate: Date): Promise<Date> {
121
- let databaseLastEventDate: Date | undefined;
122
-
123
- try {
124
- databaseLastEventDate = await this.database.getLastEventDate();
125
- } catch (error) {
126
- if (
127
- error instanceof StoreEngineError.RecordNotFoundError ||
128
- (error as Error).constructor.name === StoreEngineError.RecordNotFoundError.name
129
- ) {
130
- return this.database.createLastEventDate(eventDate);
131
- }
132
- throw error;
133
- }
134
-
135
- if (databaseLastEventDate && eventDate > databaseLastEventDate) {
136
- return this.database.updateLastEventDate(eventDate);
137
- }
138
-
139
- return databaseLastEventDate;
140
- }
141
-
142
- public async setLastNotificationId(lastNotification: Notification): Promise<string> {
143
- return this.database.updateLastNotificationId(lastNotification);
144
- }
145
-
146
- public async handleNotificationStream(notificationHandler: NotificationHandler): Promise<void> {
147
- const notifications = await this.getAllNotifications();
148
- for (const notification of notifications) {
149
- await notificationHandler(notification, PayloadBundleSource.NOTIFICATION_STREAM).catch(error =>
150
- this.logger.error(error),
151
- );
152
- }
153
- }
154
-
155
- public readonly handleNotification: NotificationHandler = async (
156
- notification: Notification,
157
- source: PayloadBundleSource,
158
- ): Promise<void> => {
159
- for (const event of notification.payload) {
160
- let data: PayloadBundle | void;
161
-
162
- try {
163
- this.logger.log(`Handling event of type "${event.type}" for notification with ID "${notification.id}"`, event);
164
- data = await this.handleEvent(event, source);
165
- if (!notification.transient) {
166
- await this.setLastNotificationId(notification);
167
- }
168
- } catch (error) {
169
- this.logger.error(
170
- `There was an error with notification ID "${notification.id}": ${(error as Error).message}`,
171
- error,
172
- );
173
- const notificationError: NotificationError = {
174
- error: error as Error,
175
- notification,
176
- type: CoreError.NOTIFICATION_ERROR,
177
- };
178
- this.emit(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError);
179
- continue;
180
- }
181
-
182
- if (data) {
183
- switch (data.type) {
184
- case PayloadBundleType.ASSET_IMAGE:
185
- case PayloadBundleType.BUTTON_ACTION:
186
- case PayloadBundleType.CALL:
187
- case PayloadBundleType.CLIENT_ACTION:
188
- case PayloadBundleType.CLIENT_ADD:
189
- case PayloadBundleType.CLIENT_REMOVE:
190
- case PayloadBundleType.CONFIRMATION:
191
- case PayloadBundleType.CONNECTION_REQUEST:
192
- case PayloadBundleType.LOCATION:
193
- case PayloadBundleType.MESSAGE_DELETE:
194
- case PayloadBundleType.MESSAGE_EDIT:
195
- case PayloadBundleType.MESSAGE_HIDE:
196
- case PayloadBundleType.PING:
197
- case PayloadBundleType.REACTION:
198
- case PayloadBundleType.TEXT:
199
- case PayloadBundleType.USER_UPDATE:
200
- this.emit(data.type, data);
201
- break;
202
- case PayloadBundleType.ASSET: {
203
- const assetContent = data.content as AssetContent;
204
- const isMetaData = !!assetContent && !!assetContent.original && !assetContent.uploaded;
205
- const isAbort = !!assetContent.abortReason || (!assetContent.original && !assetContent.uploaded);
206
-
207
- if (isMetaData) {
208
- data.type = PayloadBundleType.ASSET_META;
209
- this.emit(PayloadBundleType.ASSET_META, data);
210
- } else if (isAbort) {
211
- data.type = PayloadBundleType.ASSET_ABORT;
212
- this.emit(PayloadBundleType.ASSET_ABORT, data);
213
- } else {
214
- this.emit(PayloadBundleType.ASSET, data);
215
- }
216
- break;
217
- }
218
- case PayloadBundleType.TIMER_UPDATE:
219
- case PayloadBundleType.CONVERSATION_RENAME:
220
- case PayloadBundleType.CONVERSATION_CLEAR:
221
- case PayloadBundleType.MEMBER_JOIN:
222
- case PayloadBundleType.TYPING:
223
- this.emit(data.type, event);
224
- break;
225
- }
226
- } else {
227
- const {type, conversation, from} = event as Events.ConversationEvent;
228
- const conversationText = conversation ? ` in conversation "${conversation}"` : '';
229
- const fromText = from ? ` from user "${from}".` : '';
230
-
231
- this.logger.log(`Received unsupported event "${type}"${conversationText}${fromText}`, {event});
232
- }
233
- }
234
- };
235
-
236
- private async handleEvent(event: Events.BackendEvent, source: PayloadBundleSource): Promise<PayloadBundle | void> {
237
- switch (event.type) {
238
- // Encrypted events
239
- case Events.CONVERSATION_EVENT.OTR_MESSAGE_ADD: {
240
- return this.cryptographyService.decodeGenericMessage(event, source);
241
- }
242
- // Meta events
243
- case Events.CONVERSATION_EVENT.MEMBER_JOIN:
244
- case Events.CONVERSATION_EVENT.MESSAGE_TIMER_UPDATE:
245
- case Events.CONVERSATION_EVENT.RENAME:
246
- case Events.CONVERSATION_EVENT.TYPING: {
247
- const {conversation, from} = event;
248
- const metaEvent = {...event, conversation, from};
249
- return ConversationMapper.mapConversationEvent(metaEvent, source);
250
- }
251
- // User events
252
- case Events.USER_EVENT.CONNECTION:
253
- case Events.USER_EVENT.CLIENT_ADD:
254
- case Events.USER_EVENT.UPDATE:
255
- case Events.USER_EVENT.CLIENT_REMOVE: {
256
- return UserMapper.mapUserEvent(event, this.apiClient.context!.userId, source);
257
- }
258
- }
259
- }
260
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;AAEH,wDAAsC"}