comty.js 0.69.0 → 0.72.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.
Files changed (66) hide show
  1. package/dist/classes/FileUploadBrowser.js +36 -41
  2. package/dist/helpers/handleAfterRequest.js +32 -24
  3. package/dist/helpers/handleBeforeRequest.js +7 -6
  4. package/dist/helpers/reduceStandardPaginatedMap.js +14 -0
  5. package/dist/helpers/refreshToken.js +0 -4
  6. package/dist/helpers/withStorage.js +22 -21
  7. package/dist/hooks/use/index.js +41 -0
  8. package/dist/hooks/useChannelChat/index.js +7 -0
  9. package/dist/hooks/useChat/index.js +442 -0
  10. package/dist/hooks/useDMChat/index.js +7 -0
  11. package/dist/hooks/useRequest/index.js +1 -0
  12. package/dist/models/badges/index.js +16 -0
  13. package/dist/models/chats/index.js +5 -35
  14. package/dist/models/chats/methods/channels/deleteChannelMessage.js +22 -0
  15. package/dist/models/chats/methods/channels/getChannelChat.js +19 -0
  16. package/dist/models/chats/methods/channels/index.js +11 -0
  17. package/dist/models/chats/methods/channels/sendToChannelChat.js +23 -0
  18. package/dist/models/chats/methods/dm/deleteMessage.js +18 -0
  19. package/dist/models/chats/methods/dm/getMessages.js +15 -0
  20. package/dist/models/chats/methods/dm/index.js +14 -0
  21. package/dist/models/chats/methods/dm/listRooms.js +11 -0
  22. package/dist/models/chats/methods/dm/sendMessage.js +19 -0
  23. package/dist/models/decorations/index.js +16 -0
  24. package/dist/models/files/index.js +2 -0
  25. package/dist/models/groups/channels/index.js +20 -0
  26. package/dist/models/groups/channels/methods/changeChannelsOrder.js +19 -0
  27. package/dist/models/groups/{methods → channels/methods}/createChannel.js +1 -1
  28. package/dist/models/groups/{methods → channels/methods}/deleteChannel.js +1 -1
  29. package/dist/models/groups/channels/methods/disconnectUser.js +22 -0
  30. package/dist/models/groups/{methods/getChannel.js → channels/methods/getGroupChannel.js} +1 -1
  31. package/dist/models/groups/channels/methods/getGroupChannels.js +18 -0
  32. package/dist/models/groups/{methods → channels/methods}/modifyChannel.js +1 -1
  33. package/dist/models/groups/index.js +24 -17
  34. package/dist/models/groups/members/index.js +9 -0
  35. package/dist/models/groups/members/methods/getGroupMember.js +18 -0
  36. package/dist/models/groups/{methods → members/methods}/getGroupMembers.js +3 -3
  37. package/dist/models/groups/members/methods/removeGroupMember.js +18 -0
  38. package/dist/models/groups/methods/createInvite.js +15 -0
  39. package/dist/models/groups/methods/deleteInvite.js +18 -0
  40. package/dist/models/groups/methods/getAllInvites.js +14 -0
  41. package/dist/models/groups/methods/getInviteData.js +21 -0
  42. package/dist/models/groups/methods/getSoundpadItems.js +10 -0
  43. package/dist/models/groups/methods/joinWithInviteKey.js +17 -0
  44. package/dist/models/music/getters/library.js +9 -9
  45. package/dist/models/music/getters/timings.js +11 -0
  46. package/dist/models/session/index.js +2 -18
  47. package/dist/models/stickers/index.js +29 -0
  48. package/dist/models/user/UserV2.js +30 -0
  49. package/dist/models/user/index.js +34 -130
  50. package/dist/models/user/methods/data.js +37 -0
  51. package/dist/models/user/methods/getAvatar.js +15 -0
  52. package/dist/models/user/methods/getBadges.js +15 -0
  53. package/dist/models/user/methods/getConfig.js +13 -0
  54. package/dist/models/user/methods/getPublicKey.js +15 -0
  55. package/dist/models/user/methods/getRoles.js +10 -0
  56. package/dist/models/user/methods/isUserConnected.js +19 -0
  57. package/dist/models/user/methods/unsetPublicName.js +7 -0
  58. package/dist/models/user/methods/updateConfig.js +11 -0
  59. package/dist/models/user/methods/updateData.js +11 -0
  60. package/dist/models/user/methods/updatePublicKey.js +13 -0
  61. package/dist/models/user/methods/v2/getDecorations.js +15 -0
  62. package/dist/remotes.js +8 -11
  63. package/dist/request.js +34 -35
  64. package/dist/utils/usersDataMap.js +17 -0
  65. package/dist/ws.js +35 -85
  66. package/package.json +5 -6
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _events = require('@foxify/events'); var _events2 = _interopRequireDefault(_events);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _events = require('@foxify/events'); var _events2 = _interopRequireDefault(_events);
2
2
 
