@viewberapp/chat 0.1.10 → 0.1.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 (65) hide show
  1. package/LICENSE +20 -20
  2. package/dist/API.d.ts +91 -91
  3. package/dist/API.js +241 -241
  4. package/dist/CachedChat.d.ts +64 -64
  5. package/dist/CachedChat.js +241 -241
  6. package/dist/Chat.d.ts +66 -66
  7. package/dist/Chat.js +270 -270
  8. package/dist/ChatError.d.ts +4 -4
  9. package/dist/ChatError.js +2 -2
  10. package/dist/ChatSubscription.d.ts +82 -82
  11. package/dist/ChatSubscription.js +128 -128
  12. package/dist/Message.d.ts +25 -25
  13. package/dist/Message.js +35 -35
  14. package/dist/OnlineUser.d.ts +8 -8
  15. package/dist/OnlineUser.js +9 -9
  16. package/dist/PendingMessage.d.ts +23 -23
  17. package/dist/PendingMessage.js +23 -23
  18. package/dist/index.d.ts +8 -8
  19. package/dist/index.js +27 -27
  20. package/dist/logger/ConsoleLogger.d.ts +8 -8
  21. package/dist/logger/ConsoleLogger.js +20 -20
  22. package/dist/logger/NullLogger.d.ts +8 -8
  23. package/dist/logger/NullLogger.js +10 -10
  24. package/dist/logger/RollbarLogger.d.ts +11 -11
  25. package/dist/logger/RollbarLogger.js +23 -23
  26. package/dist/logger/index.d.ts +12 -12
  27. package/dist/logger/index.js +12 -12
  28. package/dist/react/components/AdminMessage.d.ts +6 -6
  29. package/dist/react/components/AdminMessage.js +59 -59
  30. package/dist/react/components/ConnectionAndChannelStatusLabel.d.ts +7 -7
  31. package/dist/react/components/ConnectionAndChannelStatusLabel.js +59 -59
  32. package/dist/react/components/Message.d.ts +23 -23
  33. package/dist/react/components/Message.js +87 -87
  34. package/dist/react/components/MessageDateTime.d.ts +8 -8
  35. package/dist/react/components/MessageDateTime.js +31 -31
  36. package/dist/react/components/MessageList.d.ts +46 -46
  37. package/dist/react/components/MessageList.js +107 -107
  38. package/dist/react/components/MessageRow.d.ts +5 -5
  39. package/dist/react/components/MessageRow.js +34 -34
  40. package/dist/react/components/index.d.ts +6 -6
  41. package/dist/react/components/index.js +13 -13
  42. package/dist/react/index.d.ts +3 -3
  43. package/dist/react/index.js +16 -16
  44. package/dist/react/useAppointmentChat.d.ts +3 -3
  45. package/dist/react/useAppointmentChat.js +10 -10
  46. package/dist/react/useChat.d.ts +38 -38
  47. package/dist/react/useChat.js +125 -125
  48. package/dist/react/useRealtimeTotalUserUnreadChatMessages.d.ts +12 -12
  49. package/dist/react/useRealtimeTotalUserUnreadChatMessages.js +137 -137
  50. package/dist/util/getLatestMessage.d.ts +3 -3
  51. package/dist/util/getLatestMessage.js +17 -17
  52. package/dist/util/getLatestMessageId.d.ts +3 -0
  53. package/dist/util/getLatestMessageId.js +18 -0
  54. package/dist/util/getLatestMessageId.js.map +1 -0
  55. package/dist/util/groupMessages.d.ts +8 -8
  56. package/dist/util/groupMessages.js +30 -30
  57. package/dist/util/index.d.ts +4 -4
  58. package/dist/util/index.js +9 -9
  59. package/dist/util/isNil.d.ts +1 -1
  60. package/dist/util/isNil.js +7 -7
  61. package/dist/util/jwtTokenChanged.d.ts +1 -1
  62. package/dist/util/jwtTokenChanged.js +10 -10
  63. package/dist/util/useIsMounted.d.ts +1 -1
  64. package/dist/util/useIsMounted.js +13 -13
  65. package/package.json +2 -2
