stream-chat-react-native-core 5.27.0-beta.11 → 5.27.0-beta.12

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 (81) hide show
  1. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js +100 -37
  2. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js.map +1 -1
  3. package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js +3 -1
  4. package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js.map +1 -1
  5. package/lib/commonjs/i18n/en.json +1 -1
  6. package/lib/commonjs/i18n/es.json +43 -43
  7. package/lib/commonjs/i18n/fr.json +43 -43
  8. package/lib/commonjs/i18n/he.json +43 -43
  9. package/lib/commonjs/i18n/hi.json +43 -43
  10. package/lib/commonjs/i18n/it.json +43 -43
  11. package/lib/commonjs/i18n/ja.json +42 -42
  12. package/lib/commonjs/i18n/ko.json +42 -42
  13. package/lib/commonjs/i18n/nl.json +42 -42
  14. package/lib/commonjs/i18n/pt-BR.json +42 -42
  15. package/lib/commonjs/i18n/ru.json +42 -42
  16. package/lib/commonjs/i18n/tr.json +42 -42
  17. package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js +21 -0
  18. package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js.map +1 -0
  19. package/lib/commonjs/store/mappers/mapChannelToStorable.js +63 -0
  20. package/lib/commonjs/store/mappers/mapChannelToStorable.js.map +1 -0
  21. package/lib/commonjs/utils/DBSyncManager.js +73 -68
  22. package/lib/commonjs/utils/DBSyncManager.js.map +1 -1
  23. package/lib/commonjs/version.json +1 -1
  24. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js +100 -37
  25. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js.map +1 -1
  26. package/lib/module/components/Chat/hooks/useSyncDatabase.js +3 -1
  27. package/lib/module/components/Chat/hooks/useSyncDatabase.js.map +1 -1
  28. package/lib/module/i18n/en.json +1 -1
  29. package/lib/module/i18n/es.json +43 -43
  30. package/lib/module/i18n/fr.json +43 -43
  31. package/lib/module/i18n/he.json +43 -43
  32. package/lib/module/i18n/hi.json +43 -43
  33. package/lib/module/i18n/it.json +43 -43
  34. package/lib/module/i18n/ja.json +42 -42
  35. package/lib/module/i18n/ko.json +42 -42
  36. package/lib/module/i18n/nl.json +42 -42
  37. package/lib/module/i18n/pt-BR.json +42 -42
  38. package/lib/module/i18n/ru.json +42 -42
  39. package/lib/module/i18n/tr.json +42 -42
  40. package/lib/module/store/apis/upsertChannelDataFromChannel.js +21 -0
  41. package/lib/module/store/apis/upsertChannelDataFromChannel.js.map +1 -0
  42. package/lib/module/store/mappers/mapChannelToStorable.js +63 -0
  43. package/lib/module/store/mappers/mapChannelToStorable.js.map +1 -0
  44. package/lib/module/utils/DBSyncManager.js +73 -68
  45. package/lib/module/utils/DBSyncManager.js.map +1 -1
  46. package/lib/module/version.json +1 -1
  47. package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts +4 -2
  48. package/lib/typescript/i18n/en.json +1 -1
  49. package/lib/typescript/i18n/es.json +43 -43
  50. package/lib/typescript/i18n/fr.json +43 -43
  51. package/lib/typescript/i18n/he.json +43 -43
  52. package/lib/typescript/i18n/hi.json +43 -43
  53. package/lib/typescript/i18n/it.json +43 -43
  54. package/lib/typescript/i18n/ja.json +42 -42
  55. package/lib/typescript/i18n/ko.json +42 -42
  56. package/lib/typescript/i18n/nl.json +42 -42
  57. package/lib/typescript/i18n/pt-BR.json +42 -42
  58. package/lib/typescript/i18n/ru.json +42 -42
  59. package/lib/typescript/i18n/tr.json +42 -42
  60. package/lib/typescript/store/apis/upsertChannelDataFromChannel.d.ts +6 -0
  61. package/lib/typescript/store/mappers/mapChannelToStorable.d.ts +4 -0
  62. package/lib/typescript/utils/DBSyncManager.d.ts +1 -1
  63. package/package.json +1 -1
  64. package/src/components/Chat/hooks/handleEventToSyncDB.ts +132 -46
  65. package/src/components/Chat/hooks/useSyncDatabase.ts +1 -1
  66. package/src/i18n/en.json +1 -1
  67. package/src/i18n/es.json +43 -43
  68. package/src/i18n/fr.json +43 -43
  69. package/src/i18n/he.json +43 -43
  70. package/src/i18n/hi.json +43 -43
  71. package/src/i18n/it.json +43 -43
  72. package/src/i18n/ja.json +42 -42
  73. package/src/i18n/ko.json +42 -42
  74. package/src/i18n/nl.json +42 -42
  75. package/src/i18n/pt-BR.json +42 -42
  76. package/src/i18n/ru.json +42 -42
  77. package/src/i18n/tr.json +42 -42
  78. package/src/store/apis/upsertChannelDataFromChannel.ts +25 -0
  79. package/src/store/mappers/mapChannelToStorable.ts +68 -0
  80. package/src/utils/DBSyncManager.ts +7 -3
  81. package/src/version.json +1 -1
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.upsertChannelDataFromChannel = void 0;
5
+ var _mapChannelToStorable = require("../mappers/mapChannelToStorable");
6
+ var _QuickSqliteClient = require("../QuickSqliteClient");
7
+ var _createUpsertQuery = require("../sqlite-utils/createUpsertQuery");
8
+ var upsertChannelDataFromChannel = function upsertChannelDataFromChannel(_ref) {
9
+ var channel = _ref.channel,
10
+ _ref$flush = _ref.flush,
11
+ flush = _ref$flush === void 0 ? true : _ref$flush;
12
+ var storableChannel = (0, _mapChannelToStorable.mapChannelToStorable)(channel);
13
+ if (!storableChannel) return;
14
+ var query = (0, _createUpsertQuery.createUpsertQuery)('channels', storableChannel);
15
+ if (flush) {
16
+ _QuickSqliteClient.QuickSqliteClient.executeSqlBatch([query]);
17
+ }
18
+ return [query];
19
+ };
20
+ exports.upsertChannelDataFromChannel = upsertChannelDataFromChannel;
21
+ //# sourceMappingURL=upsertChannelDataFromChannel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mapChannelToStorable","require","_QuickSqliteClient","_createUpsertQuery","upsertChannelDataFromChannel","_ref","channel","_ref$flush","flush","storableChannel","mapChannelToStorable","query","createUpsertQuery","QuickSqliteClient","executeSqlBatch","exports"],"sources":["upsertChannelDataFromChannel.ts"],"sourcesContent":["import { DefaultStreamChatGenerics } from 'src/types/types';\nimport type { Channel } from 'stream-chat';\n\nimport { mapChannelToStorable } from '../mappers/mapChannelToStorable';\nimport { QuickSqliteClient } from '../QuickSqliteClient';\nimport { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';\n\nexport const upsertChannelDataFromChannel = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n channel,\n flush = true,\n}: {\n channel: Channel<StreamChatGenerics>;\n flush?: boolean;\n}) => {\n const storableChannel = mapChannelToStorable(channel);\n if (!storableChannel) return;\n const query = createUpsertQuery('channels', storableChannel);\n if (flush) {\n QuickSqliteClient.executeSqlBatch([query]);\n }\n\n return [query];\n};\n"],"mappings":";;;;AAGA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AAEO,IAAMG,4BAA4B,GAAG,SAA/BA,4BAA4BA,CAAAC,IAAA,EAQnC;EAAA,IALJC,OAAO,GAAAD,IAAA,CAAPC,OAAO;IAAAC,UAAA,GAAAF,IAAA,CACPG,KAAK;IAALA,KAAK,GAAAD,UAAA,cAAG,IAAI,GAAAA,UAAA;EAKZ,IAAME,eAAe,GAAG,IAAAC,0CAAoB,EAACJ,OAAO,CAAC;EACrD,IAAI,CAACG,eAAe,EAAE;EACtB,IAAME,KAAK,GAAG,IAAAC,oCAAiB,EAAC,UAAU,EAAEH,eAAe,CAAC;EAC5D,IAAID,KAAK,EAAE;IACTK,oCAAiB,CAACC,eAAe,CAAC,CAACH,KAAK,CAAC,CAAC;EAC5C;EAEA,OAAO,CAACA,KAAK,CAAC;AAChB,CAAC;AAACI,OAAA,CAAAX,4BAAA,GAAAA,4BAAA"}
@@ -0,0 +1,63 @@
1
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.mapChannelToStorable = void 0;
6
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
7
+ var _mapDateTimeToStorable = require("./mapDateTimeToStorable");
8
+ var _excluded = ["auto_translation_enabled", "auto_translation_language", "cid", "config", "cooldown", "created_at", "deleted_at", "disabled", "frozen", "hidden", "id", "invites", "last_message_at", "member_count", "members", "muted", "own_capabilities", "team", "truncated_at", "truncated_by", "truncated_by_id", "type", "updated_at"];
9
+ var mapChannelToStorable = function mapChannelToStorable(channel) {
10
+ if (!channel.data) return;
11
+ var _ref = channel.data,
12
+ auto_translation_enabled = _ref.auto_translation_enabled,
13
+ auto_translation_language = _ref.auto_translation_language,
14
+ cid = _ref.cid,
15
+ config = _ref.config,
16
+ cooldown = _ref.cooldown,
17
+ created_at = _ref.created_at,
18
+ deleted_at = _ref.deleted_at,
19
+ disabled = _ref.disabled,
20
+ frozen = _ref.frozen,
21
+ hidden = _ref.hidden,
22
+ id = _ref.id,
23
+ invites = _ref.invites,
24
+ last_message_at = _ref.last_message_at,
25
+ member_count = _ref.member_count,
26
+ members = _ref.members,
27
+ muted = _ref.muted,
28
+ own_capabilities = _ref.own_capabilities,
29
+ team = _ref.team,
30
+ truncated_at = _ref.truncated_at,
31
+ truncated_by = _ref.truncated_by,
32
+ truncated_by_id = _ref.truncated_by_id,
33
+ type = _ref.type,
34
+ updated_at = _ref.updated_at,
35
+ extraData = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
36
+ return {
37
+ autoTranslationEnabled: auto_translation_enabled,
38
+ autoTranslationLanguage: auto_translation_language,
39
+ cid: cid,
40
+ config: config && JSON.stringify(config),
41
+ cooldown: cooldown,
42
+ createdAt: (0, _mapDateTimeToStorable.mapDateTimeToStorable)(created_at),
43
+ deletedAt: (0, _mapDateTimeToStorable.mapDateTimeToStorable)(deleted_at),
44
+ disabled: disabled,
45
+ extraData: JSON.stringify(extraData),
46
+ frozen: frozen,
47
+ hidden: hidden,
48
+ id: id,
49
+ invites: invites && JSON.stringify(invites),
50
+ lastMessageAt: (0, _mapDateTimeToStorable.mapDateTimeToStorable)(last_message_at),
51
+ memberCount: member_count,
52
+ muted: muted,
53
+ ownCapabilities: own_capabilities && JSON.stringify(own_capabilities),
54
+ team: team,
55
+ truncatedAt: truncated_at,
56
+ truncatedBy: truncated_by && JSON.stringify(truncated_by),
57
+ truncatedById: truncated_by_id,
58
+ type: type,
59
+ updatedAt: updated_at
60
+ };
61
+ };
62
+ exports.mapChannelToStorable = mapChannelToStorable;
63
+ //# sourceMappingURL=mapChannelToStorable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mapDateTimeToStorable","require","_excluded","mapChannelToStorable","channel","data","_ref","auto_translation_enabled","auto_translation_language","cid","config","cooldown","created_at","deleted_at","disabled","frozen","hidden","id","invites","last_message_at","member_count","members","muted","own_capabilities","team","truncated_at","truncated_by","truncated_by_id","type","updated_at","extraData","_objectWithoutProperties2","autoTranslationEnabled","autoTranslationLanguage","JSON","stringify","createdAt","mapDateTimeToStorable","deletedAt","lastMessageAt","memberCount","ownCapabilities","truncatedAt","truncatedBy","truncatedById","updatedAt","exports"],"sources":["mapChannelToStorable.ts"],"sourcesContent":["import type { Channel, ChannelResponse } from 'stream-chat';\n\nimport { mapDateTimeToStorable } from './mapDateTimeToStorable';\n\nimport type { DefaultStreamChatGenerics } from '../../types/types';\n\nimport type { TableRow } from '../types';\n\nexport const mapChannelToStorable = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n channel: Channel<StreamChatGenerics>,\n): TableRow<'channels'> | undefined => {\n if (!channel.data) return;\n const {\n auto_translation_enabled,\n auto_translation_language,\n cid,\n config,\n cooldown,\n created_at,\n deleted_at,\n disabled,\n frozen,\n hidden,\n id,\n invites,\n last_message_at,\n member_count,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n members,\n muted,\n own_capabilities,\n team,\n truncated_at,\n truncated_by,\n truncated_by_id,\n type,\n updated_at,\n ...extraData\n } = channel.data as unknown as ChannelResponse<StreamChatGenerics>;\n\n return {\n autoTranslationEnabled: auto_translation_enabled,\n autoTranslationLanguage: auto_translation_language,\n cid,\n config: config && JSON.stringify(config),\n cooldown,\n createdAt: mapDateTimeToStorable(created_at),\n deletedAt: mapDateTimeToStorable(deleted_at),\n disabled,\n extraData: JSON.stringify(extraData),\n frozen,\n hidden,\n id,\n invites: invites && JSON.stringify(invites),\n lastMessageAt: mapDateTimeToStorable(last_message_at),\n memberCount: member_count,\n muted,\n ownCapabilities: own_capabilities && JSON.stringify(own_capabilities),\n team,\n truncatedAt: truncated_at,\n truncatedBy: truncated_by && JSON.stringify(truncated_by),\n truncatedById: truncated_by_id,\n type,\n updatedAt: updated_at,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,sBAAA,GAAAC,OAAA;AAAgE,IAAAC,SAAA;AAMzD,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAG/BC,OAAoC,EACC;EACrC,IAAI,CAACA,OAAO,CAACC,IAAI,EAAE;EACnB,IAAAC,IAAA,GA0BIF,OAAO,CAACC,IAAI;IAzBdE,wBAAwB,GAAAD,IAAA,CAAxBC,wBAAwB;IACxBC,yBAAyB,GAAAF,IAAA,CAAzBE,yBAAyB;IACzBC,GAAG,GAAAH,IAAA,CAAHG,GAAG;IACHC,MAAM,GAAAJ,IAAA,CAANI,MAAM;IACNC,QAAQ,GAAAL,IAAA,CAARK,QAAQ;IACRC,UAAU,GAAAN,IAAA,CAAVM,UAAU;IACVC,UAAU,GAAAP,IAAA,CAAVO,UAAU;IACVC,QAAQ,GAAAR,IAAA,CAARQ,QAAQ;IACRC,MAAM,GAAAT,IAAA,CAANS,MAAM;IACNC,MAAM,GAAAV,IAAA,CAANU,MAAM;IACNC,EAAE,GAAAX,IAAA,CAAFW,EAAE;IACFC,OAAO,GAAAZ,IAAA,CAAPY,OAAO;IACPC,eAAe,GAAAb,IAAA,CAAfa,eAAe;IACf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EAAEjB,YAAY;IACzBkB,WAAW,EAAEjB,YAAY,IAAIQ,IAAI,CAACC,SAAS,CAACT,YAAY,CAAC;IACzDkB,aAAa,EAAEjB,eAAe;IAC9BC,IAAI,EAAJA,IAAI;IACJiB,SAAS,EAAEhB;EACb,CAAC;AACH,CAAC;AAACiB,OAAA,CAAA3C,oBAAA,GAAAA,oBAAA"}
@@ -105,73 +105,78 @@ DBSyncManager.onSyncStatusChange = function (listener) {
105
105
  }
