@amityco/ts-sdk 0.0.1-beta.22 → 0.0.1-beta.25
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/@types/core/events.d.ts +5 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -2
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +1 -1
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +2 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts +3 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts +1 -0
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts +1 -0
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/index.cjs.js +381 -67
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +376 -68
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/poll/api/closePoll.d.ts.map +1 -1
- package/dist/poll/api/deletePoll.d.ts.map +1 -1
- package/dist/poll/api/votePoll.d.ts.map +1 -1
- package/dist/poll/events/index.d.ts +3 -0
- package/dist/poll/events/index.d.ts.map +1 -0
- package/dist/poll/events/onPollDeleted.d.ts +17 -0
- package/dist/poll/events/onPollDeleted.d.ts.map +1 -0
- package/dist/poll/events/onPollUpdated.d.ts +17 -0
- package/dist/poll/events/onPollUpdated.d.ts.map +1 -0
- package/dist/poll/observers/index.d.ts +2 -0
- package/dist/poll/observers/index.d.ts.map +1 -0
- package/dist/poll/observers/observePoll.d.ts +18 -0
- package/dist/poll/observers/observePoll.d.ts.map +1 -0
- package/dist/post/api/approvePost.d.ts +17 -0
- package/dist/post/api/approvePost.d.ts.map +1 -0
- package/dist/post/api/declinePost.d.ts +17 -0
- package/dist/post/api/declinePost.d.ts.map +1 -0
- package/dist/post/api/index.d.ts +2 -0
- package/dist/post/api/index.d.ts.map +1 -1
- package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
- package/dist/reaction/utils/index.d.ts +1 -0
- package/dist/reaction/utils/index.d.ts.map +1 -1
- package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts +3 -0
- package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +6 -1
- package/src/@types/domains/channel.ts +1 -2
- package/src/@types/domains/reaction.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +4 -4
- package/src/channel/api/updateChannel.ts +1 -1
- package/src/client/api/connectClient.ts +12 -7
- package/src/comment/api/queryComments.ts +6 -3
- package/src/core/model/identifyModel.ts +18 -0
- package/src/core/query/query.ts +19 -1
- package/src/index.ts +2 -0
- package/src/message/api/createMessage.ts +22 -6
- package/src/message/events/onMessageUpdated.ts +9 -1
- package/src/poll/api/closePoll.ts +3 -0
- package/src/poll/api/deletePoll.ts +3 -0
- package/src/poll/api/votePoll.ts +3 -0
- package/src/poll/events/index.ts +2 -0
- package/src/poll/events/onPollDeleted.ts +31 -0
- package/src/poll/events/onPollUpdated.ts +31 -0
- package/src/poll/observers/index.ts +1 -0
- package/src/poll/observers/observePoll.ts +67 -0
- package/src/post/api/approvePost.ts +48 -0
- package/src/post/api/declinePost.ts +48 -0
- package/src/post/api/index.ts +3 -0
- package/src/reaction/events/onReactionAdded.ts +4 -0
- package/src/reaction/utils/index.ts +1 -0
- package/src/reaction/utils/prepareMessagePayloadForCache.ts +40 -0
- package/src/report/api/createReport.ts +7 -1
- package/src/report/api/deleteReport.ts +7 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/message/api/createMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/message/api/createMessage.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa;2JAKvB,QAAQ,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC;IAmBvC;;;;;;;;;;;;;;;OAeG;2BAEO,KACN,MAAM,OAAO,EACb,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAChF,GACA,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS;CAvBzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMessageUpdated.d.ts","sourceRoot":"","sources":["../../../src/message/events/onMessageUpdated.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onMessageUpdated.d.ts","sourceRoot":"","sources":["../../../src/message/events/onMessageUpdated.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,aAAc,MAAM,QAAQ,CAAC,MAAM,OAAO,CAAC,KAAG,MAAM,YAgBhF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/closePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"closePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/closePoll.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAoBlC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deletePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/deletePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deletePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/deletePoll.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,CAiB9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"votePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/votePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"votePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/votePoll.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,WACX,MAAM,IAAI,CAAC,QAAQ,CAAC,aACjB,MAAM,EAAE,KAClB,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAoBlC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/poll/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onPollDeleted } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onPollDeleted(poll => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Poll} has been deleted
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category Poll Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onPollDeleted: (callback: Amity.Listener<Amity.Poll>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onPollDeleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onPollDeleted.d.ts","sourceRoot":"","sources":["../../../src/poll/events/onPollDeleted.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAU1E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onPollUpdated } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onPollUpdated(poll => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Poll} has been updated
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category Poll Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onPollUpdated: (callback: Amity.Listener<Amity.Poll>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onPollUpdated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onPollUpdated.d.ts","sourceRoot":"","sources":["../../../src/poll/events/onPollUpdated.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAU1E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/poll/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { observePoll } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* let poll = {}
|
|
6
|
+
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Observe all mutation on a given {@link Amity.Poll}
|
|
10
|
+
*
|
|
11
|
+
* @param pollId the ID of the poll to observe
|
|
12
|
+
* @param callback the function to call when new data are available
|
|
13
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
14
|
+
*
|
|
15
|
+
* @category Poll Observer
|
|
16
|
+
*/
|
|
17
|
+
export declare const observePoll: <Events extends ["onFetch", "onUpdate", "onDelete"]>(pollId: string, callback: Amity.ObjectListener<Amity.Snapshot<Amity.Poll | undefined>, Events>, policy?: Amity.QueryPolicy) => Amity.Unsubscriber;
|
|
18
|
+
//# sourceMappingURL=observePoll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/observers/observePoll.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,+DACd,MAAM,2FAEN,MAAM,WAAW,KACxB,MAAM,YAsCR,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* const { data: post } = await approvePost('postId')
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Approves a {@link Amity.Post}
|
|
9
|
+
*
|
|
10
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
11
|
+
* @return A {@link Amity.Post} that was approved
|
|
12
|
+
*
|
|
13
|
+
* @category Post API
|
|
14
|
+
* @async
|
|
15
|
+
*/
|
|
16
|
+
export declare const approvePost: (postId: Amity.Post['postId']) => Promise<Amity.Cached<Amity.Post>>;
|
|
17
|
+
//# sourceMappingURL=approvePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approvePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/approvePost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAyBlC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* const {data: post} = await declinePost('postId')
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Declines a {@link Amity.Post}
|
|
9
|
+
*
|
|
10
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
11
|
+
* @return A {@link Amity.Post} that was declined
|
|
12
|
+
*
|
|
13
|
+
* @category Post API
|
|
14
|
+
* @async
|
|
15
|
+
*/
|
|
16
|
+
export declare const declinePost: (postId: Amity.Post['postId']) => Promise<Amity.Cached<Amity.Post>>;
|
|
17
|
+
//# sourceMappingURL=declinePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declinePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/declinePost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAyBlC,CAAC"}
|
package/dist/post/api/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/post/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/post/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAE7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/onReactionAdded.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,eAAe,kBACX,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,0FAEzC,MAAM,
|
|
1
|
+
{"version":3,"file":"onReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/onReactionAdded.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,eAAe,kBACX,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,0FAEzC,MAAM,YA0CR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareMessagePayloadForCache.d.ts","sourceRoot":"","sources":["../../../src/reaction/utils/prepareMessagePayloadForCache.ts"],"names":[],"mappings":"AAGA,cAAc;AAKd,eAAO,MAAM,6BAA6B,YAAa,MAAM,OAAO,SA+BnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/createReport.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"createReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/createReport.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,CA0BjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/deleteReport.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAG1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"deleteReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/deleteReport.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAG1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,CA0BjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -116,6 +116,11 @@ declare global {
|
|
|
116
116
|
MqttUserMessageEvents &
|
|
117
117
|
MqttFollowMessageEvents;
|
|
118
118
|
|
|
119
|
-
type
|
|
119
|
+
type LocalEvents = {
|
|
120
|
+
'poll.updated': Amity.PollPayload;
|
|
121
|
+
'poll.deleted': Amity.PollPayload;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type Events = WsEvents & MqttEvents & MqttMessageEvents & LocalEvents;
|
|
120
125
|
}
|
|
121
126
|
}
|
|
@@ -2,13 +2,12 @@ export {};
|
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
|
-
type ChannelType = '
|
|
5
|
+
type ChannelType = 'broadcast' | 'conversation' | 'community' | 'live';
|
|
6
6
|
|
|
7
7
|
type Channel<T extends ChannelType = any> = {
|
|
8
8
|
channelId: string;
|
|
9
9
|
displayName?: string;
|
|
10
10
|
avatarFileId?: File<'image'>['fileId'];
|
|
11
|
-
description?: string;
|
|
12
11
|
type: T;
|
|
13
12
|
|
|
14
13
|
isDistinct?: boolean;
|
|
@@ -19,22 +19,22 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
19
19
|
* */
|
|
20
20
|
export const queryChannelMembers = async (query: {
|
|
21
21
|
channelId: string;
|
|
22
|
-
|
|
22
|
+
memberships?: ('muted' | 'banned' | 'member')[];
|
|
23
23
|
roles?: string[];
|
|
24
24
|
sortBy?: 'firstCreated' | 'lastCreated';
|
|
25
|
+
search?: string;
|
|
25
26
|
page?: Amity.Page;
|
|
26
27
|
}): Promise<Amity.Cached<Amity.Paged<Amity.Membership<'channel'>>>> => {
|
|
27
28
|
const client = getActiveClient();
|
|
28
29
|
client.log('channel/queryChannelMembers', query);
|
|
29
30
|
|
|
30
|
-
const { page, channelId,
|
|
31
|
+
const { page, channelId, ...params } = query ?? {};
|
|
31
32
|
|
|
32
33
|
const { data } = await client.http.get<Amity.ChannelMembershipPayload & Amity.Pagination>(
|
|
33
|
-
`/api/
|
|
34
|
+
`/api/v4/channels/${encodeURIComponent(channelId)}/users`,
|
|
34
35
|
{
|
|
35
36
|
params: {
|
|
36
37
|
...params,
|
|
37
|
-
filter: membership,
|
|
38
38
|
options: {
|
|
39
39
|
token: toToken(page, 'skiplimit'),
|
|
40
40
|
},
|
|
@@ -19,7 +19,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
19
19
|
*/
|
|
20
20
|
export const updateChannel = async (
|
|
21
21
|
channelId: Amity.Channel['channelId'],
|
|
22
|
-
patch: Patch<Amity.Channel, 'displayName' | '
|
|
22
|
+
patch: Patch<Amity.Channel, 'displayName' | 'avatarFileId' | 'tags' | 'metadata'>,
|
|
23
23
|
): Promise<Amity.Cached<Amity.Channel>> => {
|
|
24
24
|
const client = getActiveClient();
|
|
25
25
|
client.log('channel/updateChannel', channelId, patch);
|
|
@@ -32,12 +32,15 @@ import { onUserDeleted } from '~/user/events/onUserDeleted';
|
|
|
32
32
|
* @category Client API
|
|
33
33
|
* @async
|
|
34
34
|
*/
|
|
35
|
-
export const connectClient = async (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
export const connectClient = async (
|
|
36
|
+
params: {
|
|
37
|
+
userId: Amity.User['userId'];
|
|
38
|
+
displayName?: Amity.User['displayName'];
|
|
39
|
+
authToken?: string;
|
|
40
|
+
deviceId?: Amity.Device['deviceId'];
|
|
41
|
+
},
|
|
42
|
+
config?: { disableRTE: boolean },
|
|
43
|
+
): Promise<boolean> => {
|
|
41
44
|
const client = getActiveClient();
|
|
42
45
|
client.log('client/api/connectClient', { apiKey: client.apiKey, ...params });
|
|
43
46
|
|
|
@@ -70,7 +73,9 @@ export const connectClient = async (params: {
|
|
|
70
73
|
|
|
71
74
|
setActiveUser(users[0]);
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
if (config?.disableRTE !== true) {
|
|
77
|
+
subscribeTopic(getNetworkTopic());
|
|
78
|
+
}
|
|
74
79
|
|
|
75
80
|
const subscriptions = [
|
|
76
81
|
onClientBanned(() => {
|
|
@@ -22,6 +22,7 @@ import { getResolver } from '~/core/model';
|
|
|
22
22
|
export const queryComments = async (query: {
|
|
23
23
|
referenceType: Amity.Comment['referenceType'];
|
|
24
24
|
referenceId: Amity.Comment['referenceId'];
|
|
25
|
+
sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated';
|
|
25
26
|
parentId?: Amity.Comment['commentId'] | null;
|
|
26
27
|
hasFlag?: boolean;
|
|
27
28
|
isDeleted?: Amity.Comment['isDeleted'];
|
|
@@ -32,6 +33,10 @@ export const queryComments = async (query: {
|
|
|
32
33
|
|
|
33
34
|
const { page = { limit: 10 }, ...params } = query;
|
|
34
35
|
|
|
36
|
+
const options = {
|
|
37
|
+
type: params.sortBy ? 'pagination' : undefined,
|
|
38
|
+
token: toToken(page, params.sortBy ? 'skiplimit' : 'afterbefore'),
|
|
39
|
+
};
|
|
35
40
|
// const filterByParentId = query.parentId !== undefined
|
|
36
41
|
|
|
37
42
|
// API-FIX: parameters should be querystring. (1)
|
|
@@ -43,9 +48,7 @@ export const queryComments = async (query: {
|
|
|
43
48
|
params: {
|
|
44
49
|
...params,
|
|
45
50
|
// filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
|
|
46
|
-
options
|
|
47
|
-
token: toToken(page, 'afterbefore'),
|
|
48
|
-
},
|
|
51
|
+
options,
|
|
49
52
|
},
|
|
50
53
|
},
|
|
51
54
|
);
|
|
@@ -57,3 +57,21 @@ export const identifyModel = (model: Record<string, unknown>) => {
|
|
|
57
57
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
58
|
return criterias.find(([_, keys]) => hasKeys(model, keys))?.[0];
|
|
59
59
|
};
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Identify the modal key for a model
|
|
63
|
+
* Used to get args for optimistic updates
|
|
64
|
+
* Example: createMessage: get messageId on optimistic message creation
|
|
65
|
+
*
|
|
66
|
+
* @param model to be recognized
|
|
67
|
+
* @returns model key array if one if found or undefined
|
|
68
|
+
*/
|
|
69
|
+
export const identifyModelKey = (model: Record<string, unknown>): string | undefined => {
|
|
70
|
+
const modalKey = identifyModel(model);
|
|
71
|
+
|
|
72
|
+
if (!modalKey) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return CRITERIAS[modalKey]?.[0];
|
|
77
|
+
};
|
package/src/core/query/query.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { isPaged } from './paging';
|
|
3
|
+
import { identifyModelKey } from '~/core/model';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
@@ -201,7 +202,24 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
201
202
|
);
|
|
202
203
|
}
|
|
203
204
|
|
|
204
|
-
|
|
205
|
+
let optimisticArgs = args;
|
|
206
|
+
/* get args for optimistic method calls
|
|
207
|
+
*
|
|
208
|
+
* On optimistic updates, the modal key for the update needs to be passed to
|
|
209
|
+
* the server so as to avoid duplicate modal creation
|
|
210
|
+
*
|
|
211
|
+
* ex: on creating a new message pass the modalKey is messageId, pass this
|
|
212
|
+
* id onto the server so that a duplicate with seperate messageId is not
|
|
213
|
+
* created.
|
|
214
|
+
*/
|
|
215
|
+
if (isMutator(func)) {
|
|
216
|
+
// @ts-ignore
|
|
217
|
+
const modelKey = local && local.data && identifyModelKey(local.data);
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
optimisticArgs = modelKey ? [...args, { [modelKey]: local.data[modelKey] }] : args;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
func(...optimisticArgs)
|
|
205
223
|
.then(fresh => {
|
|
206
224
|
// @ts-ignore i know.
|
|
207
225
|
// isLocal(local) && syncInCache(local, fresh)
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { upsertInCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
import { fireEvent } from '~/core/events';
|
|
6
|
+
import { uuid } from '~/core/uuid';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* ```js
|
|
@@ -28,6 +29,7 @@ export const createMessage = async <T extends Amity.MessageContentType>(
|
|
|
28
29
|
>,
|
|
29
30
|
): Promise<Amity.Cached<Amity.Message>> => {
|
|
30
31
|
const client = getActiveClient();
|
|
32
|
+
|
|
31
33
|
client.log('user/createMessage', bundle);
|
|
32
34
|
|
|
33
35
|
const { data } = await client.http.post<Amity.MessagePayload>('/api/v3/messages', bundle);
|
|
@@ -67,23 +69,37 @@ createMessage.optimistically = (
|
|
|
67
69
|
>,
|
|
68
70
|
): Amity.Cached<Amity.Message> | undefined => {
|
|
69
71
|
const client = getActiveClient();
|
|
70
|
-
client.log('user/createMessage.locally', bundle);
|
|
71
72
|
|
|
72
73
|
if (!client.cache) return;
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
/*
|
|
76
|
+
* when creating messages optimistically a messageId needs to be added by the
|
|
77
|
+
* client, created a new variable so as to allow backward compatibility of API
|
|
78
|
+
*
|
|
79
|
+
* Updated to handle client requirement to add messageId while uploading
|
|
80
|
+
* message with image. Temporary!
|
|
81
|
+
*/
|
|
82
|
+
const bundleWithMessageId = { messageId: uuid(), ...bundle };
|
|
83
|
+
|
|
84
|
+
// only log if cache is enabled
|
|
85
|
+
client.log('user/createMessage.locally', bundleWithMessageId);
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
const channel = pullFromCache<Amity.Channel>(['channel', 'get', bundleWithMessageId.channelId]);
|
|
88
|
+
|
|
89
|
+
upsertInCache(['channel', 'get', bundleWithMessageId.channelId], {
|
|
77
90
|
...channel?.data,
|
|
78
91
|
messageCount: (channel?.data.messageCount ?? 0) + 1,
|
|
79
92
|
});
|
|
80
93
|
|
|
94
|
+
// as reused to update created and updated time, which should be the same
|
|
95
|
+
const createdTime = new Date().toISOString();
|
|
96
|
+
|
|
81
97
|
const message = {
|
|
82
|
-
messageId: Math.random().toString(16),
|
|
83
98
|
userId: client.userId,
|
|
84
99
|
channelSegment: (channel?.data.messageCount ?? 0) + 1,
|
|
85
|
-
createdAt:
|
|
86
|
-
|
|
100
|
+
createdAt: createdTime,
|
|
101
|
+
updatedAt: createdTime,
|
|
102
|
+
...bundleWithMessageId,
|
|
87
103
|
} as Amity.Message;
|
|
88
104
|
|
|
89
105
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt: -1 });
|
|
@@ -2,6 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { prepareMessagePayloadForCache } from '~/reaction/utils';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* ```js
|
|
@@ -23,7 +24,14 @@ export const onMessageUpdated = (callback: Amity.Listener<Amity.Message>): Amity
|
|
|
23
24
|
|
|
24
25
|
const filter = (payload: Amity.MessagePayload) => {
|
|
25
26
|
ingestInCache(payload);
|
|
26
|
-
|
|
27
|
+
const message = payload.messages[0];
|
|
28
|
+
|
|
29
|
+
// if payload does not have myReactions
|
|
30
|
+
if (!message?.myReactions) {
|
|
31
|
+
prepareMessagePayloadForCache(message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
callback(message);
|
|
27
35
|
};
|
|
28
36
|
|
|
29
37
|
return createEventSubscriber(client, 'message/onMessageUpdated', 'v3.message.didUpdate', filter);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
@@ -30,6 +31,8 @@ export const closePoll = async (
|
|
|
30
31
|
const cachedAt = client.cache && Date.now();
|
|
31
32
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
32
33
|
|
|
34
|
+
fireEvent('poll.updated', data);
|
|
35
|
+
|
|
33
36
|
const { polls } = data;
|
|
34
37
|
|
|
35
38
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { upsertInCache } from '~/cache/api';
|
|
@@ -32,5 +33,7 @@ export const deletePoll = async (pollId: Amity.Poll['pollId']): Promise<boolean>
|
|
|
32
33
|
|
|
33
34
|
upsertInCache(['poll', 'get', pollId], deleted);
|
|
34
35
|
|
|
36
|
+
fireEvent('poll.deleted', { polls: [deleted], users: [] });
|
|
37
|
+
|
|
35
38
|
return success;
|
|
36
39
|
};
|
package/src/poll/api/votePoll.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
@@ -34,6 +35,8 @@ export const votePoll = async (
|
|
|
34
35
|
|
|
35
36
|
const { polls } = data;
|
|
36
37
|
|
|
38
|
+
fireEvent('poll.updated', data);
|
|
39
|
+
|
|
37
40
|
return {
|
|
38
41
|
data: polls.find(poll => poll.pollId === pollId)!,
|
|
39
42
|
cachedAt,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onPollDeleted } from '@amityco/ts-sdk'
|
|
9
|
+
* const dispose = onPollDeleted(poll => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when an {@link Amity.Poll} has been deleted
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Poll Events
|
|
20
|
+
*/
|
|
21
|
+
export const onPollDeleted = (callback: Amity.Listener<Amity.Poll>): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const filter = (payload: Amity.PollPayload) => {
|
|
25
|
+
if (client.cache) ingestInCache(payload);
|
|
26
|
+
|
|
27
|
+
callback(payload.polls[0]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onPollUpdated } from '@amityco/ts-sdk'
|
|
9
|
+
* const dispose = onPollUpdated(poll => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when an {@link Amity.Poll} has been updated
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Poll Events
|
|
20
|
+
*/
|
|
21
|
+
export const onPollUpdated = (callback: Amity.Listener<Amity.Poll>): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const filter = (payload: Amity.PollPayload) => {
|
|
25
|
+
if (client.cache) ingestInCache(payload);
|
|
26
|
+
|
|
27
|
+
callback(payload.polls[0]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './observePoll';
|