@viewberapp/chat 0.0.21 → 0.0.24
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.
- package/dist/API.d.ts +43 -0
- package/dist/API.js +81 -0
- package/dist/API.js.map +1 -0
- package/dist/CachedChat.d.ts +12 -10
- package/dist/CachedChat.js +101 -29
- package/dist/CachedChat.js.map +1 -1
- package/dist/Chat.d.ts +3 -30
- package/dist/Chat.js +31 -83
- package/dist/Chat.js.map +1 -1
- package/dist/ChatError.d.ts +3 -0
- package/dist/ChatError.js +3 -0
- package/dist/ChatError.js.map +1 -0
- package/dist/ChatSubscription.d.ts +9 -12
- package/dist/ChatSubscription.js +8 -19
- package/dist/ChatSubscription.js.map +1 -1
- package/dist/Message.d.ts +22 -0
- package/dist/Message.js +29 -0
- package/dist/Message.js.map +1 -0
- package/dist/PendingMessage.d.ts +10 -0
- package/dist/PendingMessage.js +13 -0
- package/dist/PendingMessage.js.map +1 -0
- package/dist/react/useChat.d.ts +2 -1
- package/dist/react/useChat.js +6 -4
- package/dist/react/useChat.js.map +1 -1
- package/package.json +2 -2
package/dist/API.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import ChatError from "./ChatError";
|
|
3
|
+
import Message from './Message';
|
|
4
|
+
export interface ConstructApiParams {
|
|
5
|
+
axios: AxiosInstance;
|
|
6
|
+
jwtToken?: string;
|
|
7
|
+
getChatMessagesRoute: (chatId: number) => string;
|
|
8
|
+
getChatStoreMessageRoute: (chatId: number) => string;
|
|
9
|
+
getChatForAppointmentRoute: (appointmentId: number) => string;
|
|
10
|
+
}
|
|
11
|
+
export declare type StoreMessageReturnValue = {
|
|
12
|
+
message: Message;
|
|
13
|
+
error?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
message?: undefined;
|
|
16
|
+
error: ChatError;
|
|
17
|
+
};
|
|
18
|
+
export declare type GetLatestMessagesReturnValue = {
|
|
19
|
+
messages: Message[];
|
|
20
|
+
error?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
messages?: undefined;
|
|
23
|
+
error: ChatError;
|
|
24
|
+
};
|
|
25
|
+
export declare type GetChatIdFromAppointmentIdReturnValue = {
|
|
26
|
+
chatId: number;
|
|
27
|
+
error?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
chatId?: undefined;
|
|
30
|
+
error: ChatError;
|
|
31
|
+
};
|
|
32
|
+
export default class API {
|
|
33
|
+
private axios;
|
|
34
|
+
private jwtToken?;
|
|
35
|
+
private getChatMessagesRoute;
|
|
36
|
+
private getChatStoreMessageRoute;
|
|
37
|
+
private getChatForAppointmentRoute;
|
|
38
|
+
constructor(params: ConstructApiParams);
|
|
39
|
+
storeMessage: (chatId: number, message: string) => Promise<StoreMessageReturnValue>;
|
|
40
|
+
getLatestMessages: (chatId: number) => Promise<GetLatestMessagesReturnValue>;
|
|
41
|
+
getChatIdFromAppointmentId: (appointmentId: number) => Promise<GetChatIdFromAppointmentIdReturnValue>;
|
|
42
|
+
private constructHeaders;
|
|
43
|
+
}
|
package/dist/API.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const Message_1 = __importDefault(require("./Message"));
|
|
8
|
+
class API {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
this.storeMessage = (chatId, message) => new Promise((resolve, reject) => {
|
|
11
|
+
this.axios.post(this.getChatStoreMessageRoute(chatId), { message }, {
|
|
12
|
+
headers: this.constructHeaders(),
|
|
13
|
+
}).then(response => {
|
|
14
|
+
resolve({
|
|
15
|
+
message: new Message_1.default({
|
|
16
|
+
id: response.data.id,
|
|
17
|
+
chatId: response.data.chat_id,
|
|
18
|
+
message: response.data.message,
|
|
19
|
+
senderId: response.data.sender_id,
|
|
20
|
+
sender: response.data.sender,
|
|
21
|
+
isAdminMessage: response.data.is_admin_message
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
}).catch(err => {
|
|
25
|
+
var _a;
|
|
26
|
+
if (axios_1.default.isAxiosError(err) && ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 403) {
|
|
27
|
+
resolve({ error: { code: 'unauthorized' } });
|
|
28
|
+
}
|
|
29
|
+
resolve({ error: { code: 'error' } });
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
this.getLatestMessages = (chatId) => new Promise((resolve, reject) => {
|
|
33
|
+
this.axios.get(this.getChatMessagesRoute(chatId), {
|
|
34
|
+
headers: this.constructHeaders(),
|
|
35
|
+
}).then(response => {
|
|
36
|
+
resolve({
|
|
37
|
+
messages: response.data.data.map((m) => new Message_1.default({
|
|
38
|
+
id: m.id,
|
|
39
|
+
chatId: m.chat_id,
|
|
40
|
+
message: m.message,
|
|
41
|
+
senderId: m.sender_id,
|
|
42
|
+
sender: m.sender,
|
|
43
|
+
isAdminMessage: m.is_admin_message
|
|
44
|
+
}))
|
|
45
|
+
});
|
|
46
|
+
}).catch(err => {
|
|
47
|
+
var _a;
|
|
48
|
+
if (axios_1.default.isAxiosError(err) && ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 403) {
|
|
49
|
+
resolve({ error: { code: 'unauthorized' } });
|
|
50
|
+
}
|
|
51
|
+
resolve({ error: { code: 'error' } });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
this.getChatIdFromAppointmentId = (appointmentId) => new Promise((resolve, reject) => {
|
|
55
|
+
this.axios.get(this.getChatForAppointmentRoute(appointmentId), {
|
|
56
|
+
headers: this.constructHeaders()
|
|
57
|
+
}).then(response => {
|
|
58
|
+
resolve({ chatId: response.data.data.id });
|
|
59
|
+
}).catch(err => {
|
|
60
|
+
var _a;
|
|
61
|
+
if (axios_1.default.isAxiosError(err) && ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 403) {
|
|
62
|
+
resolve({ error: { code: 'unauthorized' } });
|
|
63
|
+
}
|
|
64
|
+
resolve({ error: { code: 'error' } });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
this.constructHeaders = () => {
|
|
68
|
+
if (this.jwtToken) {
|
|
69
|
+
return { 'Authorization': `Bearer ${this.jwtToken}` };
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
this.axios = params.axios;
|
|
74
|
+
this.jwtToken = params.jwtToken;
|
|
75
|
+
this.getChatMessagesRoute = params.getChatMessagesRoute;
|
|
76
|
+
this.getChatStoreMessageRoute = params.getChatStoreMessageRoute;
|
|
77
|
+
this.getChatForAppointmentRoute = params.getChatForAppointmentRoute;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = API;
|
|
81
|
+
//# sourceMappingURL=API.js.map
|
package/dist/API.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAG1B,wDAAgC;AAsBhC,MAAqB,GAAG;IAOpB,YAAY,MAA0B;QAQtC,iBAAY,GAAG,CAAC,MAAc,EAAE,OAAe,EAAoC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,EAAC,OAAO,EAAC,EAAE;gBAC9D,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE;aACnC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACf,OAAO,CAAC;oBACJ,OAAO,EAAE,IAAI,iBAAO,CAAC;wBACjB,EAAE,EAAE,QAAQ,CAAC,IAAI,CAA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K,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,EAAC,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEK,qBAAgB,GAAG,GAAqC,EAAE;YAC9D,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,OAAO,EAAC,eAAe,EAAE,UAAU,IAAI,CAAC,QAAQ,EAAE,EAAC,CAAC;aACvD;YACD,OAAO,SAAS,CAAC;QACrB,CAAC,CAAA;QArEG,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,CAAC;QACxD,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC,wBAAwB,CAAC;QAChE,IAAI,CAAC,0BAA0B,GAAG,MAAM,CAAC,0BAA0B,CAAC;IACxE,CAAC;CAiEJ;AA9ED,sBA8EC"}
|
package/dist/CachedChat.d.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
1
|
import { PresenceChannel } from "laravel-echo";
|
|
3
|
-
import
|
|
2
|
+
import API from "./API";
|
|
4
3
|
import ChatSubscription from "./ChatSubscription";
|
|
5
4
|
import { Logger } from "./Logger";
|
|
5
|
+
import Message from "./Message";
|
|
6
|
+
import PendingMessage from "./PendingMessage";
|
|
6
7
|
export interface CachedChatParams {
|
|
7
8
|
id: number;
|
|
8
|
-
|
|
9
|
-
axios: AxiosInstance;
|
|
9
|
+
api: API;
|
|
10
10
|
channel: PresenceChannel;
|
|
11
11
|
logger: Logger;
|
|
12
|
-
getChatStoreMessageRoute: ChatOptions['getChatStoreMessageRoute'];
|
|
13
12
|
leave: () => void;
|
|
14
13
|
}
|
|
14
|
+
export declare type Messages = (Message | PendingMessage)[];
|
|
15
15
|
export default class CachedChat {
|
|
16
16
|
private id;
|
|
17
|
-
private
|
|
18
|
-
private axios;
|
|
17
|
+
private api;
|
|
19
18
|
private messages;
|
|
20
19
|
private subscriptions;
|
|
21
20
|
private channel;
|
|
22
21
|
private logger;
|
|
23
|
-
private getChatStoreMessageRoute;
|
|
24
22
|
private _leave;
|
|
25
|
-
constructor({ id,
|
|
26
|
-
sendMessage(message: string): Promise<
|
|
23
|
+
constructor({ id, api, channel, logger, leave }: CachedChatParams);
|
|
24
|
+
sendMessage(message: string): Promise<void>;
|
|
25
|
+
getLatestMessages(): void;
|
|
26
|
+
addMessage(message: Message | PendingMessage): void;
|
|
27
|
+
private replacePendingMessage;
|
|
27
28
|
addSubscription(subscription: ChatSubscription): void;
|
|
28
29
|
cancelSubscription(subscription: ChatSubscription): void;
|
|
29
30
|
cancelAllSubscriptions(): void;
|
|
31
|
+
private fireMessagesEventOnEachActiveSubscription;
|
|
30
32
|
leave(): void;
|
|
31
33
|
cancelAllSubscriptionsAndLeave(): void;
|
|
32
34
|
}
|
package/dist/CachedChat.js
CHANGED
|
@@ -1,48 +1,72 @@
|
|
|
1
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const Message_1 = __importStar(require("./Message"));
|
|
30
|
+
const PendingMessage_1 = __importDefault(require("./PendingMessage"));
|
|
3
31
|
class CachedChat {
|
|
4
|
-
constructor({ id,
|
|
32
|
+
constructor({ id, api, channel, logger, leave }) {
|
|
5
33
|
this.id = id;
|
|
6
|
-
this.
|
|
7
|
-
this.axios = axios;
|
|
34
|
+
this.api = api;
|
|
8
35
|
this.messages = [];
|
|
9
36
|
this.subscriptions = [];
|
|
10
37
|
this.channel = channel;
|
|
11
38
|
this.logger = logger;
|
|
12
|
-
this.getChatStoreMessageRoute = getChatStoreMessageRoute;
|
|
13
39
|
this._leave = leave;
|
|
14
40
|
channel
|
|
15
41
|
.here((users) => {
|
|
16
42
|
console.log('Cached here', users);
|
|
17
43
|
this.subscriptions.forEach((subscription) => {
|
|
18
|
-
|
|
19
|
-
subscription.event('onHere', users);
|
|
20
|
-
}
|
|
44
|
+
subscription.fireEventIfActive('here', users);
|
|
21
45
|
});
|
|
22
46
|
})
|
|
23
47
|
.joining((user) => {
|
|
24
48
|
console.log('Cached joining', user);
|
|
25
49
|
this.subscriptions.forEach((subscription) => {
|
|
26
|
-
|
|
27
|
-
subscription.event('onUserJoining', user);
|
|
28
|
-
}
|
|
50
|
+
subscription.fireEventIfActive('userJoining', user);
|
|
29
51
|
});
|
|
30
52
|
})
|
|
31
53
|
.leaving((user) => {
|
|
32
54
|
console.log('Cached leaving', user);
|
|
33
55
|
this.subscriptions.forEach((subscription) => {
|
|
34
|
-
|
|
35
|
-
subscription.event('onUserLeaving', user);
|
|
36
|
-
}
|
|
56
|
+
subscription.fireEventIfActive('userLeaving', user);
|
|
37
57
|
});
|
|
38
58
|
})
|
|
39
59
|
.listen('.chat.message.created', (event) => {
|
|
40
|
-
console.log('
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
console.log('.chat.message.created', event);
|
|
61
|
+
this.addMessage(new Message_1.default({
|
|
62
|
+
id: event.id,
|
|
63
|
+
chatId: event.chat_id,
|
|
64
|
+
message: event.message,
|
|
65
|
+
senderId: event.sender_id,
|
|
66
|
+
sender: event.sender,
|
|
67
|
+
isAdminMessage: event.isAdminMessage
|
|
68
|
+
}));
|
|
69
|
+
this.fireMessagesEventOnEachActiveSubscription();
|
|
46
70
|
})
|
|
47
71
|
.error((error) => {
|
|
48
72
|
console.error(error);
|
|
@@ -50,21 +74,64 @@ class CachedChat {
|
|
|
50
74
|
}
|
|
51
75
|
sendMessage(message) {
|
|
52
76
|
return new Promise((resolve, reject) => {
|
|
53
|
-
|
|
54
|
-
message
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
const pendingMessage = new PendingMessage_1.default({
|
|
78
|
+
message,
|
|
79
|
+
status: 'pending'
|
|
80
|
+
});
|
|
81
|
+
this.addMessage(pendingMessage);
|
|
82
|
+
this.fireMessagesEventOnEachActiveSubscription();
|
|
83
|
+
this.api.storeMessage(this.id, message).then(({ message, error }) => {
|
|
84
|
+
if (error) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.replacePendingMessage(pendingMessage, message);
|
|
88
|
+
this.fireMessagesEventOnEachActiveSubscription();
|
|
62
89
|
}).catch(err => {
|
|
63
90
|
this.logger.error(err);
|
|
64
|
-
reject(err);
|
|
65
91
|
});
|
|
66
92
|
});
|
|
67
93
|
}
|
|
94
|
+
getLatestMessages() {
|
|
95
|
+
this.api.getLatestMessages(this.id).then(({ messages, error }) => {
|
|
96
|
+
if (messages) {
|
|
97
|
+
messages.forEach(m => this.addMessage(m));
|
|
98
|
+
this.fireMessagesEventOnEachActiveSubscription();
|
|
99
|
+
}
|
|
100
|
+
}).catch(err => {
|
|
101
|
+
this.logger.error(err);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
addMessage(message) {
|
|
105
|
+
if (message instanceof PendingMessage_1.default) {
|
|
106
|
+
this.messages.push(message);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let index = -1;
|
|
110
|
+
for (let i = this.messages.length; i >= 0; i--) {
|
|
111
|
+
if ((0, Message_1.isMessageThen)(this.messages[i], m => m.id < message.id)) {
|
|
112
|
+
index = i;
|
|
113
|
+
}
|
|
114
|
+
if ((0, Message_1.isMessageThen)(this.messages[i], m => m.id === message.id)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (index === -1) {
|
|
119
|
+
this.messages.unshift(message);
|
|
120
|
+
this.messages = this.messages.concat([]);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.messages.splice(index, 0, message);
|
|
124
|
+
this.messages = this.messages.concat([]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
replacePendingMessage(pendingMessage, message) {
|
|
128
|
+
this.messages = this.messages.map((m) => {
|
|
129
|
+
if (m === pendingMessage) {
|
|
130
|
+
return message;
|
|
131
|
+
}
|
|
132
|
+
return m;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
68
135
|
addSubscription(subscription) {
|
|
69
136
|
this.subscriptions.push(subscription);
|
|
70
137
|
}
|
|
@@ -76,6 +143,11 @@ class CachedChat {
|
|
|
76
143
|
this.cancelSubscription(subscription);
|
|
77
144
|
});
|
|
78
145
|
}
|
|
146
|
+
fireMessagesEventOnEachActiveSubscription() {
|
|
147
|
+
this.subscriptions.forEach((subscription) => {
|
|
148
|
+
subscription.fireEventIfActive('messages', this.messages);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
79
151
|
leave() {
|
|
80
152
|
this._leave();
|
|
81
153
|
}
|
package/dist/CachedChat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachedChat.js","sourceRoot":"","sources":["../src/CachedChat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CachedChat.js","sourceRoot":"","sources":["../src/CachedChat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,qDAAmD;AACnD,sEAA8C;AAY9C,MAAqB,UAAU;IAS3B,YAAY,EACR,EAAE,EACF,GAAG,EACH,OAAO,EACP,MAAM,EACN,KAAK,EACU;QACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,OAAO;aACF,IAAI,CAAC,CAAC,KAAU,EAAE,EAAE;YACjB,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAClC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,YAA8B,EAAE,EAAE;gBAC1D,YAAY,CAAC,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;aACD,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;YACpC,I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AA8B;QAC7C,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED,sBAAsB;QAClB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACtC,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,yCAAyC;QAC7C,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,YAA8B,EAAE,EAAE;YAC1D,YAAY,CAAC,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;IAED,8BAA8B;QAC1B,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ;AArMD,6BAqMC"}
|
package/dist/Chat.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import Echo from "laravel-echo";
|
|
2
|
-
import
|
|
2
|
+
import ChatError from "./ChatError";
|
|
3
3
|
import CachedChat from "./CachedChat";
|
|
4
4
|
import { AxiosInstance } from 'axios';
|
|
5
|
+
import { Logger } from "./Logger";
|
|
5
6
|
import ChatSubscription from "./ChatSubscription";
|
|
6
7
|
export interface ChatOptions {
|
|
7
8
|
echo: Echo;
|
|
8
|
-
axios
|
|
9
|
+
axios: AxiosInstance;
|
|
9
10
|
logger?: Logger;
|
|
10
11
|
jwtToken?: string;
|
|
11
12
|
constructPusher: (config: ConstructPusherConfig) => any;
|
|
@@ -26,30 +27,6 @@ export declare type GetReturnValue = {
|
|
|
26
27
|
subscription?: undefined;
|
|
27
28
|
error: ChatError;
|
|
28
29
|
};
|
|
29
|
-
export interface GetLatestChatMessagesOptions {
|
|
30
|
-
headers?: {
|
|
31
|
-
[index: string]: string | undefined;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export declare type GetLatestChatMessagesReturnValue = {
|
|
35
|
-
messages: any[];
|
|
36
|
-
error?: undefined;
|
|
37
|
-
} | {
|
|
38
|
-
messages?: undefined;
|
|
39
|
-
error: ChatError;
|
|
40
|
-
};
|
|
41
|
-
export interface GetChatIdFromAppointmentIdOptions {
|
|
42
|
-
headers?: {
|
|
43
|
-
[index: string]: string | undefined;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export declare type GetChatIdFromAppointmentIdReturnValue = {
|
|
47
|
-
chatId: number;
|
|
48
|
-
error?: undefined;
|
|
49
|
-
} | {
|
|
50
|
-
chatId?: undefined;
|
|
51
|
-
error: ChatError;
|
|
52
|
-
};
|
|
53
30
|
export declare type GetChatReturnValue = {
|
|
54
31
|
chat: CachedChat;
|
|
55
32
|
error?: undefined;
|
|
@@ -57,10 +34,6 @@ export declare type GetChatReturnValue = {
|
|
|
57
34
|
chat?: undefined;
|
|
58
35
|
error: ChatError;
|
|
59
36
|
};
|
|
60
|
-
export interface ChatError {
|
|
61
|
-
code: ChatErrorCode;
|
|
62
|
-
}
|
|
63
|
-
export declare type ChatErrorCode = 'error' | 'unauthorized' | 'chat_not_initialized' | 'echo_is_not_defined';
|
|
64
37
|
declare const Chat: {
|
|
65
38
|
init: (_options: ChatOptions) => void;
|
|
66
39
|
isInitialized: () => boolean;
|
package/dist/Chat.js
CHANGED
|
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const laravel_echo_1 = __importDefault(require("laravel-echo"));
|
|
16
|
-
const
|
|
16
|
+
const API_1 = __importDefault(require("./API"));
|
|
17
17
|
const CachedChat_1 = __importDefault(require("./CachedChat"));
|
|
18
|
-
const
|
|
18
|
+
const Logger_1 = require("./Logger");
|
|
19
19
|
const ChatSubscription_1 = __importDefault(require("./ChatSubscription"));
|
|
20
20
|
const Chat = (function () {
|
|
21
21
|
let initialized = false;
|
|
22
22
|
let echo;
|
|
23
|
-
let
|
|
23
|
+
let api;
|
|
24
24
|
let logger;
|
|
25
25
|
let options;
|
|
26
26
|
const chats = {};
|
|
@@ -37,7 +37,13 @@ const Chat = (function () {
|
|
|
37
37
|
jwtToken: options.jwtToken
|
|
38
38
|
})
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
api = new API_1.default({
|
|
41
|
+
axios: options.axios,
|
|
42
|
+
jwtToken: options.jwtToken,
|
|
43
|
+
getChatMessagesRoute: options.getChatMessagesRoute,
|
|
44
|
+
getChatStoreMessageRoute: options.getChatStoreMessageRoute,
|
|
45
|
+
getChatForAppointmentRoute: options.getChatForAppointmentRoute
|
|
46
|
+
});
|
|
41
47
|
logger = options.logger || new Logger_1.ConsoleLogger;
|
|
42
48
|
};
|
|
43
49
|
const isInitialized = () => {
|
|
@@ -54,103 +60,47 @@ const Chat = (function () {
|
|
|
54
60
|
jwtToken: options.jwtToken
|
|
55
61
|
})
|
|
56
62
|
});
|
|
63
|
+
api = new API_1.default({
|
|
64
|
+
axios: options.axios,
|
|
65
|
+
jwtToken: options.jwtToken,
|
|
66
|
+
getChatMessagesRoute: options.getChatMessagesRoute,
|
|
67
|
+
getChatStoreMessageRoute: options.getChatStoreMessageRoute,
|
|
68
|
+
getChatForAppointmentRoute: options.getChatForAppointmentRoute
|
|
69
|
+
});
|
|
57
70
|
};
|
|
58
71
|
const logout = () => {
|
|
72
|
+
if (typeof echo === 'undefined') {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const _echo = echo;
|
|
76
|
+
echo = undefined;
|
|
59
77
|
for (const chatId in chats) {
|
|
60
78
|
if (Object.prototype.hasOwnProperty.call(chats, chatId)) {
|
|
61
79
|
chats[chatId].cancelAllSubscriptionsAndLeave();
|
|
62
80
|
delete chats[chatId];
|
|
63
81
|
}
|
|
64
82
|
}
|
|
65
|
-
|
|
66
|
-
echo.disconnect();
|
|
67
|
-
echo = undefined;
|
|
68
|
-
}
|
|
83
|
+
_echo.disconnect();
|
|
69
84
|
};
|
|
70
85
|
const get = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const { chat, error
|
|
72
|
-
if (
|
|
73
|
-
return { error
|
|
74
|
-
}
|
|
75
|
-
let { messages, error: getLatestChatMessagesError } = yield getLatestChatMessages(id, {
|
|
76
|
-
headers: options.jwtToken
|
|
77
|
-
? { 'Authorization': `Bearer ${options.jwtToken}` }
|
|
78
|
-
: undefined
|
|
79
|
-
});
|
|
80
|
-
console.log('MESSAGES', messages);
|
|
81
|
-
if (getLatestChatMessagesError) {
|
|
82
|
-
return { error: getLatestChatMessagesError };
|
|
86
|
+
const { chat, error } = getChat(id);
|
|
87
|
+
if (error) {
|
|
88
|
+
return { error };
|
|
83
89
|
}
|
|
84
90
|
const subscription = new ChatSubscription_1.default(chat, {
|
|
85
91
|
status: 'active'
|
|
86
92
|
});
|
|
87
93
|
chat.addSubscription(subscription);
|
|
94
|
+
chat.getLatestMessages();
|
|
88
95
|
return { subscription };
|
|
89
96
|
});
|
|
90
97
|
const appointment = (appointmentId) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const result = yield getChatIdFromAppointmentId(appointmentId);
|
|
95
|
-
if (result.error) {
|
|
96
|
-
return { error: result.error };
|
|
97
|
-
}
|
|
98
|
-
chatId = result.chatId;
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (!(error instanceof Error)) {
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
logger.error(error);
|
|
105
|
-
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 403) {
|
|
106
|
-
return { error: { code: 'unauthorized' } };
|
|
107
|
-
}
|
|
108
|
-
return { error: { code: 'error' } };
|
|
98
|
+
const { chatId, error } = yield api.getChatIdFromAppointmentId(appointmentId);
|
|
99
|
+
if (error) {
|
|
100
|
+
return { error };
|
|
109
101
|
}
|
|
110
102
|
return yield get(chatId);
|
|
111
103
|
});
|
|
112
|
-
const getLatestChatMessages = (id, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
var _b;
|
|
114
|
-
try {
|
|
115
|
-
const response = yield axios.get(options.getChatMessagesRoute(id), {
|
|
116
|
-
headers: options.jwtToken
|
|
117
|
-
? { 'Authorization': `Bearer ${options.jwtToken}` }
|
|
118
|
-
: undefined
|
|
119
|
-
});
|
|
120
|
-
return { messages: response.data.data };
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
if (!(error instanceof Error)) {
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
logger.error(error);
|
|
127
|
-
if (axios_1.default.isAxiosError(error) && ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 403) {
|
|
128
|
-
return { error: { code: 'unauthorized' } };
|
|
129
|
-
}
|
|
130
|
-
return { error: { code: 'error' } };
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
const getChatIdFromAppointmentId = (appointmentId, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
var _c;
|
|
135
|
-
try {
|
|
136
|
-
const response = yield axios.get(options.getChatForAppointmentRoute(appointmentId), {
|
|
137
|
-
headers: options.jwtToken
|
|
138
|
-
? { 'Authorization': `Bearer ${options.jwtToken}` }
|
|
139
|
-
: undefined
|
|
140
|
-
});
|
|
141
|
-
return { chatId: response.data.data.id };
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
if (!(error instanceof Error)) {
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
logger.error(error);
|
|
148
|
-
if (axios_1.default.isAxiosError(error) && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 403) {
|
|
149
|
-
return { error: { code: 'unauthorized' } };
|
|
150
|
-
}
|
|
151
|
-
return { error: { code: 'error' } };
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
104
|
const getChat = (chatId) => {
|
|
155
105
|
if (!echo) {
|
|
156
106
|
return { error: {
|
|
@@ -160,11 +110,9 @@ const Chat = (function () {
|
|
|
160
110
|
if (!(chatId.toString() in chats)) {
|
|
161
111
|
chats[chatId] = new CachedChat_1.default({
|
|
162
112
|
id: chatId,
|
|
163
|
-
|
|
164
|
-
axios,
|
|
113
|
+
api,
|
|
165
114
|
channel: echo.join(getChannelName(chatId)),
|
|
166
115
|
logger,
|
|
167
|
-
getChatStoreMessageRoute: options.getChatStoreMessageRoute,
|
|
168
116
|
leave: () => echo === null || echo === void 0 ? void 0 : echo.leave(getChannelName(chatId))
|
|
169
117
|
});
|
|
170
118
|
}
|
package/dist/Chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.js","sourceRoot":"","sources":["../src/Chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gEAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"Chat.js","sourceRoot":"","sources":["../src/Chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gEAAgC;AAChC,gDAAwB;AAExB,8DAAsC;AAEtC,qCAAiD;AACjD,0EAAkD;AA6BlD,MAAM,IAAI,GAAG,CAAC;IACV,IAAI,WAAW,GAAY,KAAK,CAAC;IACjC,IAAI,IAAoB,CAAC;IACzB,IAAI,GAAQ,CAAC;IACb,IAAI,MAAc,CAAC;IACnB,IAAI,OAAoB,CAAC;IAEzB,MAAM,KAAK,GAAkC,EAAE,CAAC;IAQhD,MAAM,IAAI,GAAG,CAAC,QAAqB,EAAQ,EAAE;QACzC,IAAI,WAAW,EAAE;YACb,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;YACjE,OAAO;SACV;QACD,WAAW,GAAG,IAAI,CAAC;QACnB,OAAO,GAAG,QAAQ,CAAC;QACnB,IAAI,GAAG,IAAI,sBAAI,CAAC;YACZ,WAAW,EAAE,QAAQ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AC9B,EAAC,CAAC;SACN;QAED,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,KAAK,CAAC,EAAE;YAC/B,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,oBAAU,CAAC;gBAC3B,EAAE,EAAE,MAAM;gBACV,GAAG;gBACH,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;gBAC1C,MAAM;gBACN,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;aACnD,CAAC,CAAC;SACN;QAED,OAAO,EAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EAAC,CAAC;IACjC,CAAC,CAAA;IAED,MAAM,cAAc,GAAG,CAAC,MAAc,EAAU,EAAE;QAC9C,OAAO,QAAQ,MAAM,EAAE,CAAA;IAC3B,CAAC,CAAA;IAED,OAAO;QACH,IAAI;QACJ,aAAa;QACb,KAAK;QACL,MAAM;QACN,GAAG;QACH,WAAW;KACd,CAAA;AACL,CAAC,CAAC,EAAE,CAAC;AAEL,kBAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatError.js","sourceRoot":"","sources":["../src/ChatError.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import CachedChat from "./CachedChat";
|
|
1
|
+
import CachedChat, { Messages } from "./CachedChat";
|
|
2
2
|
export declare type ChatSubscriptionStatus = 'active' | 'cancelled';
|
|
3
3
|
export interface ChatSubscriptionOptions {
|
|
4
4
|
status: ChatSubscriptionStatus;
|
|
5
5
|
}
|
|
6
6
|
export interface ChatSubscriptionEventHandlers {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
messages?: (messages: Messages) => void;
|
|
8
|
+
here?: (event: any) => void;
|
|
9
|
+
userJoining?: (event: any) => void;
|
|
10
|
+
userLeaving?: (event: any) => void;
|
|
11
|
+
statusChange?: (status: ChatSubscriptionStatus) => void;
|
|
12
12
|
}
|
|
13
13
|
export default class ChatSubscription {
|
|
14
14
|
private chat;
|
|
@@ -18,11 +18,8 @@ export default class ChatSubscription {
|
|
|
18
18
|
getStatus(): ChatSubscriptionStatus;
|
|
19
19
|
setStatus(status: ChatSubscriptionStatus): void;
|
|
20
20
|
sendMessage(message: string): Promise<any>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
onUserLeaving(handler: ChatSubscriptionEventHandlers['onUserLeaving']): this;
|
|
25
|
-
onStatusChange(handler: ChatSubscriptionEventHandlers['onStatusChange']): this;
|
|
26
|
-
event(name: keyof ChatSubscriptionEventHandlers, data: any): void;
|
|
21
|
+
on<Event extends keyof ChatSubscriptionEventHandlers>(event: Event, handler: ChatSubscriptionEventHandlers[Event]): this;
|
|
22
|
+
fireEvent(name: keyof ChatSubscriptionEventHandlers, data: any): void;
|
|
23
|
+
fireEventIfActive(name: keyof ChatSubscriptionEventHandlers, data: any): void;
|
|
27
24
|
cancel(): void;
|
|
28
25
|
}
|
package/dist/ChatSubscription.js
CHANGED
|
@@ -15,30 +15,19 @@ class ChatSubscription {
|
|
|
15
15
|
sendMessage(message) {
|
|
16
16
|
return this.chat.sendMessage(message);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
this.eventHandlers
|
|
18
|
+
on(event, handler) {
|
|
19
|
+
this.eventHandlers[event] = handler;
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
this.eventHandlers.onHere = handler;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
onUserJoining(handler) {
|
|
27
|
-
this.eventHandlers.onUserJoining = handler;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
onUserLeaving(handler) {
|
|
31
|
-
this.eventHandlers.onUserLeaving = handler;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
onStatusChange(handler) {
|
|
35
|
-
this.eventHandlers.onStatusChange = handler;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
event(name, data) {
|
|
22
|
+
fireEvent(name, data) {
|
|
39
23
|
var _a, _b;
|
|
40
24
|
(_b = (_a = this.eventHandlers)[name]) === null || _b === void 0 ? void 0 : _b.call(_a, data);
|
|
41
25
|
}
|
|
26
|
+
fireEventIfActive(name, data) {
|
|
27
|
+
if (this.status === 'active') {
|
|
28
|
+
this.fireEvent(name, data);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
42
31
|
cancel() {
|
|
43
32
|
this.chat.cancelSubscription(this);
|
|
44
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatSubscription.js","sourceRoot":"","sources":["../src/ChatSubscription.ts"],"names":[],"mappings":";;AAkBA,MAAqB,gBAAgB;IAKjC,YAAY,IAAgB,EAAE,OAAgC;QAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,MAA8B;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,OAAe;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"ChatSubscription.js","sourceRoot":"","sources":["../src/ChatSubscription.ts"],"names":[],"mappings":";;AAkBA,MAAqB,gBAAgB;IAKjC,YAAY,IAAgB,EAAE,OAAgC;QAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,MAA8B;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,OAAe;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,EAAE,CAAoD,KAAY,EAAE,OAA6C;QAC7G,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;QACpC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,IAAyC,EAAE,IAAS;;QAC1D,MAAA,MAAA,IAAI,CAAC,aAAa,EAAC,IAAI,CAAC,mDAAG,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,iBAAiB,CAAC,IAAyC,EAAE,IAAS;QAClE,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE;YAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAC9B;IACL,CAAC;IAED,MAAM;QACF,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ;AAzCD,mCAyCC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Sender {
|
|
2
|
+
first_name: string;
|
|
3
|
+
}
|
|
4
|
+
export default class Message {
|
|
5
|
+
readonly id: number;
|
|
6
|
+
readonly chatId: number;
|
|
7
|
+
readonly message: string;
|
|
8
|
+
readonly senderId: number;
|
|
9
|
+
readonly sender: Sender;
|
|
10
|
+
readonly isAdminMessage: boolean;
|
|
11
|
+
constructor({ id, chatId, message, senderId, sender, isAdminMessage }: {
|
|
12
|
+
id: number;
|
|
13
|
+
chatId: number;
|
|
14
|
+
message: string;
|
|
15
|
+
senderId: number;
|
|
16
|
+
sender: Sender;
|
|
17
|
+
isAdminMessage: boolean;
|
|
18
|
+
});
|
|
19
|
+
get isPendingMessage(): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const isMessage: (m: unknown) => m is Message;
|
|
22
|
+
export declare const isMessageThen: (m: unknown, then: (m: Message) => boolean) => boolean;
|
package/dist/Message.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMessageThen = exports.isMessage = void 0;
|
|
4
|
+
class Message {
|
|
5
|
+
constructor({ id, chatId, message, senderId, sender, isAdminMessage }) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.chatId = chatId;
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.senderId = senderId;
|
|
10
|
+
this.sender = sender;
|
|
11
|
+
this.isAdminMessage = isAdminMessage;
|
|
12
|
+
}
|
|
13
|
+
get isPendingMessage() {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Message;
|
|
18
|
+
const isMessage = (m) => {
|
|
19
|
+
return m instanceof Message;
|
|
20
|
+
};
|
|
21
|
+
exports.isMessage = isMessage;
|
|
22
|
+
const isMessageThen = (m, then) => {
|
|
23
|
+
if ((0, exports.isMessage)(m)) {
|
|
24
|
+
return then(m);
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
exports.isMessageThen = isMessageThen;
|
|
29
|
+
//# sourceMappingURL=Message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../src/Message.ts"],"names":[],"mappings":";;;AAIA,MAAqB,OAAO;IAQxB,YAAY,EACR,EAAE,EACF,MAAM,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,cAAc,EAQjB;QACG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,IAAW,gBAAgB;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAlCD,0BAkCC;AAEM,MAAM,SAAS,GAAG,CAAC,CAAU,EAAgB,EAAE;IAClD,OAAO,CAAC,YAAY,OAAO,CAAC;AAChC,CAAC,CAAA;AAFY,QAAA,SAAS,aAErB;AAEM,MAAM,aAAa,GAAG,CAAC,CAAU,EAAE,IAA6B,EAAW,EAAE;IAChF,IAAI,IAAA,iBAAS,EAAC,CAAC,CAAC,EAAE;QACd,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;KAClB;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAA;AALY,QAAA,aAAa,iBAKzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default class PendingMessage {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
status: 'pending' | 'failed';
|
|
4
|
+
constructor({ message, status }: {
|
|
5
|
+
message: string;
|
|
6
|
+
status: PendingMessageStatus;
|
|
7
|
+
});
|
|
8
|
+
get isPendingMessage(): boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare type PendingMessageStatus = 'pending' | 'failed';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PendingMessage {
|
|
4
|
+
constructor({ message, status }) {
|
|
5
|
+
this.message = message;
|
|
6
|
+
this.status = status;
|
|
7
|
+
}
|
|
8
|
+
get isPendingMessage() {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = PendingMessage;
|
|
13
|
+
//# sourceMappingURL=PendingMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PendingMessage.js","sourceRoot":"","sources":["../src/PendingMessage.ts"],"names":[],"mappings":";;AAKA,MAAqB,cAAc;IAI/B,YAAY,EAAE,OAAO,EAAE,MAAM,EAAqD;QAC9E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAW,gBAAgB;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAZD,iCAYC"}
|
package/dist/react/useChat.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Messages } from '../CachedChat';
|
|
1
2
|
export interface UseChatOptions {
|
|
2
3
|
idType?: 'appointment';
|
|
3
4
|
}
|
|
4
5
|
export interface UseChatReturnValue {
|
|
5
|
-
messages:
|
|
6
|
+
messages: Messages;
|
|
6
7
|
sendMessage: (message: string) => Promise<any> | void;
|
|
7
8
|
}
|
|
8
9
|
declare const useChat: (id: number, { idType }: UseChatOptions) => UseChatReturnValue;
|
package/dist/react/useChat.js
CHANGED
|
@@ -17,14 +17,16 @@ const useChat = (id, { idType }) => {
|
|
|
17
17
|
const handleUserLeaving = (user) => {
|
|
18
18
|
console.log('handleUserLeaving', user);
|
|
19
19
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const handleMessages = (messages) => {
|
|
21
|
+
setMessages(messages);
|
|
22
22
|
};
|
|
23
23
|
const handleStatusChange = (status) => {
|
|
24
24
|
console.log('status change', status);
|
|
25
25
|
};
|
|
26
26
|
(0, react_1.useEffect)(() => {
|
|
27
|
-
const method = idType === 'appointment'
|
|
27
|
+
const method = idType === 'appointment'
|
|
28
|
+
? 'appointment'
|
|
29
|
+
: 'get';
|
|
28
30
|
Chat_1.default[method](id).then(({ subscription, error }) => {
|
|
29
31
|
if (error) {
|
|
30
32
|
console.log('ERROR', error);
|
|
@@ -37,7 +39,7 @@ const useChat = (id, { idType }) => {
|
|
|
37
39
|
}, []);
|
|
38
40
|
(0, react_1.useEffect)(() => {
|
|
39
41
|
var _a, _b, _c, _d;
|
|
40
|
-
(_d = (_c = (_b = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.
|
|
42
|
+
(_d = (_c = (_b = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.on('here', handleHere)) === null || _a === void 0 ? void 0 : _a.on('userJoining', handleUserJoining)) === null || _b === void 0 ? void 0 : _b.on('userLeaving', handleUserLeaving)) === null || _c === void 0 ? void 0 : _c.on('messages', handleMessages)) === null || _d === void 0 ? void 0 : _d.on('statusChange', handleStatusChange);
|
|
41
43
|
return () => {
|
|
42
44
|
subscription === null || subscription === void 0 ? void 0 : subscription.cancel();
|
|
43
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../src/react/useChat.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAC3B,iCAA0C;
|
|
1
|
+
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../src/react/useChat.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAC3B,iCAA0C;AAa1C,MAAM,OAAO,GAAG,CAAC,EAAU,EAAE,EAAE,MAAM,EAAkB,EAAsB,EAAE;IAC3E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,GAA8B,CAAC;IAC/E,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAW,EAAE,CAAC,CAAC;IAEvD,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE;QAC9B,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,CAAC,IAAS,EAAE,EAAE;QACpC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAA;IAED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kB,CAAC,CAAA;QAE5C,OAAO,GAAG,EAAE;YACR,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE,CAAC;QAC3B,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO;QACH,QAAQ;QACR,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW,CAAC,OAAO,CAAC;KACvE,CAAA;AACL,CAAC,CAAA;AAED,kBAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewberapp/chat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Viewber chat",
|
|
5
5
|
"author": "Jacob <jacob.chen@viewber.co.uk>",
|
|
6
6
|
"homepage": "https://bitbucket.org/ezadr/viewberjs#readme",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"react": "^16.14.0",
|
|
40
40
|
"rollbar": "^2.25.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3ef800ca3530449f36fe93a6aaf4cfca5d853224"
|
|
43
43
|
}
|