quickblox-react-ui-kit 0.5.1-beta.1 → 0.5.1-join-dialog-off.1

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 (95) hide show
  1. package/dist/CommonTypes/BaseViewModel.d.ts +2 -0
  2. package/dist/CommonTypes/BaseViewModel.d.ts.map +1 -1
  3. package/dist/CommonTypes/CommonTypes.d.ts +1 -0
  4. package/dist/CommonTypes/CommonTypes.d.ts.map +1 -1
  5. package/dist/Data/Stubs.d.ts.map +1 -1
  6. package/dist/Data/dto/dialog/RemoteDialogDTO.d.ts +1 -0
  7. package/dist/Data/dto/dialog/RemoteDialogDTO.d.ts.map +1 -1
  8. package/dist/Data/mapper/DialogRemoteDTOMapper.d.ts.map +1 -1
  9. package/dist/Data/repository/DialogsRepository.d.ts +3 -0
  10. package/dist/Data/repository/DialogsRepository.d.ts.map +1 -1
  11. package/dist/Data/source/remote/IRemoteDataSource.d.ts +3 -0
  12. package/dist/Data/source/remote/IRemoteDataSource.d.ts.map +1 -1
  13. package/dist/Data/source/remote/Mapper/DialogDTOMapper.d.ts.map +1 -1
  14. package/dist/Data/source/remote/RemoteDataSource.d.ts +3 -0
  15. package/dist/Data/source/remote/RemoteDataSource.d.ts.map +1 -1
  16. package/dist/Domain/repository/IDialogsRepository.d.ts +3 -0
  17. package/dist/Domain/repository/IDialogsRepository.d.ts.map +1 -1
  18. package/dist/Domain/use_cases/CreateDialogWithAutoJoinUseCase.d.ts +13 -0
  19. package/dist/Domain/use_cases/CreateDialogWithAutoJoinUseCase.d.ts.map +1 -0
  20. package/dist/Domain/use_cases/JoinFromTheDialogUseCase.d.ts +11 -0
  21. package/dist/Domain/use_cases/JoinFromTheDialogUseCase.d.ts.map +1 -0
  22. package/dist/Domain/use_cases/UnJoinFromTheDialogUseCase.d.ts +11 -0
  23. package/dist/Domain/use_cases/UnJoinFromTheDialogUseCase.d.ts.map +1 -0
  24. package/dist/Presentation/Views/Dialog/useDialogViewModel.d.ts.map +1 -1
  25. package/dist/Presentation/Views/DialogInfo/DialogInfo.d.ts.map +1 -1
  26. package/dist/Presentation/Views/DialogList/DialogListViewModel.d.ts +4 -1
  27. package/dist/Presentation/Views/DialogList/DialogListViewModel.d.ts.map +1 -1
  28. package/dist/Presentation/Views/DialogList/useDialogListViewModel.d.ts.map +1 -1
  29. package/dist/Presentation/Views/EditDialog/EditDialog.d.ts.map +1 -1
  30. package/dist/Presentation/Views/Flow/CreateDialogFlow/CreateNewDialogFlow.d.ts.map +1 -1
  31. package/dist/QBconfig.d.ts.map +1 -1
  32. package/dist/index-ui.js +438 -90
  33. package/dist/qb-api-calls/index.d.ts +2 -0
  34. package/dist/qb-api-calls/index.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/src/CommonTypes/BaseViewModel.ts +4 -0
  37. package/src/CommonTypes/CommonTypes.ts +1 -0
  38. package/src/Data/Stubs.ts +20 -10
  39. package/src/Data/dto/dialog/RemoteDialogDTO.ts +4 -0
  40. package/src/Data/mapper/DialogRemoteDTOMapper.ts +6 -0
  41. package/src/Data/repository/DialogsRepository.ts +57 -0
  42. package/src/Data/source/remote/IRemoteDataSource.ts +10 -0
  43. package/src/Data/source/remote/Mapper/DialogDTOMapper.ts +13 -0
  44. package/src/Data/source/remote/RemoteDataSource.ts +163 -65
  45. package/src/Domain/repository/IDialogsRepository.ts +10 -0
  46. package/src/Domain/use_cases/CreateDialogWithAutoJoinUseCase.ts +77 -0
  47. package/src/Domain/use_cases/JoinFromTheDialogUseCase.ts +61 -0
  48. package/src/Domain/use_cases/UnJoinFromTheDialogUseCase.ts +61 -0
  49. package/src/Presentation/Views/Dialog/useDialogViewModel.ts +46 -4
  50. package/src/Presentation/Views/DialogInfo/DialogInfo.tsx +36 -1
  51. package/src/Presentation/Views/DialogList/DialogListViewModel.ts +4 -1
  52. package/src/Presentation/Views/DialogList/useDialogListViewModel.ts +141 -12
  53. package/src/Presentation/Views/EditDialog/EditDialog.scss +18 -0
  54. package/src/Presentation/Views/EditDialog/EditDialog.tsx +10 -1
  55. package/src/Presentation/Views/Flow/CreateDialogFlow/CreateNewDialogFlow.tsx +25 -10
  56. package/src/Presentation/layouts/Desktop/DesktopLayout.scss +7 -0
  57. package/src/Presentation/ui-components/Header/Header.scss +7 -0
  58. package/src/QBconfig.ts +2 -0
  59. package/src/qb-api-calls/index.ts +88 -42
  60. package/storybook-static/{217.07d5c7a3.iframe.bundle.js → 217.f067a49f.iframe.bundle.js} +3 -3
  61. package/storybook-static/{217.07d5c7a3.iframe.bundle.js.map → 217.f067a49f.iframe.bundle.js.map} +1 -1
  62. package/storybook-static/{363.a2d33b79.iframe.bundle.js → 363.f6fcc1b9.iframe.bundle.js} +2 -2
  63. package/storybook-static/844.be4346f2.iframe.bundle.js +95 -0
  64. package/storybook-static/844.be4346f2.iframe.bundle.js.map +1 -0
  65. package/storybook-static/Presentation-ui-components-DialogWindow-DialogWindow-stories.46997cb0.iframe.bundle.js +2 -0
  66. package/storybook-static/Presentation-ui-components-Header-Header-stories.a4edfcc6.iframe.bundle.js +2 -0
  67. package/storybook-static/{Presentation-ui-components-MessageInput-MessageInput-stories.9b4b2514.iframe.bundle.js → Presentation-ui-components-MessageInput-MessageInput-stories.2af0de55.iframe.bundle.js} +1 -1
  68. package/storybook-static/docs-Introduction-mdx.46ed11c4.iframe.bundle.js +1 -0
  69. package/storybook-static/docs-Styling-mdx.3a86be03.iframe.bundle.js +1 -0
  70. package/storybook-static/iframe.html +2 -2
  71. package/storybook-static/project.json +1 -1
  72. package/storybook-static/{runtime~main.940703c6.iframe.bundle.js → runtime~main.ebabbef9.iframe.bundle.js} +1 -1
  73. package/storybook-static/sb-addons/essentials-backgrounds-5/manager-bundle.js +1 -1
  74. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +8 -8
  75. package/storybook-static/sb-addons/essentials-docs-4/manager-bundle.js +4 -4
  76. package/storybook-static/sb-addons/essentials-measure-8/manager-bundle.js +1 -1
  77. package/storybook-static/sb-addons/essentials-outline-9/manager-bundle.js +1 -1
  78. package/storybook-static/sb-addons/essentials-viewport-6/manager-bundle.js +1 -1
  79. package/storybook-static/sb-addons/interactions-11/manager-bundle.js +1 -1
  80. package/storybook-static/sb-addons/onboarding-1/manager-bundle.js +1 -1
  81. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  82. package/storybook-static/sb-manager/globals-runtime.js +10372 -9836
  83. package/storybook-static/sb-manager/runtime.js +119 -119
  84. package/webpack.app.config.js +3 -3
  85. package/storybook-static/844.e8bfd664.iframe.bundle.js +0 -95
  86. package/storybook-static/844.e8bfd664.iframe.bundle.js.map +0 -1
  87. package/storybook-static/Presentation-ui-components-DialogWindow-DialogWindow-stories.a724643f.iframe.bundle.js +0 -2
  88. package/storybook-static/Presentation-ui-components-Header-Header-stories.978f0af5.iframe.bundle.js +0 -2
  89. package/storybook-static/docs-Introduction-mdx.5addfa61.iframe.bundle.js +0 -1
  90. package/storybook-static/docs-Styling-mdx.9f4235f1.iframe.bundle.js +0 -1
  91. /package/storybook-static/{217.07d5c7a3.iframe.bundle.js.LICENSE.txt → 217.f067a49f.iframe.bundle.js.LICENSE.txt} +0 -0
  92. /package/storybook-static/{363.a2d33b79.iframe.bundle.js.LICENSE.txt → 363.f6fcc1b9.iframe.bundle.js.LICENSE.txt} +0 -0
  93. /package/storybook-static/{844.e8bfd664.iframe.bundle.js.LICENSE.txt → 844.be4346f2.iframe.bundle.js.LICENSE.txt} +0 -0
  94. /package/storybook-static/{Presentation-ui-components-DialogWindow-DialogWindow-stories.a724643f.iframe.bundle.js.LICENSE.txt → Presentation-ui-components-DialogWindow-DialogWindow-stories.46997cb0.iframe.bundle.js.LICENSE.txt} +0 -0
  95. /package/storybook-static/{Presentation-ui-components-Header-Header-stories.978f0af5.iframe.bundle.js.LICENSE.txt → Presentation-ui-components-Header-Header-stories.a4edfcc6.iframe.bundle.js.LICENSE.txt} +0 -0