@@ -1,242 +1,242 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const uuid_1 = require("uuid");
27
- const PendingMessage_1 = __importStar(require("./PendingMessage"));
28
- const Message_1 = __importStar(require("./Message"));
29
- class CachedChat {
30
- constructor({ id, api, channel, connectionStatus, logger, debugLogger, debug }) {
31
- this.getLatestMessagesStatus = 'initialized';
32
- this.id = id;
33
- this.api = api;
34
- this.messages = [];
35
- this.onlineUsers = [];
36
- this.subscriptions = [];
37
- this.channel = channel;
38
- this.channelStatus = this.channel.state;
39
- this.connectionStatus = connectionStatus;
40
- this.logger = logger;
41
- this.debugLogger = debugLogger;
42
- this.debug = debug;
43
- this.disabled_at = null;
44
- this.channel.on(this.handleChannelStateChange.bind(this));
45
- this.channel.subscribe((message) => {
46
- var _a;
47
- if ((_a = this.debug) === null || _a === void 0 ? void 0 : _a.inboundAblyMessages) {
48
- this.debugLogger.debug('[Ably] [InboundMessage]', message);
49
- }
50
- if (message.name === 'chat.message.created') {
51
- this.addMessage(new Message_1.default({
52
- id: message.data.id,
53
- chatId: message.data.chat_id,
54
- message: message.data.message,
55
- senderId: message.data.sender_id,
56
- sender: message.data.sender,
57
- isAdminMessage: message.data.is_admin_message,
58
- createdAt: new Date(message.data.created_at)
59
- }));
60
- this.fireMessagesEventOnEachNonCancelledSubscription();
61
- }
62
- });
63
- }
64
- sendMessage(message, options) {
65
- return new Promise((resolve, reject) => {
66
- const pendingMessage = new PendingMessage_1.default({
67
- id: (0, uuid_1.v4)(),
68
- message,
69
- status: 'initialized',
70
- options,
71
- createdAt: new Date
72
- });
73
- this.addMessage(pendingMessage);
74
- this.fireMessagesEventOnEachNonCancelledSubscription();
75
- this.sendPendingMessage(pendingMessage)
76
- .then(() => resolve())
77
- .catch(err => reject(err));
78
- });
79
- }
80
- reportChat(reason) {
81
- return new Promise((resolve, reject) => {
82
- this.api.reportChat(this.id, reason)
83
- .then(() => resolve())
84
- .catch(err => reject(err));
85
- });
86
- }
87
- toggleChatEnabled() {
88
- return new Promise((resolve, reject) => {
89
- this.api.toggleChatEnabled(this.id)
90
- .then(() => resolve())
91
- .catch(err => reject(err));
92
- });
93
- }
94
- sendPendingMessage(pendingMessage) {
95
- return new Promise((resolve, reject) => {
96
- if (!(0, PendingMessage_1.isPendingMessage)(pendingMessage) || pendingMessage.status === 'pending') {
97
- return resolve();
98
- }
99
- this.updatePendingMessageStatus(pendingMessage, 'pending');
100
- this.fireMessagesEventOnEachNonCancelledSubscription();
101
- this.api.storeMessage(this.id, pendingMessage.message, pendingMessage.options).then(({ message, error }) => {
102
- if (error) {
103
- this.updatePendingMessageStatus(pendingMessage, 'failed');
104
- this.fireMessagesEventOnEachNonCancelledSubscription();
105
- return reject(new Error(error.message));
106
- }
107
- this.replacePendingMessage(pendingMessage, message);
108
- this.fireMessagesEventOnEachNonCancelledSubscription();
109
- resolve();
110
- }).catch(err => {
111
- this.updatePendingMessageStatus(pendingMessage, 'failed');
112
- this.fireMessagesEventOnEachNonCancelledSubscription();
113
- reject(err);
114
- });
115
- });
116
- }
117
- getLatestMessages() {
118
- this.setGetLatestMessagesStatus('fetching');
119
- this.api.getLatestMessages(this.id).then(({ messages, error }) => {
120
- if (messages) {
121
- messages.forEach(m => this.addMessage(m));
122
- this.setGetLatestMessagesStatus('success');
123
- this.fireMessagesEventOnEachNonCancelledSubscription();
124
- return;
125
- }
126
- this.setGetLatestMessagesStatus('failed');
127
- }).catch(err => {
128
- this.setGetLatestMessagesStatus('failed');
129
- });
130
- }
131
- markMessagesReadUpTo(message) {
132
- return this.api.markChatMessagesReadUpTo(this.id, message);
133
- }
134
- setDisabledAt(disabled_at) {
135
- this.disabled_at = disabled_at;
136
- }
137
- getDisabledAt() {
138
- return this.disabled_at;
139
- }
140
- addMessage(message) {
141
- if (message instanceof PendingMessage_1.default) {
142
- this.messages.push(message);
143
- return;
144
- }
145
- let index = -1;
146
- for (let i = (this.messages.length - 1); i >= 0; i--) {
147
- if ((0, Message_1.isMessageAnd)(this.messages[i], m => m.id < message.id) && index === -1) {
148
- index = i;
149
- }
150
- if ((0, Message_1.isMessageAnd)(this.messages[i], m => m.id === message.id)) {
151
- return;
152
- }
153
- }
154
- if (index === -1) {
155
- this.messages.unshift(message);
156
- this.messages = this.messages.concat([]);
157
- }
158
- else {
159
- this.messages.splice(index + 1, 0, message);
160
- this.messages = this.messages.concat([]);
161
- }
162
- }
163
- replacePendingMessage(pendingMessage, message) {
164
- this.messages = this.messages.filter((m) => {
165
- return m.id !== pendingMessage.id;
166
- });
167
- this.addMessage(message);
168
- }
169
- updatePendingMessageStatus(pendingMessage, status) {
170
- this.messages = this.messages.map((m) => {
171
- if ((0, PendingMessage_1.isPendingMessage)(m) && m.id === pendingMessage.id) {
172
- return m.clone({ status });
173
- }
174
- return m;
175
- });
176
- }
177
- addSubscription(subscription) {
178
- this.subscriptions.push(subscription);
179
- }
180
- getConnectionStatus() {
181
- return this.connectionStatus;
182
- }
183
- setConnectionStatus(status) {
184
- this.connectionStatus = status;
185
- this.subscriptions.forEach(subscription => {
186
- if (subscription.getStatus() !== 'cancelled') {
187
- subscription.setConnectionStatus(this.connectionStatus);
188
- }
189
- });
190
- }
191
- getChannelStatus() {
192
- return this.channelStatus;
193
- }
194
- handleChannelStateChange(stateChange) {
195
- this.channelStatus = stateChange.current;
196
- this.subscriptions.forEach(subscription => {
197
- if (subscription.getStatus() !== 'cancelled') {
198
- subscription.setChannelStatus(this.channelStatus);
199
- }
200
- });
201
- }
202
- getGetLatestMessagesStatus() {
203
- return this.getLatestMessagesStatus;
204
- }
205
- setGetLatestMessagesStatus(status) {
206
- this.getLatestMessagesStatus = status;
207
- this.subscriptions.forEach(subscription => {
208
- if (subscription.getStatus() !== 'cancelled') {
209
- subscription.setGetLatestMessagesStatus(this.getLatestMessagesStatus);
210
- }
211
- });
212
- }
213
- detachChannel(callback) {
214
- this.channel.detach(callback);
215
- }
216
- fireMessagesEventOnEachNonCancelledSubscription() {
217
- this.fireEventOnEachSubscription('messages', {
218
- messages: this.messages.concat()
219
- }, {
220
- whereStatusNotIn: ['cancelled']
221
- });
222
- }
223
- fireEventOnEachSubscription(name, data, options) {
224
- for (let i = 0, il = this.subscriptions.length; i < il; i++) {
225
- const subscription = this.subscriptions[i];
226
- if (options && Array.isArray(options.whereStatusNotIn) && options.whereStatusNotIn.includes(subscription.getStatus())) {
227
- continue;
228
- }
229
- subscription.fireEvent(name, data);
230
- }
231
- }
232
- cancelSubscription(subscription) {
233
- subscription.setStatus('cancelled');
234
- }
235
- cancelAllSubscriptions() {
236
- this.subscriptions.forEach(subscription => {
237
- this.cancelSubscription(subscription);
238
- });
239
- }
240
- }
241
- exports.default = CachedChat;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const uuid_1 = require("uuid");
27
+ const PendingMessage_1 = __importStar(require("./PendingMessage"));
28
+ const Message_1 = __importStar(require("./Message"));
29
+ class CachedChat {
30
+ constructor({ id, api, channel, connectionStatus, logger, debugLogger, debug }) {
31
+ this.getLatestMessagesStatus = 'initialized';
32
+ this.id = id;
33
+ this.api = api;
34
+ this.messages = [];
35
+ this.onlineUsers = [];
36
+ this.subscriptions = [];
37
+ this.channel = channel;
38
+ this.channelStatus = this.channel.state;
39
+ this.connectionStatus = connectionStatus;
40
+ this.logger = logger;
41
+ this.debugLogger = debugLogger;
42
+ this.debug = debug;
43
+ this.disabled_at = null;
44
+ this.channel.on(this.handleChannelStateChange.bind(this));
45
+ this.channel.subscribe((message) => {
46
+ var _a;
47
+ if ((_a = this.debug) === null || _a === void 0 ? void 0 : _a.inboundAblyMessages) {
48
+ this.debugLogger.debug('[Ably] [InboundMessage]', message);
49
+ }
50
+ if (message.name === 'chat.message.created') {
51
+ this.addMessage(new Message_1.default({
52
+ id: message.data.id,
53
+ chatId: message.data.chat_id,
54
+ message: message.data.message,
55
+ senderId: message.data.sender_id,
56
+ sender: message.data.sender,
57
+ isAdminMessage: message.data.is_admin_message,
58
+ createdAt: new Date(message.data.created_at)
59
+ }));
60
+ this.fireMessagesEventOnEachNonCancelledSubscription();
61
+ }
62
+ });
63
+ }
64
+ sendMessage(message, options) {
65
+ return new Promise((resolve, reject) => {
66
+ const pendingMessage = new PendingMessage_1.default({
67
+ id: (0, uuid_1.v4)(),
68
+ message,
69
+ status: 'initialized',
70
+ options,
71
+ createdAt: new Date
72
+ });
73
+ this.addMessage(pendingMessage);
74
+ this.fireMessagesEventOnEachNonCancelledSubscription();
75
+ this.sendPendingMessage(pendingMessage)
76
+ .then(() => resolve())
77
+ .catch(err => reject(err));
78
+ });
79
+ }
80
+ reportChat(reason) {
81
+ return new Promise((resolve, reject) => {
82
+ this.api.reportChat(this.id, reason)
83
+ .then(() => resolve())
84
+ .catch(err => reject(err));
85
+ });
86
+ }
87
+ toggleChatEnabled() {
88
+ return new Promise((resolve, reject) => {
89
+ this.api.toggleChatEnabled(this.id)
90
+ .then(() => resolve())
91
+ .catch(err => reject(err));
92
+ });
93
+ }
94
+ sendPendingMessage(pendingMessage) {
95
+ return new Promise((resolve, reject) => {
96
+ if (!(0, PendingMessage_1.isPendingMessage)(pendingMessage) || pendingMessage.status === 'pending') {
97
+ return resolve();
98
+ }
99
+ this.updatePendingMessageStatus(pendingMessage, 'pending');
100
+ this.fireMessagesEventOnEachNonCancelledSubscription();
101
+ this.api.storeMessage(this.id, pendingMessage.message, pendingMessage.options).then(({ message, error }) => {
102
+ if (error) {
103
+ this.updatePendingMessageStatus(pendingMessage, 'failed');
104
+ this.fireMessagesEventOnEachNonCancelledSubscription();
105
+ return reject(new Error(error.message));
106
+ }
107
+ this.replacePendingMessage(pendingMessage, message);
108
+ this.fireMessagesEventOnEachNonCancelledSubscription();
109
+ resolve();
110
+ }).catch(err => {
111
+ this.updatePendingMessageStatus(pendingMessage, 'failed');
112
+ this.fireMessagesEventOnEachNonCancelledSubscription();
113
+ reject(err);
114
+ });
115
+ });
116
+ }
117
+ getLatestMessages() {
118
+ this.setGetLatestMessagesStatus('fetching');
119
+ this.api.getLatestMessages(this.id).then(({ messages, error }) => {
120
+ if (messages) {
121
+ messages.forEach(m => this.addMessage(m));
122
+ this.setGetLatestMessagesStatus('success');
123
+ this.fireMessagesEventOnEachNonCancelledSubscription();
124
+ return;
125
+ }
126
+ this.setGetLatestMessagesStatus('failed');
127
+ }).catch(err => {
128
+ this.setGetLatestMessagesStatus('failed');
129
+ });
130
+ }
131
+ markMessagesReadUpTo(message) {
132
+ return this.api.markChatMessagesReadUpTo(this.id, message);
133
+ }
134
+ setDisabledAt(disabled_at) {
135
+ this.disabled_at = disabled_at;
136
+ }
137
+ getDisabledAt() {
138
+ return this.disabled_at;
139
+ }
140
+ addMessage(message) {
141
+ if (message instanceof PendingMessage_1.default) {
142
+ this.messages.push(message);
143
+ return;
144
+ }
145
+ let index = -1;
146
+ for (let i = (this.messages.length - 1); i >= 0; i--) {
147
+ if ((0, Message_1.isMessageAnd)(this.messages[i], m => m.id < message.id) && index === -1) {
148
+ index = i;
149
+ }
150
+ if ((0, Message_1.isMessageAnd)(this.messages[i], m => m.id === message.id)) {
151
+ return;
152
+ }
153
+ }
154
+ if (index === -1) {
155
+ this.messages.unshift(message);
156
+ this.messages = this.messages.concat([]);
157
+ }
158
+ else {
159
+ this.messages.splice(index + 1, 0, message);
160
+ this.messages = this.messages.concat([]);
161
+ }
162
+ }
163
+ replacePendingMessage(pendingMessage, message) {
164
+ this.messages = this.messages.filter((m) => {
165
+ return m.id !== pendingMessage.id;
166
+ });
167
+ this.addMessage(message);
168
+ }
169
+ updatePendingMessageStatus(pendingMessage, status) {
170
+ this.messages = this.messages.map((m) => {
171
+ if ((0, PendingMessage_1.isPendingMessage)(m) && m.id === pendingMessage.id) {
172
+ return m.clone({ status });
173
+ }
174
+ return m;
175
+ });
176
+ }
177
+ addSubscription(subscription) {
178
+ this.subscriptions.push(subscription);
179
+ }
180
+ getConnectionStatus() {
181
+ return this.connectionStatus;
182
+ }
183
+ setConnectionStatus(status) {
184
+ this.connectionStatus = status;
185
+ this.subscriptions.forEach(subscription => {
186
+ if (subscription.getStatus() !== 'cancelled') {
187
+ subscription.setConnectionStatus(this.connectionStatus);
188
+ }
189
+ });
190
+ }
191
+ getChannelStatus() {
192
+ return this.channelStatus;
193
+ }
194
+ handleChannelStateChange(stateChange) {
195
+ this.channelStatus = stateChange.current;
196
+ this.subscriptions.forEach(subscription => {
197
+ if (subscription.getStatus() !== 'cancelled') {
198
+ subscription.setChannelStatus(this.channelStatus);
199
+ }
200
+ });
201
+ }
202
+ getGetLatestMessagesStatus() {
203
+ return this.getLatestMessagesStatus;
204
+ }
205
+ setGetLatestMessagesStatus(status) {
206
+ this.getLatestMessagesStatus = status;
207
+ this.subscriptions.forEach(subscription => {
208
+ if (subscription.getStatus() !== 'cancelled') {
209
+ subscription.setGetLatestMessagesStatus(this.getLatestMessagesStatus);
210
+ }
211
+ });
212
+ }
213
+ detachChannel(callback) {
214
+ this.channel.detach(callback);
215
+ }
216
+ fireMessagesEventOnEachNonCancelledSubscription() {
217
+ this.fireEventOnEachSubscription('messages', {
218
+ messages: this.messages.concat()
219
+ }, {
220
+ whereStatusNotIn: ['cancelled']
221
+ });
222
+ }
223
+ fireEventOnEachSubscription(name, data, options) {
224
+ for (let i = 0, il = this.subscriptions.length; i < il; i++) {
225
+ const subscription = this.subscriptions[i];
226
+ if (options && Array.isArray(options.whereStatusNotIn) && options.whereStatusNotIn.includes(subscription.getStatus())) {
227
+ continue;
228
+ }
229
+ subscription.fireEvent(name, data);
230
+ }
231
+ }
232
+ cancelSubscription(subscription) {
233
+ subscription.setStatus('cancelled');
234
+ }
235
+ cancelAllSubscriptions() {
236
+ this.subscriptions.forEach(subscription => {
237
+ this.cancelSubscription(subscription);
238
+ });
239
+ }
240
+ }
241
+ exports.default = CachedChat;
242
242
  //# sourceMappingURL=CachedChat.js.map