106
106
  };
107
107
  };
108
- DBSyncManager.sync = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3() {
109
- var _DBSyncManager$client;
110
- var cids, lastSyncedAt, lastSyncedAtDate, lastSyncedAtDayJs, nowDayJs, diff, result, queries;
111
- return _regenerator["default"].wrap(function _callee3$(_context3) {
112
- while (1) switch (_context3.prev = _context3.next) {
113
- case 0:
114
- if ((_DBSyncManager$client = DBSyncManager.client) != null && _DBSyncManager$client.user) {
115
- _context3.next = 2;
116
- break;
117
- }
118
- return _context3.abrupt("return");
119
- case 2:
120
- cids = (0, _apis.getAllChannelIds)();
121
- if (!(cids.length === 0)) {
122
- _context3.next = 5;
123
- break;
124
- }
125
- return _context3.abrupt("return");
126
- case 5:
127
- lastSyncedAt = (0, _apis.getLastSyncedAt)({
128
- currentUserId: DBSyncManager.client.user.id
129
- });
130
- if (!lastSyncedAt) {
108
+ DBSyncManager.sync = function () {
109
+ var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3(client) {
110
+ var _DBSyncManager$client;
111
+ var cids, lastSyncedAt, lastSyncedAtDate, lastSyncedAtDayJs, nowDayJs, diff, result, queries;
112
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
113
+ while (1) switch (_context3.prev = _context3.next) {
114
+ case 0:
115
+ if ((_DBSyncManager$client = DBSyncManager.client) != null && _DBSyncManager$client.user) {
116
+ _context3.next = 2;
117
+ break;
118
+ }
119
+ return _context3.abrupt("return");
120
+ case 2:
121
+ cids = (0, _apis.getAllChannelIds)();
122
+ if (!(cids.length === 0)) {
123
+ _context3.next = 5;
124
+ break;
125
+ }
126
+ return _context3.abrupt("return");
127
+ case 5:
128
+ lastSyncedAt = (0, _apis.getLastSyncedAt)({
129
+ currentUserId: DBSyncManager.client.user.id
130
+ });
131
+ if (!lastSyncedAt) {
132
+ _context3.next = 26;
133
+ break;
134
+ }
135
+ lastSyncedAtDate = new Date(lastSyncedAt);
136
+ lastSyncedAtDayJs = (0, _dayjs["default"])(lastSyncedAtDate);
137
+ nowDayJs = (0, _dayjs["default"])();
138
+ diff = nowDayJs.diff(lastSyncedAtDayJs, 'days');
139
+ if (!(diff > 30)) {
140
+ _context3.next = 15;
141
+ break;
142
+ }
143
+ _QuickSqliteClient.QuickSqliteClient.resetDB();
131
144
  _context3.next = 26;
132
145
  break;
133
- }
134
- lastSyncedAtDate = new Date(lastSyncedAt);
135
- lastSyncedAtDayJs = (0, _dayjs["default"])(lastSyncedAtDate);
136
- nowDayJs = (0, _dayjs["default"])();
137
- diff = nowDayJs.diff(lastSyncedAtDayJs, 'days');
138
- if (!(diff > 30)) {
139
- _context3.next = 15;
146
+ case 15:
147
+ _context3.prev = 15;
148
+ _context3.next = 18;
149
+ return DBSyncManager.client.sync(cids, lastSyncedAtDate.toISOString());
150
+ case 18:
151
+ result = _context3.sent;
152
+ queries = result.events.reduce(function (queries, event) {
153
+ queries = queries.concat((0, _handleEventToSyncDB.handleEventToSyncDB)(event, client, false));
154
+ return queries;
155
+ }, []);
156
+ if (queries.length) {
157
+ _QuickSqliteClient.QuickSqliteClient.executeSqlBatch(queries);
158
+ }
159
+ _context3.next = 26;
140
160
  break;
141
- }
142
- _QuickSqliteClient.QuickSqliteClient.resetDB();
143
- _context3.next = 26;
144
- break;
145
- case 15:
146
- _context3.prev = 15;
147
- _context3.next = 18;
148
- return DBSyncManager.client.sync(cids, lastSyncedAtDate.toISOString());
149
- case 18:
150
- result = _context3.sent;
151
- queries = result.events.reduce(function (queries, event) {
152
- queries = queries.concat((0, _handleEventToSyncDB.handleEventToSyncDB)(event, false));
153
- return queries;
154
- }, []);
155
- if (queries.length) {
156
- _QuickSqliteClient.QuickSqliteClient.executeSqlBatch(queries);
157
- }
158
- _context3.next = 26;
159
- break;
160
- case 23:
161
- _context3.prev = 23;
162
- _context3.t0 = _context3["catch"](15);
163
- _QuickSqliteClient.QuickSqliteClient.resetDB();
164
- case 26:
165
- (0, _apis.upsertUserSyncStatus)({
166
- currentUserId: DBSyncManager.client.user.id,
167
- lastSyncedAt: new Date().toString()
168
- });
169
- case 27:
170
- case "end":
171
- return _context3.stop();
172
- }
173
- }, _callee3, null, [[15, 23]]);
174
- }));
161
+ case 23:
162
+ _context3.prev = 23;
163
+ _context3.t0 = _context3["catch"](15);
164
+ _QuickSqliteClient.QuickSqliteClient.resetDB();
165
+ case 26:
166
+ (0, _apis.upsertUserSyncStatus)({
167
+ currentUserId: DBSyncManager.client.user.id,
168
+ lastSyncedAt: new Date().toString()
169
+ });
170
+ case 27:
171
+ case "end":
172
+ return _context3.stop();
173
+ }
174
+ }, _callee3, null, [[15, 23]]);
175
+ }));
176
+ return function (_x3) {
177
+ return _ref3.apply(this, arguments);
178
+ };
179
+ }();
175
180
  DBSyncManager.syncAndExecutePendingTasks = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4() {
176
181
  return _regenerator["default"].wrap(function _callee4$(_context4) {
177
182
  while (1) switch (_context4.prev = _context4.next) {
@@ -186,7 +191,7 @@ DBSyncManager.syncAndExecutePendingTasks = (0, _asyncToGenerator2["default"])(_r
186
191
  return DBSyncManager.executePendingTasks(DBSyncManager.client);
187
192
  case 4:
188
193
  _context4.next = 6;
189
- return DBSyncManager.sync();
194
+ return DBSyncManager.sync(DBSyncManager.client);
190
195
  case 6:
191
196
  case "end":
192
197
  return _context4.stop();
@@ -231,7 +236,7 @@ DBSyncManager.queueTask = function () {
231
236
  }
232
237
  }, _callee5, null, [[2, 8]]);
233
238
  }));