3
3
  class FileUploadBrowser {
4
- constructor(params) {;FileUploadBrowser.prototype.__init.call(this);FileUploadBrowser.prototype.__init2.call(this);FileUploadBrowser.prototype.__init3.call(this);
4
+ constructor(params) {;FileUploadBrowser.prototype.__init.call(this);FileUploadBrowser.prototype.__init2.call(this);FileUploadBrowser.prototype.__init3.call(this);FileUploadBrowser.prototype.__init4.call(this);
5
5
  const {
6
6
  endpoint,
7
7
  file,
@@ -61,6 +61,19 @@
61
61
  "offline",
62
62
  () => ((this.offline = true), this.events.emit("offline")),
63
63
  )
64
+
65
+ this.websocket =
66
+ _nullishCoalesce(_optionalChain([globalThis, 'access', _ => _.__comty_shared_state, 'optionalAccess', _2 => _2.ws, 'optionalAccess', _3 => _3.sockets, 'optionalAccess', _4 => _4.get, 'call', _5 => _5("main")]), () => ( null))
67
+
68
+ this.websocketJobEvent = `job:${this.headers["uploader-file-id"]}`
69
+
70
+ if (!this.websocket) {
71
+ new Error(
72
+ "Cannot listen to job events over websocket. Socket/Context no available",
73
+ )
74
+ }
75
+
76
+ this.websocket.on(this.websocketJobEvent, this.handleJobWebsocketEvent)
64
77
  }
65
78
 
66
79
  __init() {this._reader = new FileReader()}
@@ -160,11 +173,9 @@
160
173
  this.nextSend()
161
174
  }
162
175
 
163
- // check if is the last chunk, if so, handle sse events
176
+ // check if is the last chunk
164
177
  if (this.chunkCount === this.totalChunks) {
165
- if (data.sseChannelId || data.sseUrl) {
166
- this.waitOnSSE(data)
167
- } else {
178
+ if (!data.useWebsocketEvents) {
168
179
  this.events.emit("finish", data)
169
180
  }
170
181
  }
@@ -186,44 +197,28 @@
186
197
  }
187
198
  }
188
199
 
