qiscus-sdk-core 2.16.0 → 2.16.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/qiscus-sdk-core.js +24475 -34766
- package/dist/qiscus-sdk-core.js.map +1 -1
- package/dist/qiscus-sdk-core.min.js +24 -8
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +1847 -2705
- package/lib/lib/Comment.js +89 -142
- package/lib/lib/Room.js +52 -94
- package/lib/lib/adapters/auth.js +42 -69
- package/lib/lib/adapters/custom-event.js +26 -35
- package/lib/lib/adapters/expired-token.js +86 -113
- package/lib/lib/adapters/hook.js +15 -19
- package/lib/lib/adapters/http.js +129 -253
- package/lib/lib/adapters/mqtt.js +422 -648
- package/lib/lib/adapters/room.js +121 -147
- package/lib/lib/adapters/sync.js +233 -421
- package/lib/lib/adapters/user.js +175 -210
- package/lib/lib/is.js +13 -47
- package/lib/lib/match.js +49 -92
- package/lib/lib/url-builder.js +7 -18
- package/lib/lib/util.js +6 -20
- package/lib/lib/utils.js +52 -97
- package/package.json +21 -55
package/lib/lib/adapters/room.js
CHANGED
|
@@ -1,160 +1,134 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var RoomAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
2
|
+
class RoomAdapter {
|
|
11
3
|
/**
|
|
12
4
|
* Params used in this class
|
|
13
5
|
* @method constructor
|
|
14
6
|
* @param {Object} HTTPAdapter [Qiscus HTTP adapter]
|
|
15
7
|
* @return {void} Returns nothing
|
|
16
8
|
*/
|
|
17
|
-
|
|
18
|
-
(0, _classCallCheck2["default"])(this, RoomAdapter);
|
|
9
|
+
constructor(HTTPAdapter) {
|
|
19
10
|
this.HTTPAdapter = HTTPAdapter;
|
|
20
11
|
this.token = HTTPAdapter.token;
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
room.
|
|
82
|
-
|
|
83
|
-
id:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
avatarURL: room.avatar_url,
|
|
89
|
-
options: room.options,
|
|
90
|
-
participants: room.participants.map(function (participant) {
|
|
91
|
-
return {
|
|
92
|
-
id: participant.id,
|
|
93
|
-
email: participant.email,
|
|
94
|
-
username: participant.username,
|
|
95
|
-
avatarURL: participant.avatar_url
|
|
96
|
-
};
|
|
97
|
-
})
|
|
98
|
-
});
|
|
13
|
+
getOrCreateRoom(email, options, distinctId) {
|
|
14
|
+
let params = { emails: email };
|
|
15
|
+
if (distinctId) params[distinctId] = distinctId;
|
|
16
|
+
if (options) params["options"] = JSON.stringify(options);
|
|
17
|
+
return this.HTTPAdapter.post(
|
|
18
|
+
`api/v2/sdk/get_or_create_room_with_target`,
|
|
19
|
+
params
|
|
20
|
+
).then((res) => {
|
|
21
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
22
|
+
const room = res.body.results.room;
|
|
23
|
+
room.avatar = room.avatar_url;
|
|
24
|
+
room.comments = res.body.results.comments.reverse();
|
|
25
|
+
const rivalUser = room.participants.find((p) => p.email === email);
|
|
26
|
+
room.name = rivalUser ? rivalUser.username : "Room name";
|
|
27
|
+
return Promise.resolve(room);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getRoomById(id) {
|
|
31
|
+
return this.HTTPAdapter.get(`api/v2/sdk/get_room_by_id?id=${id}`).then(
|
|
32
|
+
(res) => res.body
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
getOrCreateRoomByUniqueId(id, name, avatarURL) {
|
|
36
|
+
let params = {
|
|
37
|
+
unique_id: id,
|
|
38
|
+
name,
|
|
39
|
+
avatar_url: avatarURL
|
|
40
|
+
};
|
|
41
|
+
return this.HTTPAdapter.post(
|
|
42
|
+
`api/v2/sdk/get_or_create_room_with_unique_id`,
|
|
43
|
+
params
|
|
44
|
+
).then((res) => {
|
|
45
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
46
|
+
const room = res.body.results.room;
|
|
47
|
+
room.avatar = room.avatar_url;
|
|
48
|
+
room.comments = res.body.results.comments.reverse();
|
|
49
|
+
room.name = room.room_name;
|
|
50
|
+
return Promise.resolve(room);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
createRoom(name, emails, opts = {}, optionalData = {}) {
|
|
54
|
+
const optsData = Object.keys(optionalData).length <= 0 ? null : JSON.stringify(optionalData);
|
|
55
|
+
const body = {
|
|
56
|
+
name,
|
|
57
|
+
"participants[]": emails,
|
|
58
|
+
avatar_url: opts.avatarURL,
|
|
59
|
+
options: optsData
|
|
60
|
+
};
|
|
61
|
+
return this.HTTPAdapter.post(`api/v2/sdk/create_room`, body).then((res) => {
|
|
62
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
63
|
+
const room = res.body.results.room;
|
|
64
|
+
room.comments = res.body.results.comments;
|
|
65
|
+
return Promise.resolve({
|
|
66
|
+
id: room.id,
|
|
67
|
+
name: room.room_name,
|
|
68
|
+
lastCommentId: room.last_comment_id,
|
|
69
|
+
lastCommentMessage: room.last_comment_message,
|
|
70
|
+
lastTopicId: room.last_topic_id,
|
|
71
|
+
avatarURL: room.avatar_url,
|
|
72
|
+
options: room.options,
|
|
73
|
+
participants: room.participants.map((participant) => ({
|
|
74
|
+
id: participant.id,
|
|
75
|
+
email: participant.email,
|
|
76
|
+
username: participant.username,
|
|
77
|
+
avatarURL: participant.avatar_url
|
|
78
|
+
}))
|
|
99
79
|
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (args.options) params['options'] = JSON.stringify(args.options);
|
|
111
|
-
return this.HTTPAdapter.post("api/v2/sdk/update_room", params).then(function (res) {
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
updateRoom(args) {
|
|
83
|
+
if (!args.id) throw new Error("id is required");
|
|
84
|
+
let params = { id: args.id };
|
|
85
|
+
if (args.room_name) params["room_name"] = args.room_name;
|
|
86
|
+
if (args.avatar_url) params["avatar_url"] = args.avatar_url;
|
|
87
|
+
if (args.options) params["options"] = JSON.stringify(args.options);
|
|
88
|
+
return this.HTTPAdapter.post(`api/v2/sdk/update_room`, params).then(
|
|
89
|
+
(res) => {
|
|
112
90
|
if (res.body.status !== 200) return Promise.reject(res);
|
|
113
91
|
return Promise.resolve(res.body.results.room);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
}]);
|
|
159
|
-
}();
|
|
160
|
-
module.exports = exports.default;
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
getTotalUnreadCount() {
|
|
96
|
+
return this.HTTPAdapter.get(`api/v2/sdk/total_unread_count`).then(
|
|
97
|
+
(resp) => resp.body.results.total_unread_count
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
getRoomUnreadCount() {
|
|
101
|
+
return this.HTTPAdapter.get(`api/v2/sdk/get_room_unread_count`).then(
|
|
102
|
+
(r) => r.body.results.total_unread_count
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
addParticipantsToGroup(roomId, emails = []) {
|
|
106
|
+
if (!roomId || !emails) throw new Error("room_id and emails is required");
|
|
107
|
+
let params = {
|
|
108
|
+
room_id: roomId,
|
|
109
|
+
"emails[]": emails
|
|
110
|
+
};
|
|
111
|
+
return this.HTTPAdapter.post(
|
|
112
|
+
`api/v2/sdk/add_room_participants`,
|
|
113
|
+
params
|
|
114
|
+
).then((res) => {
|
|
115
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
116
|
+
return Promise.resolve(res.body.results.participants_added);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
removeParticipantsFromGroup(roomId, emails = []) {
|
|
120
|
+
if (!roomId || !emails) throw new Error("room_id and emails is required");
|
|
121
|
+
let params = {
|
|
122
|
+
room_id: roomId,
|
|
123
|
+
"emails[]": emails
|
|
124
|
+
};
|
|
125
|
+
return this.HTTPAdapter.post(
|
|
126
|
+
`api/v2/sdk/remove_room_participants`,
|
|
127
|
+
params
|
|
128
|
+
).then((res) => {
|
|
129
|
+
if (res.body.status !== 200) return Promise.reject(res);
|
|
130
|
+
return Promise.resolve(res.body.results.participants_removed);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
module.exports = RoomAdapter;
|