@@ -64,6 +64,8 @@ import {
64
64
  QBUsersGetById,
65
65
  setQB,
66
66
  getQB,
67
+ QBCreateGroupDialogWithAutojoinFalse,
68
+ QBLeaveDialog,
67
69
  } from '../../../qb-api-calls';
68
70
  import { UserDTOMapper } from './Mapper/UserDTOMapper';
69
71
  import { MessageDTOMapper } from './Mapper/MessageDTOMapper';
@@ -184,7 +186,9 @@ export class RemoteDataSource implements IRemoteDataSource {
184
186
  let hasMoreUsers = true;
185
187
 
186
188
  while (hasMoreUsers) {
187
- const { ResultData, PaginationResult } = await this.getAllUsers(pagination);
189
+ const { ResultData, PaginationResult } = await this.getAllUsers(
190
+ pagination,
191
+ );
188
192
 
189
193
  for (const user of ResultData) {
190
194
  if (!this.userCache.has(user.id)) {
@@ -192,14 +196,18 @@ export class RemoteDataSource implements IRemoteDataSource {
192
196
  }
193
197
  }
194
198
 
195
- if (PaginationResult.getCurrentPage() >= PaginationResult.totalPages) {
199
+ if (
200
+ PaginationResult.getCurrentPage() >= PaginationResult.totalPages
201
+ ) {
196
202
  hasMoreUsers = false;
197
203
  } else {
198
204
  pagination.setCurrentPage(pagination.getCurrentPage() + 1);
199
205
  }
200
206
  }
201
207
 
202
- console.log(`User cache preload complete. Loaded ${this.userCache.size} users.`);
208
+ console.log(
209
+ `User cache preload complete. Loaded ${this.userCache.size} users.`,
210
+ );
203
211
 
204
212
  clearInterval(this.userCachePreloadInterval!);
205
213
  this.userCachePreloadInterval = null;
@@ -890,19 +898,30 @@ export class RemoteDataSource implements IRemoteDataSource {
890
898
  //get dialogs flow
891
899
 
892
900
  private async joinGroupDialog(dialogId: string): Promise<void> {
893
- try {
894
- await QBJoinGroupDialog(dialogId).catch(() => {
895
- this.joinStatusMap.set(dialogId, false);
896
- throw new RemoteDataSourceException(
897
- INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_MESSAGE,
898
- INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_CODE,
899
- );
900
- });
901
- this.joinStatusMap.set(dialogId, true);
902
- } catch (reason) {
903
- console.log(`QBJoinGroupDialog error for dialog ${dialogId}:`, reason);
901
+ // try {
902
+ // await QBJoinGroupDialog(dialogId).catch(() => {
903
+ // this.joinStatusMap.set(dialogId, false);
904
+ // throw new RemoteDataSourceException(
905
+ // INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_MESSAGE,
906
+ // INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_CODE,
907
+ // );
908
+ // });
909
+ // this.joinStatusMap.set(dialogId, true);
910
+ // } catch (reason) {
911
+ // console.log(`QBJoinGroupDialog error for dialog ${dialogId}:`, reason);
912
+ // this.joinStatusMap.set(dialogId, false);
913
+ // }
914
+ }
915
+
916
+ public async joinDialog(dialogDto: RemoteDialogDTO): Promise<void> {
917
+ const dialogId = dialogDto.id;
918
+ await QBJoinGroupDialog(dialogId).catch(() => {
904
919
  this.joinStatusMap.set(dialogId, false);
905
- }
920
+ throw new RemoteDataSourceException(
921
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_MESSAGE,
922
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_CODE,
923
+ );
924
+ });
906
925
  }
907
926
 
908
927
  //version 0.5.0-beta.11,12,14
@@ -929,7 +948,9 @@ export class RemoteDataSource implements IRemoteDataSource {
929
948
  private async processDialogsInBackground(dialogIds: string[]): Promise<void> {
930
949
  const BATCH_SIZE = 12;
931
950
 
932
- console.log(`Starting background processing for ${dialogIds.length} dialogs`);
951
+ console.log(
952
+ `Starting background processing for ${dialogIds.length} dialogs`,
953
+ );
933
954
 
934
955
  for (let i = 0; i < dialogIds.length; i += BATCH_SIZE) {
935
956
  const batch = dialogIds.slice(i, i + BATCH_SIZE);
@@ -955,7 +976,7 @@ export class RemoteDataSource implements IRemoteDataSource {
955
976
  const pageNumber = currentPagination.getCurrentPage() || 1;
956
977
  const perPage = currentPagination.perPage || 100;
957
978
 
958
- const params: Dictionary<any> = {
979
+ const params: Dictionary<any> = {
959
980
  created_at: { lt: Date.now() / 1000 },
960
981
  sort_desc: 'updated_at',
961
982
  page: pageNumber,
@@ -983,9 +1004,13 @@ export class RemoteDataSource implements IRemoteDataSource {
983
1004
  const qbEntity: QBChatDialog = item;
984
1005
  if (!qbEntity) continue;
985
1006
 
986
- const newDTO: RemoteDialogDTO = await this.getCurrentDialogDTOMapper().toTDO(qbEntity);
1007
+ const newDTO: RemoteDialogDTO =
1008
+ await this.getCurrentDialogDTOMapper().toTDO(qbEntity);
987
1009
 
988
- if (newDTO.type === DialogType.group && !this.processedDialogs.has(newDTO.id)) {
1010
+ if (
1011
+ newDTO.type === DialogType.group &&
1012
+ !this.processedDialogs.has(newDTO.id)
1013
+ ) {
989
1014
  this.processedDialogs.add(newDTO.id);
990
1015
 
991
1016
  if (!this.joinStatusMap.has(newDTO.id)) {
@@ -1250,6 +1275,54 @@ export class RemoteDataSource implements IRemoteDataSource {
1250
1275
  return Promise.resolve(newDTO);
1251
1276
  }
1252
1277
 
1278
+ async createDialogWithAutojoin(
1279
+ dto: RemoteDialogDTO,
1280
+ ): Promise<RemoteDialogDTO> {
1281
+ console.log(
1282
+ 'call createDialogWithAutoJoin in remote with params: ',
1283
+ JSON.stringify(dto),
1284
+ );
1285
+ const qbEntity: QBChatDialog =
1286
+ await this.getCurrentDialogDTOMapper().fromDTO(dto);
1287
+
1288
+ let qbDialog: QBChatDialog | undefined | null;
1289
+
1290
+ if (qbEntity.type === DialogType.private) {
1291
+ const participantId = qbEntity.occupants_ids[0];
1292
+
1293
+ qbDialog = await QBCreatePrivateDialog(participantId, qbEntity.name);
1294
+ } else if (qbEntity.type === DialogType.group) {
1295
+ const participants = qbEntity.occupants_ids;
1296
+
1297
+ const data = { photo: qbEntity.photo };
1298
+
1299
+ qbDialog = await QBCreateGroupDialogWithAutojoinFalse(
1300
+ participants,
1301
+ qbEntity.name,
1302
+ data,
1303
+ );
1304
+ }
1305
+
1306
+ if (qbDialog === null || qbDialog === undefined) {
1307
+ return Promise.reject(
1308
+ new RemoteDataSourceException(
1309
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_MESSAGE,
1310
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_CODE,
1311
+ ),
1312
+ );
1313
+ }
1314
+
1315
+ const newDTO: RemoteDialogDTO =
1316
+ await this.getCurrentDialogDTOMapper().toTDO(qbDialog);
1317
+
1318
+ console.log(
1319
+ 'have result in createDialog in remote ds: ',
1320
+ JSON.stringify(newDTO),
1321
+ );
1322
+
1323
+ return Promise.resolve(newDTO);
1324
+ }
1325
+
1253
1326
  async updateDialog(dto: RemoteDialogDTO): Promise<RemoteDialogDTO> {
1254
1327
  const qbEntity: QBUIKitChatDialog =
1255
1328
  await this.getCurrentDialogDTOMapper().fromDTO(dto);
@@ -1370,6 +1443,24 @@ export class RemoteDataSource implements IRemoteDataSource {
1370
1443
  return Promise.resolve();
1371
1444
  }
1372
1445
 
1446
+ async unjoinUsersFromDialog(dialogDTO: RemoteDialogDTO): Promise<void> {
1447
+ const qbEntity: QBChatDialog =
1448
+ await this.getCurrentDialogDTOMapper().fromDTO(dialogDTO);
1449
+
1450
+ const qbResult = await QBLeaveDialog(qbEntity._id);
1451
+
1452
+ if (qbResult === null || qbResult === undefined) {
1453
+ return Promise.reject(
1454
+ new RemoteDataSourceException(
1455
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_MESSAGE,
1456
+ INCORRECT_REMOTE_DATASOURCE_DATA_EXCEPTION_CODE,
1457
+ ),
1458
+ );
1459
+ }
1460
+
1461
+ return Promise.resolve();
1462
+ }
1463
+
1373
1464
  // async getUser(dto: RemoteUserDTO): Promise<RemoteUserDTO> {
1374
1465
  // const currentItem: QBUser | undefined = await QBUsersGetById(
1375
1466
  // parseInt(dto.id, 10),
@@ -1582,9 +1673,7 @@ export class RemoteDataSource implements IRemoteDataSource {
1582
1673
  ),
1583
1674
  );
1584
1675
  }
1585
- console.log(
1586
- `GET MESSAGES ${qbMessages.items.length} FROM SERVER.`,
1587
- );
1676
+ console.log(`GET MESSAGES ${qbMessages.items.length} FROM SERVER.`);
1588
1677
  const currentUserId = this._authInformation?.userId;
1589
1678
 
1590
1679
  await Promise.all(
@@ -1665,46 +1754,46 @@ export class RemoteDataSource implements IRemoteDataSource {
1665
1754
  //
1666
1755
  const messageText = dto.message;
1667
1756
 
1668
- const extension: Partial<QBUIKitChatNewMessage['extension']> = {
1669
- save_to_history: 1,
1670
- dialog_id: dto.dialogId,
1671
- };
1672
-
1673
- if (dto.notification_type) {
1674
- extension.notification_type = dto.notification_type;
1675
- }
1676
-
1677
- if (dto.sender_id || dto.recipient_id) {
1678
- extension.sender_id = dto.sender_id || dto.recipient_id;
1679
- }
1757
+ const extension: Partial<QBUIKitChatNewMessage['extension']> = {
1758
+ save_to_history: 1,
1759
+ dialog_id: dto.dialogId,
1760
+ };
1680
1761
 
1681
- if (dto.qb_message_action) {
1682
- extension.qb_message_action = dto.qb_message_action;
1683
- }
1762
+ if (dto.notification_type) {
1763
+ extension.notification_type = dto.notification_type;
1764
+ }
1684
1765
 
1685
- if (dto.origin_sender_name) {
1686
- extension.origin_sender_name = dto.origin_sender_name;
1687
- }
1766
+ if (dto.sender_id || dto.recipient_id) {
1767
+ extension.sender_id = dto.sender_id || dto.recipient_id;
1768
+ }
1688
1769
 
1689
- const originalMessages = MessageDTOMapper.translateOriginalDataToJSON(
1690
- MessageDTOMapper.convertToQBChatNewMessage(dto.qb_original_messages || []) || [],
1691
- );
1770
+ if (dto.qb_message_action) {
1771
+ extension.qb_message_action = dto.qb_message_action;
1772
+ }
1692
1773
 
1693
- if (originalMessages && originalMessages.length > 0) {
1694
- extension.qb_original_messages = originalMessages;
1695
- }
1774
+ if (dto.origin_sender_name) {
1775
+ extension.origin_sender_name = dto.origin_sender_name;
1776
+ }
1696
1777
 
1778
+ const originalMessages = MessageDTOMapper.translateOriginalDataToJSON(
1779
+ MessageDTOMapper.convertToQBChatNewMessage(
1780
+ dto.qb_original_messages || [],
1781
+ ) || [],
1782
+ );
1697
1783
 
1698
- const qbEntity: QBUIKitChatNewMessage = {
1699
- type: dto.dialog_type === DialogType.private ? 'chat' : 'groupchat',
1700
- body: messageText || '',
1701
- dialog_id: dto.dialogId,
1702
- extension: extension as QBUIKitChatNewMessage['extension'],
1703
- markable: 1,
1704
- };
1784
+ if (originalMessages && originalMessages.length > 0) {
1785
+ extension.qb_original_messages = originalMessages;
1786
+ }
1705
1787
 
1788
+ const qbEntity: QBUIKitChatNewMessage = {
1789
+ type: dto.dialog_type === DialogType.private ? 'chat' : 'groupchat',
1790
+ body: messageText || '',
1791
+ dialog_id: dto.dialogId,
1792
+ extension: extension as QBUIKitChatNewMessage['extension'],
1793
+ markable: 1,
1794
+ };
1706
1795
 
1707
- // const qbEntity: QBUIKitChatNewMessage = {
1796
+ // const qbEntity: QBUIKitChatNewMessage = {
1708
1797
  // type: dto.dialog_type === DialogType.private ? 'chat' : 'groupchat',
1709
1798
  // body: messageText || '',
1710
1799
  // notification_type: dto.notification_type,
@@ -1736,13 +1825,13 @@ export class RemoteDataSource implements IRemoteDataSource {
1736
1825
  // type: att.type.toString(),
1737
1826
  // uid: att.uid,
1738
1827
  // };
1739
- const chatMessageAttachment: ChatMessageAttachment = {
1740
- id: att.id?.toString(),
1741
- name: att.name?.toString(),
1742
- size: att.size?.toString(),
1743
- type: att.type?.toString(),
1744
- uid: att.uid?.toString(),
1745
- };
1828
+ const chatMessageAttachment: ChatMessageAttachment = {
1829
+ id: att.id?.toString(),
1830
+ name: att.name?.toString(),
1831
+ size: att.size?.toString(),
1832
+ type: att.type?.toString(),
1833
+ uid: att.uid?.toString(),
1834
+ };
1746
1835
 
1747
1836
  qbEntity.extension.attachments?.push(chatMessageAttachment);
1748
1837
  });
@@ -1767,13 +1856,22 @@ export class RemoteDataSource implements IRemoteDataSource {
1767
1856
  const dialogJid = QB.chat.helpers.getRoomJidFromDialogId(dto.dialogId);
1768
1857
  try {
1769
1858
  qbMessageId = await QBChatSendMessage(dialogJid, qbEntity);
1770
- console.log(`Dialog joined status is ${this.joinStatusMap.has(dto.dialogId)} and message was sent with Id: ${qbMessageId}`);
1771
- }catch (e) {
1859
+ console.log(
1860
+ `Dialog joined status is ${this.joinStatusMap.has(
1861
+ dto.dialogId,
1862
+ )} and message was sent with Id: ${qbMessageId}`,
1863
+ );
1864
+ } catch (e) {
1772
1865
  qbMessageId = undefined;
1773
- const errorMessage = `Error in DataSource: send message throw: ${stringifyError(e)}`;
1866
+ const errorMessage = `Error in DataSource: send message throw: ${stringifyError(
1867
+ e,
1868
+ )}`;
1774
1869
  console.log('Error in DataSource: send message throw: ', errorMessage);
1775
1870
  console.warn('Error in DataSource: send message throw: ', errorMessage);
1776
- console.error('Error in DataSource: send message throw: ', errorMessage);
1871
+ console.error(
1872
+ 'Error in DataSource: send message throw: ',
1873
+ errorMessage,
1874
+ );
1777
1875
  }
1778
1876
  }
1779
1877
 
@@ -7,6 +7,8 @@ export interface IDialogsRepository {
7
7
 
8
8
  createDialogInRemote(dialog: DialogEntity): Promise<DialogEntity>;
9
9
 
10
+ createDialogWithAutojoinInRemote(dialog: DialogEntity): Promise<DialogEntity>;
11
+
10
12
  updateDialogInLocal(dialog: DialogEntity): Promise<DialogEntity>;
11
13
 
12
14
  updateDialogInRemote(dialog: DialogEntity): Promise<DialogEntity>;
@@ -30,6 +32,14 @@ export interface IDialogsRepository {
30
32
  userIds: Array<number>,
31
33
  ): Promise<boolean>;
32
34
 
35
+ unjoinUsersFromDialog(
36
+ dialogId: string,
37
+ ): Promise<boolean>;
38
+
39
+ joinUsersFromDialog(
40
+ dialogId: string,
41
+ ): Promise<boolean>;
42
+
33
43
  subscribeLocalSync(subscriber: FunctionTypeVoidToVoid): void;
34
44
 
35
45
  unsubscribeLocalSync(): void;
@@ -0,0 +1,77 @@
1
+ import { DialogEntity } from '../entity/DialogEntity';
2
+ import DialogsRepository from '../../Data/repository/DialogsRepository';
3
+ import { IUseCase } from './base/IUseCase';
4
+ import { GroupDialogEntity } from '../entity/GroupDialogEntity';
5
+ import { stringifyError } from '../../utils/parse';
6
+ import { RemoteMessageDTO } from '../../Data/dto/message/RemoteMessageDTO';
7
+ import { NotificationTypes } from '../entity/NotificationTypes';
8
+ import EventMessagesRepository from '../../Data/repository/EventMessagesRepository';
9
+ import EventMessageType from '../entity/EventMessageType';
10
+
11
+ export class CreateDialogWithAutoJoinUseCase implements IUseCase<void, DialogEntity> {
12
+ private dialogRepository: DialogsRepository;
13
+
14
+ private eventMessagesRepository: EventMessagesRepository;
15
+
16
+ private newDialog: GroupDialogEntity;
17
+
18
+ private textInformationMessage: string;
19
+
20
+ constructor(
21
+ eventMessagesRepository: EventMessagesRepository,
22
+ dialogRepository: DialogsRepository,
23
+ newDialog: GroupDialogEntity,
24
+ textInformationMessage: string,
25
+ ) {
26
+ this.dialogRepository = dialogRepository;
27
+ this.newDialog = newDialog;
28
+ this.eventMessagesRepository = eventMessagesRepository;
29
+ this.textInformationMessage = textInformationMessage;
30
+ }
31
+
32
+ async execute(): Promise<DialogEntity> {
33
+ console.log('execute CreateDialogWithAutoJoinUseCase', JSON.stringify(this.newDialog));
34
+ const result: DialogEntity = await this.dialogRepository
35
+ .createDialogWithAutojoinInRemote(this.newDialog)
36
+ .catch((e) => {
37
+ const message = stringifyError(e);
38
+
39
+ console.log('EXCEPTION IN CREATE DIALOG WITH AUTO JOIN USE CASE', message);
40
+ throw Error(message);
41
+ });
42
+
43
+ await this.dialogRepository.saveDialogToLocal(result);
44
+
45
+ this.eventMessagesRepository.dispatchEvent<DialogEntity>(
46
+ EventMessageType.LocalMessage,
47
+ result,
48
+ [],
49
+ );
50
+ const remoteMessageDTO: RemoteMessageDTO = new RemoteMessageDTO();
51
+
52
+ remoteMessageDTO.dialogId = result.id;
53
+ remoteMessageDTO.notification_type = NotificationTypes.NEW_DIALOG;
54
+
55
+ this.eventMessagesRepository.dispatchEvent<RemoteMessageDTO>(
56
+ EventMessageType.SystemMessage,
57
+ remoteMessageDTO,
58
+ [...this.newDialog.participantIds],
59
+ );
60
+
61
+ remoteMessageDTO.dialogId = result.id;
62
+ remoteMessageDTO.notification_type = NotificationTypes.NEW_DIALOG;
63
+ remoteMessageDTO.date_sent = Date.now() / 1000;
64
+ remoteMessageDTO.message =
65
+ this.textInformationMessage && this.textInformationMessage.length > 0
66
+ ? this.textInformationMessage
67
+ : `User ${this.newDialog.ownerId} create new dialog ${this.newDialog.name}`;
68
+
69
+ this.eventMessagesRepository.dispatchEvent<RemoteMessageDTO>(
70
+ EventMessageType.RegularMessage,
71
+ remoteMessageDTO,
72
+ [...this.newDialog.participantIds],
73
+ );
74
+
75
+ return Promise.resolve(result);
76
+ }
77
+ }
@@ -0,0 +1,61 @@
1
+ import { IUseCase } from './base/IUseCase';
2
+ import DialogsRepository from '../../Data/repository/DialogsRepository';
3
+ import EventMessagesRepository from '../../Data/repository/EventMessagesRepository';
4
+ import { DialogEntity } from '../entity/DialogEntity';
5
+ import { RemoteMessageDTO } from '../../Data/dto/message/RemoteMessageDTO';
6
+ import { DialogType } from '../entity/DialogTypes';
7
+ import { GroupDialogEntity } from '../entity/GroupDialogEntity';
8
+ import { PrivateDialogEntity } from '../entity/PrivateDialogEntity';
9
+ import { NotificationTypes } from '../entity/NotificationTypes';
10
+ import EventMessageType from '../entity/EventMessageType';
11
+ import { stringifyError } from '../../utils/parse';
12
+
13
+ export class JoinFromTheDialogUseCase
14
+ implements IUseCase<void, boolean>
15
+ {
16
+ private dialogRepository: DialogsRepository;
17
+
18
+ private eventMessagesRepository: EventMessagesRepository;
19
+
20
+ private dialogToLeave: DialogEntity;
21
+
22
+ constructor(
23
+ eventMessagesRepository: EventMessagesRepository,
24
+ dialogRepository: DialogsRepository,
25
+ dialog: DialogEntity,
26
+ ) {
27
+ this.eventMessagesRepository = eventMessagesRepository;
28
+ this.dialogRepository = dialogRepository;
29
+ this.dialogToLeave = dialog;
30
+ }
31
+
32
+ async execute(): Promise<boolean> {
33
+ console.log('execute JoinFromTheDialogUseCase');
34
+ let resultOperation = false;
35
+
36
+ const remoteMessageDTO: RemoteMessageDTO = new RemoteMessageDTO();
37
+
38
+ remoteMessageDTO.dialogId = this.dialogToLeave.id;
39
+ remoteMessageDTO.notification_type = NotificationTypes.DELETE_LEAVE_DIALOG;
40
+ remoteMessageDTO.date_sent = Date.now();
41
+
42
+ await this.dialogRepository
43
+ .joinUsersFromDialog(this.dialogToLeave.id)
44
+ .then(() => {
45
+ resultOperation = true;
46
+ console.log('join to Dialog successes');
47
+
48
+ return resultOperation;
49
+ })
50
+ .catch((reason) => {
51
+ console.log(
52
+ 'have exception in delete users from Dialog : ',
53
+ stringifyError(reason),
54
+ );
55
+ resultOperation = false;
56
+ });
57
+
58
+
59
+ return resultOperation;
60
+ }
61
+ }
@@ -0,0 +1,61 @@
1
+ import { IUseCase } from './base/IUseCase';
2
+ import DialogsRepository from '../../Data/repository/DialogsRepository';
3
+ import EventMessagesRepository from '../../Data/repository/EventMessagesRepository';
4
+ import { DialogEntity } from '../entity/DialogEntity';
5
+ import { RemoteMessageDTO } from '../../Data/dto/message/RemoteMessageDTO';
6
+ import { DialogType } from '../entity/DialogTypes';
7
+ import { GroupDialogEntity } from '../entity/GroupDialogEntity';
8
+ import { PrivateDialogEntity } from '../entity/PrivateDialogEntity';
9
+ import { NotificationTypes } from '../entity/NotificationTypes';
10
+ import EventMessageType from '../entity/EventMessageType';
11
+ import { stringifyError } from '../../utils/parse';
12
+
13
+ export class UnJoinFromTheDialogUseCase
14
+ implements IUseCase<void, boolean>
15
+ {
16
+ private dialogRepository: DialogsRepository;
17
+
18
+ private eventMessagesRepository: EventMessagesRepository;
19
+
20
+ private dialogToLeave: DialogEntity;
21
+
22
+ constructor(
23
+ eventMessagesRepository: EventMessagesRepository,
24
+ dialogRepository: DialogsRepository,
25
+ dialog: DialogEntity,
26
+ ) {
27
+ this.eventMessagesRepository = eventMessagesRepository;
28
+ this.dialogRepository = dialogRepository;
29
+ this.dialogToLeave = dialog;
30
+ }
31
+
32
+ async execute(): Promise<boolean> {
33
+ console.log('execute UnJoinFromTheDialogUseCase');
34
+ let resultOperation = false;
35
+
36
+ const remoteMessageDTO: RemoteMessageDTO = new RemoteMessageDTO();
37
+
38
+ remoteMessageDTO.dialogId = this.dialogToLeave.id;
39
+ remoteMessageDTO.notification_type = NotificationTypes.DELETE_LEAVE_DIALOG;
40
+ remoteMessageDTO.date_sent = Date.now();
41
+
42
+ await this.dialogRepository
43
+ .unjoinUsersFromDialog(this.dialogToLeave.id)
44
+ .then(() => {
45
+ resultOperation = true;
46
+ console.log('Leave from Dialog successes');
47
+
48
+ return resultOperation;
49
+ })
50
+ .catch((reason) => {
51
+ console.log(
52
+ 'have exception in leave Dialog : ',
53
+ stringifyError(reason),
54
+ );
55
+ resultOperation = false;
56
+ });
57
+
58
+
59
+ return resultOperation;
60
+ }
61
+ }
@@ -184,11 +184,20 @@ export default function useDialogViewModel(
184
184
  setError((e as unknown as Error).message);
185
185
  });
186
186
 
187
- //
188
-
189
187
  const senderIds = Array.from(
190
- new Set(messagesDialog.map((msg) => msg.sender_id)),
188
+ new Set(
189
+ messagesDialog.flatMap((msg) => {
190
+ const ids = [msg.sender_id];
191
+
192
+ if (Array.isArray(msg.qb_original_messages) && msg.qb_original_messages.length > 0) {
193
+ ids.push(msg.qb_original_messages[0].sender_id);
194
+ }
195
+
196
+ return ids;
197
+ })
198
+ )
191
199
  );
200
+
192
201
  const missingSenderIds = senderIds.filter((id) => !(id in userDictionary));
193
202
 
194
203
  const getMissingSenderUsersFromDialogByIdsUseCase: GetUsersByIdsUseCase =
@@ -426,7 +435,10 @@ export default function useDialogViewModel(
426
435
  userTypingMessageUseCase.execute().catch((reason) => {
427
436
  const errorMessage: string = stringifyError(reason);
428
437
 
429
- console.log('Error: have exception in sendTypingTextMessage: ', errorMessage);
438
+ console.log(
439
+ 'Error: have exception in sendTypingTextMessage: ',
440
+ errorMessage,
441
+ );
430
442
  });
431
443
  };
432
444
 
@@ -684,6 +696,8 @@ export default function useDialogViewModel(
684
696
  relatedMessage: MessageEntity,
685
697
  ): Promise<void> => {
686
698
  //
699
+ const senderRepliedMessage = messagesToReply[0].sender;
700
+
687
701
  const replyMessagesUseCase: ReplyMessagesUseCase = new ReplyMessagesUseCase(
688
702
  new MessagesRepository(LOCAL_DATA_SOURCE, REMOTE_DATA_SOURCE),
689
703
  messagesToReply,
@@ -705,8 +719,36 @@ export default function useDialogViewModel(
705
719
  })
706
720
  .finally(() => {
707
721
  setMessages((prevState) => {
722
+
723
+ if (messageEntity.qb_original_messages) {
724
+ const nestedObj = messageEntity.qb_original_messages
725
+
726
+ if (nestedObj && nestedObj.length > 0) {
727
+ nestedObj[0].sender = senderRepliedMessage;
728
+ if (
729
+ nestedObj[0].sender &&
730
+ nestedObj[0].sender.full_name &&
731
+ regex &&
732
+ !regex.test(nestedObj[0].sender.full_name)
733
+ ) {
734
+ nestedObj[0].sender.full_name = 'Unknown';
735
+ }
736
+ messageEntity.qb_original_messages = nestedObj
737
+ }
738
+ }
739
+
740
+ if (
741
+ messageEntity.sender &&
742
+ messageEntity.sender.full_name &&
743
+ regex &&
744
+ !regex.test(messageEntity.sender.full_name)
745
+ ) {
746
+ messageEntity.sender.full_name = 'Unknown';
747
+ }
748
+
708
749
  const newState = [...prevState, messageEntity];
709
750
 
751
+
710
752
  return newState;
711
753
  });
712
754
  });