189
- waitOnSSE(data) {
190
- // temporal solution until a better solution
191
- const url = `${app.cores.api.client().mainOrigin}/upload/sse_events/${data.sseChannelId}`
192
-
193
- console.log(`[UPLOADER] Connecting to SSE channel >`, url)
194
- const eventSource = new EventSource(url)
195
-
196
- eventSource.onerror = (error) => {
197
- this.events.emit("error", error)
198
- eventSource.close()
200
+ __init4() {this.handleJobWebsocketEvent = (data) => {
201
+ if (data.event === "done") {
202
+ this.events.emit("finish", data.result)
203
+ this.websocket.off(
204
+ this.websocketJobEvent,
205
+ this.handleJobWebsocketEvent,
206
+ )
199
207
  }
200
208
 
201
- eventSource.onopen = () => {
202
- console.log(`[UPLOADER] SSE channel opened`)
209
+ if (data.event === "error") {
210
+ this.events.emit("error", data.result)
211
+ this.websocket.off(
212
+ this.websocketJobEvent,
213
+ this.handleJobWebsocketEvent,
214
+ )
203
215
  }
204
216
 
205
- eventSource.onmessage = (event) => {
206
- // parse json
207
- const messageData = JSON.parse(event.data)
208
-
209
- console.log(`[UPLOADER] SSE Event >`, messageData)
210
-
211
- if (messageData.event === "done") {
212
- this.events.emit("finish", messageData.result)
213
- eventSource.close()
214
- }
215
-
216
- if (messageData.event === "error") {
217
- this.events.emit("error", messageData.result)
218
- eventSource.close()
219
- }
220
-
221
- if (messageData.state) {
222
- this.events.emit("progress", {
223
- percent: messageData.percent,
224
- state: messageData.state,
225
- })
226
- }
217
+ if (data.state) {
218
+ this.events.emit("progress", {
219
+ percent: data.percent,
220
+ state: data.state,
221
+ })
227
222
  }
228
- }
223
+ }}
229
224
  } exports.default = FileUploadBrowser;
@@ -1,32 +1,40 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _refreshToken = require('./refreshToken'); var _refreshToken2 = _interopRequireDefault(_refreshToken);
2
2
 
3
3
  exports. default = async (data, callback) => {
4
- // handle 401, 403 responses
5
- if (data instanceof Error) {
6
- if (data.code && (data.code === "ECONNABORTED" || data.code === "ERR_NETWORK")) {
7
- console.error(`Request aborted or network error`)
8
- return false
9
- }
4
+ // handle 401, 403 responses
5
+ if (data instanceof Error) {
6
+ if (
7
+ data.code &&
8
+ (data.code === "ECONNABORTED" || data.code === "ERR_NETWORK")
9
+ ) {
10
+ console.error(`Request aborted or network error`)
11
+ return false
12
+ }
10
13
 
11
- if (data.response) {
12
- if (data.response.status === 401) {
13
- // check if the server issue a refresh token on data
14
- if (data.response.data.expired) {
15
- try {
16
- console.log(`Session expired, trying to regenerate...`)
14
+ if (data.response) {
15
+ if (data.response.status === 401) {
16
+ // check if the server issue a refresh token on data
17
+ if (data.response.data.expired) {
18
+ try {
19
+ console.log(`Session expired, trying to regenerate...`)
17
20
 
18
- await _refreshToken2.default.call(void 0, )
19
- } catch (error) {
20
- __comty_shared_state.eventBus.emit("session.invalid", error.message)
21
+ await _refreshToken2.default.call(void 0, )
22
+ } catch (error) {
23
+ __comty_shared_state.eventBus.emit(
24
+ "session:invalid",
25
+ error.message,
26
+ )
21
27
 
22
- console.error(`Failed to regenerate token: ${error.message}`)
28
+ console.error(
29
+ `Failed to regenerate token: ${error.message}`,
30
+ )
23
31
 
24
- throw new Error(`Invalid or Expired session`)
25
- }
32
+ throw new Error(`Invalid or Expired session`)
33
+ }
26
34
 
27
- return await callback()
28
- }
29
- }
30
- }
31
- }
32
- }
35
+ return await callback()
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -1,7 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});exports. default = async () => {
2
- if (__comty_shared_state.refreshingToken === true) {
3
- await new Promise((resolve) => {
4
- __comty_shared_state.eventBus.once("session:refreshed", resolve)
5
- })
6
- }
7
- }
2
+ // await to token being refreshed
3
+ if (__comty_shared_state.refreshingToken === true) {
4
+ await new Promise((resolve) => {
5
+ __comty_shared_state.eventBus.once("session:refreshed", resolve)
6
+ })
7
+ }
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});exports. default = (curr = {}, obj = {}) => {
2
+ return [curr, obj].reduce(
3
+ (acc, source) => {
4
+ if (Array.isArray(source.items)) {
5
+ acc.items.push(...source.items)
6
+ }
7
+ if (Number.isInteger(source.total_items)) {
8
+ acc.total_items += source.total_items
9
+ }
10
+ return acc
11
+ },
12
+ { items: [], total_items: 0 },
13
+ )
14
+ }
@@ -38,9 +38,5 @@ exports. default = async () => {
38
38
  __comty_shared_state.eventBus.emit("session:refreshed")
39
39
  __comty_shared_state.refreshingToken = false
40
40
 
41
- if (typeof __comty_shared_state.ws === "object") {
42
- await __comty_shared_state.ws.connectAll()
43
- }
44
-
45
41
  return true
46
42
  }
@@ -1,31 +1,32 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _jscookie = require('js-cookie'); var _jscookie2 = _interopRequireDefault(_jscookie);
2
2
 
3
3
  class InternalStorage {
4
- #storage = {}
4
+ #storage = {}
5
5
 
6
- get(key) {
7
- // get value from storage
8
- return this.#storage[key]
9
- }
6
+ get(key) {
7
+ // get value from storage
8
+ return this.#storage[key]
9
+ }
10
10
 
11
- set(key, value) {
12
- // storage securely in memory
13
- return this.#storage[key] = value
14
- }
11
+ set(key, value) {
12
+ // storage securely in memory
13
+ return (this.#storage[key] = value)
14
+ }
15
15
  }
16
16
 
17
17
  class Storage {
18
- static get engine() {
19
- // check if is running in browser, if is import js-cookie
20
- // else use in-memory safe storage
21
- if (typeof window !== "undefined") {
22
- return _jscookie2.default
23
- }
18
+ static get engine() {
19
+ // check if is running in browser, if is import js-cookie
20
+ // else use in-memory safe storage
21
+ if (typeof window !== "undefined") {
22
+ return _jscookie2.default
23
+ }
24
24
 
25
- if (!globalThis.__comty_shared_state["_internal_storage"]) {
26
- globalThis.__comty_shared_state["_internal_storage"] = new InternalStorage()
27
- }
25
+ if (!globalThis.__comty_shared_state["_internal_storage"]) {
26
+ globalThis.__comty_shared_state["_internal_storage"] =
27
+ new InternalStorage()
28
+ }
28
29
 
29
- return globalThis.__comty_shared_state["_internal_storage"]
30
- }
31
- } exports.default = Storage;
30
+ return globalThis.__comty_shared_state["_internal_storage"]
31
+ }
32
+ } exports.default = Storage;
@@ -0,0 +1,41 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _react = require('react'); var _react2 = _interopRequireDefault(_react);
2
+
3
+ exports. default = (method, ...args) => {
4
+ const [loading, setLoading] = _react2.default.useState(true)
5
+ const [result, setResult] = _react2.default.useState(null)
6
+ const [error, setError] = _react2.default.useState(null)
7
+
8
+ if (typeof method !== "function") {
9
+ return [() => {}, null, new Error("Method is not a function"), () => {}]
10
+ }
11
+
12
+ const req = async (..._) => {
13
+ setLoading(true)
14
+ setError(null)
15
+
16
+ try {
17
+ setResult(await method(..._))
18
+ } catch (err) {
19
+ console.error(err)
20
+ setError(err)
21
+ }
22
+
23
+ setLoading(false)
24
+ }
25
+
26
+ // perform request on mount
27
+ _react2.default.useEffect(() => {
28
+ req(...args)
29
+ }, [])
30
+
31
+ return {
32
+ loading: loading,
33
+ error: error,
34
+
35
+ result: result,
36
+ setResult: setResult,
37
+
38
+ req: req,
39
+ repeat: () => req(...args),
40
+ }
41
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _useChat = require('../useChat'); var _useChat2 = _interopRequireDefault(_useChat);
2
+
3
+ function useChannelChat(group_id, channel_id, events) {
4
+ return _useChat2.default.call(void 0, "channel", { group_id, channel_id }, events)
5
+ }
6
+
7
+ exports. default = useChannelChat