package/dist/Chat.d.ts CHANGED
@@ -1,66 +1,66 @@
1
- import * as Ably from 'ably';
2
- import ChatError from "./ChatError";
3
- import { AxiosInstance } from 'axios';
4
- import API, { ConstructApiParams } from "./API";
5
- import { Logger } from "./logger";
6
- import ChatSubscription from "./ChatSubscription";
7
- export interface ChatOptions {
8
- axios: AxiosInstance;
9
- logger?: Logger;
10
- jwtToken?: string;
11
- routes: Routes;
12
- debug?: DebugOptions;
13
- }
14
- export interface Routes {
15
- getReportChatRoute: ConstructApiParams['getReportChatRoute'];
16
- getChatMessagesRoute: ConstructApiParams['getChatMessagesRoute'];
17
- getChatAblyTokenRoute: ConstructApiParams['getChatAblyTokenRoute'];
18
- getChatStoreMessageRoute: ConstructApiParams['getChatStoreMessageRoute'];
19
- getToggleChatEnabledRoute: ConstructApiParams['getToggleChatEnabledRoute'];
20
- getChatForAppointmentRoute: ConstructApiParams['getChatForAppointmentRoute'];
21
- markChatMessagesReadUpToRoute: ConstructApiParams['markChatMessagesReadUpToRoute'];
22
- getUserChatUnreadMessageCountRoute: ConstructApiParams['getUserChatUnreadMessageCountRoute'];
23
- }
24
- export interface DebugOptions {
25
- apiResponses: boolean;
26
- apiErrors: boolean;
27
- inboundAblyMessages: boolean;
28
- }
29
- export declare type ConnectionStatus = 'initialized' | 'connecting' | 'connected' | 'disconnected' | 'suspended' | 'closing' | 'closed' | 'failed';
30
- export declare type ChannelStatus = 'initialized' | 'attaching' | 'attached' | 'detaching' | 'detached' | 'suspended' | 'failed';
31
- export interface ChatEvents {
32
- initialized: boolean;
33
- }
34
- export declare type ChatEventCallbacks = {
35
- [Event in keyof ChatEvents]: (data: ChatEvents[Event]) => void;
36
- };
37
- export declare type ChatEventListeners = {
38
- [Event in keyof ChatEvents]: ChatEventCallbacks[Event][];
39
- };
40
- declare const Chat: {
41
- init: (options: ChatOptions) => void;
42
- isInitialized: () => boolean;
43
- setJwtToken: (_jwtToken?: string) => void;
44
- api: () => API;
45
- get: (id: number, disabled_at?: Date | null | undefined) => Promise<{
46
- subscription: ChatSubscription;
47
- error?: undefined;
48
- } | {
49
- subscription?: undefined;
50
- error: ChatError;
51
- }>;
52
- appointment: (appointmentId: number) => Promise<{
53
- subscription: ChatSubscription;
54
- error?: undefined;
55
- } | {
56
- subscription?: undefined;
57
- error: ChatError;
58
- }>;
59
- connect: () => void;
60
- close: () => void;
61
- channel: (channelName: string) => Ably.Types.RealtimeChannelCallbacks;
62
- addEventListener: <Event_1 extends "initialized">(event: Event_1, listener: ChatEventCallbacks[Event_1]) => void;
63
- removeEventListener: <Event_2 extends "initialized">(event: Event_2, listener: ChatEventCallbacks[Event_2]) => void;
64
- logout: () => void;
65
- };
66
- export default Chat;
1
+ import * as Ably from 'ably';
2
+ import ChatError from "./ChatError";
3
+ import { AxiosInstance } from 'axios';
4
+ import API, { ConstructApiParams } from "./API";
5
+ import { Logger } from "./logger";
6
+ import ChatSubscription from "./ChatSubscription";
7
+ export interface ChatOptions {
8
+ axios: AxiosInstance;
9
+ logger?: Logger;
10
+ jwtToken?: string;
11
+ routes: Routes;
12
+ debug?: DebugOptions;
13
+ }
14
+ export interface Routes {
15
+ getReportChatRoute: ConstructApiParams['getReportChatRoute'];
16
+ getChatMessagesRoute: ConstructApiParams['getChatMessagesRoute'];
17
+ getChatAblyTokenRoute: ConstructApiParams['getChatAblyTokenRoute'];
18
+ getChatStoreMessageRoute: ConstructApiParams['getChatStoreMessageRoute'];
19
+ getToggleChatEnabledRoute: ConstructApiParams['getToggleChatEnabledRoute'];
20
+ getChatForAppointmentRoute: ConstructApiParams['getChatForAppointmentRoute'];
21
+ markChatMessagesReadUpToRoute: ConstructApiParams['markChatMessagesReadUpToRoute'];
22
+ getUserChatUnreadMessageCountRoute: ConstructApiParams['getUserChatUnreadMessageCountRoute'];
23
+ }
24
+ export interface DebugOptions {
25
+ apiResponses: boolean;
26
+ apiErrors: boolean;
27
+ inboundAblyMessages: boolean;
28
+ }
29
+ export declare type ConnectionStatus = 'initialized' | 'connecting' | 'connected' | 'disconnected' | 'suspended' | 'closing' | 'closed' | 'failed';
30
+ export declare type ChannelStatus = 'initialized' | 'attaching' | 'attached' | 'detaching' | 'detached' | 'suspended' | 'failed';
31
+ export interface ChatEvents {
32
+ initialized: boolean;
33
+ }
34
+ export declare type ChatEventCallbacks = {
35
+ [Event in keyof ChatEvents]: (data: ChatEvents[Event]) => void;
36
+ };
37
+ export declare type ChatEventListeners = {
38
+ [Event in keyof ChatEvents]: ChatEventCallbacks[Event][];
39
+ };
40
+ declare const Chat: {
41
+ init: (options: ChatOptions) => void;
42
+ isInitialized: () => boolean;
43
+ setJwtToken: (_jwtToken?: string) => void;
44
+ api: () => API;
45
+ get: (id: number, disabled_at?: Date | null | undefined) => Promise<{
46
+ subscription: ChatSubscription;
47
+ error?: undefined;
48
+ } | {
49
+ subscription?: undefined;
50
+ error: ChatError;
51
+ }>;
52
+ appointment: (appointmentId: number) => Promise<{
53
+ subscription: ChatSubscription;
54
+ error?: undefined;
55
+ } | {
56
+ subscription?: undefined;
57
+ error: ChatError;
58
+ }>;
59
+ connect: () => void;
60
+ close: () => void;
61
+ channel: (channelName: string) => Ably.Types.RealtimeChannelCallbacks;
62
+ addEventListener: <Event_1 extends "initialized">(event: Event_1, listener: ChatEventCallbacks[Event_1]) => void;
63
+ removeEventListener: <Event_2 extends "initialized">(event: Event_2, listener: ChatEventCallbacks[Event_2]) => void;
64
+ logout: () => void;
65
+ };
66
+ export default Chat;