234
- return function (_x3) {
239
+ return function (_x4) {
235
240
  return _ref6.apply(this, arguments);
236
241
  };
237
242
  }();
@@ -277,7 +282,7 @@ DBSyncManager.executeTask = function () {
277
282
  }
278
283
  }, _callee6);
279
284
  }));
280
- return function (_x4) {
285
+ return function (_x5) {
281
286
  return _ref8.apply(this, arguments);
282
287
  };
283
288
  }();
@@ -336,7 +341,7 @@ DBSyncManager.executePendingTasks = function () {
336
341
  }
337
342
  }, _callee7, null, [[6, 11]]);
338
343
  }));
339
- return function (_x5) {
344
+ return function (_x6) {
340
345
  return _ref9.apply(this, arguments);
341
346
  };
342
347
  }();
@@ -1 +1 @@
1
- {"version":3,"names":["_dayjs","_interopRequireDefault","require","_handleEventToSyncDB","_apis","_addPendingTask","_deletePendingTask","_getPendingTasks","_QuickSqliteClient","_createForOfIteratorHelperLoose","o","allowArrayLike","it","Symbol","iterator","call","next","bind","Array","isArray","_unsupportedIterableToArray","length","i","done","value","TypeError","minLen","_arrayLikeToArray","n","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","restBeforeNextTask","Promise","resolve","setTimeout","DBSyncManager","_createClass2","_classCallCheck2","exports","syncStatus","listeners","client","getSyncStatus","init","_ref","_asyncToGenerator2","_regenerator","mark","_callee2","_client$user","_client$wsConnection","wrap","_callee2$","_context2","prev","user","id","wsConnection","isHealthy","syncAndExecutePendingTasks","forEach","l","on","_ref2","_callee","event","_callee$","_context","online","stop","_x2","apply","arguments","_x","onSyncStatusChange","listener","push","unsubscribe","filter","el","sync","_callee3","_DBSyncManager$client","cids","lastSyncedAt","lastSyncedAtDate","lastSyncedAtDayJs","nowDayJs","diff","result","queries","_callee3$","_context3","abrupt","getAllChannelIds","getLastSyncedAt","currentUserId","Date","dayjs","QuickSqliteClient","resetDB","toISOString","sent","events","reduce","concat","handleEventToSyncDB","executeSqlBatch","t0","upsertUserSyncStatus","_callee4","_callee4$","_context4","executePendingTasks","queueTask","_ref6","_callee5","_ref5","task","removeFromApi","response","_response","_response$data","_callee5$","_context5","addPendingTask","executeTask","data","code","_x3","_ref8","_callee6","_ref7","channel","_callee6$","_context6","channelType","channelId","type","sendReaction","_toConsumableArray2","payload","deleteReaction","deleteMessage","Error","_x4","_ref9","_callee7","queue","_iterator","_step","_response2","_response2$data","_callee7$","_context7","getPendingTasks","deletePendingTask","_x5","dropPendingTasks","conditions","tasks","_iterator2","_step2"],"sources":["DBSyncManager.ts"],"sourcesContent":["import type { AxiosError } from 'axios';\nimport dayjs from 'dayjs';\nimport type { APIErrorResponse, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from '../components/Chat/hooks/handleEventToSyncDB';\nimport { getAllChannelIds, getLastSyncedAt, upsertUserSyncStatus } from '../store/apis';\n\nimport { addPendingTask } from '../store/apis/addPendingTask';\n\nimport { deletePendingTask } from '../store/apis/deletePendingTask';\nimport { getPendingTasks } from '../store/apis/getPendingTasks';\nimport { QuickSqliteClient } from '../store/QuickSqliteClient';\nimport type { PendingTask, PreparedQueries } from '../store/types';\nimport type { DefaultStreamChatGenerics } from '../types/types';\n\n/**\n * DBSyncManager has the responsibility to sync the channel states\n * within local database whenever possible.\n *\n * Components can get the current sync status using DBSyncManager.getCurrentStatus().\n * Or components can attach a listener for status change as following:\n *\n * ```tsx\n * useEffect(() => {\n * const unsubscribe = DBSyncManager.onSyncStatusChange((syncStatus) => {\n * if (syncStatus) {\n * doSomething();\n * }\n * })\n *\n * return () => unsubscribe();\n * })\n * ```\n */\nconst restBeforeNextTask = () => new Promise((resolve) => setTimeout(resolve, 500));\n\nexport class DBSyncManager {\n static syncStatus = false;\n static listeners: Array<(status: boolean) => void> = [];\n static client: StreamChat | null = null;\n\n /**\n * Returns weather channel states in local DB are synced with backend or not.\n * @returns boolean\n */\n static getSyncStatus = () => this.syncStatus;\n\n /**\n * Initializes the DBSyncManager. This function should be called only once\n * throughout the lifetime of SDK.\n *\n * @param client\n */\n static init = async (client: StreamChat) => {\n this.client = client;\n // If the websocket connection is already active, then straightaway\n // call the sync api and also execute pending api calls.\n // Otherwise wait for `connection.changed` event.\n if (client.user?.id && client.wsConnection?.isHealthy) {\n await this.syncAndExecutePendingTasks();\n this.syncStatus = true;\n this.listeners.forEach((l) => l(true));\n }\n\n this.client.on('connection.changed', async (event) => {\n if (event.online) {\n await this.syncAndExecutePendingTasks();\n this.syncStatus = true;\n this.listeners.forEach((l) => l(true));\n } else {\n this.syncStatus = false;\n this.listeners.forEach((l) => l(false));\n }\n });\n };\n\n /**\n * Subscribes a listener for sync status change.\n *\n * @param listener {function}\n * @returns {function} to unsubscribe the listener.\n */\n static onSyncStatusChange = (listener: (status: boolean) => void) => {\n this.listeners.push(listener);\n\n return {\n unsubscribe: () => {\n this.listeners = this.listeners.filter((el) => el !== listener);\n },\n };\n };\n\n static sync = async () => {\n if (!this.client?.user) return;\n const cids = getAllChannelIds();\n // If there are no channels, then there is no need to sync.\n if (cids.length === 0) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: this.client.user.id,\n });\n\n if (lastSyncedAt) {\n const lastSyncedAtDate = new Date(lastSyncedAt);\n const lastSyncedAtDayJs = dayjs(lastSyncedAtDate);\n const nowDayJs = dayjs();\n const diff = nowDayJs.diff(lastSyncedAtDayJs, 'days');\n if (diff > 30) {\n // stream backend will send an error if we try to sync after 30 days.\n // In that case reset the entire DB and start fresh.\n QuickSqliteClient.resetDB();\n } else {\n try {\n const result = await this.client.sync(cids, lastSyncedAtDate.toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // Error will be raised by the sync API if there are too many events.\n // In that case reset the entire DB and start fresh.\n QuickSqliteClient.resetDB();\n }\n }\n }\n upsertUserSyncStatus({\n currentUserId: this.client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n static syncAndExecutePendingTasks = async () => {\n if (!this.client) return;\n\n await this.executePendingTasks(this.client);\n await this.sync();\n };\n\n static queueTask = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >({\n client,\n task,\n }: {\n client: StreamChat<StreamChatGenerics>;\n task: PendingTask;\n }) => {\n const removeFromApi = addPendingTask(task);\n\n let response;\n try {\n response = await this.executeTask<StreamChatGenerics>({ client, task });\n } catch (e) {\n if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {\n // Error code 16 - message already exists\n // ignore\n } else {\n throw e;\n }\n }\n\n removeFromApi();\n\n return response;\n };\n\n static executeTask = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >({\n client,\n task,\n }: {\n client: StreamChat<StreamChatGenerics>;\n task: PendingTask;\n }) => {\n const channel = client.channel(task.channelType, task.channelId);\n\n if (task.type === 'send-reaction') {\n return await channel.sendReaction(...task.payload);\n }\n\n if (task.type === 'delete-reaction') {\n return await channel.deleteReaction(...task.payload);\n }\n\n if (task.type === 'delete-message') {\n return await client.deleteMessage(...task.payload);\n }\n\n throw new Error('Invalid task type');\n };\n\n static executePendingTasks = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >(\n client: StreamChat<StreamChatGenerics>,\n ) => {\n const queue = getPendingTasks();\n for (const task of queue) {\n if (!task.id) continue;\n\n try {\n await this.executeTask<StreamChatGenerics>({\n client,\n task,\n });\n } catch (e) {\n if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {\n // Error code 16 - message already exists\n // ignore\n } else {\n throw e;\n }\n }\n\n deletePendingTask({\n id: task.id,\n });\n await restBeforeNextTask();\n }\n };\n\n static dropPendingTasks = (conditions: { messageId: string }) => {\n const tasks = getPendingTasks(conditions);\n\n for (const task of tasks) {\n if (!task.id) continue;\n\n deletePendingTask({\n id: task.id,\n });\n }\n };\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,oBAAA,GAAAD,OAAA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xB,IAAI,qBAAnDyB,eAAA,CAAqDxB,IAAI,MAAK,CAAC;YAAA0B,SAAA,CAAAnJ,IAAA;YAAA;UAAA;UAAAmJ,SAAA,CAAAnJ,IAAA;UAAA;QAAA;UAAA,MAAAmJ,SAAA,CAAA9C,EAAA;QAAA;UAQrE,IAAAgD,oCAAiB,EAAC;YAChBpG,EAAE,EAAE8D,IAAI,CAAC9D;UACX,CAAC,CAAC;UAACkG,SAAA,CAAAnJ,IAAA;UAAA,OACGwB,kBAAkB,CAAC,CAAC;QAAA;UAAA2H,SAAA,CAAAnJ,IAAA;UAAA;QAAA;QAAA;UAAA,OAAAmJ,SAAA,CAAArF,IAAA;MAAA;IAAA,GAAA8E,QAAA;EAAA,CAE7B;EAAA,iBAAAU,GAAA;IAAA,OAAAX,KAAA,CAAA3E,KAAA,OAAAC,SAAA;EAAA;AAAA;AA5LUrC,aAAa,CA8LjB2H,gBAAgB,GAAG,UAACC,UAAiC,EAAK;EAC/D,IAAMC,KAAK,GAAG,IAAAL,gCAAe,EAACI,UAAU,CAAC;EAEzC,SAAAE,UAAA,GAAAjK,+BAAA,CAAmBgK,KAAK,GAAAE,MAAA,IAAAA,MAAA,GAAAD,UAAA,IAAAnJ,IAAA,GAAE;IAAA,IAAfwG,IAAI,GAAA4C,MAAA,CAAAnJ,KAAA;IACb,IAAI,CAACuG,IAAI,CAAC9D,EAAE,EAAE;IAEd,IAAAoG,oCAAiB,EAAC;MAChBpG,EAAE,EAAE8D,IAAI,CAAC9D;IACX,CAAC,CAAC;EACJ;AACF,CAAC"}
1
+ {"version":3,"names":["_dayjs","_interopRequireDefault","require","_handleEventToSyncDB","_apis","_addPendingTask","_deletePendingTask","_getPendingTasks","_QuickSqliteClient","_createForOfIteratorHelperLoose","o","allowArrayLike","it","Symbol","iterator","call","next","bind","Array","isArray","_unsupportedIterableToArray","length","i","done","value","TypeError","minLen","_arrayLikeToArray","n","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","restBeforeNextTask","Promise","resolve","setTimeout","DBSyncManager","_createClass2","_classCallCheck2","exports","syncStatus","listeners","client","getSyncStatus","init","_ref","_asyncToGenerator2","_regenerator","mark","_callee2","_client$user","_client$wsConnection","wrap","_callee2$","_context2","prev","user","id","wsConnection","isHealthy","syncAndExecutePendingTasks","forEach","l","on","_ref2","_callee","event","_callee$","_context","online","stop","_x2","apply","arguments","_x","onSyncStatusChange","listener","push","unsubscribe","filter","el","sync","_ref3","_callee3","_DBSyncManager$client","cids","lastSyncedAt","lastSyncedAtDate","lastSyncedAtDayJs","nowDayJs","diff","result","queries","_callee3$","_context3","abrupt","getAllChannelIds","getLastSyncedAt","currentUserId","Date","dayjs","QuickSqliteClient","resetDB","toISOString","sent","events","reduce","concat","handleEventToSyncDB","executeSqlBatch","t0","upsertUserSyncStatus","_x3","_callee4","_callee4$","_context4","executePendingTasks","queueTask","_ref6","_callee5","_ref5","task","removeFromApi","response","_response","_response$data","_callee5$","_context5","addPendingTask","executeTask","data","code","_x4","_ref8","_callee6","_ref7","channel","_callee6$","_context6","channelType","channelId","type","sendReaction","_toConsumableArray2","payload","deleteReaction","deleteMessage","Error","_x5","_ref9","_callee7","queue","_iterator","_step","_response2","_response2$data","_callee7$","_context7","getPendingTasks","deletePendingTask","_x6","dropPendingTasks","conditions","tasks","_iterator2","_step2"],"sources":["DBSyncManager.ts"],"sourcesContent":["import type { AxiosError } from 'axios';\nimport dayjs from 'dayjs';\nimport type { APIErrorResponse, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from '../components/Chat/hooks/handleEventToSyncDB';\nimport { getAllChannelIds, getLastSyncedAt, upsertUserSyncStatus } from '../store/apis';\n\nimport { addPendingTask } from '../store/apis/addPendingTask';\n\nimport { deletePendingTask } from '../store/apis/deletePendingTask';\nimport { getPendingTasks } from '../store/apis/getPendingTasks';\nimport { QuickSqliteClient } from '../store/QuickSqliteClient';\nimport type { PendingTask, PreparedQueries } from '../store/types';\nimport type { DefaultStreamChatGenerics } from '../types/types';\n\n/**\n * DBSyncManager has the responsibility to sync the channel states\n * within local database whenever possible.\n *\n * Components can get the current sync status using DBSyncManager.getCurrentStatus().\n * Or components can attach a listener for status change as following:\n *\n * ```tsx\n * useEffect(() => {\n * const unsubscribe = DBSyncManager.onSyncStatusChange((syncStatus) => {\n * if (syncStatus) {\n * doSomething();\n * }\n * })\n *\n * return () => unsubscribe();\n * })\n * ```\n */\nconst restBeforeNextTask = () => new Promise((resolve) => setTimeout(resolve, 500));\n\nexport class DBSyncManager {\n static syncStatus = false;\n static listeners: Array<(status: boolean) => void> = [];\n static client: StreamChat | null = null;\n\n /**\n * Returns weather channel states in local DB are synced with backend or not.\n * @returns boolean\n */\n static getSyncStatus = () => this.syncStatus;\n\n /**\n * Initializes the DBSyncManager. This function should be called only once\n * throughout the lifetime of SDK.\n *\n * @param client\n */\n static init = async (client: StreamChat) => {\n this.client = client;\n // If the websocket connection is already active, then straightaway\n // call the sync api and also execute pending api calls.\n // Otherwise wait for `connection.changed` event.\n if (client.user?.id && client.wsConnection?.isHealthy) {\n await this.syncAndExecutePendingTasks();\n this.syncStatus = true;\n this.listeners.forEach((l) => l(true));\n }\n\n this.client.on('connection.changed', async (event) => {\n if (event.online) {\n await this.syncAndExecutePendingTasks();\n this.syncStatus = true;\n this.listeners.forEach((l) => l(true));\n } else {\n this.syncStatus = false;\n this.listeners.forEach((l) => l(false));\n }\n });\n };\n\n /**\n * Subscribes a listener for sync status change.\n *\n * @param listener {function}\n * @returns {function} to unsubscribe the listener.\n */\n static onSyncStatusChange = (listener: (status: boolean) => void) => {\n this.listeners.push(listener);\n\n return {\n unsubscribe: () => {\n this.listeners = this.listeners.filter((el) => el !== listener);\n },\n };\n };\n\n static sync = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >(\n client: StreamChat<StreamChatGenerics>,\n ) => {\n if (!this.client?.user) return;\n const cids = getAllChannelIds();\n // If there are no channels, then there is no need to sync.\n if (cids.length === 0) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: this.client.user.id,\n });\n\n if (lastSyncedAt) {\n const lastSyncedAtDate = new Date(lastSyncedAt);\n const lastSyncedAtDayJs = dayjs(lastSyncedAtDate);\n const nowDayJs = dayjs();\n const diff = nowDayJs.diff(lastSyncedAtDayJs, 'days');\n if (diff > 30) {\n // stream backend will send an error if we try to sync after 30 days.\n // In that case reset the entire DB and start fresh.\n QuickSqliteClient.resetDB();\n } else {\n try {\n const result = await this.client.sync(cids, lastSyncedAtDate.toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, client, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // Error will be raised by the sync API if there are too many events.\n // In that case reset the entire DB and start fresh.\n QuickSqliteClient.resetDB();\n }\n }\n }\n upsertUserSyncStatus({\n currentUserId: this.client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n static syncAndExecutePendingTasks = async () => {\n if (!this.client) return;\n\n await this.executePendingTasks(this.client);\n await this.sync(this.client);\n };\n\n static queueTask = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >({\n client,\n task,\n }: {\n client: StreamChat<StreamChatGenerics>;\n task: PendingTask;\n }) => {\n const removeFromApi = addPendingTask(task);\n\n let response;\n try {\n response = await this.executeTask<StreamChatGenerics>({ client, task });\n } catch (e) {\n if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {\n // Error code 16 - message already exists\n // ignore\n } else {\n throw e;\n }\n }\n\n removeFromApi();\n\n return response;\n };\n\n static executeTask = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >({\n client,\n task,\n }: {\n client: StreamChat<StreamChatGenerics>;\n task: PendingTask;\n }) => {\n const channel = client.channel(task.channelType, task.channelId);\n\n if (task.type === 'send-reaction') {\n return await channel.sendReaction(...task.payload);\n }\n\n if (task.type === 'delete-reaction') {\n return await channel.deleteReaction(...task.payload);\n }\n\n if (task.type === 'delete-message') {\n return await client.deleteMessage(...task.payload);\n }\n\n throw new Error('Invalid task type');\n };\n\n static executePendingTasks = async <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n >(\n client: StreamChat<StreamChatGenerics>,\n ) => {\n const queue = getPendingTasks();\n for (const task of queue) {\n if (!task.id) continue;\n\n try {\n await this.executeTask<StreamChatGenerics>({\n client,\n task,\n });\n } catch (e) {\n if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {\n // Error code 16 - message already exists\n // ignore\n } else {\n throw e;\n }\n }\n\n deletePendingTask({\n id: task.id,\n });\n await restBeforeNextTask();\n }\n };\n\n static dropPendingTasks = (conditions: { messageId: string }) => {\n const tasks = getPendingTasks(conditions);\n\n for (const task of tasks) {\n if (!task.id) continue;\n\n deletePendingTask({\n id: task.id,\n });\n }\n };\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,kBAAA,GAAAN,OAAA;AAA+D,SAAAO,gCAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,oBAAAE,EAAA,UAAAA,EAAA,GAAAA,EAAA,CAAAG,IAAA,CAAAL,CAAA,GAAAM,IAAA,CAAAC,IAAA,CAAAL,EAAA,OAAAM,KAAA,CAAAC,OAAA,CAAAT,CAAA,MAAAE,EAAA,GAAAQ,2BAAA,CAAAV,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAW,MAAA,qBAAAT,EA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;UAAA,OAAAqJ,SAAA,CAAAvF,IAAA;MAAA;IAAA,GAAAgF,QAAA;EAAA,CAE7B;EAAA,iBAAAU,GAAA;IAAA,OAAAX,KAAA,CAAA7E,KAAA,OAAAC,SAAA;EAAA;AAAA;AAhMUrC,aAAa,CAkMjB6H,gBAAgB,GAAG,UAACC,UAAiC,EAAK;EAC/D,IAAMC,KAAK,GAAG,IAAAL,gCAAe,EAACI,UAAU,CAAC;EAEzC,SAAAE,UAAA,GAAAnK,+BAAA,CAAmBkK,KAAK,GAAAE,MAAA,IAAAA,MAAA,GAAAD,UAAA,IAAArJ,IAAA,GAAE;IAAA,IAAf0G,IAAI,GAAA4C,MAAA,CAAArJ,KAAA;IACb,IAAI,CAACyG,IAAI,CAAChE,EAAE,EAAE;IAEd,IAAAsG,oCAAiB,EAAC;MAChBtG,EAAE,EAAEgE,IAAI,CAAChE;IACX,CAAC,CAAC;EACJ;AACF,CAAC"}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.27.0-beta.11"
2
+ "version": "5.27.0-beta.12"
3
3
  }
@@ -1,61 +1,116 @@
1
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
1
2
  Object.defineProperty(exports, "__esModule", {
2
3
  value: true
3
4
  });
4
5
  exports.handleEventToSyncDB = void 0;
6
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
5
7
  var _deleteChannel = require("../../../store/apis/deleteChannel");
6
8
  var _deleteMember = require("../../../store/apis/deleteMember");
7
9
  var _deleteMessagesForChannel = require("../../../store/apis/deleteMessagesForChannel");
8
10
  var _updateMessage = require("../../../store/apis/updateMessage");
9
11
  var _upsertChannelData = require("../../../store/apis/upsertChannelData");
12
+ var _upsertChannelDataFromChannel = require("../../../store/apis/upsertChannelDataFromChannel");
10
13
  var _upsertChannels = require("../../../store/apis/upsertChannels");
11
14
  var _upsertMembers = require("../../../store/apis/upsertMembers");
12
15
  var _upsertMessages = require("../../../store/apis/upsertMessages");
13
16
  var _upsertReads = require("../../../store/apis/upsertReads");
14
- var handleEventToSyncDB = function handleEventToSyncDB(event, flush) {
17
+ var _QuickSqliteClient = require("../../../store/QuickSqliteClient");
18
+ var _createSelectQuery = require("../../../store/sqlite-utils/createSelectQuery");
19
+ var handleEventToSyncDB = function handleEventToSyncDB(event, client, flush) {
15
20
  var type = event.type;
21
+ var queriesWithChannelGuard = function queriesWithChannelGuard(createQueries) {
22
+ var _event$channel;
23
+ var cid = event.cid || ((_event$channel = event.channel) == null ? void 0 : _event$channel.cid);
24
+ if (!cid) return createQueries(flush);
25
+ var channels = _QuickSqliteClient.QuickSqliteClient.executeSql.apply(null, (0, _createSelectQuery.createSelectQuery)('channels', ['cid'], {
26
+ cid: cid
27
+ }));
28
+ if (channels.length === 0) {
29
+ var channel = event.channel_type && event.channel_id ? client.channel(event.channel_type, event.channel_id) : undefined;
30
+ if (channel && channel.initialized && !channel.disconnected) {
31
+ var channelQuery = (0, _upsertChannelDataFromChannel.upsertChannelDataFromChannel)({
32
+ channel: channel,
33
+ flush: flush
34
+ });
35
+ if (channelQuery) {
36
+ var newQueries = [].concat((0, _toConsumableArray2["default"])(channelQuery), (0, _toConsumableArray2["default"])(createQueries(false)));
37
+ if (flush !== false) {
38
+ _QuickSqliteClient.QuickSqliteClient.executeSqlBatch(newQueries);
39
+ }
40
+ return newQueries;
41
+ } else {
42
+ console.warn("Couldnt create channel queries on " + type + " event for an initialized channel that is not in DB, skipping event", {
43
+ event: event
44
+ });
45
+ return [];
46
+ }
47
+ } else {
48
+ console.warn("Received " + type + " event for a non initialized channel that is not in DB, skipping event", {
49
+ event: event
50
+ });
51
+ return [];
52
+ }
53
+ }
54
+ return createQueries(flush);
55
+ };
16
56
  if (type === 'message.read') {
17
- var _event$user;
18
- if ((_event$user = event.user) != null && _event$user.id && event.cid) {
19
- return (0, _upsertReads.upsertReads)({
20
- cid: event.cid,
21
- flush: flush,
22
- reads: [{
23
- last_read: event.received_at,
24
- unread_messages: 0,
25
- user: event.user
26
- }]
57
+ var cid = event.cid;
58
+ var user = event.user;
59
+ if (user != null && user.id && cid) {
60
+ return queriesWithChannelGuard(function (flushOverride) {
61
+ return (0, _upsertReads.upsertReads)({
62
+ cid: cid,
63
+ flush: flushOverride,
64
+ reads: [{
65
+ last_read: event.received_at,
66
+ unread_messages: 0,
67
+ user: user
68
+ }]
69
+ });
27
70
  });
28
71
  }
29
72
  }
30
73
  if (type === 'message.new') {
31
- if (event.message && (!event.message.parent_id || event.message.show_in_channel)) {
32
- return (0, _upsertMessages.upsertMessages)({
33
- flush: flush,
34
- messages: [event.message]
74
+ var message = event.message;
75
+ if (message && (!message.parent_id || message.show_in_channel)) {
76
+ return queriesWithChannelGuard(function (flushOverride) {
77
+ return (0, _upsertMessages.upsertMessages)({
78
+ flush: flushOverride,
79
+ messages: [message]
80
+ });
35
81
  });
36
82
  }
37
83
  }
38
84
  if (type === 'message.updated' || type === 'message.deleted') {
39
- if (event.message && !event.message.parent_id) {
40
- return (0, _updateMessage.updateMessage)({
41
- flush: flush,
42
- message: event.message
85
+ var _message = event.message;
86
+ if (_message && !_message.parent_id) {
87
+ return queriesWithChannelGuard(function (flushOverride) {
88
+ return (0, _updateMessage.updateMessage)({
89
+ flush: flushOverride,
90
+ message: _message
91
+ });
43
92
  });
44
93
  }
45
94
  }
46
95
  if (type === 'reaction.updated') {
47
- if (event.message && event.reaction) {
48
- return (0, _updateMessage.updateMessage)({
49
- flush: flush,
50
- message: event.message
96
+ var _message2 = event.message;
97
+ if (_message2 && event.reaction) {
98
+ return queriesWithChannelGuard(function (flushOverride) {
99
+ return (0, _updateMessage.updateMessage)({
100
+ flush: flushOverride,
101
+ message: _message2
102
+ });
51
103
  });
52
104
  }
53
105
  }
54
106
  if (type === 'reaction.new' || type === 'reaction.deleted') {
55
- if (event.message && !event.message.parent_id) {
56
- return (0, _updateMessage.updateMessage)({
57
- flush: flush,
58
- message: event.message
107
+ var _message3 = event.message;
108
+ if (_message3 && !_message3.parent_id) {
109
+ return queriesWithChannelGuard(function (flushOverride) {
110
+ return (0, _updateMessage.updateMessage)({
111
+ flush: flushOverride,
112
+ message: _message3
113
+ });
59
114
  });
60
115
  }
61
116
  }
@@ -95,20 +150,28 @@ var handleEventToSyncDB = function handleEventToSyncDB(event, flush) {
95
150
  }
96
151
  }
97
152
  if (type === 'member.added' || type === 'member.updated') {
98
- if (event.member && event.cid) {
99
- return (0, _upsertMembers.upsertMembers)({
100
- cid: event.cid,
101
- flush: flush,
102
- members: [event.member]
153
+ var member = event.member;
154
+ var _cid = event.cid;
155
+ if (member && _cid) {
156
+ return queriesWithChannelGuard(function (flushOverride) {
157
+ return (0, _upsertMembers.upsertMembers)({
158
+ cid: _cid,
159
+ flush: flushOverride,
160
+ members: [member]
161
+ });
103
162
  });
104
163
  }
105
164
  }
106
165
  if (type === 'member.removed') {
107
- if (event.member && event.cid) {
108
- return (0, _deleteMember.deleteMember)({
109
- cid: event.cid,
110
- flush: flush,
111
- member: event.member
166
+ var _member = event.member;
167
+ var _cid2 = event.cid;
168
+ if (_member && _cid2) {
169
+ return queriesWithChannelGuard(function (flushOverride) {
170
+ return (0, _deleteMember.deleteMember)({
171
+ cid: _cid2,
172
+ flush: flushOverride,
173
+ member: _member
174
+ });
112
175
  });
113
176
  }
114
177
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_deleteChannel","require","_deleteMember","_deleteMessagesForChannel","_updateMessage","_upsertChannelData","_upsertChannels","_upsertMembers","_upsertMessages","_upsertReads","handleEventToSyncDB","event","flush","type","_event$user","user","id","cid","upsertReads","reads","last_read","received_at","unread_messages","message","parent_id","show_in_channel","upsertMessages","messages","updateMessage","reaction","channel","upsertChannelData","deleteChannel","deleteMessagesForChannel","_event$queriedChannel","_event$queriedChannel2","queriedChannels","channels","length","_event$queriedChannel3","_event$queriedChannel4","upsertChannels","isLatestMessagesSet","isLatestMessageSet","member","upsertMembers","members","deleteMember","exports"],"sources":["handleEventToSyncDB.ts"],"sourcesContent":["import type { Event } from 'stream-chat';\n\nimport { deleteChannel } from '../../../store/apis/deleteChannel';\nimport { deleteMember } from '../../../store/apis/deleteMember';\nimport { deleteMessagesForChannel } from '../../../store/apis/deleteMessagesForChannel';\nimport { updateMessage } from '../../../store/apis/updateMessage';\nimport { upsertChannelData } from '../../../store/apis/upsertChannelData';\nimport { upsertChannels } from '../../../store/apis/upsertChannels';\nimport { upsertMembers } from '../../../store/apis/upsertMembers';\nimport { upsertMessages } from '../../../store/apis/upsertMessages';\nimport { upsertReads } from '../../../store/apis/upsertReads';\n\nexport const handleEventToSyncDB = (event: Event, flush?: boolean) => {\n const { type } = event;\n\n if (type === 'message.read') {\n if (event.user?.id && event.cid) {\n return upsertReads({\n cid: event.cid,\n flush,\n reads: [\n {\n last_read: event.received_at as string,\n unread_messages: 0,\n user: event.user,\n },\n ],\n });\n }\n }\n\n if (type === 'message.new') {\n if (event.message && (!event.message.parent_id || event.message.show_in_channel)) {\n return upsertMessages({\n flush,\n messages: [event.message],\n });\n }\n }\n\n if (type === 'message.updated' || type === 'message.deleted') {\n if (event.message && !event.message.parent_id) {\n // Update only if it exists, otherwise event could be related\n // to a message which is not in database.\n return updateMessage({\n flush,\n message: event.message,\n });\n }\n }\n\n if (type === 'reaction.updated') {\n if (event.message && event.reaction) {\n // We update the entire message to make sure we also update\n // reaction_counts.\n return updateMessage({\n flush,\n message: event.message,\n });\n }\n }\n\n if (type === 'reaction.new' || type === 'reaction.deleted') {\n if (event.message && !event.message.parent_id) {\n // Here we are relying on the fact message.latest_reactions always includes\n // the new reaction. So we first delete all the existing reactions and populate\n // the reactions table with message.latest_reactions\n return updateMessage({\n flush,\n message: event.message,\n });\n }\n }\n\n if (\n type === 'channel.updated' ||\n type === 'channel.visible' ||\n type === 'notification.added_to_channel' ||\n type === 'notification.message_new'\n ) {\n if (event.channel) {\n return upsertChannelData({\n channel: event.channel,\n flush,\n });\n }\n }\n\n if (\n type === 'channel.hidden' ||\n type === 'channel.deleted' ||\n type === 'notification.removed_from_channel'\n ) {\n if (event.channel) {\n return deleteChannel({\n cid: event.channel.cid,\n flush,\n });\n }\n }\n\n if (type === 'channel.truncated') {\n if (event.channel) {\n return deleteMessagesForChannel({\n cid: event.channel.cid,\n flush,\n });\n }\n }\n\n if (type === 'channels.queried') {\n if (event.queriedChannels?.channels?.length) {\n return upsertChannels({\n channels: event.queriedChannels?.channels,\n flush,\n isLatestMessagesSet: event.queriedChannels?.isLatestMessageSet,\n });\n }\n }\n\n if (type === 'member.added' || type === 'member.updated') {\n if (event.member && event.cid) {\n return upsertMembers({\n cid: event.cid,\n flush,\n members: [event.member],\n });\n }\n }\n\n if (type === 'member.removed') {\n if (event.member && event.cid) {\n return deleteMember({\n cid: event.cid,\n flush,\n member: event.member,\n });\n }\n }\n\n return [];\n};\n"],"mappings":";;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AAEO,IAAMS,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAAIC,KAAY,EAAEC,KAAe,EAAK;EACpE,IAAQC,IAAI,GAAKF,KAAK,CAAdE,IAAI;EAEZ,IAAIA,IAAI,KAAK,cAAc,EAAE;IAAA,IAAAC,WAAA;IAC3B,IAAI,CAAAA,WAAA,GAAAH,KAAK,CAACI,IAAI,aAAVD,WAAA,CAAYE,EAAE,IAAIL,KAAK,CAACM,GAAG,EAAE;MAC/B,OAAO,IAAAC,wBAAW,EAAC;QACjBD,GAAG,EAAEN,KAAK,CAACM,GAAG;QACdL,KAAK,EAALA,KAAK;QACLO,KAAK,EAAE,CACL;UACEC,SAAS,EAAET,KAAK,CAACU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,IAAIA,IAAI,KAAK,gBAAgB,EAAE;IACxD,IAAIF,KAAK,CAACiC,MAAM,IAAIjC,KAAK,CAACM,GAAG,EAAE;MAC7B,OAAO,IAAA4B,4BAAa,EAAC;QACnB5B,GAAG,EAAEN,KAAK,CAACM,GAAG;QACdL,KAAK,EAALA,KAAK;QACLkC,OAAO,EAAE,CAACnC,KAAK,CAACiC,MAAM;MACxB,CAAC,CAAC;IACJ;EACF;EAEA,IAAI/B,IAAI,KAAK,gBAAgB,EAAE;IAC7B,IAAIF,KAAK,CAACiC,MAAM,IAAIjC,KAAK,CAACM,GAAG,EAAE;MAC7B,OAAO,IAAA8B,0BAAY,EAAC;QAClB9B,GAAG,EAAEN,KAAK,CAACM,GAAG;QACdL,KAAK,EAALA,KAAK;QACLgC,MAAM,EAAEjC,KAAK,CAACiC;MAChB,CAAC,CAAC;IACJ;EACF;EAEA,OAAO,EAAE;AACX,CAAC;AAACI,OAAA,CAAAtC,mBAAA,GAAAA,mBAAA"}
1
+ {"version":3,"names":["_deleteChannel","require","_deleteMember","_deleteMessagesForChannel","_updateMessage","_upsertChannelData","_upsertChannelDataFromChannel","_upsertChannels","_upsertMembers","_upsertMessages","_upsertReads","_QuickSqliteClient","_createSelectQuery","handleEventToSyncDB","event","client","flush","type","queriesWithChannelGuard","createQueries","_event$channel","cid","channel","channels","QuickSqliteClient","executeSql","apply","createSelectQuery","length","channel_type","channel_id","undefined","initialized","disconnected","channelQuery","upsertChannelDataFromChannel","newQueries","concat","_toConsumableArray2","executeSqlBatch","console","warn","user","id","flushOverride","upsertReads","reads","last_read","received_at","unread_messages","message","parent_id","show_in_channel","upsertMessages","messages","updateMessage","reaction","upsertChannelData","deleteChannel","deleteMessagesForChannel","_event$queriedChannel","_event$queriedChannel2","queriedChannels","_event$queriedChannel3","_event$queriedChannel4","upsertChannels","isLatestMessagesSet","isLatestMessageSet","member","upsertMembers","members","deleteMember","exports"],"sources":["handleEventToSyncDB.ts"],"sourcesContent":["import { DefaultStreamChatGenerics } from 'src/types/types';\nimport type { Event, StreamChat } from 'stream-chat';\n\nimport { deleteChannel } from '../../../store/apis/deleteChannel';\nimport { deleteMember } from '../../../store/apis/deleteMember';\nimport { deleteMessagesForChannel } from '../../../store/apis/deleteMessagesForChannel';\nimport { updateMessage } from '../../../store/apis/updateMessage';\nimport { upsertChannelData } from '../../../store/apis/upsertChannelData';\nimport { upsertChannelDataFromChannel } from '../../../store/apis/upsertChannelDataFromChannel';\nimport { upsertChannels } from '../../../store/apis/upsertChannels';\nimport { upsertMembers } from '../../../store/apis/upsertMembers';\nimport { upsertMessages } from '../../../store/apis/upsertMessages';\nimport { upsertReads } from '../../../store/apis/upsertReads';\nimport { QuickSqliteClient } from '../../../store/QuickSqliteClient';\nimport { createSelectQuery } from '../../../store/sqlite-utils/createSelectQuery';\nimport { PreparedQueries } from '../../../store/types';\n\nexport const handleEventToSyncDB = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n event: Event,\n client: StreamChat<StreamChatGenerics>,\n flush?: boolean,\n) => {\n const { type } = event;\n\n // This function is used to guard the queries that require channel to be present in the db first\n // If channel is not present in the db, we first fetch the channel data from the channel object\n // and then add the queries with a channel create query first\n const queriesWithChannelGuard = (\n createQueries: (flushOverride?: boolean) => PreparedQueries[],\n ) => {\n const cid = event.cid || event.channel?.cid;\n\n if (!cid) return createQueries(flush);\n const channels = QuickSqliteClient.executeSql.apply(\n null,\n createSelectQuery('channels', ['cid'], {\n cid,\n }),\n );\n // a channel is not present in the db, we first fetch the channel data from the channel object.\n // this can happen for example when a message.new event is received for a channel that is not in the db due to a channel being hidden.\n if (channels.length === 0) {\n const channel =\n event.channel_type && event.channel_id\n ? client.channel(event.channel_type, event.channel_id)\n : undefined;\n if (channel && channel.initialized && !channel.disconnected) {\n const channelQuery = upsertChannelDataFromChannel({\n channel,\n flush,\n });\n if (channelQuery) {\n const newQueries = [...channelQuery, ...createQueries(false)];\n if (flush !== false) {\n QuickSqliteClient.executeSqlBatch(newQueries);\n }\n return newQueries;\n } else {\n console.warn(\n `Couldnt create channel queries on ${type} event for an initialized channel that is not in DB, skipping event`,\n { event },\n );\n return [];\n }\n } else {\n console.warn(\n `Received ${type} event for a non initialized channel that is not in DB, skipping event`,\n { event },\n );\n return [];\n }\n }\n return createQueries(flush);\n };\n\n if (type === 'message.read') {\n const cid = event.cid;\n const user = event.user;\n if (user?.id && cid) {\n return queriesWithChannelGuard((flushOverride) =>\n upsertReads({\n cid,\n flush: flushOverride,\n reads: [\n {\n last_read: event.received_at as string,\n unread_messages: 0,\n user,\n },\n ],\n }),\n );\n }\n }\n\n if (type === 'message.new') {\n const message = event.message;\n if (message && (!message.parent_id || message.show_in_channel)) {\n return queriesWithChannelGuard((flushOverride) =>\n upsertMessages({\n flush: flushOverride,\n messages: [message],\n }),\n );\n }\n }\n\n if (type === 'message.updated' || type === 'message.deleted') {\n const message = event.message;\n if (message && !message.parent_id) {\n // Update only if it exists, otherwise event could be related\n // to a message which is not in database.\n return queriesWithChannelGuard((flushOverride) =>\n updateMessage({\n flush: flushOverride,\n message,\n }),\n );\n }\n }\n\n if (type === 'reaction.updated') {\n const message = event.message;\n if (message && event.reaction) {\n // We update the entire message to make sure we also update\n // reaction_counts.\n return queriesWithChannelGuard((flushOverride) =>\n updateMessage({\n flush: flushOverride,\n message,\n }),\n );\n }\n }\n\n if (type === 'reaction.new' || type === 'reaction.deleted') {\n const message = event.message;\n if (message && !message.parent_id) {\n // Here we are relying on the fact message.latest_reactions always includes\n // the new reaction. So we first delete all the existing reactions and populate\n // the reactions table with message.latest_reactions\n return queriesWithChannelGuard((flushOverride) =>\n updateMessage({\n flush: flushOverride,\n message,\n }),\n );\n }\n }\n\n if (\n type === 'channel.updated' ||\n type === 'channel.visible' ||\n type === 'notification.added_to_channel' ||\n type === 'notification.message_new'\n ) {\n if (event.channel) {\n return upsertChannelData({\n channel: event.channel,\n flush,\n });\n }\n }\n\n if (\n type === 'channel.hidden' ||\n type === 'channel.deleted' ||\n type === 'notification.removed_from_channel'\n ) {\n if (event.channel) {\n return deleteChannel({\n cid: event.channel.cid,\n flush,\n });\n }\n }\n\n if (type === 'channel.truncated') {\n if (event.channel) {\n return deleteMessagesForChannel({\n cid: event.channel.cid,\n flush,\n });\n }\n }\n\n if (type === 'channels.queried') {\n if (event.queriedChannels?.channels?.length) {\n return upsertChannels({\n channels: event.queriedChannels?.channels,\n flush,\n isLatestMessagesSet: event.queriedChannels?.isLatestMessageSet,\n });\n }\n }\n\n if (type === 'member.added' || type === 'member.updated') {\n const member = event.member;\n const cid = event.cid;\n if (member && cid) {\n return queriesWithChannelGuard((flushOverride) =>\n upsertMembers({\n cid,\n flush: flushOverride,\n members: [member],\n }),\n );\n }\n }\n\n if (type === 'member.removed') {\n const member = event.member;\n const cid = event.cid;\n if (member && cid) {\n return queriesWithChannelGuard((flushOverride) =>\n deleteMember({\n cid,\n flush: flushOverride,\n member,\n }),\n );\n }\n }\n\n return [];\n};\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,6BAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,eAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,kBAAA,GAAAV,OAAA;AACA,IAAAW,kBAAA,GAAAX,OAAA;AAGO,IAAMY,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAG9BC,KAAY,EACZC,MAAsC,EACtCC,KAAe,EACZ;EACH,IAAQC,IAAI,GAAKH,KAAK,CAAdG,IAAI;EAKZ,IAAMC,uBAAuB,GAAG,SAA1BA,uBAAuBA,CAC3BC,aAA6D,EAC1D;IAAA,IAAAC,cAA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