favesalon-embed 0.1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chat-button.cjs.entry.js +118 -0
- package/dist/cjs/favesalon-embed.cjs.js +7 -3
- package/dist/cjs/google-map_5.cjs.entry.js +26 -7
- package/dist/cjs/{index-e6bea8f5.js → index-47c2a5f6.js} +512 -208
- package/dist/cjs/loader.cjs.js +4 -3
- package/dist/cjs/relativeTime-3721080d.js +9 -0
- package/dist/cjs/salon-booking-modal.cjs.entry.js +3 -2
- package/dist/cjs/salon-booking.cjs.entry.js +3 -2
- package/dist/cjs/salon-gift-card-modal.cjs.entry.js +3 -2
- package/dist/cjs/salon-gift-card.cjs.entry.js +3 -2
- package/dist/cjs/salon-latest-reviews.cjs.entry.js +5 -3
- package/dist/cjs/salon-lookbook.cjs.entry.js +7 -3
- package/dist/cjs/salon-ranking.cjs.entry.js +3 -2
- package/dist/cjs/salon-reviews.cjs.entry.js +10 -3
- package/dist/cjs/salon-services.cjs.entry.js +6 -3
- package/dist/cjs/salon-stylists.cjs.entry.js +9 -3
- package/dist/cjs/services-125c82d8.js +21492 -0
- package/dist/cjs/style-detail.cjs.entry.js +11 -9
- package/dist/cjs/user-avatar.cjs.entry.js +7 -3
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/chat-button/index.css +122 -0
- package/dist/collection/components/chat-button/index.js +218 -0
- package/dist/collection/components/chat-conversation/index.js +103 -0
- package/dist/collection/components/google-map/index.js +72 -68
- package/dist/collection/components/salon-booking/index.css +5 -0
- package/dist/collection/components/salon-booking/index.js +85 -80
- package/dist/collection/components/salon-booking/salon-booking-modal.js +73 -69
- package/dist/collection/components/salon-gift-card/index.css +6 -1
- package/dist/collection/components/salon-gift-card/index.js +85 -80
- package/dist/collection/components/salon-gift-card/salon-gift-card-modal.js +56 -52
- package/dist/collection/components/salon-info/index.css +1 -0
- package/dist/collection/components/salon-info/index.js +60 -54
- package/dist/collection/components/salon-latest-reviews/index.css +3 -0
- package/dist/collection/components/salon-latest-reviews/index.js +131 -144
- package/dist/collection/components/salon-latest-styles/index.css +2 -0
- package/dist/collection/components/salon-latest-styles/index.js +143 -138
- package/dist/collection/components/salon-locations/index.css +3 -0
- package/dist/collection/components/salon-locations/index.js +112 -120
- package/dist/collection/components/salon-lookbook/index.css +3 -0
- package/dist/collection/components/salon-lookbook/index.js +182 -190
- package/dist/collection/components/salon-ranking/index.js +68 -65
- package/dist/collection/components/salon-reviews/index.css +3 -0
- package/dist/collection/components/salon-reviews/index.js +146 -183
- package/dist/collection/components/salon-schedules/index.css +3 -0
- package/dist/collection/components/salon-schedules/index.js +129 -151
- package/dist/collection/components/salon-services/index.css +1 -0
- package/dist/collection/components/salon-services/index.js +117 -127
- package/dist/collection/components/salon-stylists/index.css +8 -0
- package/dist/collection/components/salon-stylists/index.js +137 -136
- package/dist/collection/components/style-detail/index.css +14 -0
- package/dist/collection/components/style-detail/index.js +265 -340
- package/dist/collection/components/user-avatar/index.js +119 -112
- package/dist/collection/mocks/users.js +10 -0
- package/dist/collection/services/services.js +121 -0
- package/dist/collection/types/chat.js +23 -0
- package/dist/collection/types/user.js +1 -1
- package/dist/custom-elements/index.d.ts +6 -0
- package/dist/custom-elements/index.js +24628 -8605
- package/dist/esm/chat-button.entry.js +114 -0
- package/dist/esm/favesalon-embed.js +4 -3
- package/dist/esm/google-map_5.entry.js +26 -7
- package/dist/esm/{index-6af0a03d.js → index-3fae868e.js} +512 -209
- package/dist/esm/loader.js +4 -3
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm/relativeTime-cd452e6d.js +7 -0
- package/dist/esm/salon-booking-modal.entry.js +3 -2
- package/dist/esm/salon-booking.entry.js +3 -2
- package/dist/esm/salon-gift-card-modal.entry.js +3 -2
- package/dist/esm/salon-gift-card.entry.js +3 -2
- package/dist/esm/salon-latest-reviews.entry.js +5 -3
- package/dist/esm/salon-lookbook.entry.js +7 -3
- package/dist/esm/salon-ranking.entry.js +3 -2
- package/dist/esm/salon-reviews.entry.js +10 -3
- package/dist/esm/salon-services.entry.js +6 -3
- package/dist/esm/salon-stylists.entry.js +9 -3
- package/dist/esm/services-40a3e622.js +21485 -0
- package/dist/esm/style-detail.entry.js +10 -8
- package/dist/esm/user-avatar.entry.js +7 -3
- package/dist/favesalon-embed/favesalon-embed.esm.js +1 -1
- package/dist/favesalon-embed/p-019c5ccd.entry.js +1 -0
- package/dist/favesalon-embed/p-083a8821.entry.js +1 -0
- package/dist/favesalon-embed/p-0d0ed9ea.entry.js +1 -0
- package/dist/favesalon-embed/p-119db8de.entry.js +1 -0
- package/dist/favesalon-embed/p-1432c51b.entry.js +1 -0
- package/dist/favesalon-embed/p-22093506.entry.js +1 -0
- package/dist/favesalon-embed/p-32b314e9.js +2 -0
- package/dist/favesalon-embed/p-4a5eca9a.js +1 -1
- package/dist/favesalon-embed/p-58d2e9be.js +1 -0
- package/dist/favesalon-embed/p-71404b6a.entry.js +1 -0
- package/dist/favesalon-embed/p-857c3a61.entry.js +1 -0
- package/dist/favesalon-embed/p-99ec77f7.entry.js +1 -0
- package/dist/favesalon-embed/p-b0c3673a.entry.js +1 -0
- package/dist/favesalon-embed/p-b287b1ea.entry.js +1 -0
- package/dist/favesalon-embed/p-b3af7842.entry.js +1 -0
- package/dist/favesalon-embed/p-b630ae68.js +1580 -0
- package/dist/favesalon-embed/p-ce2c1c9a.entry.js +1 -0
- package/dist/favesalon-embed/p-d9b7ad58.entry.js +1 -0
- package/dist/favesalon-embed/p-fc9a5551.js +1 -1
- package/dist/types/components/chat-button/index.d.ts +24 -0
- package/dist/types/components.d.ts +22 -0
- package/dist/types/mocks/users.d.ts +10 -0
- package/dist/types/services/services.d.ts +15 -0
- package/dist/types/stencil-public-runtime.d.ts +85 -11
- package/dist/types/types/chat.d.ts +17 -0
- package/loader/index.d.ts +9 -0
- package/loader/package.json +1 -0
- package/package.json +3 -3
- package/readme.md +2 -2
- package/dist/cjs/services-eee8f251.js +0 -5634
- package/dist/esm/services-295247b1.js +0 -5627
- package/dist/favesalon-embed/p-292b97ba.entry.js +0 -1
- package/dist/favesalon-embed/p-4869dfed.entry.js +0 -1
- package/dist/favesalon-embed/p-4aee4fd9.entry.js +0 -1
- package/dist/favesalon-embed/p-5528c705.entry.js +0 -1
- package/dist/favesalon-embed/p-612ad685.entry.js +0 -1
- package/dist/favesalon-embed/p-75aef7e0.entry.js +0 -1
- package/dist/favesalon-embed/p-8c780874.entry.js +0 -1
- package/dist/favesalon-embed/p-8dbf04c5.js +0 -1
- package/dist/favesalon-embed/p-9f31061a.entry.js +0 -1
- package/dist/favesalon-embed/p-a60d78e9.entry.js +0 -1
- package/dist/favesalon-embed/p-a6debdae.entry.js +0 -1
- package/dist/favesalon-embed/p-bad1e9a7.entry.js +0 -1
- package/dist/favesalon-embed/p-c2ecb365.js +0 -1
- package/dist/favesalon-embed/p-c7dea70c.entry.js +0 -1
- package/dist/favesalon-embed/p-f0e14641.entry.js +0 -1
- package/dist/types/types/tmp.d.ts +0 -0
- /package/dist/{collection/types/tmp.js → types/components/chat-conversation/index.d.ts} +0 -0
|
@@ -1,127 +1,134 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h } from '@stencil/core';
|
|
2
2
|
import { Colors } from '../../constants/colors';
|
|
3
3
|
export class UserAvatar {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.size = 24;
|
|
6
|
+
this.name = undefined;
|
|
7
|
+
this.nameStyle = undefined;
|
|
8
|
+
this.shortName = undefined;
|
|
9
|
+
this.avatar = undefined;
|
|
6
10
|
}
|
|
7
11
|
render() {
|
|
8
|
-
return (h("div", { style: { display: "flex", alignItems: "center" } },
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
minWidth: `${this.size}px`,
|
|
30
|
-
} }, this.shortName)),
|
|
31
|
-
h("div", { style: Object.assign({ flexShrink: '1', flexGrow: '1', marginLeft: '12px', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }, this.nameStyle) }, this.name)));
|
|
12
|
+
return (h("div", { style: { display: "flex", alignItems: "center" } }, this.avatar && (h("div", { style: {
|
|
13
|
+
backgroundImage: `url("${this.avatar}")`,
|
|
14
|
+
backgroundColor: Colors.Gray01,
|
|
15
|
+
backgroundPosition: 'center center',
|
|
16
|
+
backgroundSize: 'cover',
|
|
17
|
+
borderRadius: '50%',
|
|
18
|
+
height: `${this.size}px`,
|
|
19
|
+
width: `${this.size}px`,
|
|
20
|
+
minWidth: `${this.size}px`,
|
|
21
|
+
} })), !this.avatar && (h("div", { style: {
|
|
22
|
+
backgroundColor: Colors.Gray01,
|
|
23
|
+
backgroundPosition: 'center center',
|
|
24
|
+
backgroundSize: 'cover',
|
|
25
|
+
borderRadius: '50%',
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
justifyContent: 'center',
|
|
29
|
+
height: `${this.size}px`,
|
|
30
|
+
width: `${this.size}px`,
|
|
31
|
+
minWidth: `${this.size}px`,
|
|
32
|
+
} }, this.shortName)), this.name && (h("div", { style: Object.assign({ flexShrink: '1', flexGrow: '1', marginLeft: '12px', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }, this.nameStyle) }, this.name))));
|
|
32
33
|
}
|
|
33
34
|
static get is() { return "user-avatar"; }
|
|
34
|
-
static get originalStyleUrls() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
static get originalStyleUrls() {
|
|
36
|
+
return {
|
|
37
|
+
"$": ["index.css"]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static get styleUrls() {
|
|
41
|
+
return {
|
|
42
|
+
"$": ["index.css"]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static get properties() {
|
|
46
|
+
return {
|
|
47
|
+
"size": {
|
|
48
|
+
"type": "number",
|
|
49
|
+
"mutable": false,
|
|
50
|
+
"complexType": {
|
|
51
|
+
"original": "number",
|
|
52
|
+
"resolved": "number",
|
|
53
|
+
"references": {}
|
|
54
|
+
},
|
|
55
|
+
"required": false,
|
|
56
|
+
"optional": false,
|
|
57
|
+
"docs": {
|
|
58
|
+
"tags": [],
|
|
59
|
+
"text": ""
|
|
60
|
+
},
|
|
61
|
+
"attribute": "size",
|
|
62
|
+
"reflect": false,
|
|
63
|
+
"defaultValue": "24"
|
|
54
64
|
},
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
65
|
+
"name": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"mutable": false,
|
|
68
|
+
"complexType": {
|
|
69
|
+
"original": "string",
|
|
70
|
+
"resolved": "string",
|
|
71
|
+
"references": {}
|
|
72
|
+
},
|
|
73
|
+
"required": false,
|
|
74
|
+
"optional": false,
|
|
75
|
+
"docs": {
|
|
76
|
+
"tags": [],
|
|
77
|
+
"text": ""
|
|
78
|
+
},
|
|
79
|
+
"attribute": "name",
|
|
80
|
+
"reflect": false
|
|
66
81
|
},
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
82
|
+
"nameStyle": {
|
|
83
|
+
"type": "unknown",
|
|
84
|
+
"mutable": false,
|
|
85
|
+
"complexType": {
|
|
86
|
+
"original": "object",
|
|
87
|
+
"resolved": "object",
|
|
88
|
+
"references": {}
|
|
89
|
+
},
|
|
90
|
+
"required": false,
|
|
91
|
+
"optional": true,
|
|
92
|
+
"docs": {
|
|
93
|
+
"tags": [],
|
|
94
|
+
"text": ""
|
|
95
|
+
}
|
|
72
96
|
},
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
"
|
|
97
|
+
"shortName": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"mutable": false,
|
|
100
|
+
"complexType": {
|
|
101
|
+
"original": "string",
|
|
102
|
+
"resolved": "string",
|
|
103
|
+
"references": {}
|
|
104
|
+
},
|
|
105
|
+
"required": false,
|
|
106
|
+
"optional": false,
|
|
107
|
+
"docs": {
|
|
108
|
+
"tags": [],
|
|
109
|
+
"text": ""
|
|
110
|
+
},
|
|
111
|
+
"attribute": "short-name",
|
|
112
|
+
"reflect": false
|
|
83
113
|
},
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
|
|
114
|
+
"avatar": {
|
|
115
|
+
"type": "string",
|
|
116
|
+
"mutable": false,
|
|
117
|
+
"complexType": {
|
|
118
|
+
"original": "string",
|
|
119
|
+
"resolved": "string",
|
|
120
|
+
"references": {}
|
|
121
|
+
},
|
|
122
|
+
"required": false,
|
|
123
|
+
"optional": false,
|
|
124
|
+
"docs": {
|
|
125
|
+
"tags": [],
|
|
126
|
+
"text": ""
|
|
127
|
+
},
|
|
128
|
+
"attribute": "avatar",
|
|
129
|
+
"reflect": false
|
|
89
130
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
"type": "string",
|
|
93
|
-
"mutable": false,
|
|
94
|
-
"complexType": {
|
|
95
|
-
"original": "string",
|
|
96
|
-
"resolved": "string",
|
|
97
|
-
"references": {}
|
|
98
|
-
},
|
|
99
|
-
"required": false,
|
|
100
|
-
"optional": false,
|
|
101
|
-
"docs": {
|
|
102
|
-
"tags": [],
|
|
103
|
-
"text": ""
|
|
104
|
-
},
|
|
105
|
-
"attribute": "short-name",
|
|
106
|
-
"reflect": false
|
|
107
|
-
},
|
|
108
|
-
"avatar": {
|
|
109
|
-
"type": "string",
|
|
110
|
-
"mutable": false,
|
|
111
|
-
"complexType": {
|
|
112
|
-
"original": "string",
|
|
113
|
-
"resolved": "string",
|
|
114
|
-
"references": {}
|
|
115
|
-
},
|
|
116
|
-
"required": false,
|
|
117
|
-
"optional": false,
|
|
118
|
-
"docs": {
|
|
119
|
-
"tags": [],
|
|
120
|
-
"text": ""
|
|
121
|
-
},
|
|
122
|
-
"attribute": "avatar",
|
|
123
|
-
"reflect": false
|
|
124
|
-
}
|
|
125
|
-
}; }
|
|
131
|
+
};
|
|
132
|
+
}
|
|
126
133
|
}
|
|
127
134
|
;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const consumerUser = {
|
|
2
|
+
"id": 442558,
|
|
3
|
+
"name": "Trung Luu",
|
|
4
|
+
"avatar": "https://favesalon.s3.amazonaws.com/public/media/uploads/photos/-1/2022-08-23-a982011a-4d49-488b-8a28-343631avatar1.jpg",
|
|
5
|
+
};
|
|
6
|
+
export const salonOwner = {
|
|
7
|
+
"id": 373905,
|
|
8
|
+
"name": "Nick Test",
|
|
9
|
+
"avatar": "https://d3m4d8z2xvy8tb.cloudfront.net/public/media/uploads/salon/profile/2018-11-13-575a6133-724f-4d63-8595-f545396ad96d.png",
|
|
10
|
+
};
|
|
@@ -1,12 +1,31 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s)
|
|
4
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import get from 'lodash/get';
|
|
14
|
+
import each from 'lodash/each';
|
|
1
15
|
import sortBy from 'lodash/sortBy';
|
|
2
16
|
import axios from 'axios';
|
|
3
17
|
import { createSalon } from '../types/salon';
|
|
18
|
+
import { initializeApp } from 'firebase/app';
|
|
19
|
+
import { child, getDatabase, ref, onValue, push, update } from 'firebase/database';
|
|
4
20
|
import { createFaveStyle, createFaveStyleComment } from '../types/style';
|
|
5
21
|
import { createService } from '../types/service';
|
|
6
22
|
import { createStylist } from '../types/stylist';
|
|
7
23
|
import { createReview } from '../types/review';
|
|
8
24
|
import { apiV1Prefix } from '../types/common';
|
|
25
|
+
import { createChatMessage, createChatRoom } from '../types/chat';
|
|
26
|
+
import dayjs from 'dayjs';
|
|
9
27
|
const apiV2Prefix = 'api-ver2';
|
|
28
|
+
const firebaseMessagesNode = 'favesalon--messages';
|
|
10
29
|
class HttpService {
|
|
11
30
|
constructor() {
|
|
12
31
|
this.http = null;
|
|
@@ -15,6 +34,21 @@ class HttpService {
|
|
|
15
34
|
// baseURL: 'http://13.57.216.170',
|
|
16
35
|
headers: {},
|
|
17
36
|
});
|
|
37
|
+
try {
|
|
38
|
+
if (!this.firebaseApp) {
|
|
39
|
+
this.firebaseApp = initializeApp({
|
|
40
|
+
apiKey: "AIzaSyD5IdiIA9QUZeguRbi8DEZ25TrNXPU3-uI",
|
|
41
|
+
authDomain: "favestyle-b57d4.firebaseapp.com",
|
|
42
|
+
databaseURL: "https://favestyle-b57d4.firebaseio.com",
|
|
43
|
+
projectId: "favestyle-b57d4",
|
|
44
|
+
storageBucket: "favestyle-b57d4.appspot.com",
|
|
45
|
+
messagingSenderId: "105638847842",
|
|
46
|
+
appId: "1:105638847842:web:35f50dfe0e8eb52f46783b",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
this.firebaseDatabase = getDatabase(this.firebaseApp);
|
|
50
|
+
}
|
|
51
|
+
catch (error) { }
|
|
18
52
|
}
|
|
19
53
|
fetchStyleDetail(styleId) {
|
|
20
54
|
return this.http.get(`${apiV2Prefix}/style/${styleId}/detail`)
|
|
@@ -170,5 +204,92 @@ class HttpService {
|
|
|
170
204
|
})
|
|
171
205
|
.catch(() => ({ total: 0, data: [] }));
|
|
172
206
|
}
|
|
207
|
+
createChatRoom(receiverId, accessToken) {
|
|
208
|
+
const url = `${apiV2Prefix}/chatroom/create/${receiverId}?access_token=${accessToken}`;
|
|
209
|
+
return this.http.get(url)
|
|
210
|
+
.then(response => {
|
|
211
|
+
const blob = get(response, 'data.data', {});
|
|
212
|
+
return createChatRoom(blob);
|
|
213
|
+
})
|
|
214
|
+
.catch(() => (null));
|
|
215
|
+
}
|
|
216
|
+
fetchRooms(accessToken, page, allRooms = []) {
|
|
217
|
+
const url = `${apiV2Prefix}/chatroom/get?page=${page}&limit=20&access_token=${accessToken}`;
|
|
218
|
+
return this.http.get(url)
|
|
219
|
+
.then(response => {
|
|
220
|
+
const blobs = get(response, 'data.data', []);
|
|
221
|
+
const chatRooms = blobs.map(createChatRoom);
|
|
222
|
+
// fetch next page's styles
|
|
223
|
+
if (chatRooms.length >= 20) {
|
|
224
|
+
return this.fetchRooms(accessToken, page + 1, allRooms.concat(chatRooms));
|
|
225
|
+
}
|
|
226
|
+
return page === 1 ? chatRooms : allRooms.concat(chatRooms);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
fetchChatRooms(accessToken) {
|
|
230
|
+
return this.fetchRooms(accessToken, 1)
|
|
231
|
+
.catch(() => ([]));
|
|
232
|
+
}
|
|
233
|
+
fetchChatMessages(roomId, onDone) {
|
|
234
|
+
if (this.firebaseDatabase) {
|
|
235
|
+
try {
|
|
236
|
+
const roomMessagesRef = ref(this.firebaseDatabase, `${firebaseMessagesNode}/${roomId}`);
|
|
237
|
+
onValue(roomMessagesRef, (snapshot) => {
|
|
238
|
+
const conversations = [];
|
|
239
|
+
each(snapshot.val(), (message, key) => {
|
|
240
|
+
const chatMessage = createChatMessage(Object.assign(Object.assign({}, message), { uid: key }));
|
|
241
|
+
conversations.push(chatMessage);
|
|
242
|
+
});
|
|
243
|
+
onDone(sortBy(conversations, 'timestamp'));
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
onDone([]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return Promise.resolve({});
|
|
251
|
+
}
|
|
252
|
+
markMessagesAsRead(roomId, roomMessages) {
|
|
253
|
+
if (this.firebaseDatabase) {
|
|
254
|
+
try {
|
|
255
|
+
const roomMessagesRef = ref(this.firebaseDatabase, `${firebaseMessagesNode}/${roomId}`);
|
|
256
|
+
const updates = {};
|
|
257
|
+
roomMessages.forEach(message => {
|
|
258
|
+
const { uid } = message, nestedMessage = __rest(message, ["uid"]);
|
|
259
|
+
updates[`${message.uid}`] = Object.assign(Object.assign({}, nestedMessage), { unRead: 0 });
|
|
260
|
+
});
|
|
261
|
+
return update(roomMessagesRef, updates);
|
|
262
|
+
}
|
|
263
|
+
catch (error) { }
|
|
264
|
+
}
|
|
265
|
+
return Promise.reject();
|
|
266
|
+
}
|
|
267
|
+
sendChatMessage(options) {
|
|
268
|
+
if (this.firebaseDatabase) {
|
|
269
|
+
try {
|
|
270
|
+
const { message, senderId, chatRoomId } = options;
|
|
271
|
+
// Get a key for a new message.
|
|
272
|
+
const roomMessagesRef = ref(this.firebaseDatabase, `${firebaseMessagesNode}`);
|
|
273
|
+
const newMessageKey = push(child(roomMessagesRef, chatRoomId)).key;
|
|
274
|
+
const newMessageKeyPath = `/${chatRoomId}/${newMessageKey}`;
|
|
275
|
+
const newMessage = {
|
|
276
|
+
message,
|
|
277
|
+
unRead: 1,
|
|
278
|
+
senderId,
|
|
279
|
+
timestamp: dayjs().valueOf(),
|
|
280
|
+
};
|
|
281
|
+
// Store new message in Firebase
|
|
282
|
+
const updates = {
|
|
283
|
+
[newMessageKeyPath]: newMessage,
|
|
284
|
+
};
|
|
285
|
+
return update(roomMessagesRef, updates)
|
|
286
|
+
.then(() => {
|
|
287
|
+
return Object.assign(Object.assign({}, newMessage), { uid: newMessageKey });
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
catch (error) { }
|
|
291
|
+
}
|
|
292
|
+
return Promise.reject();
|
|
293
|
+
}
|
|
173
294
|
}
|
|
174
295
|
export default () => new HttpService();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createUser } from './user';
|
|
2
|
+
export function createChatMessage(blob) {
|
|
3
|
+
return {
|
|
4
|
+
uid: blob.uid,
|
|
5
|
+
message: blob.message,
|
|
6
|
+
timestamp: blob.timestamp,
|
|
7
|
+
unRead: blob.unRead,
|
|
8
|
+
senderId: blob.senderId,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export class ChatRoom {
|
|
12
|
+
constructor(fields) {
|
|
13
|
+
Object.assign(this, fields);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function createChatRoom(blob) {
|
|
17
|
+
return new ChatRoom({
|
|
18
|
+
id: blob.id,
|
|
19
|
+
uid: blob.firebase_room_id,
|
|
20
|
+
members: blob.from_user && blob.to_user ? [createUser(blob.from_user), createUser(blob.to_user)] : [],
|
|
21
|
+
messages: [],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function createUser(blob) {
|
|
2
2
|
const userNames = [blob.first_name, blob.last_name].filter(name => !!name);
|
|
3
3
|
return {
|
|
4
|
-
id: blob.user_id,
|
|
4
|
+
id: blob.id || blob.user_id,
|
|
5
5
|
firstName: blob.first_name,
|
|
6
6
|
lastName: blob.last_name,
|
|
7
7
|
fullName: userNames.length > 0 ? userNames.join(' ') : (blob.fullName || blob.name || blob.username),
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Components, JSX } from "../types/components";
|
|
4
4
|
|
|
5
|
+
interface ChatButton extends Components.ChatButton, HTMLElement {}
|
|
6
|
+
export const ChatButton: {
|
|
7
|
+
prototype: ChatButton;
|
|
8
|
+
new (): ChatButton;
|
|
9
|
+
};
|
|
10
|
+
|
|
5
11
|
interface GoogleMap extends Components.GoogleMap, HTMLElement {}
|
|
6
12
|
export const GoogleMap: {
|
|
7
13
|
prototype: GoogleMap;
|